Fixed possible bug in NzMusic
Caused by sending a non-updated buffer to OpenAL Former-commit-id: 4441bcc9cd8cee874ba8bc5f66f1234cfffd3621
This commit is contained in:
parent
26fb8abbbd
commit
601346a566
|
|
@ -61,7 +61,7 @@ class NAZARA_API NzMusic : public NzSoundEmitter
|
|||
private:
|
||||
NzMusicImpl* m_impl = nullptr;
|
||||
|
||||
bool FillBuffer(unsigned int buffer);
|
||||
bool FillAndQueueBuffer(unsigned int buffer);
|
||||
void MusicThread();
|
||||
|
||||
static NzMusicLoader::LoaderList s_loaders;
|
||||
|
|
|
|||
|
|
@ -199,22 +199,25 @@ void NzMusic::Stop()
|
|||
}
|
||||
}
|
||||
|
||||
bool NzMusic::FillBuffer(unsigned int buffer)
|
||||
bool NzMusic::FillAndQueueBuffer(unsigned int buffer)
|
||||
{
|
||||
unsigned int sampleCount = m_impl->chunkSamples.size();
|
||||
unsigned int sampleRead = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
sampleRead += m_impl->stream->Read(&m_impl->chunkSamples[sampleRead], sampleCount-sampleRead);
|
||||
if (sampleRead != sampleCount && m_impl->loop)
|
||||
sampleRead += m_impl->stream->Read(&m_impl->chunkSamples[sampleRead], sampleCount - sampleRead);
|
||||
if (sampleRead < sampleCount && m_impl->loop)
|
||||
m_impl->stream->Seek(0);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (sampleRead > 0)
|
||||
{
|
||||
alBufferData(buffer, m_impl->audioFormat, &m_impl->chunkSamples[0], sampleRead*sizeof(nzInt16), m_impl->sampleRate);
|
||||
alSourceQueueBuffers(m_source, 1, &buffer);
|
||||
}
|
||||
|
||||
return sampleRead != sampleCount; // Fin du fichier (N'arrive pas en cas de loop)
|
||||
}
|
||||
|
|
@ -226,11 +229,8 @@ void NzMusic::MusicThread()
|
|||
|
||||
for (unsigned int i = 0; i < NAZARA_AUDIO_STREAMEDBUFFERCOUNT; ++i)
|
||||
{
|
||||
bool eof = FillBuffer(buffers[i]);
|
||||
alSourceQueueBuffers(m_source, 1, &buffers[i]);
|
||||
|
||||
if (eof)
|
||||
break; // Nous avons fini, nous ne continuons pas
|
||||
if (FillAndQueueBuffer(buffers[i])) // Fin du fichier ?
|
||||
break; // Nous avons atteint la fin du fichier, inutile de rajouter des buffers
|
||||
}
|
||||
|
||||
alSourcePlay(m_source);
|
||||
|
|
@ -251,8 +251,8 @@ void NzMusic::MusicThread()
|
|||
while (processedCount--)
|
||||
{
|
||||
alSourceUnqueueBuffers(m_source, 1, &buffer);
|
||||
if (!FillBuffer(buffer)) // Fin du fichier ?
|
||||
alSourceQueueBuffers(m_source, 1, &buffer);
|
||||
if (FillAndQueueBuffer(buffer))
|
||||
break;
|
||||
}
|
||||
|
||||
NzThread::Sleep(50);
|
||||
|
|
|
|||
Loading…
Reference in New Issue