Skip to content

Commit 73179a0

Browse files
committed
adress feedback (I believe that this captures all changes requested)
1 parent 831a175 commit 73179a0

5 files changed

Lines changed: 533 additions & 558 deletions

File tree

examples/duplex_feedback.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
//! Feeds back the input stream directly into the output stream using a duplex stream.
2-
//!
3-
//! Unlike the `feedback.rs` example which uses separate input/output streams with a ring buffer,
4-
//! duplex streams provide hardware-synchronized input/output without additional buffering.
5-
//!
6-
//! Note: Currently only supported on macOS (CoreAudio). Windows (WASAPI) and Linux (ALSA)
7-
//! implementations are planned.
1+
// Duplex feedback example: feeds the input stream directly into the output.
82

93
#[cfg(target_os = "macos")]
104
mod imp {
@@ -41,7 +35,6 @@ mod imp {
4135
let opt = Opt::parse();
4236
let host = cpal::default_host();
4337

44-
// Find the device by device ID or use default
4538
let device = match opt.device {
4639
Some(device_id_str) => {
4740
let device_id = device_id_str.parse().expect("failed to parse device id");
@@ -55,7 +48,6 @@ mod imp {
5548

5649
println!("Using device: \"{}\"", device.description()?.name());
5750

58-
// Create duplex stream configuration.
5951
let config = DuplexStreamConfig {
6052
input_channels: opt.input_channels,
6153
output_channels: opt.output_channels,

src/duplex.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
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-
81
use 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)]
165
pub struct DuplexCallbackInfo {
176
input_timestamp: InputStreamTimestamp,
187
output_timestamp: OutputStreamTimestamp,
198
}
209

2110
impl 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)]
5631
pub 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

Comments
 (0)