|
|
|
@ -33,13 +33,8 @@ CMusicChannelAL::CMusicChannelAL(CSoundDriverAL *soundDriver)
|
|
|
|
|
{
|
|
|
|
|
// create a default source for music streaming
|
|
|
|
|
_Source = static_cast<CSourceAL*>(_SoundDriver->createSource());
|
|
|
|
|
_Source->setPos(CVector(0, 0, 0));
|
|
|
|
|
_Source->setVelocity(CVector(0, 0, 0));
|
|
|
|
|
_Source->setDirection(CVector(0, 0, 0));
|
|
|
|
|
_Source->setSourceRelativeMode(true);
|
|
|
|
|
_Source->setStreamingBuffersMax(4);
|
|
|
|
|
_Source->setType(SourceMusic);
|
|
|
|
|
_Source->setStreamingBufferSize(32768);
|
|
|
|
|
// _Source->setStreaming(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMusicChannelAL::~CMusicChannelAL()
|
|
|
|
@ -110,9 +105,6 @@ void CMusicChannelAL::setBufferFormat(IBuffer *buffer)
|
|
|
|
|
|
|
|
|
|
void CMusicChannelAL::run()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (_Async)
|
|
|
|
|
{
|
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
|
|
// use queued buffers
|
|
|
|
@ -140,6 +132,8 @@ void CMusicChannelAL::run()
|
|
|
|
|
for(uint i = 0; i < buffers.size(); ++i)
|
|
|
|
|
fillBuffer(buffers[i], _Source->getStreamingBufferSize());
|
|
|
|
|
|
|
|
|
|
// _Source->updateManualRolloff();
|
|
|
|
|
|
|
|
|
|
// play the source
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
@ -151,9 +145,23 @@ void CMusicChannelAL::run()
|
|
|
|
|
nlSleep(100);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
_Buffer = _SoundDriver->createBuffer();
|
|
|
|
|
|
|
|
|
@ -170,23 +178,14 @@ void CMusicChannelAL::run()
|
|
|
|
|
_MusicBuffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete previous queued buffers
|
|
|
|
|
_Source->setStreamingBuffersMax(0);
|
|
|
|
|
|
|
|
|
|
// use this buffer as source
|
|
|
|
|
_Source->setStaticBuffer(_Buffer);
|
|
|
|
|
|
|
|
|
|
// play the source
|
|
|
|
|
_Source->play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// music finished without interruption
|
|
|
|
|
if (_Playing)
|
|
|
|
|
{
|
|
|
|
|
// wait until source is not playing
|
|
|
|
|
while(_Source->isPlaying() && _Playing) nlSleep(1000);
|
|
|
|
|
|
|
|
|
|
_Source->stop();
|
|
|
|
|
|
|
|
|
|
_Playing = false;
|
|
|
|
|
}
|
|
|
|
|
return _Source->play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
|
|
|
|
|
if (_MusicBuffer)
|
|
|
|
|
{
|
|
|
|
|
_Async = async;
|
|
|
|
|
_Playing = true;
|
|
|
|
|
|
|
|
|
|
_Source->setSourceRelativeMode(true);
|
|
|
|
|
|
|
|
|
|
if (_Async)
|
|
|
|
|
{
|
|
|
|
|
// create the thread if it's not yet created
|
|
|
|
|
if (!_Thread) _Thread = IThread::create(this);
|
|
|
|
@ -214,16 +220,24 @@ bool CMusicChannelAL::play(const std::string &filepath, bool async, bool loop)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_Async = async;
|
|
|
|
|
_Playing = true;
|
|
|
|
|
// use 4 queued buffers
|
|
|
|
|
_Source->setStreamingBuffersMax(4);
|
|
|
|
|
|
|
|
|
|
// we need to loop the source only if not async
|
|
|
|
|
_Source->setLooping(async ? false:loop);
|
|
|
|
|
_Source->setLooping(false);
|
|
|
|
|
|
|
|
|
|
// start the thread
|
|
|
|
|
_Thread->start();
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
return false;
|
|
|
|
@ -298,6 +312,16 @@ void CMusicChannelAL::setVolume(float gain)
|
|
|
|
|
_Source->setGain(gain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Update music
|
|
|
|
|
void CMusicChannelAL::update()
|
|
|
|
|
{
|
|
|
|
|
// stop sync music once finished playing
|
|
|
|
|
if (_Playing && !_Async && !_Source->isPlaying())
|
|
|
|
|
{
|
|
|
|
|
stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} /* namespace NLSOUND */
|
|
|
|
|
|
|
|
|
|
/* end of file */
|
|
|
|
|