Skip to content

Commit

Permalink
feat: upgrade to rodio 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
anon authored and mbillingr committed Feb 8, 2021
1 parent 9ac234f commit c29eea3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ keywords = ["audio", "ambisonics", "3D", "sound", "gamedev"]
include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"]

[dependencies]
cpal = "< 0.12, >= 0.8"
rodio = "< 0.12, >= 0.9"
#cpal = "< 0.12, >= 0.8"
#rodio = "< 0.12, >= 0.9"
cpal = "0.13"
rodio = "0.13"
rand = {version = "0.7.3", features = ["small_rng"]}
rand_distr = "0.3.0"
4 changes: 1 addition & 3 deletions src/bformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ impl Sample for Bformat {

// 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.")
}
const FORMAT: SampleFormat = SampleFormat::F32;

fn to_f32(&self) -> f32 {
panic!("The B-format is not intended to be used as a CPAL sample directly. Use a renderer instead.")
Expand Down
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ impl AmbisonicBuilder {

/// Build the ambisonic context
pub fn build(self) -> Ambisonic {
let device = self
.device
.unwrap_or_else(|| rodio::default_output_device().unwrap());
let sink = rodio::Sink::new(&device);
let (stream, stream_handle) = if let Some(device) = self.device {
rodio::OutputStream::try_from_device(&device).unwrap()
} else {
rodio::OutputStream::try_default().unwrap()
};

let sink = rodio::Sink::try_new(&stream_handle).unwrap();

let (mixer, controller) = bmixer::bmixer(self.sample_rate);

Expand All @@ -129,6 +132,7 @@ impl AmbisonicBuilder {

Ambisonic {
sink,
output_stream: stream,
composer: controller,
}
}
Expand Down Expand Up @@ -169,9 +173,12 @@ impl Default for AmbisonicBuilder {
///
/// Stops playing all sounds when dropped.
pub struct Ambisonic {
// disable warning that `sink` is unused. We need it to keep the audio alive.
// We need to hold on to Sink and Stream to keep the Audio alive
#[allow(dead_code)]
sink: rodio::Sink,
#[allow(dead_code)]
output_stream: rodio::OutputStream,

composer: Arc<BmixerComposer>,
}

Expand Down

0 comments on commit c29eea3

Please sign in to comment.