From 1f903accd95361735c841c87fdc6494ad3331b40 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 7 Jun 2023 13:19:45 +1000 Subject: Flesh out audio state machine for playback Also fix mono playback --- src/audio/audio_decoder.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/audio/audio_decoder.cpp') diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index 5a2c75c7..af026262 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -98,27 +98,27 @@ auto AudioDecoder::Process(const std::vector& inputs, while (true) { if (has_samples_to_send_) { - if (!current_output_format_) { - auto format = current_codec_->GetOutputFormat(); + auto format = current_codec_->GetOutputFormat(); + if (format.has_value()) { current_output_format_ = StreamInfo::Pcm{ - .channels = format.num_channels, - .bits_per_sample = format.bits_per_sample, - .sample_rate = format.sample_rate_hz, + .channels = format->num_channels, + .bits_per_sample = format->bits_per_sample, + .sample_rate = format->sample_rate_hz, }; - } - if (!output->prepare(*current_output_format_)) { - break; - } + if (!output->prepare(*current_output_format_)) { + break; + } - auto write_res = current_codec_->WriteOutputSamples(output->data()); - output->add(write_res.first); - has_samples_to_send_ = !write_res.second; + auto write_res = current_codec_->WriteOutputSamples(output->data()); + output->add(write_res.first); + has_samples_to_send_ = !write_res.second; - if (has_samples_to_send_) { - // We weren't able to fit all the generated samples into the output - // buffer. Stop trying; we'll finish up during the next pass. - break; + if (has_samples_to_send_) { + // We weren't able to fit all the generated samples into the output + // buffer. Stop trying; we'll finish up during the next pass. + break; + } } } -- cgit v1.2.3