webaudio: set the channel_count in the AudioDestinationNode (#768)

Co-authored-by: Vincent Jousse <vincent.jousse@luminvent.com>
This commit is contained in:
VincentJousse
2023-03-30 16:05:42 +02:00
committed by GitHub
parent 17e7ab61fd
commit 61a2210d70

View File

@@ -220,15 +220,24 @@ impl DeviceTrait for Device {
// Create the WebAudio stream.
let mut stream_opts = AudioContextOptions::new();
stream_opts.sample_rate(config.sample_rate.0 as f32);
let ctx = Arc::new(
AudioContext::new_with_context_options(&stream_opts).map_err(
|err| -> BuildStreamError {
let description = format!("{:?}", err);
let err = BackendSpecificError { description };
err.into()
},
)?,
);
let ctx = AudioContext::new_with_context_options(&stream_opts).map_err(
|err| -> BuildStreamError {
let description = format!("{:?}", err);
let err = BackendSpecificError { description };
err.into()
},
)?;
let destination = ctx.destination();
// If possible, set the destination's channel_count to the given config.channel.
// If not, fallback on the default destination channel_count to keep previous behavior
// and do not return an error.
if config.channels as u32 <= destination.max_channel_count() {
destination.set_channel_count(config.channels as u32);
}
let ctx = Arc::new(ctx);
// A container for managing the lifecycle of the audio callbacks.
let mut on_ended_closures: Vec<Arc<RwLock<Option<Closure<dyn FnMut()>>>>> = Vec::new();