audio: Make AudioConverterConfig::set_mix_matrix generic

So that we can set the mix matrix using both `&[&[f64]]` and
`&[Vec<f64>]`.
This commit is contained in:
Jan Alexander Steffens (heftig) 2021-02-10 11:29:27 +01:00 committed by Sebastian Dröge
parent cebc7456ce
commit caadaab184

View file

@ -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<T: AsRef<[f64]>>(&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);
}
}