From 6b444968f6f3b53a86538f8df58983990072ca72 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 8 Oct 2008 18:25:00 +0200 Subject: [PATCH] Use the buffer size user requested. Audio buffer size is there to allow a balancing act between smooth sound playback (ie. big buffer) and low latency times (ie. small buffer). The original author clearly didn't understood this concept, as the buffer size here always was 256 bytes, which resulted in playback system that had all the minuses of the two approaches but no pluses. --- src/audio/symbian/SDL_epocaudio.cpp | 56 ++++++++++++++----------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/src/audio/symbian/SDL_epocaudio.cpp b/src/audio/symbian/SDL_epocaudio.cpp index 81643a0..be44a6d 100644 --- a/src/audio/symbian/SDL_epocaudio.cpp +++ b/src/audio/symbian/SDL_epocaudio.cpp @@ -119,19 +119,18 @@ class CEpocAudio : public CBase, public MStreamObs, public MStreamProvider TPtrC8 Data(); void ConstructL(int aFill); - int iBufferSize; CStreamPlayer* iPlayer; int iBufferRate; int iRate; int iChannels; TUint32 iType; - int iPosition; TThreadId iTid; - TUint8* iAudioPtr; + int iBufferSize; TUint8* iBuffer; TTime iStart; int iTune; CSimpleWait* iWait; + bool iPause; }; inline CEpocAudio& CEpocAudio::Current(SDL_AudioDevice* thisdevice) @@ -157,7 +156,7 @@ void CEpocAudio::Free(SDL_AudioDevice* thisdevice) } CEpocAudio::CEpocAudio(int aBufferSize) - : iBufferSize(aBufferSize), iPosition(-1) + : iBufferSize(aBufferSize), iPause(true) { } @@ -174,24 +173,21 @@ void CEpocAudio::ConstructL(int aFill) { iBuffer = new TUint8[iBufferSize]; memset(iBuffer, aFill, iBufferSize); - iAudioPtr = iBuffer; } TBool CEpocAudio::SetPause(TBool aPause) { - if(aPause && iPosition >= 0) + if(iPlayer != NULL && aPause != iPause) { - iPosition = -1; - if(iPlayer != NULL) + if(aPause) iPlayer->Stop(); - } - if(!aPause && iPosition < 0) - { - iPosition = 0; - if(iPlayer != NULL) + else iPlayer->Start(); } - return iPosition < 0; + + iPause = aPause; + + return iPause; } void CEpocAudio::ThreadInitL(void* aDevice) @@ -212,7 +208,7 @@ void CEpocAudio::ThreadInitL(void* aDevice) TUint8* CEpocAudio::Buffer() { iStart.UniversalTime(); - return iAudioPtr; + return iBuffer; } CEpocAudio::~CEpocAudio() @@ -246,43 +242,33 @@ void CEpocAudio::Complete(int aState, int aError) } } -const int KClip = 256; - TPtrC8 CEpocAudio::Data() { - if(iPosition < 0) + if(iPause) return KNullDesC8(); - TPtrC8 data(iAudioPtr + iPosition, KClip); + TPtrC8 data(iBuffer, iBufferSize); - iPosition += KClip; - if(iPosition >= iBufferSize) + iPause = true; + if(iWait->IsActive()) { - iAudioPtr += iBufferSize; - - if((iAudioPtr - iBuffer) >= iBufferSize) - iAudioPtr = iBuffer; - - iPosition = -1; - if(iWait->IsActive()) - { - iWait->Cancel(); - CActiveScheduler::Stop(); - } + iWait->Cancel(); + CActiveScheduler::Stop(); } + return data; } void CEpocAudio::Play() { - iPosition = 0; + iPause = false; } void CEpocAudio::Wait() { - if(iPosition >= 0) + if(!iPause) { - const TInt64 bufMs = TInt64(iBufferSize - KClip) * TInt64(1000000); + const TInt64 bufMs = TInt64(iBufferSize) * TInt64(1000000); const TInt64 specTime = bufMs / TInt64(iRate * iChannels * 2); iWait->After(specTime); -- 2.11.4.GIT