From d64ffb1b9b282fa01decace386bb1c3064cb64f5 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sat, 11 Nov 2023 20:27:48 -0600 Subject: [PATCH] LibWeb: Output audio in stereo regardless of the encoded channel count Audio loaders currently always output two channels, even if they were encoded as mono. Therefore, we have to hardcode the channel count in our audio plugin to avoid crashing until we can handle mono or multi- channel audio better. Fixes #21898 --- .../Libraries/LibWeb/Platform/AudioCodecPluginAgnostic.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Platform/AudioCodecPluginAgnostic.cpp b/Userland/Libraries/LibWeb/Platform/AudioCodecPluginAgnostic.cpp index 1ba5459453..ad72665d32 100644 --- a/Userland/Libraries/LibWeb/Platform/AudioCodecPluginAgnostic.cpp +++ b/Userland/Libraries/LibWeb/Platform/AudioCodecPluginAgnostic.cpp @@ -37,8 +37,10 @@ ErrorOr> AudioCodecPluginAgnostic::creat auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) AudioCodecPluginAgnostic(loader, duration, move(update_timer)))); constexpr u32 latency_ms = 100; + // FIXME: Audio loaders are hard-coded to output stereo audio. Once that changes, the channel count provided + // below should be retrieved from the audio loader instead of being hard-coded to 2. RefPtr output = TRY(Audio::PlaybackStream::create( - Audio::OutputState::Suspended, loader->sample_rate(), loader->num_channels(), latency_ms, + Audio::OutputState::Suspended, loader->sample_rate(), /* channels = */ 2, latency_ms, [&plugin = *plugin, loader](Bytes buffer, Audio::PcmSampleFormat format, size_t sample_count) -> ReadonlyBytes { VERIFY(format == Audio::PcmSampleFormat::Float32); auto samples = loader->get_more_samples(sample_count).release_value_but_fixme_should_propagate_errors();