all repos — mgba @ 20ba3d1390e81ec7104cf7d7f564c30b6600c61f

mGBA Game Boy Advance Emulator

PSP2: Fix audio
Jeffrey Pfau jeffrey@endrift.com
Sat, 29 Aug 2015 16:50:51 -0700
commit

20ba3d1390e81ec7104cf7d7f564c30b6600c61f

parent

d8c3306bf233812bc7487c2e1958d15bdabc3539

2 files changed, 9 insertions(+), 7 deletions(-)

jump to
M PORTING.mdPORTING.md

@@ -29,7 +29,6 @@ * MIPS dynarec

* Hardware acceleration ### PS Vita (master) -* Fix audio * Make it faster * Threaded renderer shim * Hardware acceleration
M src/platform/psp2/psp2-context.csrc/platform/psp2/psp2-context.c

@@ -55,24 +55,27 @@ }

static THREAD_ENTRY _audioThread(void* context) { struct GBAPSP2AudioContext* audio = (struct GBAPSP2AudioContext*) context; - struct GBAStereoSample buffer[PSP2_AUDIO_BUFFER_SIZE]; - int audioPort = sceAudioOutOpenPort(PSP2_AUDIO_OUT_PORT_TYPE_MAIN, PSP2_AUDIO_BUFFER_SIZE, 48000, PSP2_AUDIO_OUT_MODE_STEREO); + struct GBAStereoSample buffer[PSP2_SAMPLES]; + int audioPort = sceAudioOutOpenPort(PSP2_AUDIO_OUT_PORT_TYPE_MAIN, PSP2_SAMPLES, 48000, PSP2_AUDIO_OUT_MODE_STEREO); while (audio->running) { + memset(buffer, 0, sizeof(buffer)); MutexLock(&audio->mutex); int len = CircleBufferSize(&audio->buffer); len /= sizeof(buffer[0]); - if (len > PSP2_AUDIO_BUFFER_SIZE) { - len = PSP2_AUDIO_BUFFER_SIZE; + if (len > PSP2_SAMPLES) { + len = PSP2_SAMPLES; } if (len > 0) { len &= ~(PSP2_AUDIO_MIN_LEN - 1); CircleBufferRead(&audio->buffer, buffer, len * sizeof(buffer[0])); MutexUnlock(&audio->mutex); - sceAudioOutSetConfig(audioPort, len, -1, -1); sceAudioOutOutput(audioPort, buffer); MutexLock(&audio->mutex); } - ConditionWait(&audio->cond, &audio->mutex); + + if (CircleBufferSize(&audio->buffer) < PSP2_SAMPLES) { + ConditionWait(&audio->cond, &audio->mutex); + } MutexUnlock(&audio->mutex); } sceAudioOutReleasePort(audioPort);