mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 06:04:16 +00:00
update cpal to 0.15 (#478)
This commit is contained in:
parent
317ec569fe
commit
0c0e086b6a
10 changed files with 118 additions and 26 deletions
|
@ -11,7 +11,7 @@ exclude = ["assets/**", "tests/**"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cpal = "0.14"
|
cpal = "0.15"
|
||||||
claxon = { version = "0.4.2", optional = true }
|
claxon = { version = "0.4.2", optional = true }
|
||||||
hound = { version = "3.3.1", optional = true }
|
hound = { version = "3.3.1", optional = true }
|
||||||
lewton = { version = "0.10", optional = true }
|
lewton = { version = "0.10", optional = true }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use cpal::Sample as CpalSample;
|
use cpal::{FromSample, Sample as CpalSample};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
/// Converts the samples data type to `O`.
|
/// Converts the samples data type to `O`.
|
||||||
|
@ -29,13 +29,13 @@ impl<I, O> Iterator for DataConverter<I, O>
|
||||||
where
|
where
|
||||||
I: Iterator,
|
I: Iterator,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
O: Sample,
|
O: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
type Item = O;
|
type Item = O;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<O> {
|
fn next(&mut self) -> Option<O> {
|
||||||
self.input.next().map(|s| CpalSample::from(&s))
|
self.input.next().map(|s| CpalSample::from_sample(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -48,7 +48,7 @@ impl<I, O> ExactSizeIterator for DataConverter<I, O>
|
||||||
where
|
where
|
||||||
I: ExactSizeIterator,
|
I: ExactSizeIterator,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
O: Sample,
|
O: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ impl Sample for u16 {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn amplify(self, value: f32) -> u16 {
|
fn amplify(self, value: f32) -> u16 {
|
||||||
self.to_i16().amplify(value).to_u16()
|
((self as f32) * value) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::time::Duration;
|
||||||
|
|
||||||
use crate::stream::{OutputStreamHandle, PlayError};
|
use crate::stream::{OutputStreamHandle, PlayError};
|
||||||
use crate::{queue, source::Done, Sample, Source};
|
use crate::{queue, source::Done, Sample, Source};
|
||||||
|
use cpal::FromSample;
|
||||||
|
|
||||||
/// Handle to an device that outputs sounds.
|
/// Handle to an device that outputs sounds.
|
||||||
///
|
///
|
||||||
|
@ -61,8 +62,8 @@ impl Sink {
|
||||||
pub fn append<S>(&self, source: S)
|
pub fn append<S>(&self, source: S)
|
||||||
where
|
where
|
||||||
S: Source + Send + 'static,
|
S: Source + Send + 'static,
|
||||||
S::Item: Sample,
|
f32: FromSample<S::Item>,
|
||||||
S::Item: Send,
|
S::Item: Sample + Send,
|
||||||
{
|
{
|
||||||
let controls = self.controls.clone();
|
let controls = self.controls.clone();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cpal::FromSample;
|
||||||
|
|
||||||
use crate::source::{FadeIn, Mix, TakeDuration};
|
use crate::source::{FadeIn, Mix, TakeDuration};
|
||||||
use crate::{Sample, Source};
|
use crate::{Sample, Source};
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ pub fn crossfade<I1, I2>(
|
||||||
where
|
where
|
||||||
I1: Source,
|
I1: Source,
|
||||||
I2: Source,
|
I2: Source,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
let mut input_fadeout = input_fadeout.take_duration(duration);
|
let mut input_fadeout = input_fadeout.take_duration(duration);
|
||||||
|
|
|
@ -3,12 +3,13 @@ use std::time::Duration;
|
||||||
|
|
||||||
use crate::source::uniform::UniformSourceIterator;
|
use crate::source::uniform::UniformSourceIterator;
|
||||||
use crate::{Sample, Source};
|
use crate::{Sample, Source};
|
||||||
|
use cpal::{FromSample, Sample as CpalSample};
|
||||||
|
|
||||||
/// Internal function that builds a `Mix` object.
|
/// Internal function that builds a `Mix` object.
|
||||||
pub fn mix<I1, I2>(input1: I1, input2: I2) -> Mix<I1, I2>
|
pub fn mix<I1, I2>(input1: I1, input2: I2) -> Mix<I1, I2>
|
||||||
where
|
where
|
||||||
I1: Source,
|
I1: Source,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2: Source,
|
I2: Source,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
|
@ -26,18 +27,18 @@ where
|
||||||
pub struct Mix<I1, I2>
|
pub struct Mix<I1, I2>
|
||||||
where
|
where
|
||||||
I1: Source,
|
I1: Source,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2: Source,
|
I2: Source,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
input1: UniformSourceIterator<I1, I1::Item>,
|
input1: UniformSourceIterator<I1, I1::Item>,
|
||||||
input2: UniformSourceIterator<I2, I1::Item>,
|
input2: UniformSourceIterator<I2, I2::Item>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I1, I2> Iterator for Mix<I1, I2>
|
impl<I1, I2> Iterator for Mix<I1, I2>
|
||||||
where
|
where
|
||||||
I1: Source,
|
I1: Source,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2: Source,
|
I2: Source,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
|
@ -49,9 +50,9 @@ where
|
||||||
let s2 = self.input2.next();
|
let s2 = self.input2.next();
|
||||||
|
|
||||||
match (s1, s2) {
|
match (s1, s2) {
|
||||||
(Some(s1), Some(s2)) => Some(s1.saturating_add(s2)),
|
(Some(s1), Some(s2)) => Some(s1.saturating_add(CpalSample::from_sample(s2))),
|
||||||
(Some(s1), None) => Some(s1),
|
(Some(s1), None) => Some(s1),
|
||||||
(None, Some(s2)) => Some(s2),
|
(None, Some(s2)) => Some(CpalSample::from_sample(s2)),
|
||||||
(None, None) => None,
|
(None, None) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ where
|
||||||
impl<I1, I2> ExactSizeIterator for Mix<I1, I2>
|
impl<I1, I2> ExactSizeIterator for Mix<I1, I2>
|
||||||
where
|
where
|
||||||
I1: Source + ExactSizeIterator,
|
I1: Source + ExactSizeIterator,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2: Source + ExactSizeIterator,
|
I2: Source + ExactSizeIterator,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
|
@ -83,7 +84,7 @@ where
|
||||||
impl<I1, I2> Source for Mix<I1, I2>
|
impl<I1, I2> Source for Mix<I1, I2>
|
||||||
where
|
where
|
||||||
I1: Source,
|
I1: Source,
|
||||||
I1::Item: Sample,
|
I1::Item: FromSample<I2::Item> + Sample,
|
||||||
I2: Source,
|
I2: Source,
|
||||||
I2::Item: Sample,
|
I2::Item: Sample,
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cpal::FromSample;
|
||||||
|
|
||||||
use crate::Sample;
|
use crate::Sample;
|
||||||
|
|
||||||
pub use self::amplify::Amplify;
|
pub use self::amplify::Amplify;
|
||||||
|
@ -158,6 +160,7 @@ where
|
||||||
fn mix<S>(self, other: S) -> Mix<Self, S>
|
fn mix<S>(self, other: S) -> Mix<Self, S>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
Self::Item: FromSample<S::Item>,
|
||||||
S: Source,
|
S: Source,
|
||||||
S::Item: Sample,
|
S::Item: Sample,
|
||||||
{
|
{
|
||||||
|
@ -224,6 +227,7 @@ where
|
||||||
fn take_crossfade_with<S: Source>(self, other: S, duration: Duration) -> Crossfade<Self, S>
|
fn take_crossfade_with<S: Source>(self, other: S, duration: Duration) -> Crossfade<Self, S>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
Self::Item: FromSample<S::Item>,
|
||||||
<S as Iterator>::Item: Sample,
|
<S as Iterator>::Item: Sample,
|
||||||
{
|
{
|
||||||
crossfade::crossfade(self, other, duration)
|
crossfade::crossfade(self, other, duration)
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::{Sample, Source};
|
use crate::{Sample, Source};
|
||||||
use cpal::Sample as CpalSample;
|
use cpal::{FromSample, Sample as CpalSample};
|
||||||
|
|
||||||
/// An iterator that reads from a `Source` and converts the samples to a specific rate and
|
/// An iterator that reads from a `Source` and converts the samples to a specific rate and
|
||||||
/// channels count.
|
/// channels count.
|
||||||
|
@ -47,13 +47,13 @@ impl<I, D> Iterator for SamplesConverter<I, D>
|
||||||
where
|
where
|
||||||
I: Source,
|
I: Source,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
D: Sample,
|
D: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
type Item = D;
|
type Item = D;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<D> {
|
fn next(&mut self) -> Option<D> {
|
||||||
self.inner.next().map(|s| CpalSample::from(&s))
|
self.inner.next().map(|s| CpalSample::from_sample(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -66,7 +66,7 @@ impl<I, D> ExactSizeIterator for SamplesConverter<I, D>
|
||||||
where
|
where
|
||||||
I: Source + ExactSizeIterator,
|
I: Source + ExactSizeIterator,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
D: Sample,
|
D: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ impl<I, D> Source for SamplesConverter<I, D>
|
||||||
where
|
where
|
||||||
I: Source,
|
I: Source,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
D: Sample,
|
D: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn current_frame_len(&self) -> Option<usize> {
|
fn current_frame_len(&self) -> Option<usize> {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cpal::FromSample;
|
||||||
|
|
||||||
use crate::conversions::{ChannelCountConverter, DataConverter, SampleRateConverter};
|
use crate::conversions::{ChannelCountConverter, DataConverter, SampleRateConverter};
|
||||||
use crate::{Sample, Source};
|
use crate::{Sample, Source};
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ impl<I, D> Iterator for UniformSourceIterator<I, D>
|
||||||
where
|
where
|
||||||
I: Source,
|
I: Source,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
D: Sample,
|
D: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
type Item = D;
|
type Item = D;
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ impl<I, D> Source for UniformSourceIterator<I, D>
|
||||||
where
|
where
|
||||||
I: Iterator + Source,
|
I: Iterator + Source,
|
||||||
I::Item: Sample,
|
I::Item: Sample,
|
||||||
D: Sample,
|
D: FromSample<I::Item> + Sample,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn current_frame_len(&self) -> Option<usize> {
|
fn current_frame_len(&self) -> Option<usize> {
|
||||||
|
|
|
@ -2,6 +2,8 @@ use std::f32;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cpal::FromSample;
|
||||||
|
|
||||||
use crate::source::Spatial;
|
use crate::source::Spatial;
|
||||||
use crate::stream::{OutputStreamHandle, PlayError};
|
use crate::stream::{OutputStreamHandle, PlayError};
|
||||||
use crate::{Sample, Sink, Source};
|
use crate::{Sample, Sink, Source};
|
||||||
|
@ -55,6 +57,7 @@ impl SpatialSink {
|
||||||
pub fn append<S>(&self, source: S)
|
pub fn append<S>(&self, source: S)
|
||||||
where
|
where
|
||||||
S: Source + Send + 'static,
|
S: Source + Send + 'static,
|
||||||
|
f32: FromSample<S::Item>,
|
||||||
S::Item: Sample + Send,
|
S::Item: Sample + Send,
|
||||||
{
|
{
|
||||||
let positions = self.positions.clone();
|
let positions = self.positions.clone();
|
||||||
|
|
|
@ -219,14 +219,65 @@ impl CpalDeviceExt for cpal::Device {
|
||||||
.for_each(|d| *d = mixer_rx.next().unwrap_or(0f32))
|
.for_each(|d| *d = mixer_rx.next().unwrap_or(0f32))
|
||||||
},
|
},
|
||||||
error_callback,
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::F64 => self.build_output_stream::<f64, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut()
|
||||||
|
.for_each(|d| *d = mixer_rx.next().map(Sample::from_sample).unwrap_or(0f64))
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::I8 => self.build_output_stream::<i8, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut()
|
||||||
|
.for_each(|d| *d = mixer_rx.next().map(Sample::from_sample).unwrap_or(0i8))
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
cpal::SampleFormat::I16 => self.build_output_stream::<i16, _, _>(
|
cpal::SampleFormat::I16 => self.build_output_stream::<i16, _, _>(
|
||||||
&format.config(),
|
&format.config(),
|
||||||
move |data, _| {
|
move |data, _| {
|
||||||
data.iter_mut()
|
data.iter_mut()
|
||||||
.for_each(|d| *d = mixer_rx.next().map(|s| s.to_i16()).unwrap_or(0i16))
|
.for_each(|d| *d = mixer_rx.next().map(Sample::from_sample).unwrap_or(0i16))
|
||||||
},
|
},
|
||||||
error_callback,
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::I32 => self.build_output_stream::<i32, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut()
|
||||||
|
.for_each(|d| *d = mixer_rx.next().map(Sample::from_sample).unwrap_or(0i32))
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::I64 => self.build_output_stream::<i64, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut()
|
||||||
|
.for_each(|d| *d = mixer_rx.next().map(Sample::from_sample).unwrap_or(0i64))
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::U8 => self.build_output_stream::<u8, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut().for_each(|d| {
|
||||||
|
*d = mixer_rx
|
||||||
|
.next()
|
||||||
|
.map(Sample::from_sample)
|
||||||
|
.unwrap_or(u8::max_value() / 2)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
cpal::SampleFormat::U16 => self.build_output_stream::<u16, _, _>(
|
cpal::SampleFormat::U16 => self.build_output_stream::<u16, _, _>(
|
||||||
&format.config(),
|
&format.config(),
|
||||||
|
@ -234,12 +285,40 @@ impl CpalDeviceExt for cpal::Device {
|
||||||
data.iter_mut().for_each(|d| {
|
data.iter_mut().for_each(|d| {
|
||||||
*d = mixer_rx
|
*d = mixer_rx
|
||||||
.next()
|
.next()
|
||||||
.map(|s| s.to_u16())
|
.map(Sample::from_sample)
|
||||||
.unwrap_or(u16::max_value() / 2)
|
.unwrap_or(u16::max_value() / 2)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
error_callback,
|
error_callback,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
|
cpal::SampleFormat::U32 => self.build_output_stream::<u32, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut().for_each(|d| {
|
||||||
|
*d = mixer_rx
|
||||||
|
.next()
|
||||||
|
.map(Sample::from_sample)
|
||||||
|
.unwrap_or(u32::max_value() / 2)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::U64 => self.build_output_stream::<u64, _, _>(
|
||||||
|
&format.config(),
|
||||||
|
move |data, _| {
|
||||||
|
data.iter_mut().for_each(|d| {
|
||||||
|
*d = mixer_rx
|
||||||
|
.next()
|
||||||
|
.map(Sample::from_sample)
|
||||||
|
.unwrap_or(u64::max_value() / 2)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error_callback,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
_ => return Err(cpal::BuildStreamError::StreamConfigNotSupported),
|
||||||
}
|
}
|
||||||
.map(|stream| (mixer_tx, stream))
|
.map(|stream| (mixer_tx, stream))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue