Skip to content

Commit

Permalink
feat: first struct skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
mbillingr committed Jul 19, 2018
1 parent 9968666 commit 2a66dce
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
name = "ambisonic"
version = "0.1.0"
authors = ["Martin Billinger <flkazemakase@gmail.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/mbillingr/ambionics"

categories = ["multimedia", "game engines"]
keywords = ["audio", "ambionics", "3D", "sound", "gamedev"]

[dependencies]
cpal = "0.8"
rodio = "0.8"
101 changes: 101 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,104 @@
extern crate cpal;
pub extern crate rodio;

use std::time::Duration;

use cpal::{Sample as CpalSample, SampleFormat};
use rodio::{Sample, Source};

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

impl Sample for Bformat {
fn lerp(first: Self, second: Self, numerator: u32, denominator: u32) -> Self {
unimplemented!()
}

fn amplify(self, value: f32) -> Self {
unimplemented!()
}

fn saturating_add(self, other: Self) -> Self {
unimplemented!()
}

fn zero_value() -> Self {
unimplemented!()
}
}

// Why? Oh, why!?
unsafe impl CpalSample for Bformat {
fn get_format() -> SampleFormat {
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
}

fn to_f32(&self) -> f32 {
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
}

fn to_i16(&self) -> i16 {
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
}

fn to_u16(&self) -> u16 {
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
}

fn from<S>(_s: &S) -> Self
where
S: CpalSample,
{
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
}
}

struct BstreamStereoRenderer {
buffered_sample: Option<f32>,
bstream: Source<Item = Bformat>,
}

impl Source for BstreamStereoRenderer {
#[inline(always)]
fn current_frame_len(&self) -> Option<usize> {
self.bstream.current_frame_len()
}

#[inline(always)]
fn channels(&self) -> u16 {
2 // well, it's stereo...
}

#[inline(always)]
fn sample_rate(&self) -> u32 {
self.bstream.sample_rate()
}

#[inline(always)]
fn total_duration(&self) -> Option<Duration> {
self.bstream.total_duration()
}
}

impl Iterator for BstreamStereoRenderer {
type Item = f32;

fn next(&mut self) -> Option<Self::Item> {
match self.buffered_sample.take() {
Some(s) => Some(s),
None => {
let sample = self.bstream.next()?;
unimplemented!()
}
}
}
}

#[cfg(test)]
mod tests {
#[test]
Expand Down

0 comments on commit 2a66dce

Please sign in to comment.