Merge pull request #587 from remilauzier/master
Fix some typo and warnings
This commit is contained in:
commit
116ee431a6
28 changed files with 98 additions and 98 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Version 0.13.3 (2021-03-29)
|
||||
|
||||
- Give each thread an unique name
|
||||
- Give each thread a unique name
|
||||
- Fix distortion regression on some alsa configs
|
||||
|
||||
# Version 0.13.2 (2021-03-16)
|
||||
|
|
@ -106,7 +106,7 @@
|
|||
- Rename the `samples_rate` field of `Format` to `sample_rate`
|
||||
- Changed the type of the `channels` field of the `SupportedFormat` struct from `Vec<ChannelPosition>` to `ChannelCount` (an alias to `u16`)
|
||||
- Remove unused ChannelPosition API.
|
||||
- Implement `Endpoint` and `Format` Enumeration for macos.
|
||||
- Implement `Endpoint` and `Format` Enumeration for macOS.
|
||||
- Implement format handling for macos `build_voice` method.
|
||||
|
||||
# Version 0.6.0 (2017-12-11)
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
- Added improvements to the crate documentation.
|
||||
- Implement `pause` and `play` for ALSA backend.
|
||||
- Reduced the number of allocations in the CoreAudio backend.
|
||||
- Fixes for macos build (#186, #189).
|
||||
- Fixes for macOS build (#186, #189).
|
||||
|
||||
# Version 0.5.1 (2017-10-21)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ This library currently supports the following:
|
|||
- Get the current default input and output stream formats for a device.
|
||||
- Build and run input and output PCM streams on a chosen device with a given stream format.
|
||||
|
||||
Currently supported hosts include:
|
||||
Currently, supported hosts include:
|
||||
|
||||
- Linux (via ALSA or JACK)
|
||||
- Windows (via WASAPI by default, see ASIO instructions below)
|
||||
|
|
@ -73,7 +73,7 @@ WASAPI. To do so, follow these steps:
|
|||
it being useless.
|
||||
7. **Loading VCVARS**. `rust-bindgen` uses the C++ tool-chain when generating
|
||||
bindings to the ASIO SDK. As a result, it is necessary to load some
|
||||
environment variables in the command prompt that we use to build our project.
|
||||
environment variables in the command prompt that we used to build our project.
|
||||
On 64-bit machines run:
|
||||
```
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ fn main() {
|
|||
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("bad path"));
|
||||
|
||||
// Check if library exists
|
||||
// if it doesn't create it
|
||||
// If it doesn't create it
|
||||
let mut lib_path = out_dir.clone();
|
||||
lib_path.push("libasio.a");
|
||||
if !lib_path.exists() {
|
||||
|
|
@ -41,7 +41,7 @@ fn main() {
|
|||
println!("cargo:rustc-cfg=asio");
|
||||
|
||||
// Check if bindings exist
|
||||
// if they dont create them
|
||||
// If they don't create them
|
||||
let mut binding_path = out_dir.clone();
|
||||
binding_path.push("asio_bindings.rs");
|
||||
if !binding_path.exists() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# iOS Feedback Example
|
||||
|
||||
This example is an Xcode project that exercises both input and output
|
||||
audio streams. Audio samples are read in from your micrphone and then
|
||||
routed to your audio output device with a small but noticeable delay
|
||||
audio streams. Audio samples are read in from your microphone and then
|
||||
routed to your audio output device with a small but noticeable delay,
|
||||
so you can verify it is working correctly.
|
||||
|
||||
To build the example you will need to still `cargo-lipo`. While not
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ set -e
|
|||
PATH=$PATH:$HOME/.cargo/bin
|
||||
|
||||
# If you want your build to run faster, add a "--targets x86_64-apple-ios" for just using the ios simulator.
|
||||
if [ -n ${IOS_TARGETS} ]; then
|
||||
cargo lipo --targets ${IOS_TARGETS}
|
||||
if [ -n "${IOS_TARGETS}" ]; then
|
||||
cargo lipo --targets "${IOS_TARGETS}"
|
||||
else
|
||||
cargo lipo
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
))]
|
||||
let host = cpal::default_host();
|
||||
|
||||
// Setup the input device and stream with the default input config.
|
||||
// Set up the input device and stream with the default input config.
|
||||
let device = if opt.device == "default" {
|
||||
host.default_input_device()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
|||
#[wasm_bindgen(start)]
|
||||
pub fn main_js() -> Result<(), JsValue> {
|
||||
// This provides better error messages in debug mode.
|
||||
// It's disabled in release mode so it doesn't bloat up the file size.
|
||||
// It's disabled in release mode, so it doesn't bloat up the file size.
|
||||
#[cfg(debug_assertions)]
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub struct HostUnavailable;
|
|||
/// - It is unclear exactly what error might be produced by the backend API.
|
||||
/// - It does not make sense to add a variant to the enclosing error type.
|
||||
/// - No error was expected to occur at all, but we return an error to avoid the possibility of a
|
||||
/// `panic!` caused by some unforseen or unknown reason.
|
||||
/// `panic!` caused by some unforeseen or unknown reason.
|
||||
///
|
||||
/// **Note:** If you notice a `BackendSpecificError` that you believe could be better handled in a
|
||||
/// cross-platform manner, please create an issue or submit a pull request with a patch that adds
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use super::parking_lot::Mutex;
|
|||
use super::{Device, DeviceHandles};
|
||||
use {BackendSpecificError, DevicesError};
|
||||
|
||||
/// ALSA implementation for `Devices`.
|
||||
/// ALSA's implementation for `Devices`.
|
||||
pub struct Devices {
|
||||
hint_iter: alsa::device_name::HintIter,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ impl TriggerSender {
|
|||
fn wakeup(&self) {
|
||||
let buf = 1u64;
|
||||
let ret = unsafe { libc::write(self.0, &buf as *const u64 as *const _, 8) };
|
||||
assert!(ret == 8);
|
||||
assert_eq!(ret, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ impl Device {
|
|||
return Err(DefaultStreamConfigError::DeviceNotAvailable);
|
||||
}
|
||||
Err(SupportedStreamConfigsError::InvalidArgument) => {
|
||||
// this happens sometimes when querying for input and output capabilities but
|
||||
// this happens sometimes when querying for input and output capabilities, but
|
||||
// the device supports only one
|
||||
return Err(DefaultStreamConfigError::StreamTypeNotSupported);
|
||||
}
|
||||
|
|
@ -997,7 +997,7 @@ fn set_hw_params_from_format(
|
|||
}
|
||||
BufferSize::Default => {
|
||||
// These values together represent a moderate latency and wakeup interval.
|
||||
// Without them we are at the mercy of the device
|
||||
// Without them, we are at the mercy of the device
|
||||
hw_params.set_period_time_near(25_000, alsa::ValueOr::Nearest)?;
|
||||
hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub struct Device {
|
|||
pub driver: Arc<sys::Driver>,
|
||||
|
||||
// Input and/or Output stream.
|
||||
// An driver can only have one of each.
|
||||
// A driver can only have one of each.
|
||||
// They need to be created at the same time.
|
||||
pub asio_streams: Arc<Mutex<sys::AsioStreams>>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ trait AsioSample: Clone + Copy + Silence + std::ops::Add<Self, Output = Self> {
|
|||
fn from_cpal_sample<T: Sample>(&T) -> Self;
|
||||
}
|
||||
|
||||
// Used to keep track of whether or not the current current asio stream buffer requires
|
||||
// Used to keep track of whether or not the current asio stream buffer requires
|
||||
// being silencing before summing audio.
|
||||
#[derive(Default)]
|
||||
struct SilenceAsioBuffer {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//!
|
||||
//! coreaudio on iOS looks a bit different than on macOS. A lot of configuration needs to use
|
||||
//! coreaudio on iOS looks a bit different from macOS. A lot of configuration needs to use
|
||||
//! the AVAudioSession objc API which doesn't exist on macOS.
|
||||
//!
|
||||
//! TODO:
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ impl Device {
|
|||
}
|
||||
|
||||
// TODO: macOS should support U8, I16, I32, F32 and F64. This should allow for using
|
||||
// I16 but just use F32 for now as its the default anyway.
|
||||
// I16 but just use F32 for now as it's the default anyway.
|
||||
let sample_format = SampleFormat::F32;
|
||||
|
||||
// Get available sample rate ranges.
|
||||
|
|
@ -535,7 +535,7 @@ impl Device {
|
|||
|
||||
// Setting the sample rate of a device is an asynchronous process in coreaudio.
|
||||
//
|
||||
// Thus we are required to set a `listener` so that we may be notified when the
|
||||
// Thus, we are required to set a `listener` so that we may be notified when the
|
||||
// change occurs.
|
||||
unsafe extern "C" fn rate_listener(
|
||||
device_id: AudioObjectID,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ const MIN_SAMPLE_RATE: SampleRate = SampleRate(8_000);
|
|||
const MAX_SAMPLE_RATE: SampleRate = SampleRate(96_000);
|
||||
const DEFAULT_SAMPLE_RATE: SampleRate = SampleRate(44_100);
|
||||
const MIN_BUFFER_SIZE: u32 = 1;
|
||||
const MAX_BUFFER_SIZE: u32 = std::u32::MAX;
|
||||
const MAX_BUFFER_SIZE: u32 = u32::MAX;
|
||||
const DEFAULT_BUFFER_SIZE: usize = 2048;
|
||||
const SUPPORTED_SAMPLE_FORMAT: SampleFormat = SampleFormat::F32;
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ impl StreamTrait for Stream {
|
|||
}
|
||||
}
|
||||
|
||||
// The first argument of the callback function (a `void*`) is a casted pointer to `self`
|
||||
// The first argument of the callback function (a `void*`) is a cast pointer to `self`
|
||||
// and to the `callback` parameter that was passed to `run`.
|
||||
fn audio_callback_fn<D, E>(
|
||||
user_data_ptr: *mut c_void,
|
||||
|
|
@ -282,7 +282,7 @@ fn audio_callback_fn<D, E>(
|
|||
.try_into()
|
||||
.expect("failed to retrieve Value as f64");
|
||||
let callback = crate::StreamInstant::from_secs_f64(now_secs);
|
||||
// TODO: Use proper latency instead. Currently unsupported on most browsers though so
|
||||
// TODO: Use proper latency instead. Currently, unsupported on most browsers though, so
|
||||
// we estimate based on buffer size instead. Probably should use this, but it's only
|
||||
// supported by firefox (2020-04-28).
|
||||
// let latency_secs: f64 = js!(@{audio_ctxt}.outputLatency).try_into().unwrap();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl Device {
|
|||
let client_options = super::get_client_options(start_server_automatically);
|
||||
|
||||
// Create a dummy client to find out the sample rate of the server to be able to provide it as a possible config.
|
||||
// This client will be dropped and a new one will be created when making the stream.
|
||||
// This client will be dropped, and a new one will be created when making the stream.
|
||||
// This is a hack due to the fact that the Client must be moved to create the AsyncClient.
|
||||
match super::get_client(&name, client_options) {
|
||||
Ok(client) => Ok(Device {
|
||||
|
|
@ -95,7 +95,7 @@ impl Device {
|
|||
let channels = DEFAULT_NUM_CHANNELS;
|
||||
let sample_rate = self.sample_rate;
|
||||
let buffer_size = self.buffer_size.clone();
|
||||
// The sample format for JACK audio ports is always "32 bit float mono audio" in the current implementation.
|
||||
// The sample format for JACK audio ports is always "32-bit float mono audio" in the current implementation.
|
||||
// Custom formats are allowed within JACK, but this is of niche interest.
|
||||
// The format can be found programmatically by calling jack::PortSpec::port_type() on a created port.
|
||||
let sample_format = JACK_SAMPLE_FORMAT;
|
||||
|
|
@ -158,14 +158,14 @@ impl DeviceTrait for Device {
|
|||
}
|
||||
|
||||
/// Returns the default input config
|
||||
/// The sample format for JACK audio ports is always "32 bit float mono audio" unless using a custom type.
|
||||
/// The sample format for JACK audio ports is always "32-bit float mono audio" unless using a custom type.
|
||||
/// The sample rate is set by the JACK server.
|
||||
fn default_input_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> {
|
||||
self.default_config()
|
||||
}
|
||||
|
||||
/// Returns the default output config
|
||||
/// The sample format for JACK audio ports is always "32 bit float mono audio" unless using a custom type.
|
||||
/// The sample format for JACK audio ports is always "32-bit float mono audio" unless using a custom type.
|
||||
/// The sample rate is set by the JACK server.
|
||||
fn default_output_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> {
|
||||
self.default_config()
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ impl Host {
|
|||
}
|
||||
|
||||
impl HostTrait for Host {
|
||||
type Device = Device;
|
||||
type Devices = Devices;
|
||||
type Device = Device;
|
||||
|
||||
/// JACK is available if
|
||||
/// - the jack feature flag is set
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ struct LocalProcessHandler {
|
|||
input_data_callback: Option<Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static>>,
|
||||
output_data_callback: Option<Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static>>,
|
||||
|
||||
// JACK audio samples are 32 bit float (unless you do some custom dark magic)
|
||||
// JACK audio samples are 32-bit float (unless you do some custom dark magic)
|
||||
temp_input_buffer: Vec<f32>,
|
||||
temp_output_buffer: Vec<f32>,
|
||||
playing: Arc<AtomicBool>,
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@ impl DeviceTrait for Device {
|
|||
}
|
||||
|
||||
impl HostTrait for Host {
|
||||
type Device = Device;
|
||||
type Devices = Devices;
|
||||
type Device = Device;
|
||||
|
||||
fn is_available() -> bool {
|
||||
false
|
||||
|
|
|
|||
|
|
@ -48,6 +48,22 @@ where
|
|||
{
|
||||
type FrameType = (T, C);
|
||||
|
||||
fn on_error_before_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_error_after_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_audio_ready(
|
||||
&mut self,
|
||||
audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||
|
|
@ -71,20 +87,4 @@ where
|
|||
);
|
||||
oboe::DataCallbackResult::Continue
|
||||
}
|
||||
|
||||
fn on_error_before_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_error_after_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,22 @@ where
|
|||
{
|
||||
type FrameType = (T, C);
|
||||
|
||||
fn on_error_before_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_error_after_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_audio_ready(
|
||||
&mut self,
|
||||
audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||
|
|
@ -71,20 +87,4 @@ where
|
|||
);
|
||||
oboe::DataCallbackResult::Continue
|
||||
}
|
||||
|
||||
fn on_error_before_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
|
||||
fn on_error_after_close(
|
||||
&mut self,
|
||||
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||
error: oboe::Error,
|
||||
) {
|
||||
(self.error_cb)(StreamError::from(error))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ pub unsafe fn is_format_supported(
|
|||
}
|
||||
|
||||
// `IsFormatSupported` can return `S_FALSE` (which means that a compatible format
|
||||
// has been found) but we also treat this as an error
|
||||
// has been found), but we also treat this as an error
|
||||
match (hresult, check_result(hresult)) {
|
||||
(_, Err(ref e))
|
||||
if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => {
|
||||
|
|
@ -436,8 +436,8 @@ impl Device {
|
|||
// querying them via `IsFormatSupported`.
|
||||
//
|
||||
// When calling `IsFormatSupported` with the shared-mode audio engine, only the default
|
||||
// number of channels seems to be supported. Any more or less returns an invalid
|
||||
// parameter error. Thus we just assume that the default number of channels is the only
|
||||
// number of channels seems to be supported. Any, more or less returns an invalid
|
||||
// parameter error. Thus, we just assume that the default number of channels is the only
|
||||
// number supported.
|
||||
fn supported_formats(&self) -> Result<SupportedInputConfigs, SupportedStreamConfigsError> {
|
||||
// initializing COM because we call `CoTaskMemFree` to release the format.
|
||||
|
|
@ -482,7 +482,7 @@ impl Device {
|
|||
let mut test_format = {
|
||||
match WaveFormat::copy_from_waveformatex_ptr(default_waveformatex_ptr.0) {
|
||||
Some(f) => f,
|
||||
// If the format is neither EX or EXTENSIBLE we don't know how to work with it.
|
||||
// If the format is neither EX nor EXTENSIBLE we don't know how to work with it.
|
||||
None => return Ok(vec![].into_iter()),
|
||||
}
|
||||
};
|
||||
|
|
@ -650,7 +650,7 @@ impl Device {
|
|||
match config.buffer_size {
|
||||
BufferSize::Fixed(_) => {
|
||||
// TO DO: We need IAudioClient3 to get buffersize ranges first
|
||||
// Otherwise the supported ranges are unknown. In the mean time
|
||||
// Otherwise the supported ranges are unknown. In the meantime
|
||||
// the smallest buffersize is selected and used.
|
||||
return Err(BuildStreamError::StreamConfigNotSupported);
|
||||
}
|
||||
|
|
@ -676,7 +676,7 @@ impl Device {
|
|||
_ => (),
|
||||
}
|
||||
|
||||
// finally initializing the audio client
|
||||
// Finally, initializing the audio client
|
||||
let hresult = (*audio_client).Initialize(
|
||||
share_mode,
|
||||
stream_flags,
|
||||
|
|
@ -818,7 +818,7 @@ impl Device {
|
|||
match config.buffer_size {
|
||||
BufferSize::Fixed(_) => {
|
||||
// TO DO: We need IAudioClient3 to get buffersize ranges first
|
||||
// Otherwise the supported ranges are unknown. In the mean time
|
||||
// Otherwise the supported ranges are unknown. In the meantime
|
||||
// the smallest buffersize is selected and used.
|
||||
return Err(BuildStreamError::StreamConfigNotSupported);
|
||||
}
|
||||
|
|
@ -838,7 +838,7 @@ impl Device {
|
|||
_ => (),
|
||||
}
|
||||
|
||||
// finally initializing the audio client
|
||||
// Finally, initializing the audio client
|
||||
let hresult = (*audio_client).Initialize(
|
||||
share_mode,
|
||||
AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
|
||||
|
|
@ -1092,7 +1092,7 @@ lazy_static! {
|
|||
};
|
||||
}
|
||||
|
||||
/// RAII object around `IMMDeviceEnumerator`.
|
||||
/// RAII objects around `IMMDeviceEnumerator`.
|
||||
struct Enumerator(*mut IMMDeviceEnumerator);
|
||||
|
||||
unsafe impl Send for Enumerator {}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl HostTrait for Host {
|
|||
type Device = Device;
|
||||
|
||||
fn is_available() -> bool {
|
||||
// Assume WASAPI is always available on windows.
|
||||
// Assume WASAPI is always available on Windows.
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ const MIN_SAMPLE_RATE: SampleRate = SampleRate(8_000);
|
|||
const MAX_SAMPLE_RATE: SampleRate = SampleRate(96_000);
|
||||
const DEFAULT_SAMPLE_RATE: SampleRate = SampleRate(44_100);
|
||||
const MIN_BUFFER_SIZE: u32 = 1;
|
||||
const MAX_BUFFER_SIZE: u32 = std::u32::MAX;
|
||||
const MAX_BUFFER_SIZE: u32 = u32::MAX;
|
||||
const DEFAULT_BUFFER_SIZE: usize = 2048;
|
||||
const SUPPORTED_SAMPLE_FORMAT: SampleFormat = SampleFormat::F32;
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ impl DeviceTrait for Device {
|
|||
let time = Arc::new(RwLock::new(0f64));
|
||||
|
||||
// Create a set of closures / callbacks which will continuously fetch and schedule sample
|
||||
// playback. Starting with two workers, eg a front and back buffer so that audio frames
|
||||
// playback. Starting with two workers, e.g. a front and back buffer so that audio frames
|
||||
// can be fetched in the background.
|
||||
for _i in 0..2 {
|
||||
let data_callback_handle = data_callback.clone();
|
||||
|
|
@ -297,7 +297,7 @@ impl DeviceTrait for Device {
|
|||
}
|
||||
|
||||
// Deinterleave the sample data and copy into the audio context buffer.
|
||||
// We do not reference the audio context buffer directly eg getChannelData.
|
||||
// We do not reference the audio context buffer directly e.g. getChannelData.
|
||||
// As wasm-bindgen only gives us a copy, not a direct reference.
|
||||
for channel in 0..n_channels {
|
||||
for i in 0..buffer_size_frames {
|
||||
|
|
|
|||
10
src/lib.rs
10
src/lib.rs
|
|
@ -82,7 +82,7 @@
|
|||
//! > provide a blocking API (e.g. ALSA), CPAL will create a thread in order to consistently
|
||||
//! > provide non-blocking behaviour (currently this is a thread per stream, but this may change to
|
||||
//! > use a single thread for all streams). *If this is an issue for your platform or design,
|
||||
//! > please share your issue and use-case with the CPAL team on the github issue tracker for
|
||||
//! > please share your issue and use-case with the CPAL team on the GitHub issue tracker for
|
||||
//! > consideration.*
|
||||
//!
|
||||
//! In this example, we simply fill the given output buffer with silence.
|
||||
|
|
@ -409,11 +409,11 @@ impl StreamInstant {
|
|||
#[allow(dead_code)]
|
||||
fn from_nanos_i128(nanos: i128) -> Option<Self> {
|
||||
let secs = nanos / 1_000_000_000;
|
||||
if secs > std::i64::MAX as i128 || secs < std::i64::MIN as i128 {
|
||||
if secs > i64::MAX as i128 || secs < i64::MIN as i128 {
|
||||
None
|
||||
} else {
|
||||
let subsec_nanos = nanos - secs * 1_000_000_000;
|
||||
debug_assert!(subsec_nanos < std::u32::MAX as i128);
|
||||
debug_assert!(subsec_nanos < u32::MAX as i128);
|
||||
Some(Self::new(secs as i64, subsec_nanos as u32))
|
||||
}
|
||||
}
|
||||
|
|
@ -755,8 +755,8 @@ const COMMON_SAMPLE_RATES: &'static [SampleRate] = &[
|
|||
fn test_stream_instant() {
|
||||
let a = StreamInstant::new(2, 0);
|
||||
let b = StreamInstant::new(-2, 0);
|
||||
let min = StreamInstant::new(std::i64::MIN, 0);
|
||||
let max = StreamInstant::new(std::i64::MAX, 0);
|
||||
let min = StreamInstant::new(i64::MIN, 0);
|
||||
let max = StreamInstant::new(i64::MAX, 0);
|
||||
assert_eq!(
|
||||
a.sub(Duration::from_secs(1)),
|
||||
Some(StreamInstant::new(1, 0))
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ macro_rules! impl_platform_host {
|
|||
|
||||
/// The platform's dynamically dispatched **Host** type.
|
||||
///
|
||||
/// An instance of this **Host** type may represent one of any of the **Host**s available
|
||||
/// An instance of this **Host** type may represent one of the **Host**s available
|
||||
/// on the platform.
|
||||
///
|
||||
/// Use this type if you require switching between available hosts at runtime.
|
||||
///
|
||||
/// This type may be constructed via the **host_from_id** function. **HostId**s may
|
||||
/// be acquired via the **ALL_HOSTS** const and the **available_hosts** function.
|
||||
/// be acquired via the **ALL_HOSTS** const, and the **available_hosts** function.
|
||||
pub struct Host(HostInner);
|
||||
|
||||
/// The **Device** implementation associated with the platform's dynamically dispatched
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ unsafe impl Sample for i16 {
|
|||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
if *self < 0 {
|
||||
*self as f32 / -(::std::i16::MIN as f32)
|
||||
*self as f32 / -(i16::MIN as f32)
|
||||
} else {
|
||||
*self as f32 / ::std::i16::MAX as f32
|
||||
*self as f32 / i16::MAX as f32
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ unsafe impl Sample for i16 {
|
|||
#[inline]
|
||||
fn to_u16(&self) -> u16 {
|
||||
if *self < 0 {
|
||||
(*self - ::std::i16::MIN) as u16
|
||||
(*self - i16::MIN) as u16
|
||||
} else {
|
||||
(*self as u16) + 32768
|
||||
}
|
||||
|
|
@ -118,15 +118,15 @@ unsafe impl Sample for f32 {
|
|||
#[inline]
|
||||
fn to_i16(&self) -> i16 {
|
||||
if *self >= 0.0 {
|
||||
(*self * ::std::i16::MAX as f32) as i16
|
||||
(*self * i16::MAX as f32) as i16
|
||||
} else {
|
||||
(-*self * ::std::i16::MIN as f32) as i16
|
||||
(-*self * i16::MIN as f32) as i16
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_u16(&self) -> u16 {
|
||||
(((*self + 1.0) * 0.5) * ::std::u16::MAX as f32).round() as u16
|
||||
(((*self + 1.0) * 0.5) * u16::MAX as f32).round() as u16
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -192,9 +192,9 @@ mod test {
|
|||
#[test]
|
||||
fn f32_to_i16() {
|
||||
assert_eq!(0.0f32.to_i16(), 0);
|
||||
assert_eq!((-0.5f32).to_i16(), ::std::i16::MIN / 2);
|
||||
assert_eq!(1.0f32.to_i16(), ::std::i16::MAX);
|
||||
assert_eq!((-1.0f32).to_i16(), ::std::i16::MIN);
|
||||
assert_eq!((-0.5f32).to_i16(), i16::MIN / 2);
|
||||
assert_eq!(1.0f32.to_i16(), i16::MAX);
|
||||
assert_eq!((-1.0f32).to_i16(), i16::MIN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use {
|
|||
/// however it has its own limitations w.r.t. low-latency and high-performance audio applications.
|
||||
/// JACK is yet another host API that is more suitable to pro-audio applications, however it is
|
||||
/// less readily available by default in many Linux distributions and is known to be tricky to
|
||||
/// setup.
|
||||
/// set up.
|
||||
pub trait HostTrait {
|
||||
/// The type used for enumerating available devices by the host.
|
||||
type Devices: Iterator<Item = Self::Device>;
|
||||
|
|
@ -81,7 +81,7 @@ pub trait HostTrait {
|
|||
|
||||
/// A device that is capable of audio input and/or output.
|
||||
///
|
||||
/// Please note that `Device`s may become invalid if they get disconnected. Therefore all the
|
||||
/// Please note that `Device`s may become invalid if they get disconnected. Therefore, all the
|
||||
/// methods that involve a device return a `Result` allowing the user to handle this case.
|
||||
pub trait DeviceTrait {
|
||||
/// The iterator type yielding supported input stream formats.
|
||||
|
|
@ -96,14 +96,14 @@ pub trait DeviceTrait {
|
|||
|
||||
/// An iterator yielding formats that are supported by the backend.
|
||||
///
|
||||
/// Can return an error if the device is no longer valid (eg. it has been disconnected).
|
||||
/// Can return an error if the device is no longer valid (e.g. it has been disconnected).
|
||||
fn supported_input_configs(
|
||||
&self,
|
||||
) -> Result<Self::SupportedInputConfigs, SupportedStreamConfigsError>;
|
||||
|
||||
/// An iterator yielding output stream formats that are supported by the device.
|
||||
///
|
||||
/// Can return an error if the device is no longer valid (eg. it has been disconnected).
|
||||
/// Can return an error if the device is no longer valid (e.g. it has been disconnected).
|
||||
fn supported_output_configs(
|
||||
&self,
|
||||
) -> Result<Self::SupportedOutputConfigs, SupportedStreamConfigsError>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue