1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-14 00:54:05 +02:00

#129 fix multi-threading; fix android sound buffer size

This commit is contained in:
XProger
2018-07-14 18:27:11 +03:00
parent 4f3eb31ed5
commit a94e0193a5
3 changed files with 16 additions and 5 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;