void CSimpleSource::releasePhysicalSource() { if (hasPhysicalSource()) { CAudioMixerUser *mixer = CAudioMixerUser::instance(); ISource *pSource = getPhysicalSource(); nlassert(pSource != NULL); // free the track pSource->stop(); pSource->setStaticBuffer(NULL); mixer->freeTrack(_Track); _Track = NULL; } }
/// Play void CSimpleSource::play() { // nldebug("CSimpleSource %p : play", this); CAudioMixerUser *mixer = CAudioMixerUser::instance(); // -- Some test to check if we can play the source // Check if sample buffer is available and if the sound source is not too far if (_SimpleSound->getBuffer() == 0 || !_SimpleSound->getBuffer()->isBufferLoaded() //|| (mixer->getListenPosVector() - _Position).sqrnorm() > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance()) || (_RelativeMode ? getPos().sqrnorm() : (mixer->getListenPosVector() - getPos()).sqrnorm()) > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance()) { // The sample buffer is not available, don't play (we don't know the length) _WaitingForPlay = false; if (_Spawn) { if (_SpawnEndCb != 0) _SpawnEndCb(this, _CbUserParam); delete this; } // nldebug("CSimpleSource %p : play FAILED !", (CAudioMixerUser::IMixerEvent*)this); return; } // -- Here we can play the source, either in a real track or as a muted source. // Try to obtain a track if (!hasPhysicalSource()) initPhysicalSource(); if (hasPhysicalSource()) { ISource *pSource = getPhysicalSource(); nlassert(pSource != NULL); // ok, we have a track to realy play, fill the data into the track pSource->setStaticBuffer(_SimpleSound->getBuffer()); // pSource->setPos( _Position, false); pSource->setPos(getVirtualPos(), false); if (!_SimpleSound->getBuffer()->isStereo()) { pSource->setMinMaxDistances(_SimpleSound->getMinDistance(), _SimpleSound->getMaxDistance(), false); setDirection(_Direction); // because there is a workaround inside pSource->setVelocity(_Velocity); } pSource->setGain(getFinalGain()); pSource->setSourceRelativeMode(_RelativeMode); pSource->setLooping(_Looping); pSource->setPitch(_Pitch); pSource->setAlpha(_Alpha); // and play the sound bool play = pSource->play(); #ifdef NL_DEBUG nlassert(play); #else if (!play) nlwarning("Failed to play physical sound source. This is a serious error"); #endif // nldebug("CSimpleSource %p : REAL play done", (CAudioMixerUser::IMixerEvent*)this); } else { if (_Priority == HighestPri) { // This sound is not discardable, add it in waiting playlist mixer->addSourceWaitingForPlay(this); _WaitingForPlay = true; return; } // there is no available track, just do a 'muted' play mixer->addEvent(this, CTime::getLocalTime() + _SimpleSound->getDuration()); _PlayMuted = true; mixer->incPlayingSourceMuted(); // nldebug("CSimpleSource %p : MUTED play done", (CAudioMixerUser::IMixerEvent*)this); } CSourceCommon::play(); _WaitingForPlay = false; }