Migrate to edition 2018

* Remove unstable/legacy rustfmt config
* Run rustfmt
This commit is contained in:
Alex Butler 2020-01-31 00:15:41 +00:00
parent 0517ee7216
commit c93adb2582
No known key found for this signature in database
GPG key ID: E1355A2F8E415521
50 changed files with 222 additions and 242 deletions

View file

@ -1,18 +1,2 @@
fn_args_density = "Compressed"
fn_args_layout = "Visual"
fn_brace_style = "SameLineWhere"
fn_call_style = "Visual"
fn_empty_single_line = false
format_strings = true
generics_indent = "Visual"
impl_empty_single_line = false
match_block_trailing_comma = true
reorder_imported_names = true
reorder_imports = true
reorder_imports_in_group = true
spaces_around_ranges = true
use_try_shorthand = true
where_density = "Tall"
where_style = "Legacy"
wrap_match_arms = false
write_mode = "Overwrite"

View file

@ -7,6 +7,7 @@ description = "Audio playback library"
keywords = ["audio", "playback", "gamedev"]
repository = "https://github.com/RustAudio/rodio"
documentation = "http://docs.rs/rodio"
edition = "2018"
[dependencies]
claxon = { version = "0.4.2", optional = true }

View file

@ -1,5 +1,3 @@
extern crate rodio;
use std::io::BufReader;
use std::thread;
use std::time::Duration;

View file

