From 970131a386ca542adddb3dd53c7618d8ee3c6970 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 15 Nov 2008 17:07:24 +0100 Subject: [PATCH] Remove pause from audio player. Remove pause from audio player to allow easier further changes. The code is slightly more broken than it was before, but I don't care much about that, as it anyway was FUBAR already. Audio device needs to be stopped/started on focus changes to decrease energy usage. --- src/audio/symbian/SDL_epocaudio.cpp | 58 +++++++++---------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/src/audio/symbian/SDL_epocaudio.cpp b/src/audio/symbian/SDL_epocaudio.cpp index c54d4b7..b5bf1b9 100644 --- a/src/audio/symbian/SDL_epocaudio.cpp +++ b/src/audio/symbian/SDL_epocaudio.cpp @@ -103,7 +103,6 @@ class CEpocAudio : public CBase, public MStreamObs, public MStreamProvider void Play(); void ThreadInitL(); TUint8* Buffer(); - bool SetPause(bool aPause); private: void Complete(int aState, int aError); @@ -117,7 +116,6 @@ class CEpocAudio : public CBase, public MStreamObs, public MStreamProvider TUint8* iBuffer; TTime iStart; CSimpleWait* iWait; - bool iPause; }; CEpocAudio::CEpocAudio(int aBufferSize, int aFill, int aRate, int aChannels, TUint32 aType) @@ -125,7 +123,6 @@ CEpocAudio::CEpocAudio(int aBufferSize, int aFill, int aRate, int aChannels, TUi , iChannels(aChannels) , iType(aType) , iBufferSize(aBufferSize) - , iPause(true) { iBuffer = new TUint8[iBufferSize]; memset(iBuffer, aFill, iBufferSize); @@ -167,27 +164,15 @@ void CEpocAudio::Free(SDL_AudioDevice* thisdevice) ASSERT(thisdevice->hidden == NULL); } -bool CEpocAudio::SetPause(bool aPause) -{ - if(iPlayer != NULL && aPause != iPause) - { - if(aPause) - iPlayer->Stop(); - else - iPlayer->Start(); - } - - iPause = aPause; - - return iPause; -} - void CEpocAudio::ThreadInitL() { iWait = new CSimpleWait; iPlayer = new CStreamPlayer(*this, *this); iPlayer->OpenStream(iRate, iChannels, iType); + + /// \todo Implement proper start/pause conditions + iPlayer->Start(); } TUint8* CEpocAudio::Buffer() @@ -214,12 +199,8 @@ void CEpocAudio::Complete(int aState, int aError) TPtrC8 CEpocAudio::Data() { - if(iPause) - return KNullDesC8(); - TPtrC8 data(iBuffer, iBufferSize); - iPause = true; if(iWait->IsActive()) { iWait->Cancel(); @@ -231,32 +212,24 @@ TPtrC8 CEpocAudio::Data() void CEpocAudio::Play() { - iPause = false; } void CEpocAudio::Wait() { - if(!iPause) - { - const TInt64 bufMs = TInt64(iBufferSize) * TInt64(1000000); - const TInt64 specTime = bufMs / TInt64(iRate * iChannels * 2); - iWait->After(specTime); + const TInt64 bufMs = TInt64(iBufferSize) * TInt64(1000000); + const TInt64 specTime = bufMs / TInt64(iRate * iChannels * 2); + iWait->After(specTime); - CActiveScheduler::Start(); - TTime end; - end.UniversalTime(); - const TTimeIntervalMicroSeconds delta = end.MicroSecondsFrom(iStart); + CActiveScheduler::Start(); + TTime end; + end.UniversalTime(); + const TTimeIntervalMicroSeconds delta = end.MicroSecondsFrom(iStart); - const int diff = specTime - delta.Int64(); + const int diff = specTime - delta.Int64(); - if(diff > 0) - { - usleep(diff); - } - } - else + if(diff > 0) { - usleep(10000); + usleep(diff); } } @@ -382,10 +355,7 @@ static void EPOC_WaitAudio(SDL_AudioDevice* thisdevice) static void EPOC_PlayAudio(SDL_AudioDevice* thisdevice) { - if(CEpocAudio::Current(thisdevice).SetPause(SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)) - SDL_Delay(500); //hold on the busy loop - else - CEpocAudio::Current(thisdevice).Play(); + CEpocAudio::Current(thisdevice).Play(); } static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice* thisdevice) -- 2.11.4.GIT