fix(audio): add seamless playback for repeating audio (#597)
This commit is contained in:
parent
5106ba5307
commit
ba602a0a4d
@ -327,6 +327,11 @@ namespace Soundux::Objects
|
||||
|
||||
ma_uint64 readFrames{};
|
||||
ma_decoder_read_pcm_frames(sound->raw.decoder, output, frameCount, &readFrames);
|
||||
if (sound->repeat && !sound->shouldSeek && readFrames == 0)
|
||||
{
|
||||
ma_decoder_seek_to_pcm_frame(sound->raw.decoder, 0);
|
||||
ma_decoder_read_pcm_frames(sound->raw.decoder, output, frameCount, &readFrames);
|
||||
}
|
||||
|
||||
if (sound->shouldSeek)
|
||||
{
|
||||
@ -338,18 +343,27 @@ namespace Soundux::Objects
|
||||
Globals::gAudio.onSoundProgressed(sound, readFrames);
|
||||
}
|
||||
|
||||
if (readFrames <= 0)
|
||||
if (sound->repeat && !sound->shouldSeek && readFrames < frameCount)
|
||||
{
|
||||
if (sound->repeat)
|
||||
while (frameCount > 0 && readFrames > 0)
|
||||
{
|
||||
frameCount -= readFrames;
|
||||
ma_decoder_seek_to_pcm_frame(sound->raw.decoder, 0);
|
||||
Globals::gAudio.onSoundSeeked(sound, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals::gQueue.push_unique(reinterpret_cast<std::uintptr_t>(device),
|
||||
[sound = *sound] { Globals::gAudio.onFinished(sound); });
|
||||
output = reinterpret_cast<void *>(
|
||||
reinterpret_cast<ma_uint8 *>(output) +
|
||||
readFrames * ma_get_bytes_per_frame(sound->raw.decoder.load()->outputFormat,
|
||||
sound->raw.decoder.load()->outputChannels));
|
||||
ma_decoder_read_pcm_frames(sound->raw.decoder, output, frameCount, &readFrames);
|
||||
if (readFrames == frameCount)
|
||||
break;
|
||||
}
|
||||
|
||||
Globals::gAudio.onSoundSeeked(sound, readFrames);
|
||||
}
|
||||
else if (readFrames <= 0)
|
||||
{
|
||||
Globals::gQueue.push_unique(reinterpret_cast<std::uintptr_t>(device),
|
||||
[sound = *sound] { Globals::gAudio.onFinished(sound); });
|
||||
}
|
||||
}
|
||||
std::vector<AudioDevice> Audio::getAudioDevices()
|
||||
@ -490,4 +504,4 @@ namespace Soundux::Objects
|
||||
|
||||
return *this;
|
||||
}
|
||||
} // namespace Soundux::Objects
|
||||
} // namespace Soundux::Objects
|
||||
|
Loading…
x
Reference in New Issue
Block a user