bump ringbuf version in examples (#897)

This commit is contained in:
Georgy Frolov 2024-07-14 18:20:39 +03:00 • committed by GitHub
parent 0246442da2
commit 0da7ae1d42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -19,7 +19,7 @@ dasp_sample = "0.11"
[dev-dependencies] [dev-dependencies]
anyhow = "1.0" anyhow = "1.0"
hound = "3.5" hound = "3.5"
ringbuf = "0.3" ringbuf = "0.4.1"
clap = { version = "4.0", features = ["derive"] } clap = { version = "4.0", features = ["derive"] }
[target.'cfg(target_os = "android")'.dev-dependencies] [target.'cfg(target_os = "android")'.dev-dependencies]

View file

@ -8,7 +8,10 @@
use clap::Parser; use clap::Parser;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use ringbuf::HeapRb; use ringbuf::{
traits::{Consumer, Producer, Split},
HeapRb,
};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about = "CPAL feedback example", long_about = None)] #[command(version, about = "CPAL feedback example", long_about = None)]
@ -112,13 +115,13 @@ fn main() -> anyhow::Result<()> {
for _ in 0..latency_samples { for _ in 0..latency_samples {
// The ring buffer has twice as much space as necessary to add latency here, // The ring buffer has twice as much space as necessary to add latency here,
// so this should never fail // 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 input_data_fn = move |data: &[f32], _: &cpal::InputCallbackInfo| {
let mut output_fell_behind = false; let mut output_fell_behind = false;
for &sample in data { for &sample in data {
if producer.push(sample).is_err() { if producer.try_push(sample).is_err() {
output_fell_behind = true; output_fell_behind = true;
} }
} }
@ -130,7 +133,7 @@ fn main() -> anyhow::Result<()> {
let output_data_fn = move |data: &mut [f32], _: &cpal::OutputCallbackInfo| { let output_data_fn = move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
let mut input_fell_behind = false; let mut input_fell_behind = false;
for sample in data { for sample in data {
*sample = match consumer.pop() { *sample = match consumer.try_pop() {
Some(s) => s, Some(s) => s,
None => { None => {
input_fell_behind = true; input_fell_behind = true;