Skip to content

Commit

Permalink
add default filter
Browse files Browse the repository at this point in the history
  • Loading branch information
the-drunk-coder committed Jan 31, 2023
1 parent 86d63da commit 5d1488c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Binary file added binaural_filter/default.raw
Binary file not shown.
1 change: 1 addition & 0 deletions binaural_filter/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Defualt HRIR is based on: http://audiogroup.web.th-koeln.de/ku100hrir.html
31 changes: 31 additions & 0 deletions src/building_blocks/ambisonics/binauralizer_o1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::building_blocks::convolver::block_convolver::BlockConvolver;

const DEFAULT_FILTER : &'static [u8] = include_bytes!("../../../binaural_filter/default.raw");

/**
* a simple first-order convolution binauralizer
*/
Expand All @@ -9,6 +11,25 @@ pub struct BinauralizerO1<const BUFSIZE: usize> {
}

impl<const BUFSIZE: usize> BinauralizerO1<BUFSIZE> {

pub fn default_filter() -> Self {
let ir: Vec<f32> = DEFAULT_FILTER
.chunks(4)
.map(|b| (f32::from_le_bytes(b.try_into().unwrap()) as f32))
.collect();

debug_assert!(ir.len() == 1024);

let ir_proc :Vec<(Vec<f32>, Vec<f32>)> = vec![
(ir[0..128].to_vec(), ir[512..640].to_vec()),
(ir[128..256].to_vec(), ir[640..768].to_vec()),
(ir[256..384].to_vec(), ir[768..896].to_vec()),
(ir[384..512].to_vec(), ir[896..1024].to_vec()),
];

BinauralizerO1::from_ir(ir_proc)
}

// initialize with unit IRs
pub fn from_ir(ir: Vec<(Vec<f32>, Vec<f32>)>) -> Self {
let mut left = Vec::new();
Expand Down Expand Up @@ -37,3 +58,13 @@ impl<const BUFSIZE: usize> BinauralizerO1<BUFSIZE> {
bin_block
}
}

#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn test_load() {
let bin = BinauralizerO1::<128>::default_filter();
}
}

0 comments on commit 5d1488c

Please sign in to comment.