From 1caf98700b7319719f6db062f7409ea9dc9caa57 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 18:20:16 +0000 Subject: PSP: to fix the audio, I cleaned up the audio thread and changed the thread priorities. svn-id: r49200 --- backends/platform/psp/audio.cpp | 30 +++++------------------------- backends/platform/psp/audio.h | 6 ++---- backends/platform/psp/osys_psp.cpp | 2 +- backends/platform/psp/thread.h | 8 ++++---- 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/backends/platform/psp/audio.cpp b/backends/platform/psp/audio.cpp index 2afc62d450..bf1fb9ab41 100644 --- a/backends/platform/psp/audio.cpp +++ b/backends/platform/psp/audio.cpp @@ -79,7 +79,6 @@ bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, call _bufferSize = numOfSamples * numOfChannels * sizeof(uint16); // should be the right size to send the app _callback = callback; _userData = userData; - _emptyBuffers = NUM_BUFFERS - 1; // because we'll increase in the beginning _bufferToFill = 0; _bufferToPlay = 0; @@ -122,10 +121,7 @@ int PspAudio::thread(SceSize, void *__this) { }; // The real thread function -void PspAudio::audioThread() { - bool isPlaying = false; - int remainingSamples = 0; - +void PspAudio::audioThread() { assert(_callback); PSP_DEBUG_PRINT_FUNC("audio thread started\n"); @@ -138,29 +134,13 @@ void PspAudio::audioThread() { PSP_DEBUG_PRINT("audio thread unpaused\n"); } - // check if the audio is playing - remainingSamples = sceAudioGetChannelRestLen(_pspChannel); - if (remainingSamples < 0) { - PSP_ERROR("failed to get remaining samples\n"); - return; - } - isPlaying = remainingSamples ? true : false; - PSP_DEBUG_PRINT("remaining samples[%d]\n", remainingSamples); - if (!isPlaying) { - _emptyBuffers++; - } - - while (_emptyBuffers) { // we have some empty buffers - PSP_DEBUG_PRINT("filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); - _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in - nextBuffer(_bufferToFill); - _emptyBuffers--; - break; - } + PSP_DEBUG_PRINT("filling buffer[%d]\n", _bufferToFill); + _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in + nextBuffer(_bufferToFill); - PSP_DEBUG_PRINT("playing buffer[%d]. empty buffers[%d]\n", _bufferToPlay, _emptyBuffers); + PSP_DEBUG_PRINT("playing buffer[%d].\n", _bufferToPlay); playBuffer(); nextBuffer(_bufferToPlay); } // while _init diff --git a/backends/platform/psp/audio.h b/backends/platform/psp/audio.h index 97e2391319..603f8f6bfc 100644 --- a/backends/platform/psp/audio.h +++ b/backends/platform/psp/audio.h @@ -35,8 +35,8 @@ public: typedef void (* callbackFunc)(void *userData, byte *samples, int len); PspAudio() : _pspChannel(0), _numOfChannels(0), _numOfSamples(0), _callback(0), - _bufferToPlay(0), _bufferToFill(0), _emptyBuffers(NUM_BUFFERS), - _init(false), _paused(true), _stoppedPlayingOnceFlag(true) { + _bufferToPlay(0), _bufferToFill(0), + _init(false), _paused(true) { for (int i=0; i