mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 09:36:15 +00:00
Fixed: Always commit 3d positioning when calling play on sources. This avoids having to wait for update call. Sources no longer cause loud noise when ryzom client finishes loading
--HG-- branch : sound_dev
This commit is contained in:
parent
015f47d71d
commit
b6025fc008
5 changed files with 69 additions and 14 deletions
|
@ -353,7 +353,7 @@ public:
|
||||||
* In streaming mode, the time spent during buffer outruns is not
|
* In streaming mode, the time spent during buffer outruns is not
|
||||||
* counted towards the playback time, and the playback time is
|
* counted towards the playback time, and the playback time is
|
||||||
* be the current time position in the entire submitted queue.
|
* be the current time position in the entire submitted queue.
|
||||||
* When using static buffers, the result is the tot time that the
|
* When using static buffers, the result is the total time that the
|
||||||
* attached buffer has been playing. If the source is looping, the
|
* attached buffer has been playing. If the source is looping, the
|
||||||
* time will be the total of all playbacks of the buffer.
|
* time will be the total of all playbacks of the buffer.
|
||||||
* When the source is stopped, this will return the time where the
|
* When the source is stopped, this will return the time where the
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace NLSOUND {
|
||||||
CSourceAL::CSourceAL(CSoundDriverAL *soundDriver) :
|
CSourceAL::CSourceAL(CSoundDriverAL *soundDriver) :
|
||||||
_SoundDriver(NULL), _Buffer(NULL), _Source(AL_NONE),
|
_SoundDriver(NULL), _Buffer(NULL), _Source(AL_NONE),
|
||||||
_DirectFilter(AL_FILTER_NULL), _EffectFilter(AL_FILTER_NULL),
|
_DirectFilter(AL_FILTER_NULL), _EffectFilter(AL_FILTER_NULL),
|
||||||
_IsPlaying(false), _IsPaused(false), _StartTime(0),
|
_IsPlaying(false), _IsPaused(false), _StartTime(0), _IsStreaming(false),
|
||||||
_Pos(0.0f, 0.0f, 0.0f), _Gain(NLSOUND_DEFAULT_GAIN), _Alpha(1.0),
|
_Pos(0.0f, 0.0f, 0.0f), _Gain(NLSOUND_DEFAULT_GAIN), _Alpha(1.0),
|
||||||
_MinDistance(1.0f), _MaxDistance(numeric_limits<float>::max()),
|
_MinDistance(1.0f), _MaxDistance(numeric_limits<float>::max()),
|
||||||
_Effect(NULL), _Direct(true),
|
_Effect(NULL), _Direct(true),
|
||||||
|
@ -100,7 +100,7 @@ void CSourceAL::updateManualRolloff()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable or disable streaming mode. Source must be stopped to call this.
|
/// Enable or disable streaming mode. Source must be stopped to call this.
|
||||||
void CSourceAL::setStreaming(bool /* streaming */)
|
void CSourceAL::setStreaming(bool streaming)
|
||||||
{
|
{
|
||||||
nlassert(isStopped());
|
nlassert(isStopped());
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ void CSourceAL::setStreaming(bool /* streaming */)
|
||||||
alSourcei(_Source, AL_BUFFER, AL_NONE);
|
alSourcei(_Source, AL_BUFFER, AL_NONE);
|
||||||
alTestError();
|
alTestError();
|
||||||
_Buffer = NULL;
|
_Buffer = NULL;
|
||||||
|
_IsStreaming = streaming;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the buffer that will be played (no streaming)
|
/* Set the buffer that will be played (no streaming)
|
||||||
|
@ -209,28 +210,36 @@ bool CSourceAL::getLooping() const
|
||||||
/// Play the static buffer (or stream in and play)
|
/// Play the static buffer (or stream in and play)
|
||||||
bool CSourceAL::play()
|
bool CSourceAL::play()
|
||||||
{
|
{
|
||||||
if ( _Buffer != NULL )
|
// Commit 3D changes before starting play
|
||||||
|
if (_SoundDriver->getOption(ISoundDriver::OptionManualRolloff))
|
||||||
|
updateManualRolloff();
|
||||||
|
|
||||||
|
if (_Buffer)
|
||||||
{
|
{
|
||||||
// Static playing mode
|
// Static playing mode
|
||||||
_IsPaused = false;
|
_IsPaused = false;
|
||||||
alSourcePlay(_Source);
|
alSourcePlay(_Source);
|
||||||
_IsPlaying = alGetError() == AL_NO_ERROR;
|
_IsPlaying = (alGetError() == AL_NO_ERROR);
|
||||||
if (_IsPlaying)
|
if (_IsPlaying)
|
||||||
_StartTime = CTime::getLocalTime();
|
_StartTime = CTime::getLocalTime();
|
||||||
return _IsPlaying;
|
return _IsPlaying;
|
||||||
}
|
}
|
||||||
else
|
else if (_IsStreaming)
|
||||||
{
|
{
|
||||||
// TODO: Verify streaming mode?
|
|
||||||
_IsPaused = false;
|
_IsPaused = false;
|
||||||
alSourcePlay(_Source);
|
alSourcePlay(_Source);
|
||||||
_IsPlaying = true;
|
_IsPlaying = (alGetError() == AL_NO_ERROR);
|
||||||
_StartTime = CTime::getLocalTime(); // TODO: Played time should freeze when buffering fails, and be calculated based on the number of buffers played plus passed time. This is necessary for synchronizing animation with sound.
|
if (_IsPlaying)
|
||||||
return true;
|
_StartTime = CTime::getLocalTime(); // TODO: Played time should freeze when buffering fails, and be calculated based on the number of buffers played plus passed time. This is necessary for synchronizing animation with sound.
|
||||||
|
return _IsPlaying;
|
||||||
// Streaming mode
|
// Streaming mode
|
||||||
//nlwarning("AL: Cannot play null buffer; streaming not implemented" );
|
//nlwarning("AL: Cannot play null buffer; streaming not implemented" );
|
||||||
//nlstop;
|
//nlstop;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("Invalid play call, not streaming and no static buffer assigned");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop playing
|
/// Stop playing
|
||||||
|
|
|
@ -60,6 +60,8 @@ private:
|
||||||
bool _IsPaused;
|
bool _IsPaused;
|
||||||
NLMISC::TTime _StartTime;
|
NLMISC::TTime _StartTime;
|
||||||
|
|
||||||
|
bool _IsStreaming;
|
||||||
|
|
||||||
NLMISC::CVector _Pos;
|
NLMISC::CVector _Pos;
|
||||||
float _Gain;
|
float _Gain;
|
||||||
double _Alpha;
|
double _Alpha;
|
||||||
|
|
|
@ -493,8 +493,10 @@ bool CSourceXAudio2::initFormat(IBuffer::TBufferFormat bufferFormat, uint8 chann
|
||||||
_SourceVoice->SetVolume(_Gain, _OperationSet);
|
_SourceVoice->SetVolume(_Gain, _OperationSet);
|
||||||
setupVoiceSends();
|
setupVoiceSends();
|
||||||
_SoundDriver->getXAudio2()->CommitChanges(_OperationSet);
|
_SoundDriver->getXAudio2()->CommitChanges(_OperationSet);
|
||||||
|
|
||||||
|
// Also commit any 3D settings that were already done
|
||||||
|
commit3DChanges();
|
||||||
|
|
||||||
// test
|
// test
|
||||||
//XAUDIO2_VOICE_DETAILS voice_details;
|
//XAUDIO2_VOICE_DETAILS voice_details;
|
||||||
//_SourceVoice->GetVoiceDetails(&voice_details);
|
//_SourceVoice->GetVoiceDetails(&voice_details);
|
||||||
|
@ -581,6 +583,11 @@ bool CSourceXAudio2::play()
|
||||||
{
|
{
|
||||||
// nldebug(NLSOUND_XAUDIO2_PREFIX "play");
|
// nldebug(NLSOUND_XAUDIO2_PREFIX "play");
|
||||||
|
|
||||||
|
// Commit 3D changes before starting play
|
||||||
|
if (_SourceVoice)
|
||||||
|
commit3DChanges();
|
||||||
|
// else it is commit by the preparePlay > initFormat function
|
||||||
|
|
||||||
if (_IsPaused)
|
if (_IsPaused)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(_SourceVoice->Start(0))) _IsPaused = false;
|
if (SUCCEEDED(_SourceVoice->Start(0))) _IsPaused = false;
|
||||||
|
|
|
@ -183,8 +183,17 @@ void CStreamSource::play()
|
||||||
// pSource->setPos( _Position, false);
|
// pSource->setPos( _Position, false);
|
||||||
pSource->setPos(getVirtualPos(), false);
|
pSource->setPos(getVirtualPos(), false);
|
||||||
pSource->setMinMaxDistances(m_StreamSound->getMinDistance(), m_StreamSound->getMaxDistance(), false);
|
pSource->setMinMaxDistances(m_StreamSound->getMinDistance(), m_StreamSound->getMaxDistance(), false);
|
||||||
setDirection(_Direction); // because there is a workaround inside
|
if (!m_Buffers[0]->isStereo())
|
||||||
pSource->setVelocity(_Velocity);
|
{
|
||||||
|
setDirection(_Direction); // because there is a workaround inside
|
||||||
|
pSource->setVelocity(_Velocity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pSource->setDirection(NLMISC::CVector::Null);
|
||||||
|
pSource->setCone(float(Pi * 2), float(Pi * 2), 1.0f);
|
||||||
|
pSource->setVelocity(NLMISC::CVector::Null);
|
||||||
|
}
|
||||||
pSource->setGain(getFinalGain());
|
pSource->setGain(getFinalGain());
|
||||||
pSource->setSourceRelativeMode(_RelativeMode);
|
pSource->setSourceRelativeMode(_RelativeMode);
|
||||||
// pSource->setLooping(_Looping);
|
// pSource->setLooping(_Looping);
|
||||||
|
@ -223,6 +232,34 @@ void CStreamSource::play()
|
||||||
{
|
{
|
||||||
CSourceCommon::play();
|
CSourceCommon::play();
|
||||||
m_WaitingForPlay = false;
|
m_WaitingForPlay = false;
|
||||||
|
#if 1
|
||||||
|
// Dump source info
|
||||||
|
nlwarning("--- DUMP SOURCE INFO ---");
|
||||||
|
nlwarning(" * getLooping: %s", getPhysicalSource()->getLooping() ? "YES" : "NO");
|
||||||
|
nlwarning(" * isPlaying: %s", getPhysicalSource()->isPlaying() ? "YES" : "NO");
|
||||||
|
nlwarning(" * isStopped: %s", getPhysicalSource()->isStopped() ? "YES" : "NO");
|
||||||
|
nlwarning(" * isPaused: %s", getPhysicalSource()->isPaused() ? "YES" : "NO");
|
||||||
|
nlwarning(" * getPos: %f, %f, %f", getPhysicalSource()->getPos().x, getPhysicalSource()->getPos().y, getPhysicalSource()->getPos().z);
|
||||||
|
NLMISC::CVector v;
|
||||||
|
getPhysicalSource()->getVelocity(v);
|
||||||
|
nlwarning(" * getVelocity: %f, %f, %f", v.x, v.y, v.z);
|
||||||
|
getPhysicalSource()->getDirection(v);
|
||||||
|
nlwarning(" * getDirection: %f, %f, %f", v.x, v.y, v.z);
|
||||||
|
nlwarning(" * getGain: %f", getPhysicalSource()->getGain());
|
||||||
|
nlwarning(" * getPitch: %f", getPhysicalSource()->getPitch());
|
||||||
|
nlwarning(" * getSourceRelativeMode: %s", getPhysicalSource()->getSourceRelativeMode() ? "YES" : "NO");
|
||||||
|
float a, b, c;
|
||||||
|
getPhysicalSource()->getMinMaxDistances(a, b);
|
||||||
|
nlwarning(" * getMinMaxDistances: %f, %f", a, b);
|
||||||
|
getPhysicalSource()->getCone(a, b, c);
|
||||||
|
nlwarning(" * getCone: %f, %f", a, b, c);
|
||||||
|
nlwarning(" * getDirect: %s", getPhysicalSource()->getDirect() ? "YES" : "NO");
|
||||||
|
nlwarning(" * getDirectGain: %f", getPhysicalSource()->getDirectGain());
|
||||||
|
nlwarning(" * isDirectFilterEnabled: %s", getPhysicalSource()->isDirectFilterEnabled() ? "YES" : "NO");
|
||||||
|
nlwarning(" * getEffect: %s", getPhysicalSource()->getEffect() ? "YES" : "NO");
|
||||||
|
nlwarning(" * getEffectGain: %f", getPhysicalSource()->getEffectGain());
|
||||||
|
nlwarning(" * isEffectFilterEnabled: %s", getPhysicalSource()->isEffectFilterEnabled() ? "YES" : "NO");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue