From a8eca0edb87becdb2899ade7fe7d1b617fb4ffb7 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Wed, 10 Feb 2021 11:29:27 +0100 Subject: [PATCH] audio: Make AudioConverterConfig::set_mix_matrix generic So that we can set the mix matrix using both `&[&[f64]]` and `&[Vec]`. --- gstreamer-audio/src/audio_converter.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gstreamer-audio/src/audio_converter.rs b/gstreamer-audio/src/audio_converter.rs index 60847e31f..47d2e1261 100644 --- a/gstreamer-audio/src/audio_converter.rs +++ b/gstreamer-audio/src/audio_converter.rs @@ -122,11 +122,12 @@ impl AudioConverterConfig { .unwrap_or(crate::AudioResamplerMethod::BlackmanNuttall) } - pub fn set_mix_matrix(&mut self, v: &[&[f64]]) { - let length = v.get(0).map(|v| v.len()).unwrap_or(0); + pub fn set_mix_matrix>(&mut self, v: &[T]) { + let length = v.get(0).map(|v| v.as_ref().len()).unwrap_or(0); let array = gst::Array::from_owned( v.iter() .map(|val| { + let val = val.as_ref(); assert_eq!(val.len(), length); gst::Array::from_owned( val.iter() @@ -165,3 +166,23 @@ impl AudioConverterConfig { .unwrap_or_else(Vec::new) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_mix_matrix() { + const MATRIX: &[&[f64]] = &[&[1.2, 0.3], &[0.2, 0.8]]; + + gst::init().unwrap(); + + let mut config = AudioConverterConfig::new(); + config.set_mix_matrix(MATRIX); + + let matrix = config.get_mix_matrix(); + assert_eq!(matrix, MATRIX); + + config.set_mix_matrix(&matrix); + } +}