Start the VPX audio track on the first frame

MoviePlayer::Start is called about a second (potentially) before
MoviePlayer::Frame starts getting called to actually play the video, causing
the audio to start early and require significant synchronization adjustment.
This isn't ideal to constantly check if the audio track needs to play in
MoviePlayer::Frame, but it's better than starting prematurely.
This commit is contained in:
Chris Robinson 2022-10-02 21:19:32 -07:00 committed by Christoph Oelckers
parent 5e465a65e2
commit 80bf62cb3c

View file

@ -556,23 +556,9 @@ public:
{
MusicStream = ZMusic_OpenSong(GetMusicReader(reader), MDEV_DEFAULT, nullptr);
}
if (MusicStream)
if (!MusicStream)
{
bool ok = false;
SoundStreamInfo info{};
ZMusic_GetStreamInfo(MusicStream, &info);
// if mBufferSize == 0, the music stream is played externally (e.g.
// Windows' MIDI synth), which we can't keep synced. Play anyway?
if (info.mBufferSize > 0 && ZMusic_Start(MusicStream, 0, false))
{
ok = AudioTrack.Start(info.mSampleRate, abs(info.mNumChannels),
(info.mNumChannels < 0) ? MusicSamples16bit : MusicSamplesFloat, &StreamCallbackC, this);
}
if (!ok)
{
ZMusic_Close(MusicStream);
MusicStream = nullptr;
}
Printf(PRINT_BOLD, "Failed to decode %s\n", fileSystem.GetFileFullName(soundtrack, false));
}
}
animtex.SetSize(AnimTexture::YUV, width, height);
@ -605,6 +591,25 @@ public:
framenum++;
if (framenum >= numframes) stop = true;
if (!AudioTrack.GetAudioStream() && MusicStream)
{
bool ok = false;
SoundStreamInfo info{};
ZMusic_GetStreamInfo(MusicStream, &info);
// if mBufferSize == 0, the music stream is played externally (e.g.
// Windows' MIDI synth), which we can't keep synced. Play anyway?
if (info.mBufferSize > 0 && ZMusic_Start(MusicStream, 0, false))
{
ok = AudioTrack.Start(info.mSampleRate, abs(info.mNumChannels),
(info.mNumChannels < 0) ? MusicSamples16bit : MusicSamplesFloat, &StreamCallbackC, this);
}
if (!ok)
{
ZMusic_Close(MusicStream);
MusicStream = nullptr;
}
}
bool nostopsound = (flags & NOSOUNDCUTOFF);
int soundframe = convdenom ? Scale(framenum, convnumer, convdenom) : framenum;
if (soundframe > lastsoundframe)