1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Chunk-based audio streaming for Rust.
//!
//! Two traits drive the whole crate:
//!
//! - [`AudioStream`] — pull source. [`fill_chunk`](AudioStream::fill_chunk) fills a
//! pre-allocated [`AudioSamples`](audio_samples::AudioSamples) buffer and returns the
//! frame count, or `None` when exhausted.
//! - [`AudioSink`] — push destination. [`write_chunk`](AudioSink::write_chunk) accepts the
//! same buffer; [`finalize`](AudioSink::finalize) must be called when writing is complete.
//!
//! # Sources and sinks
//!
//! | Type | Direction | Feature |
//! |------|-----------|---------|
//! | [`WavFileStream`] | source | `wav` |
//! | [`WavFileSink`] | sink | `wav` |
//! | [`FlacFileStream`] | source | `flac` |
//! | [`DeviceCapture`] | source | `device` |
//! | [`DevicePlayback`] | sink | `device` |
//! | [`RodioSource`] | source adapter | `rodio` |
//! | [`AsyncAudioStream`] | stream adapter | `async` |
//!
//! No features are enabled by default.
//!
//! # Quick start
//!
//! Read `input.wav` chunk by chunk and write it to `output.wav`, using
//! [`pipeline::run`] to drive the loop. Insert per-chunk processing between
//! source and sink by writing a manual loop instead — see the `manual_loop` example.
//!
//! ```no_run
//! # #[cfg(feature = "wav")] {
//! use std::num::{NonZeroU32, NonZeroUsize};
//! use audio_samples::AudioSamples;
//! use audio_samples_streaming::{WavFileStream, WavFileSink, pipeline};
//!
//! let mut source = WavFileStream::<_, f32>::open("input.wav").unwrap();
//! let mut sink = WavFileSink::<_, f32>::create("output.wav",
//! source.num_channels(), source.sample_rate()).unwrap();
//!
//! let mut buffer = AudioSamples::<f32>::zeros_multi_channel(
//! NonZeroU32::new(source.num_channels() as u32).unwrap(),
//! NonZeroUsize::new(1024).unwrap(),
//! NonZeroU32::new(source.sample_rate()).unwrap(),
//! );
//!
//! pipeline::run(&mut source, &mut sink, &mut buffer).unwrap();
//! sink.finalize().unwrap();
//! # }
//! ```
//!
//! # Device I/O
//!
//! Enable the `device` feature for real-time capture and playback. Both types use a
//! lock-free ring buffer and condvar notification — no spin-sleep, no hot-path allocation.
//! Pass a [`Duration`](std::time::Duration) to request a specific callback period; `None`
//! uses the driver default.
//!
//! ```no_run
//! # #[cfg(feature = "device")] {
//! use std::time::Duration;
//! use audio_samples_streaming::{DeviceCapture, DevicePlayback};
//!
//! let capture = DeviceCapture::from_default_input(Some(Duration::from_millis(5))).unwrap();
//! let playback = DevicePlayback::from_default_output(Some(Duration::from_millis(5))).unwrap();
//!
//! println!("Capture: {} Hz {} ch", capture.sample_rate(), capture.channels());
//! println!("Playback: {} Hz {} ch", playback.sample_rate(), playback.channels());
//! # }
//! ```
pub
pub use ;
pub use ;
pub use WavFileSink;
pub use FlacFileStream;
pub use WavFileStream;
pub use DevicePlayback;
pub use DeviceCapture;
pub use AsyncAudioStream;
pub use RodioSource;