diff --git a/src/platform/android/app/src/main/java/org/xproger/openlara/MainActivity.java b/src/platform/android/app/src/main/java/org/xproger/openlara/MainActivity.java index 17d958a..7e9dba4 100644 --- a/src/platform/android/app/src/main/java/org/xproger/openlara/MainActivity.java +++ b/src/platform/android/app/src/main/java/org/xproger/openlara/MainActivity.java @@ -226,12 +226,14 @@ class Sound { void start(final Wrapper wrapper) { int rate = 44100; int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); - //System.out.println(String.format("sound buffer size: %d", bufSize)); - buffer = new short[size / 2]; + size /= 2; // bytes -> words + while (size % 4704 != 0) size++; + //System.out.println(String.format("sound buffer size: %d", size)); + buffer = new short[size]; try { audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, - AudioFormat.ENCODING_PCM_16BIT, size, AudioTrack.MODE_STREAM); + AudioFormat.ENCODING_PCM_16BIT, size * 2, AudioTrack.MODE_STREAM); }catch (IllegalArgumentException e){ System.out.println("Error: buffer size is zero"); return; diff --git a/src/utils.h b/src/utils.h index 46c4958..3fe3de1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1391,8 +1391,12 @@ void osLoadGame(Stream *stream) { #ifdef OS_PTHREAD_MT // multi-threading void* osMutexInit() { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_t *mutex = new pthread_mutex_t(); - pthread_mutex_init(mutex, NULL); + pthread_mutex_init(mutex, &attr); return mutex; } diff --git a/src/video.h b/src/video.h index 9c4a925..c32a023 100644 --- a/src/video.h +++ b/src/video.h @@ -431,6 +431,8 @@ struct Video { } virtual bool decodeVideo(Color32 *pixels) { + OS_LOCK(Sound::lock); + if (curVideoChunk >= chunksCount) return false; @@ -892,6 +894,8 @@ struct Video { } bool nextFrame() { + OS_LOCK(Sound::lock); + uint8 data[SECTOR_SIZE]; VideoFrame *vFrame = vFrames + vFrameIndex; @@ -1154,7 +1158,8 @@ struct Video { isPlaying = true; } - ~Video() { + virtual ~Video() { + OS_LOCK(Sound::lock); sample->decoder = NULL; sample->stop(); delete decoder;