mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
Update cpal -> 0.10
* Provide device prevous method using `cpal::default_host()` * Naively handle new cpal errors
This commit is contained in:
parent
655d05100f
commit
0151398043
3 changed files with 53 additions and 9 deletions
|
@ -10,7 +10,7 @@ documentation = "http://docs.rs/rodio"
|
|||
|
||||
[dependencies]
|
||||
claxon = { version = "0.4.2", optional = true }
|
||||
cpal = "0.8"
|
||||
cpal = "0.10"
|
||||
hound = { version = "3.3.1", optional = true }
|
||||
lazy_static = "1.0.0"
|
||||
lewton = { version = "0.9", optional = true }
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::sync::Mutex;
|
|||
use std::sync::Weak;
|
||||
use std::thread::Builder;
|
||||
|
||||
use cpal::traits::{DeviceTrait, EventLoopTrait, HostTrait};
|
||||
use cpal::Device;
|
||||
use cpal::EventLoop;
|
||||
use cpal::Sample as CpalSample;
|
||||
|
@ -24,7 +25,7 @@ where
|
|||
lazy_static! {
|
||||
static ref ENGINE: Arc<Engine> = {
|
||||
let engine = Arc::new(Engine {
|
||||
events_loop: EventLoop::new(),
|
||||
events_loop: cpal::default_host().event_loop(),
|
||||
dynamic_mixers: Mutex::new(HashMap::with_capacity(1)),
|
||||
end_points: Mutex::new(HashMap::with_capacity(1)),
|
||||
});
|
||||
|
@ -37,7 +38,9 @@ where
|
|||
let engine = engine.clone();
|
||||
move || {
|
||||
engine.events_loop.run(|stream_id, buffer| {
|
||||
audio_callback(&engine, stream_id, buffer);
|
||||
if let Ok(buf) = buffer {
|
||||
audio_callback(&engine, stream_id, buf);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -91,7 +94,7 @@ fn audio_callback(engine: &Arc<Engine>, stream_id: StreamId, buffer: StreamData)
|
|||
} => for d in buffer.iter_mut() {
|
||||
*d = mixer_rx.next().unwrap_or(0f32);
|
||||
},
|
||||
StreamData::Input { buffer: _ } => {
|
||||
StreamData::Input { .. } => {
|
||||
panic!("Can't play an input stream!");
|
||||
},
|
||||
};
|
||||
|
@ -107,7 +110,7 @@ where
|
|||
let mixer = {
|
||||
let mut end_points = engine.end_points.lock().unwrap();
|
||||
|
||||
match end_points.entry(device.name()) {
|
||||
match end_points.entry(device.name().expect("No device name")) {
|
||||
Entry::Vacant(e) => {
|
||||
let (mixer, stream) = new_output_stream(engine, device);
|
||||
e.insert(Arc::downgrade(&mixer));
|
||||
|
@ -128,7 +131,7 @@ where
|
|||
};
|
||||
|
||||
if let Some(stream) = stream_to_start {
|
||||
engine.events_loop.play_stream(stream);
|
||||
engine.events_loop.play_stream(stream).expect("play_stream failed");
|
||||
}
|
||||
|
||||
mixer.add(source);
|
||||
|
|
47
src/lib.rs
47
src/lib.rs
|
@ -96,9 +96,7 @@ extern crate lewton;
|
|||
#[cfg(feature = "mp3")]
|
||||
extern crate minimp3;
|
||||
|
||||
pub use cpal::{
|
||||
default_input_device, default_output_device, devices, input_devices, output_devices, Device,
|
||||
};
|
||||
pub use cpal::{traits::DeviceTrait, Device, Devices, DevicesError, InputDevices};
|
||||
|
||||
pub use conversions::Sample;
|
||||
pub use decoder::Decoder;
|
||||
|
@ -107,6 +105,7 @@ pub use sink::Sink;
|
|||
pub use source::Source;
|
||||
pub use spatial_sink::SpatialSink;
|
||||
|
||||
use cpal::traits::HostTrait;
|
||||
use std::io::{Read, Seek};
|
||||
|
||||
mod conversions;
|
||||
|
@ -132,3 +131,45 @@ where
|
|||
sink.append(input);
|
||||
Ok(sink)
|
||||
}
|
||||
|
||||
/// The default input audio device on the system.
|
||||
///
|
||||
/// Returns `None` if no input device is available.
|
||||
#[inline]
|
||||
pub fn default_input_device() -> Option<Device> {
|
||||
cpal::default_host().default_input_device()
|
||||
}
|
||||
|
||||
/// The default output audio device on the system.
|
||||
///
|
||||
/// Returns `None` if no output device is available.
|
||||
#[inline]
|
||||
pub fn default_output_device() -> Option<Device> {
|
||||
cpal::default_host().default_output_device()
|
||||
}
|
||||
|
||||
/// An iterator yielding all `Device`s currently available to the host on the system.
|
||||
///
|
||||
/// Can be empty if the system does not support audio in general.
|
||||
#[inline]
|
||||
pub fn devices() -> Result<Devices, DevicesError> {
|
||||
cpal::default_host().devices()
|
||||
}
|
||||
|
||||
/// An iterator yielding all `Device`s currently available to the system that support one or more
|
||||
/// input stream formats.
|
||||
///
|
||||
/// Can be empty if the system does not support audio input.
|
||||
#[inline]
|
||||
pub fn input_devices() -> Result<InputDevices<Devices>, DevicesError> {
|
||||
cpal::default_host().input_devices()
|
||||
}
|
||||
|
||||
/// An iterator yielding all `Device`s currently available to the system that support one or more
|
||||
/// output stream formats.
|
||||
///
|
||||
/// Can be empty if the system does not support audio output.
|
||||
#[inline]
|
||||
pub fn output_devices() -> Result<InputDevices<Devices>, DevicesError> {
|
||||
cpal::default_host().output_devices()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue