Migrate Sample to dasp_sample (#689)

This commit is contained in:
Kai Giebeler 2022-10-07 14:08:28 +02:00 • committed by est31
parent 8c31e908b0
commit 85d773d59f
17 changed files with 337 additions and 355 deletions

View file

@ -312,9 +312,9 @@ impl Device {
let hw_params = alsa::pcm::HwParams::any(handle)?;
// TODO: check endianness
const FORMATS: [(SampleFormat, alsa::pcm::Format); 3] = [
//SND_PCM_FORMAT_S8,
//SND_PCM_FORMAT_U8,
const FORMATS: [(SampleFormat, alsa::pcm::Format); 8] = [
(SampleFormat::I8, alsa::pcm::Format::S8),
(SampleFormat::U8, alsa::pcm::Format::U8),
(SampleFormat::I16, alsa::pcm::Format::S16LE),
//SND_PCM_FORMAT_S16_BE,
(SampleFormat::U16, alsa::pcm::Format::U16LE),
@ -323,13 +323,13 @@ impl Device {
//SND_PCM_FORMAT_S24_BE,
//SND_PCM_FORMAT_U24_LE,
//SND_PCM_FORMAT_U24_BE,
//SND_PCM_FORMAT_S32_LE,
(SampleFormat::I32, alsa::pcm::Format::S32LE),
//SND_PCM_FORMAT_S32_BE,
//SND_PCM_FORMAT_U32_LE,
(SampleFormat::U32, alsa::pcm::Format::U32LE),
//SND_PCM_FORMAT_U32_BE,
(SampleFormat::F32, alsa::pcm::Format::FloatLE),
//SND_PCM_FORMAT_FLOAT_BE,
//SND_PCM_FORMAT_FLOAT64_LE,
(SampleFormat::F64, alsa::pcm::Format::Float64LE),
//SND_PCM_FORMAT_FLOAT64_BE,
//SND_PCM_FORMAT_IEC958_SUBFRAME_LE,
//SND_PCM_FORMAT_IEC958_SUBFRAME_BE,
@ -956,15 +956,53 @@ fn set_hw_params_from_format(
let sample_format = if cfg!(target_endian = "big") {
match sample_format {
SampleFormat::I8 => alsa::pcm::Format::S8,
SampleFormat::I16 => alsa::pcm::Format::S16BE,
// SampleFormat::I24 => alsa::pcm::Format::S24BE,
SampleFormat::I32 => alsa::pcm::Format::S32BE,
// SampleFormat::I48 => alsa::pcm::Format::S48BE,
// SampleFormat::I64 => alsa::pcm::Format::S64BE,
SampleFormat::U8 => alsa::pcm::Format::U8,
SampleFormat::U16 => alsa::pcm::Format::U16BE,
// SampleFormat::U24 => alsa::pcm::Format::U24BE,
SampleFormat::U32 => alsa::pcm::Format::U32BE,
// SampleFormat::U48 => alsa::pcm::Format::U48BE,
// SampleFormat::U64 => alsa::pcm::Format::U64BE,
SampleFormat::F32 => alsa::pcm::Format::FloatBE,
SampleFormat::F64 => alsa::pcm::Format::Float64BE,
sample_format => {
return Err(BackendSpecificError {
description: format!(
"Sample format '{}' is not supported by this backend",
sample_format
),
})
}
}
} else {
match sample_format {
SampleFormat::I8 => alsa::pcm::Format::S8,
SampleFormat::I16 => alsa::pcm::Format::S16LE,
// SampleFormat::I24 => alsa::pcm::Format::S24LE,
SampleFormat::I32 => alsa::pcm::Format::S32LE,
// SampleFormat::I48 => alsa::pcm::Format::S48LE,
// SampleFormat::I64 => alsa::pcm::Format::S64LE,
SampleFormat::U8 => alsa::pcm::Format::U8,
SampleFormat::U16 => alsa::pcm::Format::U16LE,
// SampleFormat::U24 => alsa::pcm::Format::U24LE,
SampleFormat::U32 => alsa::pcm::Format::U32LE,
// SampleFormat::U48 => alsa::pcm::Format::U48LE,
// SampleFormat::U64 => alsa::pcm::Format::U64LE,
SampleFormat::F32 => alsa::pcm::Format::FloatLE,
SampleFormat::F64 => alsa::pcm::Format::Float64LE,
sample_format => {
return Err(BackendSpecificError {
description: format!(
"Sample format '{}' is not supported by this backend",
sample_format
),
})
}
}
};

View file

@ -61,7 +61,7 @@ impl Device {
) -> Result<SupportedInputConfigs, SupportedStreamConfigsError> {
// Retrieve the default config for the total supported channels and supported sample
// format.
let mut f = match self.default_input_config() {
let f = match self.default_input_config() {
Err(_) => return Err(SupportedStreamConfigsError::DeviceNotAvailable),
Ok(f) => f,
};
@ -98,7 +98,7 @@ impl Device {
) -> Result<SupportedOutputConfigs, SupportedStreamConfigsError> {
// Retrieve the default config for the total supported channels and supported sample
// format.
let mut f = match self.default_output_config() {
let f = match self.default_output_config() {
Err(_) => return Err(SupportedStreamConfigsError::DeviceNotAvailable),
Ok(f) => f,
};

View file

@ -1,12 +1,12 @@
extern crate asio_sys as sys;
extern crate parking_lot;
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
use crate::{
BuildStreamError, Data, DefaultStreamConfigError, DeviceNameError, DevicesError,
InputCallbackInfo, OutputCallbackInfo, PauseStreamError, PlayStreamError, SampleFormat,
StreamConfig, StreamError, SupportedStreamConfig, SupportedStreamConfigsError,
};
use traits::{DeviceTrait, HostTrait, StreamTrait};
pub use self::device::{Device, Devices, SupportedInputConfigs, SupportedOutputConfigs};
pub use self::stream::Stream;

View file

@ -6,24 +6,13 @@ use super::parking_lot::Mutex;
use super::Device;
use crate::{
BackendSpecificError, BufferSize, BuildStreamError, Data, InputCallbackInfo,
OutputCallbackInfo, PauseStreamError, PlayStreamError, Sample, SampleFormat, StreamConfig,
OutputCallbackInfo, PauseStreamError, PlayStreamError, SampleFormat, SizedSample, StreamConfig,
StreamError,
};
use std;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
/// Sample types whose constant silent value is known.
trait Silence {
const SILENCE: Self;
}
/// Constraints on the ASIO sample types.
trait AsioSample: Clone + Copy + Silence + std::ops::Add<Self, Output = Self> {
fn to_cpal_sample<T: Sample>(&self) -> T;
fn from_cpal_sample<T: Sample>(_: &T) -> Self;
}
// Used to keep track of whether or not the current asio stream buffer requires
// being silencing before summing audio.
#[derive(Default)]
@ -103,7 +92,7 @@ impl Device {
/// 1. Write from the ASIO buffer to the interleaved CPAL buffer.
/// 2. Deliver the CPAL buffer to the user callback.
unsafe fn process_input_callback<A, B, D, F>(
unsafe fn process_input_callback<A, D, F>(
data_callback: &mut D,
interleaved: &mut [u8],
asio_stream: &sys::AsioStream,
@ -111,27 +100,26 @@ impl Device {
sample_rate: crate::SampleRate,
from_endianness: F,
) where
A: AsioSample,
B: Sample,
A: SizedSample,
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
F: Fn(A) -> A,
{
// 1. Write the ASIO channels to the CPAL buffer.
let interleaved: &mut [B] = cast_slice_mut(interleaved);
let interleaved: &mut [A] = cast_slice_mut(interleaved);
let n_frames = asio_stream.buffer_size as usize;
let n_channels = interleaved.len() / n_frames;
let buffer_index = asio_info.buffer_index as usize;
for ch_ix in 0..n_channels {
let asio_channel = asio_channel_slice::<A>(asio_stream, buffer_index, ch_ix);
for (frame, s_asio) in interleaved.chunks_mut(n_channels).zip(asio_channel) {
frame[ch_ix] = from_endianness(*s_asio).to_cpal_sample();
frame[ch_ix] = from_endianness(*s_asio);
}
}
// 2. Deliver the interleaved buffer to the callback.
let data = interleaved.as_mut_ptr() as *mut ();
let len = interleaved.len();
let data = Data::from_parts(data, len, B::FORMAT);
let data = Data::from_parts(data, len, A::FORMAT);
let callback = system_time_to_stream_instant(asio_info.system_time);
let delay = frames_to_duration(n_frames, sample_rate);
let capture = callback
@ -144,7 +132,7 @@ impl Device {
match (&stream_type, sample_format) {
(&sys::AsioSampleType::ASIOSTInt16LSB, SampleFormat::I16) => {
process_input_callback::<i16, i16, _, _>(
process_input_callback::<i16, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -154,7 +142,7 @@ impl Device {
);
}
(&sys::AsioSampleType::ASIOSTInt16MSB, SampleFormat::I16) => {
process_input_callback::<i16, i16, _, _>(
process_input_callback::<i16, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -168,7 +156,7 @@ impl Device {
// trait for the `to_le` and `to_be` methods, but this does not support floats.
(&sys::AsioSampleType::ASIOSTFloat32LSB, SampleFormat::F32)
| (&sys::AsioSampleType::ASIOSTFloat32MSB, SampleFormat::F32) => {
process_input_callback::<f32, f32, _, _>(
process_input_callback::<f32, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -178,11 +166,8 @@ impl Device {
);
}
// TODO: Add support for the following sample formats to CPAL and simplify the
// `process_output_callback` function above by removing the unnecessary sample
// conversion function.
(&sys::AsioSampleType::ASIOSTInt32LSB, SampleFormat::I16) => {
process_input_callback::<i32, i16, _, _>(
(&sys::AsioSampleType::ASIOSTInt32LSB, SampleFormat::I32) => {
process_input_callback::<i32, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -191,8 +176,8 @@ impl Device {
from_le,
);
}
(&sys::AsioSampleType::ASIOSTInt32MSB, SampleFormat::I16) => {
process_input_callback::<i32, i16, _, _>(
(&sys::AsioSampleType::ASIOSTInt32MSB, SampleFormat::I32) => {
process_input_callback::<i32, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -201,11 +186,12 @@ impl Device {
from_be,
);
}
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
// trait for the `to_le` and `to_be` methods, but this does not support floats.
(&sys::AsioSampleType::ASIOSTFloat64LSB, SampleFormat::F32)
| (&sys::AsioSampleType::ASIOSTFloat64MSB, SampleFormat::F32) => {
process_input_callback::<f64, f32, _, _>(
(&sys::AsioSampleType::ASIOSTFloat64LSB, SampleFormat::F64)
| (&sys::AsioSampleType::ASIOSTFloat64MSB, SampleFormat::F64) => {
process_input_callback::<f64, _, _>(
&mut data_callback,
&mut interleaved,
asio_stream,
@ -310,7 +296,7 @@ impl Device {
/// 2. If required, silence the ASIO buffer.
/// 3. Finally, write the interleaved data to the non-interleaved ASIO buffer,
/// performing endianness conversions as necessary.
unsafe fn process_output_callback<A, B, D, F>(
unsafe fn process_output_callback<A, D, F>(
data_callback: &mut D,
interleaved: &mut [u8],
silence_asio_buffer: bool,
@ -319,10 +305,9 @@ impl Device {
sample_rate: crate::SampleRate,
to_endianness: F,
) where
A: Sample,
B: AsioSample,
A: SizedSample + std::ops::Add<Output = A>,
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static,
F: Fn(B) -> B,
F: Fn(A) -> A,
{
// 1. Render interleaved buffer from callback.
let interleaved: &mut [A] = cast_slice_mut(interleaved);
@ -345,26 +330,26 @@ impl Device {
if silence_asio_buffer {
for ch_ix in 0..n_channels {
let asio_channel =
asio_channel_slice_mut::<B>(asio_stream, buffer_index, ch_ix);
asio_channel_slice_mut::<A>(asio_stream, buffer_index, ch_ix);
asio_channel
.iter_mut()
.for_each(|s| *s = to_endianness(B::SILENCE));
.for_each(|s| *s = to_endianness(A::EQUILIBRIUM));
}
}
// 3. Write interleaved samples to ASIO channels, one channel at a time.
for ch_ix in 0..n_channels {
let asio_channel =
asio_channel_slice_mut::<B>(asio_stream, buffer_index, ch_ix);
asio_channel_slice_mut::<A>(asio_stream, buffer_index, ch_ix);
for (frame, s_asio) in interleaved.chunks(n_channels).zip(asio_channel) {
*s_asio = *s_asio + to_endianness(B::from_cpal_sample(&frame[ch_ix]));
*s_asio = *s_asio + to_endianness(A::from_sample(frame[ch_ix]));
}
}
}
match (sample_format, &stream_type) {
(SampleFormat::I16, &sys::AsioSampleType::ASIOSTInt16LSB) => {
process_output_callback::<i16, i16, _, _>(
process_output_callback::<i16, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -375,7 +360,7 @@ impl Device {
);
}
(SampleFormat::I16, &sys::AsioSampleType::ASIOSTInt16MSB) => {
process_output_callback::<i16, i16, _, _>(
process_output_callback::<i16, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -390,7 +375,7 @@ impl Device {
// trait for the `to_le` and `to_be` methods, but this does not support floats.
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32LSB)
| (SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32MSB) => {
process_output_callback::<f32, f32, _, _>(
process_output_callback::<f32, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -401,11 +386,8 @@ impl Device {
);
}
// TODO: Add support for the following sample formats to CPAL and simplify the
// `process_output_callback` function above by removing the unnecessary sample
// conversion function.
(SampleFormat::I16, &sys::AsioSampleType::ASIOSTInt32LSB) => {
process_output_callback::<i16, i32, _, _>(
(SampleFormat::I32, &sys::AsioSampleType::ASIOSTInt32LSB) => {
process_output_callback::<i32, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -415,8 +397,8 @@ impl Device {
to_le,
);
}
(SampleFormat::I16, &sys::AsioSampleType::ASIOSTInt32MSB) => {
process_output_callback::<i16, i32, _, _>(
(SampleFormat::I32, &sys::AsioSampleType::ASIOSTInt32MSB) => {
process_output_callback::<i32, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -426,11 +408,12 @@ impl Device {
to_be,
);
}
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
// trait for the `to_le` and `to_be` methods, but this does not support floats.
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64LSB)
| (SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64MSB) => {
process_output_callback::<f32, f64, _, _>(
(SampleFormat::F64, &sys::AsioSampleType::ASIOSTFloat64LSB)
| (SampleFormat::F64, &sys::AsioSampleType::ASIOSTFloat64MSB) => {
process_output_callback::<f64, _, _>(
&mut data_callback,
&mut interleaved,
silence,
@ -566,62 +549,6 @@ impl Drop for Stream {
}
}
impl Silence for i16 {
const SILENCE: Self = 0;
}
impl Silence for i32 {
const SILENCE: Self = 0;
}
impl Silence for f32 {
const SILENCE: Self = 0.0;
}
impl Silence for f64 {
const SILENCE: Self = 0.0;
}
impl AsioSample for i16 {
fn to_cpal_sample<T: Sample>(&self) -> T {
T::from(self)
}
fn from_cpal_sample<T: Sample>(t: &T) -> Self {
Sample::from(t)
}
}
impl AsioSample for i32 {
fn to_cpal_sample<T: Sample>(&self) -> T {
let s = (*self >> 16) as i16;
s.to_cpal_sample()
}
fn from_cpal_sample<T: Sample>(t: &T) -> Self {
let s = i16::from_cpal_sample(t);
(s as i32) << 16
}
}
impl AsioSample for f32 {
fn to_cpal_sample<T: Sample>(&self) -> T {
T::from(self)
}
fn from_cpal_sample<T: Sample>(t: &T) -> Self {
Sample::from(t)
}
}
impl AsioSample for f64 {
fn to_cpal_sample<T: Sample>(&self) -> T {
let f = *self as f32;
f.to_cpal_sample()
}
fn from_cpal_sample<T: Sample>(t: &T) -> Self {
let f = f32::from_cpal_sample(t);
f as f64
}
}
fn asio_ns_to_double(val: sys::bindings::asio_import::ASIOTimeStamp) -> f64 {
let two_raised_to_32 = 4294967296.0;
val.lo as f64 + val.hi as f64 * two_raised_to_32
@ -657,7 +584,7 @@ fn check_config(
let StreamConfig {
channels,
sample_rate,
buffer_size,
buffer_size: _,
} = config;
// Try and set the sample rate to what the user selected.
let sample_rate = sample_rate.0.into();
@ -676,7 +603,7 @@ fn check_config(
// unsigned formats are not supported by asio
match sample_format {
SampleFormat::I16 | SampleFormat::F32 => (),
SampleFormat::U16 => return Err(BuildStreamError::StreamConfigNotSupported),
_ => return Err(BuildStreamError::StreamConfigNotSupported),
}
if *channels > num_asio_channels {
return Err(BuildStreamError::StreamConfigNotSupported);

View file

@ -4,7 +4,7 @@ use std::time::Instant;
extern crate oboe;
use super::convert::{stream_instant, to_stream_instant};
use crate::{Data, InputCallbackInfo, InputStreamTimestamp, Sample, StreamError};
use crate::{Data, InputCallbackInfo, InputStreamTimestamp, SizedSample, StreamError};
pub struct CpalInputCallback<I, C> {
data_cb: Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static>,
@ -42,7 +42,7 @@ impl<I, C> CpalInputCallback<I, C> {
}
}
impl<T: Sample, C: oboe::IsChannelCount> oboe::AudioInputCallback for CpalInputCallback<T, C>
impl<T: SizedSample, C: oboe::IsChannelCount> oboe::AudioInputCallback for CpalInputCallback<T, C>
where
(T, C): oboe::IsFrameType,
{

View file

@ -9,7 +9,7 @@ use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
use crate::{
BackendSpecificError, BufferSize, BuildStreamError, Data, DefaultStreamConfigError,
DeviceNameError, DevicesError, InputCallbackInfo, OutputCallbackInfo, PauseStreamError,
PlayStreamError, Sample, SampleFormat, SampleRate, StreamConfig, StreamError,
PlayStreamError, SampleFormat, SampleRate, SizedSample, StreamConfig, StreamError,
SupportedBufferSize, SupportedStreamConfig, SupportedStreamConfigRange,
SupportedStreamConfigsError,
};
@ -225,7 +225,7 @@ fn build_input_stream<D, E, C, T>(
builder: oboe::AudioStreamBuilder<oboe::Input, C, T>,
) -> Result<Stream, BuildStreamError>
where
T: Sample + oboe::IsFormat + Send + 'static,
T: SizedSample + oboe::IsFormat + Send + 'static,
C: oboe::IsChannelCount + Send + 'static,
(T, C): oboe::IsFrameType,
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
@ -249,7 +249,7 @@ fn build_output_stream<D, E, C, T>(
builder: oboe::AudioStreamBuilder<oboe::Output, C, T>,
) -> Result<Stream, BuildStreamError>
where
T: Sample + oboe::IsFormat + Send + 'static,
T: SizedSample + oboe::IsFormat + Send + 'static,
C: oboe::IsChannelCount + Send + 'static,
(T, C): oboe::IsFrameType,
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static,
@ -385,8 +385,8 @@ impl DeviceTrait for Device {
.into())
}
}
SampleFormat::U16 => Err(BackendSpecificError {
description: "U16 format is not supported on Android.".to_owned(),
sample_format => Err(BackendSpecificError {
description: format!("{} format is not supported on Android.", sample_format),
}
.into()),
}
@ -458,8 +458,8 @@ impl DeviceTrait for Device {
.into())
}
}
SampleFormat::U16 => Err(BackendSpecificError {
description: "U16 format is not supported on Android.".to_owned(),
sample_format => Err(BackendSpecificError {
description: format!("{} format is not supported on Android.", sample_format),
}
.into()),
}

View file

@ -4,7 +4,7 @@ use std::time::Instant;
extern crate oboe;
use super::convert::{stream_instant, to_stream_instant};
use crate::{Data, OutputCallbackInfo, OutputStreamTimestamp, Sample, StreamError};
use crate::{Data, OutputCallbackInfo, OutputStreamTimestamp, SizedSample, StreamError};
pub struct CpalOutputCallback<I, C> {
data_cb: Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static>,
@ -42,7 +42,7 @@ impl<I, C> CpalOutputCallback<I, C> {
}
}
impl<T: Sample, C: oboe::IsChannelCount> oboe::AudioOutputCallback for CpalOutputCallback<T, C>
impl<T: SizedSample, C: oboe::IsChannelCount> oboe::AudioOutputCallback for CpalOutputCallback<T, C>
where
(T, C): oboe::IsFrameType,
{

View file

@ -6,7 +6,6 @@ use crate::{
SupportedStreamConfigsError, COMMON_SAMPLE_RATES,
};
use once_cell::sync::Lazy;
use std;
use std::ffi::OsString;
use std::fmt;
use std::mem;
@ -453,10 +452,7 @@ impl Device {
.map_err(windows_err_to_cpal_err::<SupportedStreamConfigsError>)?;
// If the default format can't succeed we have no hope of finding other formats.
assert_eq!(
is_format_supported(client, default_waveformatex_ptr.0)?,
true
);
assert!(is_format_supported(client, default_waveformatex_ptr.0)?);
// Copy the format to use as a test format (as to avoid mutating the original format).
let mut test_format = {
@ -496,7 +492,7 @@ impl Device {
// TODO: Test the different sample formats?
// Create the supported formats.
let format = match format_from_waveformatex_ptr(default_waveformatex_ptr.0, &client) {
let format = match format_from_waveformatex_ptr(default_waveformatex_ptr.0, client) {
Some(fmt) => fmt,
None => {
let description =
@ -509,11 +505,11 @@ impl Device {
let mut supported_formats = Vec::with_capacity(supported_sample_rates.len());
for rate in supported_sample_rates {
supported_formats.push(SupportedStreamConfigRange {
channels: format.channels.clone(),
channels: format.channels,
min_sample_rate: SampleRate(rate as _),
max_sample_rate: SampleRate(rate as _),
buffer_size: format.buffer_size.clone(),
sample_format: format.sample_format.clone(),
sample_format: format.sample_format,
})
}
Ok(supported_formats.into_iter())
@ -1015,7 +1011,7 @@ fn config_to_waveformatextensible(
let format_tag = match sample_format {
SampleFormat::I16 => Audio::WAVE_FORMAT_PCM,
SampleFormat::F32 => KernelStreaming::WAVE_FORMAT_EXTENSIBLE,
SampleFormat::U16 => return None,
_ => return None,
} as u16;
let channels = config.channels;
let sample_rate = config.sample_rate.0;
@ -1030,7 +1026,7 @@ fn config_to_waveformatextensible(
let ex_size = mem::size_of::<Audio::WAVEFORMATEX>();
(extensible_size - ex_size) as u16
}
SampleFormat::U16 => return None,
_ => return None,
};
let waveformatex = Audio::WAVEFORMATEX {
wFormatTag: format_tag,
@ -1048,7 +1044,7 @@ fn config_to_waveformatextensible(
let sub_format = match sample_format {
SampleFormat::I16 => KernelStreaming::KSDATAFORMAT_SUBTYPE_PCM,
SampleFormat::F32 => Multimedia::KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
SampleFormat::U16 => return None,
_ => return None,
};
let waveformatextensible = Audio::WAVEFORMATEXTENSIBLE {
Format: waveformatex,

View file

@ -287,7 +287,7 @@ fn run_input(
_ => unreachable!(),
};
match process_input(
&mut run_ctxt.stream,
&run_ctxt.stream,
capture_client,
data_callback,
error_callback,
@ -314,7 +314,7 @@ fn run_output(
_ => unreachable!(),
};
match process_output(
&mut run_ctxt.stream,
&run_ctxt.stream,
render_client,
data_callback,
error_callback,
@ -439,7 +439,7 @@ fn process_output(
error_callback: &mut dyn FnMut(StreamError),
) -> ControlFlow {
// The number of frames available for writing.
let frames_available = match get_available_frames(&stream) {
let frames_available = match get_available_frames(stream) {
Ok(0) => return ControlFlow::Continue, // TODO: Can this happen?
Ok(n) => n,
Err(err) => {