@ -1,5 +1,3 @@
extern crate rodio;
use std::io::BufReader;
fn main() {

View file

@ -1,5 +1,3 @@
extern crate rodio;
use std::io::BufReader;
fn main() {

View file

@ -1,5 +1,3 @@
extern crate rodio;
use std::io::BufReader;
fn main() {

View file

@ -1,5 +1,3 @@
extern crate rodio;
use std::io::BufReader;
fn main() {

View file

@ -1,4 +1,4 @@
extern crate rodio;
use rodio;
use rodio::Source;
use std::io::BufReader;

View file

@ -1,4 +1,4 @@
extern crate rodio;
use rodio;
use std::io::BufReader;
use std::thread;
@ -22,12 +22,12 @@ fn main() {
// until it stops and begins traveling to the left, it will eventually pass through the
// listener again.
// This is repeated 5 times.
for _ in 0 .. 5 {
for i in 1 .. 1001 {
for _ in 0..5 {
for i in 1..1001 {
thread::sleep(Duration::from_millis(5));
sink.set_emitter_position([(i - 500) as f32 / 50.0, 0.0, 0.0]);
}
for i in 1 .. 1001 {
for i in 1..1001 {
thread::sleep(Duration::from_millis(5));
sink.set_emitter_position([-(i - 500) as f32 / 50.0, 0.0, 0.0]);
}

View file

@ -13,9 +13,8 @@
use std::time::Duration;
use std::vec::IntoIter as VecIntoIter;
use source::Source;
use Sample;
use crate::source::Source;
use crate::Sample;
/// A buffer of samples treated as a source.
pub struct SamplesBuffer<S> {
@ -47,7 +46,8 @@ where
let data = data.into();
let duration_ns = 1_000_000_000u64.checked_mul(data.len() as u64).unwrap()
/ sample_rate as u64 / channels as u64;
/ sample_rate as u64
/ channels as u64;
let duration = Duration::new(
duration_ns / 1_000_000_000,
(duration_ns % 1_000_000_000) as u32,
@ -106,8 +106,8 @@ where
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use source::Source;
use crate::buffer::SamplesBuffer;
use crate::source::Source;
#[test]
fn basic() {

View file

@ -25,7 +25,9 @@ where
///
#[inline]
pub fn new(
input: I, from: cpal::ChannelCount, to: cpal::ChannelCount,
input: I,
from: cpal::ChannelCount,
to: cpal::ChannelCount,
) -> ChannelCountConverter<I> {
assert!(from >= 1);
assert!(to >= 1);
@ -70,7 +72,7 @@ where
self.next_output_sample_pos -= self.to;
if self.from > self.to {
for _ in self.to .. self.from {
for _ in self.to..self.from {
self.input.next(); // discarding extra input
}
}

View file

@ -1,4 +1,4 @@
use conversions::Sample;
use crate::conversions::Sample;
use cpal;
use std::mem;
@ -41,7 +41,9 @@ where
///
#[inline]
pub fn new(
mut input: I, from: cpal::SampleRate, to: cpal::SampleRate,
mut input: I,
from: cpal::SampleRate,
to: cpal::SampleRate,
num_channels: cpal::ChannelCount,
) -> SampleRateConverter<I> {
let from = from.0;
@ -103,7 +105,7 @@ where
mem::swap(&mut self.current_frame, &mut self.next_frame);
self.next_frame.clear();
for _ in 0 .. self.next_frame.capacity() {
for _ in 0..self.next_frame.capacity() {
if let Some(i) = self.input.next() {
self.next_frame.push(i);
} else {
@ -163,7 +165,8 @@ where
// `self.next_frame`.
let mut result = None;
let numerator = (self.from * self.next_output_frame_pos_in_chunk) % self.to;
for (off, (cur, next)) in self.current_frame
for (off, (cur, next)) in self
.current_frame
.iter()
.zip(self.next_frame.iter())
.enumerate()

View file

@ -2,7 +2,7 @@ use std::io::{Read, Seek, SeekFrom};
use std::mem;
use std::time::Duration;
use Source;
use crate::Source;
use claxon::FlacReader;
@ -72,7 +72,8 @@ where
fn total_duration(&self) -> Option<Duration> {
// `samples` in FLAC means "inter-channel samples" aka frames
// so we do not divide by `self.channels` here.
self.samples.map(|s| Duration::from_micros(s * 1_000_000 / self.sample_rate as u64))
self.samples
.map(|s| Duration::from_micros(s * 1_000_000 / self.sample_rate as u64))
}
}
@ -109,7 +110,7 @@ where
Ok(Some(block)) => {
self.current_block_channel_len = (block.len() / block.channels()) as usize;
self.current_block = block.into_buffer();
},
}
_ => return None,
}
}

View file

@ -5,7 +5,7 @@ use std::fmt;
use std::io::{Read, Seek};
use std::time::Duration;
use Source;
use crate::Source;
#[cfg(feature = "flac")]
mod flac;
@ -56,7 +56,7 @@ where
Err(data) => data,
Ok(decoder) => {
return Ok(Decoder(DecoderImpl::Wav(decoder)));
},
}
};
#[cfg(feature = "flac")]
@ -64,7 +64,7 @@ where
Err(data) => data,
Ok(decoder) => {
return Ok(Decoder(DecoderImpl::Flac(decoder)));
},
}
};
#[cfg(feature = "vorbis")]
@ -72,7 +72,7 @@ where
Err(data) => data,
Ok(decoder) => {
return Ok(Decoder(DecoderImpl::Vorbis(decoder)));
},
}
};
#[cfg(feature = "mp3")]
@ -80,7 +80,7 @@ where
Err(data) => data,
Ok(decoder) => {
return Ok(Decoder(DecoderImpl::Mp3(decoder)));
},
}
};
Err(DecoderError::UnrecognizedFormat)
@ -224,7 +224,7 @@ pub enum DecoderError {
}
impl fmt::Display for DecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
&DecoderError::UnrecognizedFormat => write!(f, "Unrecognized format"),
}

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek};
use std::time::Duration;
use Source;
use crate::Source;
use minimp3::{Decoder, Frame};
@ -32,7 +32,7 @@ where
impl<R> Source for Mp3Decoder<R>
where
R: Read + Seek
R: Read + Seek,
{
#[inline]
fn current_frame_len(&self) -> Option<usize> {
@ -57,7 +57,7 @@ where
impl<R> Iterator for Mp3Decoder<R>
where
R: Read + Seek
R: Read + Seek,
{
type Item = i16;
@ -76,4 +76,4 @@ where
return Some(v);
}
}
}

View file

@ -2,7 +2,7 @@ use std::io::{Read, Seek, SeekFrom};
use std::time::Duration;
use std::vec;
use Source;
use crate::Source;
use lewton::inside_ogg::OggStreamReader;

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom};
use std::time::Duration;
use Source;
use crate::Source;
use hound::{SampleFormat, WavReader};
@ -84,11 +84,7 @@ where
}
}
impl<R> ExactSizeIterator for SamplesIterator<R>
where
R: Read + Seek,
{
}
impl<R> ExactSizeIterator for SamplesIterator<R> where R: Read + Seek {}
impl<R> Source for WavDecoder<R>
where
@ -133,11 +129,7 @@ where
}
}
impl<R> ExactSizeIterator for WavDecoder<R>
where
R: Read + Seek,
{
}
impl<R> ExactSizeIterator for WavDecoder<R> where R: Read + Seek {}
/// Returns true if the stream contains WAV data, then resets it to where it was.
fn is_wave<R>(mut data: R) -> bool
@ -165,7 +157,7 @@ fn f32_to_i16(f: f32) -> i16 {
}
/// Returns a 24 bit WAV int as an i16. Note that this is a 24 bit integer, not a
/// 32 bit one. 24 bit ints are in the range [8,388,608, 8,388,607] while i16s
/// 32 bit one. 24 bit ints are in the range [8,388,608, 8,388,607] while i16s
/// are in the range [-32768, 32767]. Note that this function definitely causes
/// precision loss but hopefully this isn't too audiable when actually playing?
fn i24_to_i16(i: i32) -> i16 {

View file

@ -1,12 +1,12 @@
use crate::decoder;
use crate::device_mixer::DeviceMixer;
use crate::dynamic_mixer::{self, DynamicMixerController};
use crate::sink::Sink;
use crate::source::Source;
use cpal::{
traits::{DeviceTrait, HostTrait},
Sample,
};
use decoder;
use device_mixer::DeviceMixer;
use dynamic_mixer::{self, DynamicMixerController};
use sink::Sink;
use source::Source;
use std::cell::RefCell;
use std::io::{Read, Seek};
use std::sync::Arc;

View file

@ -1,7 +1,7 @@
use crate::device::CpalDeviceExt;
use crate::dynamic_mixer::DynamicMixerController;
use crate::source::Source;
use cpal::traits::{DeviceTrait, StreamTrait};
use device::CpalDeviceExt;
use dynamic_mixer::DynamicMixerController;
use source::Source;
use std::collections::HashMap;
use std::sync::Arc;

View file

@ -6,10 +6,9 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;
use source::Source;
use source::UniformSourceIterator;
use Sample;
use crate::source::Source;
use crate::source::UniformSourceIterator;
use crate::Sample;
/// Builds a new mixer.
///
@ -18,7 +17,8 @@ use Sample;
///
/// After creating a mixer, you can add new sounds with the controller.
pub fn mixer<S>(
channels: u16, sample_rate: u32,
channels: u16,
sample_rate: u32,
) -> (Arc<DynamicMixerController<S>>, DynamicMixer<S>)
where
S: Sample + Send + 'static,
@ -148,9 +148,9 @@ where
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use dynamic_mixer;
use source::Source;
use crate::buffer::SamplesBuffer;
use crate::dynamic_mixer;
use crate::source::Source;
#[test]
fn basic() {

View file

@ -24,7 +24,7 @@
//!
//! let file = File::open("sound.ogg").unwrap();
//! let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
//! rodio::play_raw(&device, source.convert_samples());
//! device.play_raw(source.convert_samples());
//! ```
//!
//! ## Sink
@ -82,33 +82,22 @@
//!
#![cfg_attr(test, deny(missing_docs))]
#[cfg(feature = "flac")]
extern crate claxon;
extern crate cpal;
#[cfg(feature = "wav")]
extern crate hound;
#[cfg(feature = "vorbis")]
extern crate lewton;
#[cfg(feature = "mp3")]
extern crate minimp3;
pub use cpal::{
traits::DeviceTrait, Device, Devices, DevicesError, Format, InputDevices, OutputDevices
traits::DeviceTrait, Device, Devices, DevicesError, Format, InputDevices, OutputDevices,
};
pub use conversions::Sample;
pub use decoder::Decoder;
pub use sink::Sink;
pub use source::Source;
pub use spatial_sink::SpatialSink;
pub use device::RodioDevice;
pub use crate::conversions::Sample;
pub use crate::decoder::Decoder;
pub use crate::device::RodioDevice;
pub use crate::sink::Sink;
pub use crate::source::Source;
pub use crate::spatial_sink::SpatialSink;
mod conversions;
mod device;
mod device_mixer;
mod sink;
mod spatial_sink;
mod device_mixer;
mod device;
pub mod buffer;
pub mod decoder;

View file

@ -9,11 +9,10 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;
use source::Empty;
use source::Source;
use source::Zero;
use Sample;
use crate::source::Empty;
use crate::source::Source;
use crate::source::Zero;
use crate::Sample;
/// Builds a new queue. It consists of an input and an output.
///
@ -227,9 +226,9 @@ where
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use queue;
use source::Source;
use crate::buffer::SamplesBuffer;
use crate::queue;
use crate::source::Source;
#[test]
#[ignore] // FIXME: samples rate and channel not updated immediately after transition
@ -270,7 +269,7 @@ mod tests {
assert_eq!(rx.next(), Some(10));
assert_eq!(rx.next(), Some(-10));
for _ in 0 .. 100000 {
for _ in 0..100000 {
assert_eq!(rx.next(), Some(0));
}
}
@ -280,7 +279,7 @@ mod tests {
fn no_delay_when_added() {
let (tx, mut rx) = queue::queue(true);
for _ in 0 .. 500 {
for _ in 0..500 {
assert_eq!(rx.next(), Some(0));
}

View file

@ -1,4 +1,4 @@
use device::RodioDevice;
use crate::device::RodioDevice;
use std::sync::atomic::Ordering;
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::mpsc::Receiver;
@ -6,10 +6,10 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;
use queue;
use source::Done;
use Sample;
use Source;
use crate::queue;
use crate::source::Done;
use crate::Sample;
use crate::Source;
/// Handle to an device that outputs sounds.
///
@ -176,12 +176,11 @@ impl Drop for Sink {
}
}
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use source::Source;
use sink::Sink;
use crate::buffer::SamplesBuffer;
use crate::sink::Sink;
use crate::source::Source;
#[test]
fn test_pause_and_stop() {

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Amplify` object.
pub fn amplify<I>(input: I, factor: f32) -> Amplify<I>

View file

@ -1,7 +1,7 @@
use std::f32::consts::PI;
use std::time::Duration;
use Source;
use crate::Source;
// Implemented following http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
@ -77,7 +77,8 @@ where
Some(s) => s,
};
let result = self.applier
let result = self
.applier
.as_ref()
.unwrap()
.apply(sample, self.x_n1, self.x_n2, self.y_n1, self.y_n2);
@ -100,11 +101,7 @@ where
}
}
impl<I> ExactSizeIterator for BltFilter<I>
where
I: Source<Item = f32> + ExactSizeIterator,
{
}
impl<I> ExactSizeIterator for BltFilter<I> where I: Source<Item = f32> + ExactSizeIterator {}
impl<I> Source for BltFilter<I>
where
@ -157,7 +154,7 @@ impl BltFormula {
a1: a1 / a0,
a2: a2 / a0,
}
},
}
}
}
}

View file

@ -2,8 +2,8 @@ use std::cmp;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Buffered` object.
#[inline]
@ -116,7 +116,7 @@ where
&Frame::Input(ref input) => {
let input = input.lock().unwrap().take().unwrap();
extract(input)
},
}
};
*next_frame_ptr = next_frame.clone();
@ -145,12 +145,12 @@ where
current_sample = Some(data[self.position_in_frame].clone());
self.position_in_frame += 1;
advance_frame = self.position_in_frame >= data.len();
},
}
&Frame::End => {
current_sample = None;
advance_frame = false;
},
}
&Frame::Input(_) => unreachable!(),
};

