8
8
9
9
use clap:: Parser ;
10
10
use cpal:: traits:: { DeviceTrait , HostTrait , StreamTrait } ;
11
- use ringbuf:: HeapRb ;
11
+ use ringbuf:: {
12
+ traits:: { Consumer , Producer , Split } ,
13
+ HeapRb ,
14
+ } ;
12
15
13
16
#[ derive( Parser , Debug ) ]
14
17
#[ command( version, about = "CPAL feedback example" , long_about = None ) ]
@@ -112,13 +115,13 @@ fn main() -> anyhow::Result<()> {
112
115
for _ in 0 ..latency_samples {
113
116
// The ring buffer has twice as much space as necessary to add latency here,
114
117
// so this should never fail
115
- producer. push ( 0.0 ) . unwrap ( ) ;
118
+ producer. try_push ( 0.0 ) . unwrap ( ) ;
116
119
}
117
120
118
121
let input_data_fn = move |data : & [ f32 ] , _: & cpal:: InputCallbackInfo | {
119
122
let mut output_fell_behind = false ;
120
123
for & sample in data {
121
- if producer. push ( sample) . is_err ( ) {
124
+ if producer. try_push ( sample) . is_err ( ) {
122
125
output_fell_behind = true ;
123
126
}
124
127
}
@@ -130,7 +133,7 @@ fn main() -> anyhow::Result<()> {
130
133
let output_data_fn = move |data : & mut [ f32 ] , _: & cpal:: OutputCallbackInfo | {
131
134
let mut input_fell_behind = false ;
132
135
for sample in data {
133
- * sample = match consumer. pop ( ) {
136
+ * sample = match consumer. try_pop ( ) {
134
137
Some ( s) => s,
135
138
None => {
136
139
input_fell_behind = true ;
0 commit comments