diff --git a/audio/src/libvorbis_decoder.rs b/audio/src/libvorbis_decoder.rs index 449caaeb..e7ccc984 100644 --- a/audio/src/libvorbis_decoder.rs +++ b/audio/src/libvorbis_decoder.rs @@ -45,13 +45,7 @@ where packet .data .iter() - .map(|sample| { - if *sample == 0 { - 0.0 - } else { - ((*sample as f64 + 0.5) / (0x7FFF as f64 + 0.5)) as f32 - } - }) + .map(|sample| ((*sample as f64 + 0.5) / (0x7FFF as f64 + 0.5)) as f32) .collect(), ))); } diff --git a/playback/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs index 35d0ab11..fc2a775c 100644 --- a/playback/src/audio_backend/alsa.rs +++ b/playback/src/audio_backend/alsa.rs @@ -52,8 +52,6 @@ fn open_device(dev_name: &str, format: AudioFormat) -> Result<(PCM, Frames), Box // For stereo samples encoded as 32-bit float, one frame has a length of eight bytes. let mut period_size = ((SAMPLES_PER_SECOND * format.size() as u32) as f32 * (BUFFERED_LATENCY / BUFFERED_PERIODS as f32)) as Frames; - - // Set hardware parameters: 44100 Hz / stereo / 32-bit float or 16-bit signed integer { let hwp = HwParams::any(&pcm)?; hwp.set_access(Access::RWInterleaved)?; diff --git a/playback/src/audio_backend/jackaudio.rs b/playback/src/audio_backend/jackaudio.rs index 05c6c317..ed6ae1f7 100644 --- a/playback/src/audio_backend/jackaudio.rs +++ b/playback/src/audio_backend/jackaudio.rs @@ -5,8 +5,8 @@ use crate::player::NUM_CHANNELS; use jack::{ AsyncClient, AudioOut, Client, ClientOptions, Control, Port, ProcessHandler, ProcessScope, }; +use std::io; use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; -use std::{io, mem}; pub struct JackSink { send: SyncSender, @@ -53,7 +53,7 @@ impl Open for JackSink { let ch_r = client.register_port("out_0", AudioOut::default()).unwrap(); let ch_l = client.register_port("out_1", AudioOut::default()).unwrap(); // buffer for samples from librespot (~10ms) - let (tx, rx) = sync_channel::(NUM_CHANNELS as usize * 1024 * mem::size_of::()); + let (tx, rx) = sync_channel::(NUM_CHANNELS as usize * 1024 * format.size()); let jack_data = JackData { rec: rx, port_l: ch_l, @@ -75,7 +75,7 @@ impl Sink for JackSink { for s in packet.samples().iter() { let res = self.send.send(*s); if res.is_err() { - error!("jackaudio: cannot write to channel"); + error!("cannot write to channel"); } } Ok(()) diff --git a/playback/src/audio_backend/portaudio.rs b/playback/src/audio_backend/portaudio.rs index 213f2d02..fca305e0 100644 --- a/playback/src/audio_backend/portaudio.rs +++ b/playback/src/audio_backend/portaudio.rs @@ -18,10 +18,6 @@ pub enum PortAudioSink<'a> { Option>, StreamParameters, ), - S24( - Option>, - StreamParameters, - ), S16( Option>, StreamParameters, @@ -91,11 +87,10 @@ impl<'a> Open for PortAudioSink<'a> { match format { AudioFormat::F32 => open_sink!(Self::F32, f32), AudioFormat::S32 => open_sink!(Self::S32, i32), - AudioFormat::S24 => open_sink!(Self::S24, i32), - AudioFormat::S24_3 => { - unimplemented!("PortAudio currently does not support S24_3 output") - } AudioFormat::S16 => open_sink!(Self::S16, i16), + _ => { + unimplemented!("PortAudio currently does not support {:?} output", format) + } } } } @@ -123,7 +118,6 @@ impl<'a> Sink for PortAudioSink<'a> { match self { Self::F32(stream, parameters) => start_sink!(stream, parameters), Self::S32(stream, parameters) => start_sink!(stream, parameters), - Self::S24(stream, parameters) => start_sink!(stream, parameters), Self::S16(stream, parameters) => start_sink!(stream, parameters), }; @@ -140,7 +134,6 @@ impl<'a> Sink for PortAudioSink<'a> { match self { Self::F32(stream, _parameters) => stop_sink!(stream), Self::S32(stream, _parameters) => stop_sink!(stream), - Self::S24(stream, _parameters) => stop_sink!(stream), Self::S16(stream, _parameters) => stop_sink!(stream), }; @@ -162,10 +155,6 @@ impl<'a> Sink for PortAudioSink<'a> { let samples_s32: Vec = AudioPacket::f32_to_s32(packet.samples()); write_sink!(stream, &samples_s32) } - Self::S24(stream, _parameters) => { - let samples_s24: Vec = AudioPacket::f32_to_s24(packet.samples()); - write_sink!(stream, &samples_s24) - } Self::S16(stream, _parameters) => { let samples_s16: Vec = AudioPacket::f32_to_s16(packet.samples()); write_sink!(stream, &samples_s16) diff --git a/playback/src/audio_backend/sdl.rs b/playback/src/audio_backend/sdl.rs index 32d710f8..64523732 100644 --- a/playback/src/audio_backend/sdl.rs +++ b/playback/src/audio_backend/sdl.rs @@ -8,7 +8,6 @@ use std::{io, mem, thread, time}; pub enum SdlSink { F32(AudioQueue), S32(AudioQueue), - S24(AudioQueue), S16(AudioQueue), } @@ -42,9 +41,10 @@ impl Open for SdlSink { match format { AudioFormat::F32 => open_sink!(Self::F32, f32), AudioFormat::S32 => open_sink!(Self::S32, i32), - AudioFormat::S24 => open_sink!(Self::S24, i32), - AudioFormat::S24_3 => unimplemented!("SDL currently does not support S24_3 output"), AudioFormat::S16 => open_sink!(Self::S16, i16), + _ => { + unimplemented!("SDL currently does not support {:?} output", format) + } } } } @@ -60,7 +60,6 @@ impl Sink for SdlSink { match self { Self::F32(queue) => start_sink!(queue), Self::S32(queue) => start_sink!(queue), - Self::S24(queue) => start_sink!(queue), Self::S16(queue) => start_sink!(queue), }; Ok(()) @@ -76,7 +75,6 @@ impl Sink for SdlSink { match self { Self::F32(queue) => stop_sink!(queue), Self::S32(queue) => stop_sink!(queue), - Self::S24(queue) => stop_sink!(queue), Self::S16(queue) => stop_sink!(queue), }; Ok(()) @@ -101,11 +99,6 @@ impl Sink for SdlSink { let samples_s32: Vec = AudioPacket::f32_to_s32(packet.samples()); queue.queue(&samples_s32) } - Self::S24(queue) => { - drain_sink!(queue, mem::size_of::()); - let samples_s24: Vec = AudioPacket::f32_to_s24(packet.samples()); - queue.queue(&samples_s24) - } Self::S16(queue) => { drain_sink!(queue, mem::size_of::()); let samples_s16: Vec = AudioPacket::f32_to_s16(packet.samples()); diff --git a/playback/src/config.rs b/playback/src/config.rs index 630c1406..95c97092 100644 --- a/playback/src/config.rs +++ b/playback/src/config.rs @@ -14,17 +14,17 @@ impl FromStr for Bitrate { type Err = (); fn from_str(s: &str) -> Result { match s { - "96" => Ok(Bitrate::Bitrate96), - "160" => Ok(Bitrate::Bitrate160), - "320" => Ok(Bitrate::Bitrate320), + "96" => Ok(Self::Bitrate96), + "160" => Ok(Self::Bitrate160), + "320" => Ok(Self::Bitrate320), _ => Err(()), } } } impl Default for Bitrate { - fn default() -> Bitrate { - Bitrate::Bitrate160 + fn default() -> Self { + Self::Bitrate160 } } @@ -52,7 +52,7 @@ impl TryFrom<&String> for AudioFormat { } impl Default for AudioFormat { - fn default() -> AudioFormat { + fn default() -> Self { Self::S16 } } @@ -64,7 +64,7 @@ impl AudioFormat { match self { Self::S24_3 => mem::size_of::(), Self::S16 => mem::size_of::(), - _ => mem::size_of::(), + _ => mem::size_of::(), // S32 and S24 are both stored in i32 } } } @@ -79,16 +79,16 @@ impl FromStr for NormalisationType { type Err = (); fn from_str(s: &str) -> Result { match s { - "album" => Ok(NormalisationType::Album), - "track" => Ok(NormalisationType::Track), + "album" => Ok(Self::Album), + "track" => Ok(Self::Track), _ => Err(()), } } } impl Default for NormalisationType { - fn default() -> NormalisationType { - NormalisationType::Album + fn default() -> Self { + Self::Album } } @@ -102,16 +102,16 @@ impl FromStr for NormalisationMethod { type Err = (); fn from_str(s: &str) -> Result { match s { - "basic" => Ok(NormalisationMethod::Basic), - "dynamic" => Ok(NormalisationMethod::Dynamic), + "basic" => Ok(Self::Basic), + "dynamic" => Ok(Self::Dynamic), _ => Err(()), } } } impl Default for NormalisationMethod { - fn default() -> NormalisationMethod { - NormalisationMethod::Dynamic + fn default() -> Self { + Self::Dynamic } }