Implement some basic data conversion
This commit is contained in:
parent
b23857a57c
commit
32bca93cc9
4 changed files with 180 additions and 13 deletions
41
src/conversions.rs
Normal file
41
src/conversions.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*!
|
||||
This module contains function that will convert from one PCM format to another.
|
||||
|
||||
This includes conversion between samples formats, channels or sample rates.
|
||||
|
||||
*/
|
||||
pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRate) -> Vec<T>
|
||||
where T: Copy
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn convert_channels<T>(input: &[T], from: ::ChannelsCount, to: ::ChannelsCount) -> Vec<T>
|
||||
where T: Copy
|
||||
{
|
||||
assert!(input.len() % from as uint == 0);
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
for element in input.chunks(from as uint) {
|
||||
// copying the common channels
|
||||
for i in range(0, ::std::cmp::min(from, to)) {
|
||||
result.push(element[i as uint]);
|
||||
}
|
||||
|
||||
// adding extra ones
|
||||
for i in range(0, ::std::cmp::max(0, to - from)) {
|
||||
result.push(element[i as uint % element.len()]);
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_convert_channels() {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue