mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-06 05:48:06 +03:00
Android: CD-DA emulation support
This commit is contained in:
@@ -72,7 +72,7 @@ class GameActivity : SDLActivity() {
|
||||
}
|
||||
|
||||
// These functions are called in the SDL thread by JNI.
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Int) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Boolean) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStop() = cdda.stop()
|
||||
@Suppress("unused") fun cddaCurrentPosition() = cdda.currentPosition()
|
||||
@Suppress("unused") fun midiStart(buf: ByteArray, loop: Int) = midi.start(buf, loop)
|
||||
@@ -92,18 +92,18 @@ private class CddaPlayer(private val playlistPath: File) {
|
||||
private val player = MediaPlayer()
|
||||
private var playerPaused = false
|
||||
|
||||
fun start(track: Int, loop: Int) {
|
||||
fun start(track: Int, loop: Boolean) {
|
||||
val f = playlist.elementAtOrNull(track)
|
||||
if (f.isNullOrEmpty()) {
|
||||
Log.w("cddaStart", "No playlist entry for track $track")
|
||||
return
|
||||
}
|
||||
Log.v("cddaStart", f)
|
||||
Log.v("cddaStart", "${f} Loop:${loop}")
|
||||
try {
|
||||
player.apply {
|
||||
reset()
|
||||
setDataSource(File(playlistPath.parent, f).path)
|
||||
isLooping = loop == 0
|
||||
isLooping = loop
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
|
||||
+6
-3
@@ -30,10 +30,13 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
linux/nact_linux.cpp
|
||||
emscripten/mako.cpp
|
||||
)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
set(SRC_PLATFORM
|
||||
linux/nact_linux.cpp
|
||||
android/mako.cpp
|
||||
)
|
||||
else()
|
||||
if (NOT ANDROID)
|
||||
set(DEFAULT_FONT_PATH ${CMAKE_INSTALL_PREFIX}/share/system3/fonts/)
|
||||
endif()
|
||||
set(DEFAULT_FONT_PATH ${CMAKE_INSTALL_PREFIX}/share/system3/fonts/)
|
||||
|
||||
set(SRC_MAKO
|
||||
sys/mako.cpp
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <SDL.h>
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
#include "mako.h"
|
||||
|
||||
MAKO::MAKO(NACT* parent)
|
||||
: current_music(0)
|
||||
, next_loop(0)
|
||||
{
|
||||
for (int i = 1; i <= 99; i++)
|
||||
cd_track[i] = i;
|
||||
}
|
||||
|
||||
void MAKO::play_music(int page)
|
||||
{
|
||||
if (current_music == page)
|
||||
return;
|
||||
|
||||
JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
|
||||
if (env->PushLocalFrame(16) < 0) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, "system3",
|
||||
"Failed to allocate JVM local references");
|
||||
return;
|
||||
}
|
||||
jobject context = (jobject)SDL_AndroidGetActivity();
|
||||
jmethodID mid = env->GetMethodID(env->GetObjectClass(context),
|
||||
"cddaStart", "(IZ)V");
|
||||
env->CallVoidMethod(context, mid, cd_track[page] + 1, next_loop ? 0 : 1);
|
||||
env->PopLocalFrame(NULL);
|
||||
|
||||
current_music = page;
|
||||
next_loop = 0;
|
||||
}
|
||||
|
||||
void MAKO::stop_music()
|
||||
{
|
||||
if (!current_music)
|
||||
return;
|
||||
|
||||
JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
|
||||
if (env->PushLocalFrame(16) < 0) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, "system3",
|
||||
"Failed to allocate JVM local references");
|
||||
return;
|
||||
}
|
||||
jobject context = (jobject)SDL_AndroidGetActivity();
|
||||
jmethodID mid = env->GetMethodID(env->GetObjectClass(context),
|
||||
"cddaStop", "()V");
|
||||
env->CallVoidMethod(context, mid);
|
||||
env->PopLocalFrame(NULL);
|
||||
|
||||
current_music = 0;
|
||||
}
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
#include "../common.h"
|
||||
#include "nact.h"
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
|
||||
|
||||
#define MAX_SAMPLES (128 * 1024)
|
||||
#define MAX_MMLS (128 * 1024)
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
int cd_track[100]; // Z
|
||||
};
|
||||
|
||||
#else // EMSCRIPTEN
|
||||
#else // Emscripten or Android
|
||||
|
||||
class MAKO {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user