bool GuiSound::Load(const u8 * snd, s32 len, bool isallocated) { FreeMemory(); if(!snd) return false; sound = (u8 *) snd; length = len; allocated = isallocated; SoundHandler::Instance()->AddDecoder(voice, sound, length); SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); if(!decoder) return false; if(!decoder->IsBufferReady()) { SoundHandler::Instance()->RemoveDecoder(voice); return false; } SetLoop(loop); return true; }
extern "C" void SoundCallback(s32 voice) { SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); if(!decoder) return; if(decoder->IsBufferReady()) { if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK) { decoder->LoadNext(); SoundHandler::Instance()->ThreadSignal(); } } else if(decoder->IsEOF()) { ASND_StopVoice(voice); //if(voice == 0) //MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played } else { SoundHandler::Instance()->ThreadSignal(); } }
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; } } }