From 55d9beb92eb72bfdf867a9b839e1edd8e7235555 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Mon, 28 Nov 2011 15:49:37 +0800 Subject: [PATCH] issue #880: playEffect repeatly can't work on bada platform --- CocosDenshion/bada/CCAudioOut.cpp | 103 +++++++++++++++++------------- CocosDenshion/bada/CCAudioOut.h | 13 ++-- 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/CocosDenshion/bada/CCAudioOut.cpp b/CocosDenshion/bada/CCAudioOut.cpp index 7425536d2f..6b92d9b9dd 100644 --- a/CocosDenshion/bada/CCAudioOut.cpp +++ b/CocosDenshion/bada/CCAudioOut.cpp @@ -104,7 +104,7 @@ int CCAudioOut::DecodeOgg(const char *infile) if(ov_seekable(&vf)) { seekable = 1; length = ov_pcm_total(&vf, 0); - size = bits/8 * ov_info(&vf, 0)->channels; + size = 16/8 * ov_info(&vf, 0)->channels; } //AppLog("enter"); if (ov_info(&vf,0)->channels == 2) @@ -120,13 +120,13 @@ int CCAudioOut::DecodeOgg(const char *infile) __sampleBitdepth = AUDIO_TYPE_PCM_S16_LE; //AppLog("enter"); - while((ret = ov_read(&vf, buf, buflen, endian, bits/8, sign, &bs)) != 0) { + while((ret = ov_read(&vf, buf, buflen, 0, 16/8, 1, &bs)) != 0) { if(bs != 0) { //AppLog("Only one logical bitstream currently supported\n"); break; } - if(ret < 0 && !quiet) { + if(ret < 0) { //AppLog("Warning: hole in data\n"); continue; } @@ -143,7 +143,7 @@ int CCAudioOut::DecodeOgg(const char *infile) memcpy(__pAllPcmBuffer+written, buf, ret); written += ret; - if(!quiet && seekable) { + if(seekable) { done += ret/size; if((double)done/(double)length * 200. > (double)percent) { percent = (double)done/(double)length *200; @@ -178,17 +178,14 @@ CCAudioOut::CCAudioOut() __iAllPcmBufferSize = 0; __iAllPcmPos = 0; __pAudioOut = null; - quiet = 0; - bits = 16; - endian = 0; - raw = 0; - sign = 1; __iFileType = 0; __pFile = null; __bShortPcmBuffer = false; __bBufferConstruted = false; __checkInitFiniPair = false; __iUsedBufferCount = 0; + __bLoop = false; + __bPause = false; } CCAudioOut::~CCAudioOut() @@ -516,43 +513,24 @@ void CCAudioOut::ReFeedBuffer(void) } } -result CCAudioOut::Play(void) +result CCAudioOut::Play(bool bLoop/* = false*/) { - //AppLog("Enter"); - result ret = E_FAILURE; AudioOutState state = __pAudioOut->GetState(); if(state == AUDIOOUT_STATE_PREPARED || state == AUDIOOUT_STATE_STOPPED) { - //AppLog("Enter"); + __bLoop = bLoop; ret = __pAudioOut->Start(); if (IsFailed(ret)) { - //AppLog("[Error] m_AudioOut.Start failed : %d\n", ret); + AppLog("[Error] m_AudioOut.Start failed : %d\n", ret); } } return ret; } result CCAudioOut::Stop(void) -{ - //AppLog("Enter"); - result ret = E_FAILURE; - - if( __pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING ) - { - ret = __pAudioOut->Stop(); - if (IsFailed(ret)) - { - //AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret); - } - } - - return ret; -} - -result CCAudioOut::Reset(void) { //AppLog("Enter"); AudioOutState state = __pAudioOut->GetState(); @@ -572,6 +550,40 @@ result CCAudioOut::Reset(void) return r; } +result CCAudioOut::Pause(void) +{ + result ret = E_FAILURE; + + if( __pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING ) + { + __bPause = true; + ret = __pAudioOut->Stop(); + if (IsFailed(ret)) + { + AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret); + } + } + + return ret; +} + +result CCAudioOut::Resume(void) +{ + result ret = E_FAILURE; + + if(__bPause && __pAudioOut->GetState() == AUDIOOUT_STATE_STOPPED ) + { + __bPause = false; + ret = __pAudioOut->Start(); + if (IsFailed(ret)) + { + AppLog("[Error] m_AudioOut.Stop failed : %d\n", ret); + } + } + + return ret; +} + void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src) { if (__bShortPcmBuffer) @@ -579,13 +591,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src) __iUsedBufferCount--; if (__iUsedBufferCount <= 0) { - Reset(); - //AppLog("Reset..."); + Stop(); + if (__bLoop) + { + Play(__bLoop); + } } } else { - int ret; + int ret = 0; // //AppLog("thread name is %S", Thread::GetCurrentThread()->GetName().GetPointer()); //AppLog("__buffReadCnt = %d", __buffReadCnt); __byteBuffer[__buffReadCnt++].Clear (); @@ -607,11 +622,14 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src) __finishChecker--; if(__finishChecker == 0) { - //AppLog("Reset..."); - Reset(); + Stop(); __bufWrittenCnt = PRE_BUFFERING_NUM; __buffReadCnt = 0; __buffWriteCnt = 0; + if (__bLoop) + { + Play(__bLoop); + } } } } @@ -620,19 +638,16 @@ void CCAudioOut::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src) void CCAudioOut::OnAudioOutInterrupted(Osp::Media::AudioOut& src) { - //AppLog("Enter"); - Reset(); + Pause(); } void CCAudioOut::OnAudioOutReleased(Osp::Media::AudioOut& src) { - //AppLog("Enter"); + Resume(); } void CCAudioOut::Finalize(void) { - //AppLog("Enter"); - if(__checkInitFiniPair) { @@ -650,7 +665,7 @@ void CCAudioOut::Finalize(void) r = __pAudioOut->Reset(); if(IsFailed(r)) { - //AppLog("[Error] AudioOut Reset is failed"); + AppLog("[Error] AudioOut Reset is failed"); } } @@ -662,7 +677,7 @@ void CCAudioOut::Finalize(void) r = __pAudioOut->Unprepare(); if(IsFailed(r)) { - //AppLog("[Error] AudioOut UnPrepare is failed"); + AppLog("[Error] AudioOut UnPrepare is failed"); } } } @@ -675,7 +690,7 @@ void CCAudioOut::Finalize(void) __checkInitFiniPair = false; }else{ - //AppLog("[WANRNING] This application state is not proper"); + AppLog("[WANRNING] This application state is not proper"); } } diff --git a/CocosDenshion/bada/CCAudioOut.h b/CocosDenshion/bada/CCAudioOut.h index 4ef70e289b..b9d265d516 100644 --- a/CocosDenshion/bada/CCAudioOut.h +++ b/CocosDenshion/bada/CCAudioOut.h @@ -26,9 +26,11 @@ public: void ReFeedBuffer(void); void Finalize(void); - result Play(void); + result Play(bool bLoop = false); result Stop(void); - result Reset(void); + result Pause(void); + result Resume(void); + void SetVolume(int volume); int GetVolume(void) const; Osp::Media::AudioOutState GetState(void) const; @@ -54,11 +56,8 @@ private: char* __pAllPcmBuffer; int __iAllPcmBufferSize; int __iAllPcmPos; - int quiet; - int bits; - int endian; - int raw; - int sign; + bool __bLoop; + bool __bPause; }; }