From c93adb2582c8defb21dbeacfa034301b345a00e8 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Fri, 31 Jan 2020 00:15:41 +0000 Subject: [PATCH] Migrate to edition 2018 * Remove unstable/legacy rustfmt config * Run rustfmt --- .rustfmt.toml | 16 --------------- Cargo.toml | 1 + examples/basic.rs | 2 -- examples/music_flac.rs | 2 -- examples/music_mp3.rs | 2 -- examples/music_ogg.rs | 2 -- examples/music_wav.rs | 2 -- examples/reverb.rs | 2 +- examples/spatial.rs | 8 ++++---- src/buffer.rs | 12 +++++------ src/conversions/channels.rs | 6 ++++-- src/conversions/sample_rate.rs | 11 ++++++---- src/decoder/flac.rs | 7 ++++--- src/decoder/mod.rs | 12 +++++------ src/decoder/mp3.rs | 8 ++++---- src/decoder/vorbis.rs | 2 +- src/decoder/wav.rs | 16 ++++----------- src/device.rs | 10 ++++----- src/device_mixer.rs | 6 +++--- src/dynamic_mixer.rs | 16 +++++++-------- src/lib.rs | 31 +++++++++------------------- src/queue.rs | 19 +++++++++-------- src/sink.rs | 17 ++++++++-------- src/source/amplify.rs | 4 ++-- src/source/blt.rs | 13 +++++------- src/source/buffered.rs | 10 ++++----- src/source/channel_volume.rs | 27 +++++++++++++++---------- src/source/delay.rs | 6 +++--- src/source/done.rs | 4 ++-- src/source/empty.rs | 4 ++-- src/source/fadein.rs | 4 ++-- src/source/from_factory.rs | 4 ++-- src/source/from_iter.rs | 12 +++++------ src/source/mix.rs | 6 +++--- src/source/mod.rs | 2 +- src/source/pausable.rs | 4 ++-- src/source/periodic.rs | 36 ++++++++++++++++++++------------- src/source/repeat.rs | 6 +++--- src/source/samples_converter.rs | 4 ++-- src/source/sine.rs | 2 +- src/source/spatial.rs | 19 +++++++++++------ src/source/speed.rs | 5 ++--- src/source/stoppable.rs | 4 ++-- src/source/take.rs | 6 +++--- src/source/uniform.rs | 27 +++++++++++++------------ src/source/zero.rs | 4 ++-- src/spatial_sink.rs | 18 ++++++++++------- src/static_buffer.rs | 17 ++++++++-------- tests/flac_test.rs | 2 +- tests/wav_test.rs | 4 ++-- 50 files changed, 222 insertions(+), 242 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 5d38d1c..45e2070 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 254c2bc..f66ca0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/examples/basic.rs b/examples/basic.rs index 72e984d..35a676f 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,5 +1,3 @@ -extern crate rodio; - use std::io::BufReader; use std::thread; use std::time::Duration; diff --git a/examples/music_flac.rs b/examples/music_flac.rs index 76ea55c..ff0dfa5 100644 --- a/examples/music_flac.rs +++ b/examples/music_flac.rs @@ -1,5 +1,3 @@ -extern crate rodio; - use std::io::BufReader; fn main() { diff --git a/examples/music_mp3.rs b/examples/music_mp3.rs index a6aeadf..e30ea87 100644 --- a/examples/music_mp3.rs +++ b/examples/music_mp3.rs @@ -1,5 +1,3 @@ -extern crate rodio; - use std::io::BufReader; fn main() { diff --git a/examples/music_ogg.rs b/examples/music_ogg.rs index 5a69eec..e756159 100644 --- a/examples/music_ogg.rs +++ b/examples/music_ogg.rs @@ -1,5 +1,3 @@ -extern crate rodio; - use std::io::BufReader; fn main() { diff --git a/examples/music_wav.rs b/examples/music_wav.rs index 0f405f0..27cb594 100644 --- a/examples/music_wav.rs +++ b/examples/music_wav.rs @@ -1,5 +1,3 @@ -extern crate rodio; - use std::io::BufReader; fn main() { diff --git a/examples/reverb.rs b/examples/reverb.rs index 3f39319..2629617 100644 --- a/examples/reverb.rs +++ b/examples/reverb.rs @@ -1,4 +1,4 @@ -extern crate rodio; +use rodio; use rodio::Source; use std::io::BufReader; diff --git a/examples/spatial.rs b/examples/spatial.rs index 9f3448a..994a176 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -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]); } diff --git a/src/buffer.rs b/src/buffer.rs index 6a39d06..e3295e1 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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 { @@ -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() { diff --git a/src/conversions/channels.rs b/src/conversions/channels.rs index 1821093..1d3ffbd 100644 --- a/src/conversions/channels.rs +++ b/src/conversions/channels.rs @@ -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 { 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 } } diff --git a/src/conversions/sample_rate.rs b/src/conversions/sample_rate.rs index 82feeca..2694b47 100644 --- a/src/conversions/sample_rate.rs +++ b/src/conversions/sample_rate.rs @@ -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 { 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() diff --git a/src/decoder/flac.rs b/src/decoder/flac.rs index 01111c3..4fa2bd8 100644 --- a/src/decoder/flac.rs +++ b/src/decoder/flac.rs @@ -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 { // `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, } } diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index f174ed0..4d9a3a4 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -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"), } diff --git a/src/decoder/mp3.rs b/src/decoder/mp3.rs index 9847bc3..0eb55a6 100644 --- a/src/decoder/mp3.rs +++ b/src/decoder/mp3.rs @@ -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 Source for Mp3Decoder where - R: Read + Seek + R: Read + Seek, { #[inline] fn current_frame_len(&self) -> Option { @@ -57,7 +57,7 @@ where impl Iterator for Mp3Decoder where - R: Read + Seek + R: Read + Seek, { type Item = i16; @@ -76,4 +76,4 @@ where return Some(v); } -} \ No newline at end of file +} diff --git a/src/decoder/vorbis.rs b/src/decoder/vorbis.rs index 83a82f8..490a6ab 100644 --- a/src/decoder/vorbis.rs +++ b/src/decoder/vorbis.rs @@ -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; diff --git a/src/decoder/wav.rs b/src/decoder/wav.rs index 57482b9..434bb1f 100644 --- a/src/decoder/wav.rs +++ b/src/decoder/wav.rs @@ -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 ExactSizeIterator for SamplesIterator -where - R: Read + Seek, -{ -} +impl ExactSizeIterator for SamplesIterator where R: Read + Seek {} impl Source for WavDecoder where @@ -133,11 +129,7 @@ where } } -impl ExactSizeIterator for WavDecoder -where - R: Read + Seek, -{ -} +impl ExactSizeIterator for WavDecoder where R: Read + Seek {} /// Returns true if the stream contains WAV data, then resets it to where it was. fn is_wave(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 { diff --git a/src/device.rs b/src/device.rs index 0092160..1ae49de 100644 --- a/src/device.rs +++ b/src/device.rs @@ -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; diff --git a/src/device_mixer.rs b/src/device_mixer.rs index 8c5fff5..0d739cc 100644 --- a/src/device_mixer.rs +++ b/src/device_mixer.rs @@ -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; diff --git a/src/dynamic_mixer.rs b/src/dynamic_mixer.rs index 361fff2..267a407 100644 --- a/src/dynamic_mixer.rs +++ b/src/dynamic_mixer.rs @@ -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( - channels: u16, sample_rate: u32, + channels: u16, + sample_rate: u32, ) -> (Arc>, DynamicMixer) 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() { diff --git a/src/lib.rs b/src/lib.rs index fd5b53c..fe2afac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/queue.rs b/src/queue.rs index bc837e3..8f9d63d 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -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)); } diff --git a/src/sink.rs b/src/sink.rs index 8594da9..3dcf34d 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -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() { diff --git a/src/source/amplify.rs b/src/source/amplify.rs index 6f7f050..64d2825 100644 --- a/src/source/amplify.rs +++ b/src/source/amplify.rs @@ -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(input: I, factor: f32) -> Amplify diff --git a/src/source/blt.rs b/src/source/blt.rs index de5ca54..30cf5c4 100644 --- a/src/source/blt.rs +++ b/src/source/blt.rs @@ -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 ExactSizeIterator for BltFilter -where - I: Source + ExactSizeIterator, -{ -} +impl ExactSizeIterator for BltFilter where I: Source + ExactSizeIterator {} impl Source for BltFilter where @@ -157,7 +154,7 @@ impl BltFormula { a1: a1 / a0, a2: a2 / a0, } - }, + } } } } diff --git a/src/source/buffered.rs b/src/source/buffered.rs index 55990e6..ce3aa23 100644 --- a/src/source/buffered.rs +++ b/src/source/buffered.rs @@ -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!(), }; diff --git a/src/source/channel_volume.rs b/src/source/channel_volume.rs index 29b0b84..fdaa7d1 100644 --- a/src/source/channel_volume.rs +++ b/src/source/channel_volume.rs @@ -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 { // 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), + ); } } } diff --git a/src/source/delay.rs b/src/source/delay.rs index 0fcd1fa..17c42f8 100644 --- a/src/source/delay.rs +++ b/src/source/delay.rs @@ -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(input: I, duration: Duration) -> Delay @@ -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, diff --git a/src/source/done.rs b/src/source/done.rs index 417ab6e..fb26713 100644 --- a/src/source/done.rs +++ b/src/source/done.rs @@ -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)] diff --git a/src/source/empty.rs b/src/source/empty.rs index 2f387e1..b5c6e77 100644 --- a/src/source/empty.rs +++ b/src/source/empty.rs @@ -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)] diff --git a/src/source/fadein.rs b/src/source/fadein.rs index 1c478a4..2f513c5 100644 --- a/src/source/fadein.rs +++ b/src/source/fadein.rs @@ -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(input: I, duration: Duration) -> FadeIn diff --git a/src/source/from_factory.rs b/src/source/from_factory.rs index 63d21e1..2d0d42c 100644 --- a/src/source/from_factory.rs +++ b/src/source/from_factory.rs @@ -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. /// diff --git a/src/source/from_iter.rs b/src/source/from_iter.rs index aec444e..6a6aece 100644 --- a/src/source/from_iter.rs +++ b/src/source/from_iter.rs @@ -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 { diff --git a/src/source/mix.rs b/src/source/mix.rs index 607bd51..7d55979 100644 --- a/src/source/mix.rs +++ b/src/source/mix.rs @@ -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(input1: I1, input2: I2) -> Mix diff --git a/src/source/mod.rs b/src/source/mod.rs index 1c8efa8..a26544c 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -2,7 +2,7 @@ use std::time::Duration; -use Sample; +use crate::Sample; pub use self::amplify::Amplify; pub use self::blt::BltFilter; diff --git a/src/source/pausable.rs b/src/source/pausable.rs index 9a0b6e0..6b30220 100644 --- a/src/source/pausable.rs +++ b/src/source/pausable.rs @@ -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(source: I, paused: bool) -> Pausable diff --git a/src/source/periodic.rs b/src/source/periodic.rs index d8daebe..ec5dc96 100644 --- a/src/source/periodic.rs +++ b/src/source/periodic.rs @@ -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(source: I, period: Duration, modifier: F) -> PeriodicAccess @@ -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 Iterator for PeriodicAccess 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. } } - diff --git a/src/source/repeat.rs b/src/source/repeat.rs index aa8fbc8..eb415f9 100644 --- a/src/source/repeat.rs +++ b/src/source/repeat.rs @@ -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(input: I) -> Repeat diff --git a/src/source/samples_converter.rs b/src/source/samples_converter.rs index 9aba516..af8c856 100644 --- a/src/source/samples_converter.rs +++ b/src/source/samples_converter.rs @@ -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. diff --git a/src/source/sine.rs b/src/source/sine.rs index 152e8a0..cb3fb40 100644 --- a/src/source/sine.rs +++ b/src/source/sine.rs @@ -1,5 +1,5 @@ +use crate::Source; use std::time::Duration; -use Source; /// An infinite source that produces a sine. /// diff --git a/src/source/spatial.rs b/src/source/spatial.rs index 6485556..ea7f6e7 100644 --- a/src/source/spatial.rs +++ b/src/source/spatial.rs @@ -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::() } @@ -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 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); diff --git a/src/source/speed.rs b/src/source/speed.rs index 6b87470..19fab92 100644 --- a/src/source/speed.rs +++ b/src/source/speed.rs @@ -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(input: I, factor: f32) -> Speed { @@ -42,7 +42,6 @@ where } } - impl Iterator for Speed where I: Source, diff --git a/src/source/stoppable.rs b/src/source/stoppable.rs index 4825991..ae9fd96 100644 --- a/src/source/stoppable.rs +++ b/src/source/stoppable.rs @@ -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(source: I) -> Stoppable { diff --git a/src/source/take.rs b/src/source/take.rs index 476cccd..0ed2acf 100644 --- a/src/source/take.rs +++ b/src/source/take.rs @@ -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(input: I, duration: Duration) -> TakeDuration @@ -124,7 +124,7 @@ where }; self.remaining_duration = self.remaining_duration - self.duration_per_sample; - + Some(sample) } else { None diff --git a/src/source/uniform.rs b/src/source/uniform.rs index 3f2eed5..254fef8 100644 --- a/src/source/uniform.rs +++ b/src/source/uniform.rs @@ -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 { 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>>, 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 ExactSizeIterator for Take -where - I: ExactSizeIterator, -{ -} +impl ExactSizeIterator for Take where I: ExactSizeIterator {} diff --git a/src/source/zero.rs b/src/source/zero.rs index c7521ec..e749754 100644 --- a/src/source/zero.rs +++ b/src/source/zero.rs @@ -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)] diff --git a/src/spatial_sink.rs b/src/spatial_sink.rs index 500e90a..8fe3d7c 100644 --- a/src/spatial_sink.rs +++ b/src/spatial_sink.rs @@ -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); }); diff --git a/src/static_buffer.rs b/src/static_buffer.rs index a256212..2b6f4d5 100644 --- a/src/static_buffer.rs +++ b/src/static_buffer.rs @@ -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 - { + pub fn new(channels: u16, sample_rate: u32, data: &'static [S]) -> StaticSamplesBuffer { 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() { diff --git a/tests/flac_test.rs b/tests/flac_test.rs index 7701109..7655a3d 100644 --- a/tests/flac_test.rs +++ b/tests/flac_test.rs @@ -1,4 +1,4 @@ -extern crate rodio; +use rodio; use rodio::Source; use std::{io::BufReader, time::Duration}; diff --git a/tests/wav_test.rs b/tests/wav_test.rs index e8490d2..a8b31da 100644 --- a/tests/wav_test.rs +++ b/tests/wav_test.rs @@ -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));