Changed: #1031 Music is "stopped" when client is loading with OpenAL driver
This commit is contained in:
parent
079946f022
commit
1cd25d97de
5 changed files with 116 additions and 74 deletions
|
@ -33,13 +33,8 @@ CMusicChannelAL::CMusicChannelAL(CSoundDriverAL *soundDriver)
|
||||||
{
|
{
|
||||||
// create a default source for music streaming
|
// create a default source for music streaming
|
||||||
_Source = static_cast<CSourceAL*>(_SoundDriver->createSource());
|
_Source = static_cast<CSourceAL*>(_SoundDriver->createSource());
|
||||||
_Source->setPos(CVector(0, 0, 0));
|
_Source->setType(SourceMusic);
|
||||||
_Source->setVelocity(CVector(0, 0, 0));
|
|
||||||
_Source->setDirection(CVector(0, 0, 0));
|
|
||||||
_Source->setSourceRelativeMode(true);
|
|
||||||
_Source->setStreamingBuffersMax(4);
|
|
||||||
_Source->setStreamingBufferSize(32768);
|
_Source->setStreamingBufferSize(32768);
|
||||||
// _Source->setStreaming(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CMusicChannelAL::~CMusicChannelAL()
|
CMusicChannelAL::~CMusicChannelAL()
|
||||||
|
@ -110,9 +105,6 @@ void CMusicChannelAL::setBufferFormat(IBuffer *buffer)
|
||||||
|
|
||||||
void CMusicChannelAL::run()
|
void CMusicChannelAL::run()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_Async)
|
|
||||||
{
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
// use queued buffers
|
// use queued buffers
|
||||||
|
@ -140,6 +132,8 @@ void CMusicChannelAL::run()
|
||||||
for(uint i = 0; i < buffers.size(); ++i)
|
for(uint i = 0; i < buffers.size(); ++i)
|
||||||
fillBuffer(buffers[i], _Source->getStreamingBufferSize());
|
fillBuffer(buffers[i], _Source->getStreamingBufferSize());
|
||||||
|
|
||||||
|
// _Source->updateManualRolloff();
|
||||||
|
|
||||||
// play the source
|
// play the source
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
|
@ -151,9 +145,23 @@ void CMusicChannelAL::run()
|
||||||
nlSleep(100);
|
nlSleep(100);
|
||||||
}
|
}
|
||||||
while(!_MusicBuffer->isMusicEnded() && _Playing);
|
while(!_MusicBuffer->isMusicEnded() && _Playing);
|
||||||
}
|
|
||||||
else
|
|
||||||
|
// music finished without interruption
|
||||||
|
if (_Playing)
|
||||||
{
|
{
|
||||||
|
// wait until source is not playing
|
||||||
|
while(_Source->isPlaying() && _Playing) nlSleep(1000);
|
||||||
|
|
||||||
|
_Source->stop();
|
||||||
|
|
||||||
|
_Playing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Play sync music
|
||||||
|
bool CMusicChannelAL::playSync()
|
||||||
|
{
|
||||||
// use an unique buffer managed by CMusicChannelAL
|
// use an unique buffer managed by CMusicChannelAL
|
||||||
_Buffer = _SoundDriver->createBuffer();
|
_Buffer = _SoundDriver->createBuffer();
|
||||||
|
|
||||||
|
@ -170,23 +178,14 @@ void CMusicChannelAL::run()
|
||||||
_MusicBuffer = NULL;
|
_MusicBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delete previous queued buffers
|
||||||
|
_Source->setStreamingBuffersMax(0);
|
||||||
|
|
||||||
// use this buffer as source
|
// use this buffer as source
|
||||||
_Source->setStaticBuffer(_Buffer);
|
_Source->setStaticBuffer(_Buffer);
|
||||||
|
|
||||||
// play the source
|
// play the source
|
||||||
_Source->play();
|
return _Source->play();
|
||||||
}
|
|
||||||
|
|
||||||
// music finished without interruption
|
|
||||||
if (_Playing)
|
|
||||||
{
|
|
||||||
// wait until source is not playing
|
|
||||||
while(_Source->isPlaying() && _Playing) nlSleep(1000);
|
|
||||||
|
|
||||||
_Source->stop();
|
|
||||||
|
|
||||||
_Playing = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Play some music (.ogg etc...)
|
/** Play some music (.ogg etc...)
|
||||||
|
@ -204,6 +203,13 @@ bool CMusicChannelAL::play(const std::string &filepath, bool async, bool loop)
|
||||||
_MusicBuffer = IMusicBuffer::createMusicBuffer(filepath, async, async ? loop:false);
|
_MusicBuffer = IMusicBuffer::createMusicBuffer(filepath, async, async ? loop:false);
|
||||||
|
|
||||||
if (_MusicBuffer)
|
if (_MusicBuffer)
|
||||||
|
{
|
||||||
|
_Async = async;
|
||||||
|
_Playing = true;
|
||||||
|
|
||||||
|
_Source->setSourceRelativeMode(true);
|
||||||
|
|
||||||
|
if (_Async)
|
||||||
{
|
{
|
||||||
// create the thread if it's not yet created
|
// create the thread if it's not yet created
|
||||||
if (!_Thread) _Thread = IThread::create(this);
|
if (!_Thread) _Thread = IThread::create(this);
|
||||||
|
@ -214,16 +220,24 @@ bool CMusicChannelAL::play(const std::string &filepath, bool async, bool loop)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Async = async;
|
// use 4 queued buffers
|
||||||
_Playing = true;
|
_Source->setStreamingBuffersMax(4);
|
||||||
|
|
||||||
// we need to loop the source only if not async
|
// we need to loop the source only if not async
|
||||||
_Source->setLooping(async ? false:loop);
|
_Source->setLooping(false);
|
||||||
|
|
||||||
// start the thread
|
// start the thread
|
||||||
_Thread->start();
|
_Thread->start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// we need to loop the source only if not async
|
||||||
|
_Source->setLooping(loop);
|
||||||
|
|
||||||
|
return playSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
nlwarning("AL: Can't stream file %s", filepath.c_str());
|
nlwarning("AL: Can't stream file %s", filepath.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -298,6 +312,16 @@ void CMusicChannelAL::setVolume(float gain)
|
||||||
_Source->setGain(gain);
|
_Source->setGain(gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update music
|
||||||
|
void CMusicChannelAL::update()
|
||||||
|
{
|
||||||
|
// stop sync music once finished playing
|
||||||
|
if (_Playing && !_Async && !_Source->isPlaying())
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace NLSOUND */
|
} /* namespace NLSOUND */
|
||||||
|
|
||||||
/* end of file */
|
/* end of file */
|
||||||
|
|
|
@ -91,6 +91,12 @@ public:
|
||||||
* NB: in OpenAL driver, the volume of music IS affected by IListener::setGain()
|
* NB: in OpenAL driver, the volume of music IS affected by IListener::setGain()
|
||||||
*/
|
*/
|
||||||
virtual void setVolume(float gain);
|
virtual void setVolume(float gain);
|
||||||
|
|
||||||
|
/// Play sync music
|
||||||
|
bool playSync();
|
||||||
|
|
||||||
|
/// Update music
|
||||||
|
void update();
|
||||||
}; /* class CMusicChannelAL */
|
}; /* class CMusicChannelAL */
|
||||||
|
|
||||||
} /* namespace NLSOUND */
|
} /* namespace NLSOUND */
|
||||||
|
|
|
@ -618,11 +618,16 @@ void CSoundDriverAL::commit3DChanges()
|
||||||
// Sync up sources & listener 3d position.
|
// Sync up sources & listener 3d position.
|
||||||
if (getOption(OptionManualRolloff))
|
if (getOption(OptionManualRolloff))
|
||||||
{
|
{
|
||||||
for (std::set<CSourceAL *>::iterator it(_Sources.begin()), end(_Sources.end()); it != end; ++it)
|
set<CSourceAL*>::iterator it = _Sources.begin(), iend = _Sources.end();
|
||||||
|
while(it != iend)
|
||||||
{
|
{
|
||||||
(*it)->updateManualRolloff();
|
(*it)->updateManualRolloff();
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the music (XFade etc...)
|
||||||
|
updateMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write information about the driver to the output stream.
|
/// Write information about the driver to the output stream.
|
||||||
|
@ -661,6 +666,12 @@ bool CSoundDriverAL::getMusicInfo(const std::string &filepath, std::string &arti
|
||||||
return IMusicBuffer::getInfo(filepath, artist, title);
|
return IMusicBuffer::getInfo(filepath, artist, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSoundDriverAL::updateMusic()
|
||||||
|
{
|
||||||
|
set<CMusicChannelAL *>::iterator it(_MusicChannels.begin()), end(_MusicChannels.end());
|
||||||
|
for (; it != end; ++it) (*it)->update();
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove a buffer
|
/// Remove a buffer
|
||||||
void CSoundDriverAL::removeBuffer(CBufferAL *buffer)
|
void CSoundDriverAL::removeBuffer(CBufferAL *buffer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -176,6 +176,7 @@ public:
|
||||||
float getGain();
|
float getGain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void updateMusic();
|
||||||
|
|
||||||
/// Allocate nb new buffers or sources
|
/// Allocate nb new buffers or sources
|
||||||
void allocateNewItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
|
void allocateNewItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
|
||||||
|
|
|
@ -533,7 +533,7 @@ void initMainLoop()
|
||||||
// During load of the game, fade completely out SFX, and leave outgame music
|
// During load of the game, fade completely out SFX, and leave outgame music
|
||||||
// When the game will begin, it will fade in slowly
|
// When the game will begin, it will fade in slowly
|
||||||
if(SoundMngr)
|
if(SoundMngr)
|
||||||
SoundMngr->setupFadeSound(1.f, 1.f);
|
SoundMngr->setupFadeSound(0.f, 1.f);
|
||||||
|
|
||||||
initLast = initCurrent;
|
initLast = initCurrent;
|
||||||
initCurrent = ryzomGetLocalTime();
|
initCurrent = ryzomGetLocalTime();
|
||||||
|
|
Loading…
Reference in a new issue