|
|
@ -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()
|
|
|
@ -109,9 +104,6 @@ void CMusicChannelAL::setBufferFormat(IBuffer *buffer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMusicChannelAL::run()
|
|
|
|
void CMusicChannelAL::run()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_Async)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool first = true;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
|
|
|
@ -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,8 +145,22 @@ void CMusicChannelAL::run()
|
|
|
|
nlSleep(100);
|
|
|
|
nlSleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(!_MusicBuffer->isMusicEnded() && _Playing);
|
|
|
|
while(!_MusicBuffer->isMusicEnded() && _Playing);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// music finished without interruption
|
|
|
|
|
|
|
|
if (_Playing)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// wait until source is not playing
|
|
|
|
|
|
|
|
while(_Source->isPlaying() && _Playing) nlSleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_Source->stop();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_Playing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 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 */
|
|
|
|