Skip to content

Commit

Permalink
bump ringbuf version in examples (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrlv authored Jul 14, 2024
1 parent 0246442 commit 0da7ae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dasp_sample = "0.11"
[dev-dependencies]
anyhow = "1.0"
hound = "3.5"
ringbuf = "0.3"
ringbuf = "0.4.1"
clap = { version = "4.0", features = ["derive"] }

[target.'cfg(target_os = "android")'.dev-dependencies]
Expand Down
11 changes: 7 additions & 4 deletions examples/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

use clap::Parser;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use ringbuf::HeapRb;
use ringbuf::{
traits::{Consumer, Producer, Split},
HeapRb,
};

#[derive(Parser, Debug)]
#[command(version, about = "CPAL feedback example", long_about = None)]
Expand Down Expand Up @@ -112,13 +115,13 @@ fn main() -> anyhow::Result<()> {
for _ in 0..latency_samples {
// The ring buffer has twice as much space as necessary to add latency here,
// so this should never fail
producer.push(0.0).unwrap();
producer.try_push(0.0).unwrap();
}

let input_data_fn = move |data: &[f32], _: &cpal::InputCallbackInfo| {
let mut output_fell_behind = false;
for &sample in data {
if producer.push(sample).is_err() {
if producer.try_push(sample).is_err() {
output_fell_behind = true;
}
}
Expand All @@ -130,7 +133,7 @@ fn main() -> anyhow::Result<()> {
let output_data_fn = move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
let mut input_fell_behind = false;
for sample in data {
*sample = match consumer.pop() {
*sample = match consumer.try_pop() {
Some(s) => s,
None => {
input_fell_behind = true;
Expand Down

0 comments on commit 0da7ae1

Please sign in to comment.