View file

@ -1,6 +1,6 @@
use crate::Sample;
use crate::Source;
use std::time::Duration;
use Sample;
use Source;
/// Combines channels in input into a single mono source, then plays that mono sound
/// to each channel at the volume given for that channel.
@ -29,11 +29,13 @@ where
I::Item: Sample,
{
let mut sample = None;
for _ in 0 .. input.channels() {
for _ in 0..input.channels() {
if let Some(s) = input.next() {
sample = Some(sample
.get_or_insert_with(|| I::Item::zero_value())
.saturating_add(s));
sample = Some(
sample
.get_or_insert_with(|| I::Item::zero_value())
.saturating_add(s),
);
}
}
ChannelVolume {
@ -79,17 +81,20 @@ where
#[inline]
fn next(&mut self) -> Option<I::Item> {
// return value
let ret = self.current_sample
let ret = self
.current_sample
.map(|sample| sample.amplify(self.channel_volumes[self.current_channel]));
self.current_channel += 1;
if self.current_channel >= self.channel_volumes.len() {
self.current_channel = 0;
self.current_sample = None;
for _ in 0 .. self.input.channels() {
for _ in 0..self.input.channels() {
if let Some(s) = self.input.next() {
self.current_sample = Some(self.current_sample
.get_or_insert_with(|| I::Item::zero_value())
.saturating_add(s));
self.current_sample = Some(
self.current_sample
.get_or_insert_with(|| I::Item::zero_value())
.saturating_add(s),
);
}
}
}

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Delay` object.
pub fn delay<I>(input: I, duration: Duration) -> Delay<I>
@ -10,7 +10,7 @@ where
I::Item: Sample,
{
let duration_ns = duration.as_secs() * 1000000000 + duration.subsec_nanos() as u64;
let samples = duration_ns * input.sample_rate() as u64 / 1000000000 * input.channels() as u64;
let samples = duration_ns * input.sample_rate() as u64 / 1000000000 * input.channels() as u64;
Delay {
input: input,

View file

@ -1,8 +1,8 @@
use crate::Sample;
use crate::Source;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::Duration;
use Sample;
use Source;
/// When the inner source is empty this decrements an `AtomicUsize`.
#[derive(Debug, Clone)]

View file

@ -1,7 +1,7 @@
use crate::Sample;
use crate::Source;
use std::marker::PhantomData;
use std::time::Duration;
use Sample;
use Source;
/// An empty source.
#[derive(Debug, Copy, Clone)]

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `FadeIn` object.
pub fn fadein<I>(input: I, duration: Duration) -> FadeIn<I>

View file

@ -1,5 +1,5 @@
use source::from_iter;
use source::FromIter;
use crate::source::from_iter;
use crate::source::FromIter;
/// Builds a source that chains sources built from a factory.
///

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Builds a source that chains sources provided by an iterator.
///
@ -140,13 +140,13 @@ where
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use source::from_iter;
use source::Source;
use crate::buffer::SamplesBuffer;
use crate::source::from_iter;
use crate::source::Source;
#[test]
fn basic() {
let mut rx = from_iter((0 .. 2).map(|n| {
let mut rx = from_iter((0..2).map(|n| {
if n == 0 {
SamplesBuffer::new(1, 48000, vec![10i16, -10, 10, -10])
} else if n == 1 {

View file

@ -1,10 +1,10 @@
use std::cmp;
use std::time::Duration;
use source::uniform::UniformSourceIterator;
use crate::source::uniform::UniformSourceIterator;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Mix` object.
pub fn mix<I1, I2>(input1: I1, input2: I2) -> Mix<I1, I2>

View file

@ -2,7 +2,7 @@
use std::time::Duration;
use Sample;
use crate::Sample;
pub use self::amplify::Amplify;
pub use self::blt::BltFilter;

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Pausable` object.
pub fn pausable<I>(source: I, paused: bool) -> Pausable<I>

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `PeriodicAccess` object.
pub fn periodic<I, F>(source: I, period: Duration, modifier: F) -> PeriodicAccess<I, F>
@ -18,7 +18,11 @@ where
input: source,
modifier: modifier,
// Can overflow when subtracting if this is 0
update_frequency: if update_frequency == 0 { 1 } else { update_frequency },
update_frequency: if update_frequency == 0 {
1
} else {
update_frequency
},
samples_until_update: 1,
}
}
@ -64,7 +68,6 @@ where
}
}
impl<I, F> Iterator for PeriodicAccess<I, F>
where
I: Source,
@ -119,10 +122,10 @@ where
#[cfg(test)]
mod tests {
use buffer::SamplesBuffer;
use std::time::Duration;
use source::Source;
use crate::buffer::SamplesBuffer;
use crate::source::Source;
use std::cell::RefCell;
use std::time::Duration;
#[test]
fn stereo_access() {
@ -137,13 +140,19 @@ mod tests {
assert_eq!(*cnt.borrow(), 0);
// Always called on first access!
assert_eq!(source.next(), Some(10)); assert_eq!(*cnt.borrow(), 1);
assert_eq!(source.next(), Some(10));
assert_eq!(*cnt.borrow(), 1);
// Called every 1 second afterwards
assert_eq!(source.next(), Some(-10)); assert_eq!(*cnt.borrow(), 1);
assert_eq!(source.next(), Some(10)); assert_eq!(*cnt.borrow(), 2);
assert_eq!(source.next(), Some(-10)); assert_eq!(*cnt.borrow(), 2);
assert_eq!(source.next(), Some(20)); assert_eq!(*cnt.borrow(), 3);
assert_eq!(source.next(), Some(-20)); assert_eq!(*cnt.borrow(), 3);
assert_eq!(source.next(), Some(-10));
assert_eq!(*cnt.borrow(), 1);
assert_eq!(source.next(), Some(10));
assert_eq!(*cnt.borrow(), 2);
assert_eq!(source.next(), Some(-10));
assert_eq!(*cnt.borrow(), 2);
assert_eq!(source.next(), Some(20));
assert_eq!(*cnt.borrow(), 3);
assert_eq!(source.next(), Some(-20));
assert_eq!(*cnt.borrow(), 3);
}
#[test]
@ -156,4 +165,3 @@ mod tests {
source.next(); // Would overflow here.
}
}

View file

@ -1,9 +1,9 @@
use std::time::Duration;
use source::buffered::Buffered;
use crate::source::buffered::Buffered;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Repeat` object.
pub fn repeat<I>(input: I) -> Repeat<I>

View file

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::time::Duration;
use crate::Sample;
use crate::Source;
use cpal::Sample as CpalSample;
use Sample;
use Source;
/// An iterator that reads from a `Source` and converts the samples to a specific rate and
/// channels count.

View file

@ -1,5 +1,5 @@
use crate::Source;
use std::time::Duration;
use Source;
/// An infinite source that produces a sine.
///

View file

@ -1,8 +1,8 @@
use source::ChannelVolume;
use crate::source::ChannelVolume;
use crate::Sample;
use crate::Source;
use std::fmt::Debug;
use std::time::Duration;
use Sample;
use Source;
/// Combines channels in input into a single mono source, then plays that mono sound
/// to each channel at the volume given for that channel.
@ -16,7 +16,8 @@ where
}
fn dist_sq(a: [f32; 3], b: [f32; 3]) -> f32 {
a.iter().zip(b.iter())
a.iter()
.zip(b.iter())
.map(|(a, b)| (a - b) * (a - b))
.sum::<f32>()
}
@ -27,7 +28,10 @@ where
I::Item: Sample + Debug,
{
pub fn new(
input: I, emitter_position: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3],
input: I,
emitter_position: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
) -> Spatial<I>
where
I: Source,
@ -42,7 +46,10 @@ where
/// Sets the position of the emitter and ears in the 3D world.
pub fn set_positions(
&mut self, emitter_pos: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3],
&mut self,
emitter_pos: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
) {
let left_dist_sq = dist_sq(left_ear, emitter_pos);
let right_dist_sq = dist_sq(right_ear, emitter_pos);

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Speed` object.
pub fn speed<I>(input: I, factor: f32) -> Speed<I> {
@ -42,7 +42,6 @@ where
}
}
impl<I> Iterator for Speed<I>
where
I: Source,

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `Stoppable` object.
pub fn stoppable<I>(source: I) -> Stoppable<I> {

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// Internal function that builds a `TakeDuration` object.
pub fn take_duration<I>(input: I, duration: Duration) -> TakeDuration<I>
@ -124,7 +124,7 @@ where
};
self.remaining_duration = self.remaining_duration - self.duration_per_sample;
Some(sample)
} else {
None

View file

@ -3,12 +3,12 @@ use std::time::Duration;
use cpal;
use conversions::ChannelCountConverter;
use conversions::DataConverter;
use conversions::SampleRateConverter;
use crate::conversions::ChannelCountConverter;
use crate::conversions::DataConverter;
use crate::conversions::SampleRateConverter;
use Sample;
use Source;
use crate::Sample;
use crate::Source;
/// An iterator that reads from a `Source` and converts the samples to a specific rate and
/// channels count.
@ -36,7 +36,9 @@ where
{
#[inline]
pub fn new(
input: I, target_channels: u16, target_sample_rate: u32,
input: I,
target_channels: u16,
target_sample_rate: u32,
) -> UniformSourceIterator<I, D> {
let total_duration = input.total_duration();
let input = UniformSourceIterator::bootstrap(input, target_channels, target_sample_rate);
@ -51,7 +53,9 @@ where
#[inline]
fn bootstrap(
input: I, target_channels: u16, target_sample_rate: u32,
input: I,
target_channels: u16,
target_sample_rate: u32,
) -> DataConverter<ChannelCountConverter<SampleRateConverter<Take<I>>>, D> {
let frame_len = input.current_frame_len();
@ -89,7 +93,8 @@ where
return Some(value);
}
let input = self.inner
let input = self
.inner
.take()
.unwrap()
.into_inner()
@ -183,8 +188,4 @@ where
}
}
impl<I> ExactSizeIterator for Take<I>
where
I: ExactSizeIterator,
{
}
impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {}

View file

@ -1,7 +1,7 @@
use crate::Sample;
use crate::Source;
use std::marker::PhantomData;
use std::time::Duration;
use Sample;
use Source;
/// An infinite source that produces zero.
#[derive(Clone, Debug)]

View file

@ -1,12 +1,12 @@
use device::RodioDevice;
use source::Spatial;
use crate::device::RodioDevice;
use crate::source::Spatial;
use crate::Sample;
use crate::Sink;
use crate::Source;
use std::f32;
use std::fmt::Debug;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use Sample;
use Sink;
use Source;
pub struct SpatialSink {
sink: Sink,
@ -23,7 +23,10 @@ impl SpatialSink {
/// Builds a new `SpatialSink`.
#[inline]
pub fn new(
device: &RodioDevice, emitter_position: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3],
device: &RodioDevice,
emitter_position: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
) -> SpatialSink {
SpatialSink {
sink: Sink::new(device),
@ -64,7 +67,8 @@ impl SpatialSink {
pos_lock.emitter_position,
pos_lock.left_ear,
pos_lock.right_ear,
).periodic_access(Duration::from_millis(10), move |i| {
)
.periodic_access(Duration::from_millis(10), move |i| {
let pos = positions.lock().unwrap();
i.set_positions(pos.emitter_position, pos.left_ear, pos.right_ear);
});

View file

@ -10,12 +10,11 @@
//! ```
//!
use std::time::Duration;
use std::slice::Iter as SliceIter;
use std::time::Duration;
use source::Source;
use Sample;
use crate::source::Source;
use crate::Sample;
/// A buffer of samples treated as a source.
#[derive(Clone)]
@ -42,13 +41,13 @@ where
/// - Panicks if the length of the buffer is larger than approximatively 16 billion elements.
/// This is because the calculation of the duration would overflow.
///
pub fn new(channels: u16, sample_rate: u32, data: &'static [S]) -> StaticSamplesBuffer<S>
{
pub fn new(channels: u16, sample_rate: u32, data: &'static [S]) -> StaticSamplesBuffer<S> {
assert!(channels != 0);
assert!(sample_rate != 0);
let duration_ns = 1_000_000_000u64.checked_mul(data.len() as u64).unwrap()
/ sample_rate as u64 / channels as u64;
/ sample_rate as u64
/ channels as u64;
let duration = Duration::new(
duration_ns / 1_000_000_000,
(duration_ns % 1_000_000_000) as u32,
@ -107,8 +106,8 @@ where
#[cfg(test)]
mod tests {
use static_buffer::StaticSamplesBuffer;
use source::Source;
use crate::source::Source;
use crate::static_buffer::StaticSamplesBuffer;
#[test]
fn basic() {

View file

@ -1,4 +1,4 @@
extern crate rodio;
use rodio;
use rodio::Source;
use std::{io::BufReader, time::Duration};

View file

@ -1,4 +1,4 @@
extern crate rodio;
use rodio;
use std::io::BufReader;
@ -24,7 +24,7 @@ fn test_wav_encodings() {
let mut decoder = rodio::Decoder::new(BufReader::new(file)).unwrap();
assert!(decoder.any(|x| x != 0));
// 32 bit wav file exported from LMMS (2 channels)
// 32 bit wav file exported from LMMS (2 channels)
let file = std::fs::File::open("tests/lmms32bit.wav").unwrap();
let mut decoder = rodio::Decoder::new(BufReader::new(file)).unwrap();
assert!(decoder.any(|x| x != 0));