mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-16 01:54:38 +02:00
#129 fix multi-threading; fix android sound buffer size
This commit is contained in:
@@ -226,12 +226,14 @@ class Sound {
|
|||||||
void start(final Wrapper wrapper) {
|
void start(final Wrapper wrapper) {
|
||||||
int rate = 44100;
|
int rate = 44100;
|
||||||
int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
|
int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
|
||||||
//System.out.println(String.format("sound buffer size: %d", bufSize));
|
size /= 2; // bytes -> words
|
||||||
buffer = new short[size / 2];
|
while (size % 4704 != 0) size++;
|
||||||
|
//System.out.println(String.format("sound buffer size: %d", size));
|
||||||
|
buffer = new short[size];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO,
|
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){
|
}catch (IllegalArgumentException e){
|
||||||
System.out.println("Error: buffer size is zero");
|
System.out.println("Error: buffer size is zero");
|
||||||
return;
|
return;
|
||||||
|
@@ -1391,8 +1391,12 @@ void osLoadGame(Stream *stream) {
|
|||||||
#ifdef OS_PTHREAD_MT
|
#ifdef OS_PTHREAD_MT
|
||||||
// multi-threading
|
// multi-threading
|
||||||
void* osMutexInit() {
|
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_t *mutex = new pthread_mutex_t();
|
||||||
pthread_mutex_init(mutex, NULL);
|
pthread_mutex_init(mutex, &attr);
|
||||||
return mutex;
|
return mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -431,6 +431,8 @@ struct Video {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual bool decodeVideo(Color32 *pixels) {
|
virtual bool decodeVideo(Color32 *pixels) {
|
||||||
|
OS_LOCK(Sound::lock);
|
||||||
|
|
||||||
if (curVideoChunk >= chunksCount)
|
if (curVideoChunk >= chunksCount)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -892,6 +894,8 @@ struct Video {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool nextFrame() {
|
bool nextFrame() {
|
||||||
|
OS_LOCK(Sound::lock);
|
||||||
|
|
||||||
uint8 data[SECTOR_SIZE];
|
uint8 data[SECTOR_SIZE];
|
||||||
|
|
||||||
VideoFrame *vFrame = vFrames + vFrameIndex;
|
VideoFrame *vFrame = vFrames + vFrameIndex;
|
||||||
@@ -1154,7 +1158,8 @@ struct Video {
|
|||||||
isPlaying = true;
|
isPlaying = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Video() {
|
virtual ~Video() {
|
||||||
|
OS_LOCK(Sound::lock);
|
||||||
sample->decoder = NULL;
|
sample->decoder = NULL;
|
||||||
sample->stop();
|
sample->stop();
|
||||||
delete decoder;
|
delete decoder;
|
||||||
|
Reference in New Issue
Block a user