Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **CoreAudio**: A `None` timeout now waits indefinitely for sample rate and format changes, instead of giving up after 1 or 2 seconds.
- **Linux**: `realtime` can now promote threads without requiring `realtime-dbus`.
- **PipeWire**: Set `node.rate` property so that `default.clock.allowed-rates` PipeWire config works.
- Document the interleaved sample layout in stream callbacks.

### Deprecated

Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ pub struct SupportedStreamConfig {
/// A buffer of dynamically typed audio data, passed to raw stream callbacks.
///
/// Raw input stream callbacks receive `&Data`, while raw output stream callbacks expect `&mut Data`.
///
/// # Sample layout
///
/// Samples are interleaved by frame: each frame contains one sample per channel,
/// and all samples of a frame appear before those of the next frame. Interleaving
/// does not specify which speaker or input corresponds to each channel index.
///
/// Use the stream's channel count ([`StreamConfig::channels`]) as the chunk size
/// to iterate over frames in a sample slice. For example, a two-channel stream's
/// sample slice can be split like this:
///
/// ```
/// let samples = [0.1_f32, 0.2, 0.3, 0.4];
/// let mut frames = samples.chunks_exact(2);
/// assert_eq!(frames.next(), Some(&[0.1, 0.2][..]));
/// assert_eq!(frames.next(), Some(&[0.3, 0.4][..]));
/// ```
#[derive(Debug)]
pub struct Data {
data: *mut (),
Expand Down
17 changes: 10 additions & 7 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync {
///
/// * `config` - The stream configuration including sample rate, channels, and buffer size.
/// * `data_callback` - Called periodically with captured audio data. The callback receives
/// a slice of samples in the format `T` and timing information. It is real-time code: see
/// the [crate documentation](crate) for what you must not do in it.
/// a slice of [interleaved samples](Data#sample-layout) in the format `T` and timing
/// information. It is real-time code: see the [crate documentation](crate) for what you
/// must not do in it.
/// * `error_callback` - Called when a stream error occurs (e.g., device disconnected).
/// * `timeout` - Time to wait for the backend to initialize the stream. `None` waits
/// indefinitely; `Some(duration)` limits how long to wait. Note: not all backends honor
Expand Down Expand Up @@ -421,10 +422,11 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync {
///
/// * `config` - The stream configuration including sample rate, channels, and buffer size.
/// * `data_callback` - Called periodically to fill the output buffer. The callback receives
/// a mutable slice of samples in the format `T` to be filled with audio data, along with
/// timing information. The slice is pre-filled with silence, so a callback that writes
/// fewer samples than the slice holds leaves the remainder silent rather than stale. It is
/// real-time code: see the [crate documentation](crate) for what you must not do in it.
/// a mutable slice of [interleaved samples](Data#sample-layout) in the format `T` to be
/// filled with audio data, along with timing information. The slice is pre-filled with
/// silence, so a callback that writes fewer samples than the slice holds leaves the
/// remainder silent rather than stale. It is real-time code: see the
/// [crate documentation](crate) for what you must not do in it.
/// * `error_callback` - Called when a stream error occurs (e.g., device disconnected).
/// * `timeout` - Time to wait for the backend to initialize the stream. `None` waits
/// indefinitely; `Some(duration)` limits how long to wait. Note: not all backends honor
Expand Down Expand Up @@ -569,7 +571,8 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync {
/// callback.
///
/// cpal does not compensate for drift between the two directions, and does not mix or remap
/// channels between them.
/// channels between them. Each buffer contains [interleaved samples](Data#sample-layout)
/// grouped by its own channel count.
///
/// # Parameters
///
Expand Down
Loading