void SDLAudioContext::PauseAudio(AudioObject& ao) { SDL_LockAudioDevice(m_device); RemoveAudio(ao); SDL_UnlockAudioDevice(m_device); }
void SDLAudioContext::PlayAudio(AudioObject& ao) { SDL_LockAudioDevice(m_device); // This prevents duplicates RemoveAudio(ao); m_playingAudio.push_back(&ao); SDL_UnlockAudioDevice(m_device); }
void SDLAudioContext::StopAudio(AudioObject& ao) { SDL_LockAudioDevice(m_device); if(RemoveAudio(ao)) { ao.SetPos(0.0); } SDL_UnlockAudioDevice(m_device); }
void tcDone(void) { static bool inprogress; if (!inprogress) { inprogress = true; plDone(); sndDoneFX(); /* achtung */ sndDone(); RemoveAudio(); dbDone(); CloseAnimHandler(); txtDone(); inpCloseAllInputDevs(); gfxDone(); rndDone(); if (setup.CDAudio) { if (CDRomInstalled) { CDROM_StopAudioTrack(); CDROM_UnInstall(); } } if (StdBuffer1) { TCFreeMem(StdBuffer1, STD_BUFFER1_SIZE); } if (StdBuffer0) { TCFreeMem(StdBuffer0, STD_BUFFER0_SIZE); } if (memGetAllocatedMem()) { DebugMsg(ERR_DEBUG, ERROR_MODULE_BASE, "Attention: dirty mem: %ld bytes!!!", memGetAllocatedMem()); } else { DebugMsg(ERR_DEBUG, ERROR_MODULE_BASE, "all mem returned to pool"); } pcErrClose(); SDL_Quit(); } }
void SDLAudioContext::GenerateSamples(Uint8* streamIn, int streamInLen) { size_t streamLen = (size_t)(streamInLen/2); m_stream.reserve(streamLen); float* floatStream = *(float**)(&m_stream); for(size_t i = 0; i < streamLen; i++) { floatStream[i] = 0.0f; } std::vector<AudioObject*>::iterator it = m_playingAudio.begin(); std::vector<AudioObject*>::iterator end = m_playingAudio.end(); for(; it != end; ++it) { if(!(*it)->GenerateSamples(floatStream, streamLen)) { RemoveAudio(*(*it)); } } Sint16* stream = (Sint16*)streamIn; for(size_t i = 0; i < streamLen; i++) { float val = floatStream[i]; if(val > 1.0f) { val = 1.0f; } else if(val < -1.0f) { val = -1.0f; } stream[i] = (Sint16)(val * 32767); } }