From 0da7ae1d426d471cf352550d0048bac91c8bac38 Mon Sep 17 00:00:00 2001 From: Georgy Frolov Date: Sun, 14 Jul 2024 18:20:39 +0300 Subject: [PATCH] bump ringbuf version in examples (#897) --- Cargo.toml | 2 +- examples/feedback.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b00ce902..5ccf1776b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/examples/feedback.rs b/examples/feedback.rs index eae9fa2e7..557f2020f 100644 --- a/examples/feedback.rs +++ b/examples/feedback.rs @@ -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)] @@ -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; } } @@ -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;