diff --git a/src/XNA_Song.c b/src/XNA_Song.c index f6de26c2d..d2e0021a4 100644 --- a/src/XNA_Song.c +++ b/src/XNA_Song.c @@ -91,6 +91,8 @@ static float songVolume = 1.0f; static FAudio *songAudio = NULL; static FAudioMasteringVoice *songMaster = NULL; +static unsigned int songLength = 0; +static unsigned int songOffset = 0; static FAudioSourceVoice *songVoice = NULL; static FAudioVoiceCallback callbacks; @@ -121,9 +123,6 @@ static void XNA_SongSubmitBuffer(FAudioVoiceCallback *callback, void *pBufferCon activeVorbisSongInfo.sample_rate * activeVorbisSongInfo.channels ); buffer.AudioBytes = decoded * activeVorbisSongInfo.channels * sizeof(float); - buffer.Flags = (decoded < activeVorbisSongInfo.sample_rate) ? - FAUDIO_END_OF_STREAM : - 0; } else if (activeQoaSong != NULL) { @@ -133,9 +132,6 @@ static void XNA_SongSubmitBuffer(FAudioVoiceCallback *callback, void *pBufferCon (short*) songCache ); buffer.AudioBytes = decoded * qoaChannels * sizeof(short); - buffer.Flags = (decoded < qoaSamplesPerChannelPerFrame) ? - FAUDIO_END_OF_STREAM : - 0; } if (decoded == 0) @@ -143,6 +139,8 @@ static void XNA_SongSubmitBuffer(FAudioVoiceCallback *callback, void *pBufferCon return; } + songOffset += decoded; + buffer.Flags = (songOffset >= songLength) ? FAUDIO_END_OF_STREAM : 0; buffer.pAudioData = songCache; buffer.PlayBegin = 0; buffer.PlayLength = decoded; @@ -222,6 +220,9 @@ FAUDIOAPI float XNA_PlaySong(const char *name) format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; format.cbSize = 0; + + songOffset = 0; + songLength = stb_vorbis_stream_length_in_samples(activeVorbisSong); } else /* It's not vorbis, try qoa!*/ { @@ -242,6 +243,9 @@ FAUDIOAPI float XNA_PlaySong(const char *name) format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; format.cbSize = 0; + + songOffset = 0; + songLength = qoaTotalSamplesPerChannel; } /* Allocate decode cache */