PSP2: Fix audio

This commit is contained in:
Jeffrey Pfau 2015-08-29 16:50:51 -07:00
parent d8c3306bf2
commit 20ba3d1390
2 changed files with 9 additions and 7 deletions

View File

@ -29,7 +29,6 @@ The ports are vaguely usable, but by no means should be considered stable.
* Hardware acceleration
### PS Vita (master)
* Fix audio
* Make it faster
* Threaded renderer shim
* Hardware acceleration

View File

@ -55,24 +55,27 @@ static void _mapVitaKey(struct GBAInputMap* map, int pspKey, enum GBAKey key) {
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);
}
if (CircleBufferSize(&audio->buffer) < PSP2_SAMPLES) {
ConditionWait(&audio->cond, &audio->mutex);
}
MutexUnlock(&audio->mutex);
}
sceAudioOutReleasePort(audioPort);