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
parent 219a14550c
commit a8eca0edb8
No known key found for this signature in database
GPG key ID: 3B94A80E50A477C7

View file

@ -122,11 +122,12 @@ impl AudioConverterConfig {
.unwrap_or(crate::AudioResamplerMethod::BlackmanNuttall) .unwrap_or(crate::AudioResamplerMethod::BlackmanNuttall)
} }
pub fn set_mix_matrix(&mut self, v: &[&[f64]]) { pub fn set_mix_matrix<T: AsRef<[f64]>>(&mut self, v: &[T]) {
let length = v.get(0).map(|v| v.len()).unwrap_or(0); let length = v.get(0).map(|v| v.as_ref().len()).unwrap_or(0);
let array = gst::Array::from_owned( let array = gst::Array::from_owned(
v.iter() v.iter()
.map(|val| { .map(|val| {
let val = val.as_ref();
assert_eq!(val.len(), length); assert_eq!(val.len(), length);
gst::Array::from_owned( gst::Array::from_owned(
val.iter() val.iter()
@ -165,3 +166,23 @@ impl AudioConverterConfig {
.unwrap_or_else(Vec::new) .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);
}
}