Update docs for removal of UnknownTypeBuffer
This commit is contained in:
parent
6fc2185c99
commit
5a619877f9
|
@ -43,17 +43,17 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
let stream = match format.data_type {
|
let stream = match format.data_type {
|
||||||
cpal::SampleFormat::F32 => device.build_input_stream(
|
cpal::SampleFormat::F32 => device.build_input_stream(
|
||||||
&format,
|
&format,
|
||||||
move |mut data| write_input_data::<f32, f32>(&*data, &writer_2),
|
move |data| write_input_data::<f32, f32>(&*data, &writer_2),
|
||||||
err_fn,
|
err_fn,
|
||||||
),
|
),
|
||||||
cpal::SampleFormat::I16 => device.build_input_stream(
|
cpal::SampleFormat::I16 => device.build_input_stream(
|
||||||
&format,
|
&format,
|
||||||
move |mut data| write_input_data::<i16, i16>(&*data, &writer_2),
|
move |data| write_input_data::<i16, i16>(&*data, &writer_2),
|
||||||
err_fn,
|
err_fn,
|
||||||
),
|
),
|
||||||
cpal::SampleFormat::U16 => device.build_input_stream(
|
cpal::SampleFormat::U16 => device.build_input_stream(
|
||||||
&format,
|
&format,
|
||||||
move |mut data| write_input_data::<u16, i16>(&*data, &writer_2),
|
move |data| write_input_data::<u16, i16>(&*data, &writer_2),
|
||||||
err_fn,
|
err_fn,
|
||||||
),
|
),
|
||||||
}?;
|
}?;
|
||||||
|
|
54
src/lib.rs
54
src/lib.rs
|
@ -55,13 +55,14 @@
|
||||||
//! Now that we have everything for the stream, we are ready to create it from our selected device:
|
//! Now that we have everything for the stream, we are ready to create it from our selected device:
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
|
//! use cpal::OutputData;
|
||||||
//! use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
//! use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
//! # let host = cpal::default_host();
|
//! # let host = cpal::default_host();
|
||||||
//! # let device = host.default_output_device().unwrap();
|
//! # let device = host.default_output_device().unwrap();
|
||||||
//! # let format = device.default_output_format().unwrap();
|
//! # let format = device.default_output_format().unwrap();
|
||||||
//! let stream = device.build_output_stream(
|
//! let stream = device.build_output_stream(
|
||||||
//! &format,
|
//! &format,
|
||||||
//! move |data| {
|
//! move |data: OutputData<f32>| {
|
||||||
//! // react to stream events and read or write stream data here.
|
//! // react to stream events and read or write stream data here.
|
||||||
//! },
|
//! },
|
||||||
//! move |err| {
|
//! move |err| {
|
||||||
|
@ -71,10 +72,9 @@
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! While the stream is running, the selected audio device will periodically call the data callback
|
//! While the stream is running, the selected audio device will periodically call the data callback
|
||||||
//! that was passed to the function. The callback is passed an instance of type `StreamData` that
|
//! that was passed to the function. The callback is passed an instance of either `InputData<T>` or
|
||||||
//! represents the data that must be read from or written to. The inner `UnknownTypeOutputBuffer`
|
//! `OutputData<T>` depending on whether the stream is an input stream or output stream
|
||||||
//! can be one of `I16`, `U16` or `F32` depending on the format that was passed to
|
//! respectively. Type `T` represents the desired sample format type. Supported format types
|
||||||
//! `build_output_stream`.
|
|
||||||
//!
|
//!
|
||||||
//! > **Note**: Creating and running a stream will *not* block the thread. On modern platforms, the
|
//! > **Note**: Creating and running a stream will *not* block the thread. On modern platforms, the
|
||||||
//! > given callback is called by a dedicated, high-priority thread responsible for delivering
|
//! > given callback is called by a dedicated, high-priority thread responsible for delivering
|
||||||
|
@ -88,37 +88,23 @@
|
||||||
//! In this example, we simply fill the given output buffer with zeroes.
|
//! In this example, we simply fill the given output buffer with zeroes.
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use cpal::{StreamData, UnknownTypeOutputBuffer};
|
//! use cpal::{OutputData, Sample, SampleFormat};
|
||||||
//! use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
//! use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
//! # let host = cpal::default_host();
|
//! # let host = cpal::default_host();
|
||||||
//! # let device = host.default_output_device().unwrap();
|
//! # let device = host.default_output_device().unwrap();
|
||||||
//! # let format = device.default_output_format().unwrap();
|
//! # let format = device.default_output_format().unwrap();
|
||||||
//! let stream = device.build_output_stream(
|
//! let err_fn = move |err| eprintln!("an error occurred on the output audio stream: {}", err);
|
||||||
//! &format,
|
//! let stream = match format.data_type {
|
||||||
//! move |data| {
|
//! SampleFormat::F32 => device.build_output_stream(&format, write_silence::<f32>, err_fn),
|
||||||
//! match data {
|
//! SampleFormat::I16 => device.build_output_stream(&format, write_silence::<i16>, err_fn),
|
||||||
//! StreamData::Output { buffer: UnknownTypeOutputBuffer::U16(mut buffer) } => {
|
//! SampleFormat::U16 => device.build_output_stream(&format, write_silence::<u16>, err_fn),
|
||||||
//! for elem in buffer.iter_mut() {
|
//! };
|
||||||
//! *elem = u16::max_value() / 2;
|
//!
|
||||||
|
//! fn write_silence<T: Sample>(mut data: OutputData<T>) {
|
||||||
|
//! for sample in data.iter_mut() {
|
||||||
|
//! *sample = Sample::from(&0.0);
|
||||||
//! }
|
//! }
|
||||||
//! },
|
|
||||||
//! StreamData::Output { buffer: UnknownTypeOutputBuffer::I16(mut buffer) } => {
|
|
||||||
//! for elem in buffer.iter_mut() {
|
|
||||||
//! *elem = 0;
|
|
||||||
//! }
|
//! }
|
||||||
//! },
|
|
||||||
//! StreamData::Output { buffer: UnknownTypeOutputBuffer::F32(mut buffer) } => {
|
|
||||||
//! for elem in buffer.iter_mut() {
|
|
||||||
//! *elem = 0.0;
|
|
||||||
//! }
|
|
||||||
//! },
|
|
||||||
//! _ => (),
|
|
||||||
//! }
|
|
||||||
//! },
|
|
||||||
//! move |err| {
|
|
||||||
//! eprintln!("an error occurred on the output audio stream: {}", err);
|
|
||||||
//! },
|
|
||||||
//! );
|
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Not all platforms automatically run the stream upon creation. To ensure the stream has started,
|
//! Not all platforms automatically run the stream upon creation. To ensure the stream has started,
|
||||||
|
@ -129,7 +115,9 @@
|
||||||
//! # let host = cpal::default_host();
|
//! # let host = cpal::default_host();
|
||||||
//! # let device = host.default_output_device().unwrap();
|
//! # let device = host.default_output_device().unwrap();
|
||||||
//! # let format = device.default_output_format().unwrap();
|
//! # let format = device.default_output_format().unwrap();
|
||||||
//! # let stream = device.build_output_stream(&format, move |_data| {}, move |_err| {}).unwrap();
|
//! # let data_fn = move |_data: cpal::OutputData<f32>| {};
|
||||||
|
//! # let err_fn = move |_err| {};
|
||||||
|
//! # let stream = device.build_output_stream(&format, data_fn, err_fn).unwrap();
|
||||||
//! stream.play().unwrap();
|
//! stream.play().unwrap();
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -141,7 +129,9 @@
|
||||||
//! # let host = cpal::default_host();
|
//! # let host = cpal::default_host();
|
||||||
//! # let device = host.default_output_device().unwrap();
|
//! # let device = host.default_output_device().unwrap();
|
||||||
//! # let format = device.default_output_format().unwrap();
|
//! # let format = device.default_output_format().unwrap();
|
||||||
//! # let stream = device.build_output_stream(&format, move |_data| {}, move |_err| {}).unwrap();
|
//! # let data_fn = move |_data: cpal::OutputData<f32>| {};
|
||||||
|
//! # let err_fn = move |_err| {};
|
||||||
|
//! # let stream = device.build_output_stream(&format, data_fn, err_fn).unwrap();
|
||||||
//! stream.pause().unwrap();
|
//! stream.pause().unwrap();
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue