Skip to content

Commit

Permalink
feat: impl BstreamStereoRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbillingr committed Jul 19, 2018
1 parent 04b98a5 commit fcf2e4c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ use std::time::Duration;
use cpal::{Sample as CpalSample, SampleFormat};
use rodio::{Sample, Source};


#[derive(Copy, Clone)]
struct Bweights {
w: f32,
x: f32,
y: f32,
z: f32,
}

impl Bweights {
fn dot(&self, b: Bformat) -> f32 {
self.w * b.w + self.x * b.x + self.y * b.y + self.z * b.z
}

fn virtual_microphone(direction: [f32; 3], p: f32) -> Bweights {
Bweights {
w: p * 2f32.sqrt(),
x: direction[0] * (1.0 - p),
y: direction[1] * (1.0 - p),
z: direction[2] * (1.0 - p),
}
}
}


#[derive(Copy, Clone)]
struct Bformat {
w: f32,
Expand Down Expand Up @@ -80,6 +105,8 @@ unsafe impl CpalSample for Bformat {
}

struct BstreamStereoRenderer {
left_mic: Bweights,
right_mic: Bweights,
buffered_sample: Option<f32>,
bstream: Source<Item = Bformat>,
}
Expand Down Expand Up @@ -114,7 +141,13 @@ impl Iterator for BstreamStereoRenderer {
Some(s) => Some(s),
None => {
let sample = self.bstream.next()?;
unimplemented!()

let left = self.left_mic.dot(sample);
let right = self.right_mic.dot(sample);

// emit left channel now, and right channel next time
self.buffered_sample = Some(right);
Some(left)
}
}
}
Expand Down

0 comments on commit fcf2e4c

Please sign in to comment.