1- //! Duplex audio stream support with synchronized input/output.
2- //!
3- //! This module provides types for building duplex (simultaneous input/output) audio streams
4- //! with hardware clock synchronization.
5- //!
6- //! See `examples/duplex_feedback.rs` for a working example.
7-
81use crate :: { ChannelCount , InputStreamTimestamp , OutputStreamTimestamp , SampleRate } ;
92
10- /// Information passed to duplex callbacks.
11- ///
12- /// This contains timing information for the current audio buffer, combining
13- /// both input and output timing. A duplex stream has a single callback invocation
14- /// that provides synchronized input and output data.
3+ // Timing information for a duplex callback, combining input and output timestamps.
154#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
165pub struct DuplexCallbackInfo {
176 input_timestamp : InputStreamTimestamp ,
187 output_timestamp : OutputStreamTimestamp ,
198}
209
2110impl DuplexCallbackInfo {
22- /// Create a new DuplexCallbackInfo.
23- ///
24- /// Note: Both timestamps will share the same `callback` instant since there is
25- /// only one callback invocation for a duplex stream.
2611 pub fn new (
2712 input_timestamp : InputStreamTimestamp ,
2813 output_timestamp : OutputStreamTimestamp ,
@@ -33,36 +18,19 @@ impl DuplexCallbackInfo {
3318 }
3419 }
3520
36- /// The timestamp for the input portion of the duplex stream.
37- ///
38- /// Contains the callback instant and when the input data was captured.
3921 pub fn input_timestamp ( & self ) -> InputStreamTimestamp {
4022 self . input_timestamp
4123 }
4224
43- /// The timestamp for the output portion of the duplex stream.
44- ///
45- /// Contains the callback instant and when the output data will be played.
4625 pub fn output_timestamp ( & self ) -> OutputStreamTimestamp {
4726 self . output_timestamp
4827 }
4928}
5029
51- /// Configuration for a duplex audio stream.
52- ///
53- /// Unlike separate input/output streams, duplex streams require matching
54- /// configuration for both directions since they share a single device context.
5530#[ derive( Clone , Debug , Eq , PartialEq ) ]
5631pub struct DuplexStreamConfig {
57- /// Number of input channels.
5832 pub input_channels : ChannelCount ,
59-
60- /// Number of output channels.
6133 pub output_channels : ChannelCount ,
62-
63- /// Sample rate in Hz.
6434 pub sample_rate : SampleRate ,
65-
66- /// Requested buffer size in frames.
6735 pub buffer_size : crate :: BufferSize ,
6836}
0 commit comments