Module audio_streams::capture
source · Expand description
use audio_streams::{BoxError, capture::CaptureBuffer, SampleFormat, StreamSource,
NoopStreamSource};
use std::io::Read;
const buffer_size: usize = 120;
const num_channels: usize = 2;
let mut stream_source = NoopStreamSource::new();
let sample_format = SampleFormat::S16LE;
let frame_size = num_channels * sample_format.sample_bytes();
let (_, mut stream) = stream_source
.new_capture_stream(num_channels, sample_format, 48000, buffer_size, &[])?;
// Capture 10 buffers of zeros.
let mut buf = Vec::new();
buf.resize(buffer_size * frame_size, 0xa5u8);
for _ in 0..10 {
let mut copy_func = |stream_buffer: &mut CaptureBuffer| {
assert_eq!(stream_buffer.read(&mut buf)?, buffer_size * frame_size);
Ok(())
};
stream.read_capture_buffer(&mut copy_func)?;
}
Structs§
- Async version of ’CaptureBuffer`
CaptureBuffer
contains a block of audio samples got from capture stream. It provides temporary view to those samples and will notifies capture stream when dropped. Note that it’ll always sendbuffer.len() / frame_size
to drop function when it got destroyed sinceCaptureBufferStream
assumes that users get all the samples from the buffer.- Stream that provides null capture samples.
Enums§
- Errors that are possible from a
CaptureBuffer
.
Traits§
CaptureBufferStream
providesCaptureBuffer
s to read with audio samples from capture.
Functions§
- Call
f
with aAsyncCaptureBuffer
, and trigger the buffer done call back after.f
can read the capture data from the givenAsyncCaptureBuffer
.