void SoundHandler::RemoveDecoder(int voice) { if(voice < 0 || voice >= MAX_DECODERS) return; if(DecoderList[voice] != NULL) { if(voiceList[voice]->getState() != Voice::STATE_STOPPED) { if(voiceList[voice]->getState() != Voice::STATE_STOP) voiceList[voice]->setState(Voice::STATE_STOP); while(voiceList[voice]->getState() != Voice::STATE_STOPPED) usleep(1000); } SoundDecoder *decoder = DecoderList[voice]; decoder->Lock(); DecoderList[voice] = NULL; decoder->Unlock(); delete decoder; } }
void SoundHandler::axFrameCallback(void) { for (u32 i = 0; i < MAX_DECODERS; i++) { Voice *voice = handlerInstance->getVoice(i); switch (voice->getState()) { default: case Voice::STATE_STOPPED: break; case Voice::STATE_START: { SoundDecoder * decoder = handlerInstance->getDecoder(i); decoder->Lock(); if(decoder->IsBufferReady()) { const u8 *buffer = decoder->GetBuffer(); const u32 bufferSize = decoder->GetBufferSize(); decoder->LoadNext(); const u8 *nextBuffer = NULL; u32 nextBufferSize = 0; if(decoder->IsBufferReady()) { nextBuffer = decoder->GetBuffer(); nextBufferSize = decoder->GetBufferSize(); decoder->LoadNext(); } voice->play(buffer, bufferSize, nextBuffer, nextBufferSize, decoder->GetFormat() & 0xff, decoder->GetSampleRate()); handlerInstance->ThreadSignal(); voice->setState(Voice::STATE_PLAYING); } decoder->Unlock(); break; } case Voice::STATE_PLAYING: if(voice->getInternState() == 1) { if(voice->isBufferSwitched()) { SoundDecoder * decoder = handlerInstance->getDecoder(i); decoder->Lock(); if(decoder->IsBufferReady()) { voice->setNextBuffer(decoder->GetBuffer(), decoder->GetBufferSize()); decoder->LoadNext(); handlerInstance->ThreadSignal(); } else if(decoder->IsEOF()) { voice->setState(Voice::STATE_STOP); } decoder->Unlock(); } } else { voice->setState(Voice::STATE_STOPPED); } break; case Voice::STATE_STOP: if(voice->getInternState() != 0) voice->stop(); voice->setState(Voice::STATE_STOPPED); break; } } }