void SoundSystem::StopAllSounds( SoundObjectId _id, char *_eventName ) { for( int i = 0; i < m_sounds.Size(); ++i ) { if( m_sounds.ValidIndex(i) ) { SoundInstance *instance = m_sounds[i]; if( instance->m_objId == _id ) { if( !_eventName || stricmp(instance->m_eventName, _eventName) == 0 ) { if( instance->IsPlaying() ) { instance->BeginRelease(true); } else { ShutdownSound( instance ); } } } } } }
bool SoundSystem::SoundLibraryMainCallback( unsigned int _channel, signed short *_data, unsigned int _numSamples, int *_silenceRemaining ) { if( !g_soundSystem ) return false; SoundInstanceId soundId = g_soundSystem->m_channels[_channel]; SoundInstance *instance = g_soundSystem->GetSoundInstance( soundId ); bool stereo = g_soundSystem->IsMusicChannel(_channel); if( instance && instance->m_soundSampleHandle ) { // // Fill the space with sample data float relFreq = g_soundLibrary3d->GetChannelRelFreq(_channel); int numSamplesWritten = instance->m_soundSampleHandle->Read( _data, _numSamples, stereo, relFreq); if( numSamplesWritten < _numSamples ) { signed short *loopStart = _data + numSamplesWritten; unsigned int numSamplesRemaining = _numSamples - numSamplesWritten; if( instance->m_loopType == SoundInstance::Looped || instance->m_loopType == SoundInstance::LoopedADSR ) { while( numSamplesRemaining > 0 ) { bool looped = instance->AdvanceLoop(); if( looped ) { unsigned int numWritten = instance->m_soundSampleHandle->Read( loopStart, numSamplesRemaining, stereo , relFreq); loopStart += numWritten; numSamplesRemaining -= numWritten; } else { g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining ); numSamplesRemaining = 0; } } } else if( instance->m_loopType == SoundInstance::SinglePlay) { if( numSamplesWritten > 0 ) { // The sound just came to an end, so write a whole buffers worth of silence g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining ); *_silenceRemaining = g_soundLibrary3d->GetChannelBufSize(_channel) - numSamplesRemaining; } else { // The sound came to an end and now we are writing silence g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining ); *_silenceRemaining -= numSamplesRemaining; if( *_silenceRemaining <= 0 ) { instance->BeginRelease(false); } } } } return true; } else { g_soundLibrary3d->WriteSilence( _data, _numSamples ); return false; } }