From 19f0555e7c04dcf686767a8128f1b69bc2f5320d Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 27 May 2021 23:44:45 +0200 Subject: [PATCH] Fix leftovers from merging diverging branches --- playback/src/convert.rs | 8 +-- playback/src/decoder/libvorbis_decoder.rs | 86 ----------------------- playback/src/mixer/mappings.rs | 2 +- 3 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 playback/src/decoder/libvorbis_decoder.rs diff --git a/playback/src/convert.rs b/playback/src/convert.rs index c344d3e3..a5d5a0bb 100644 --- a/playback/src/convert.rs +++ b/playback/src/convert.rs @@ -36,6 +36,10 @@ impl Converter { // the reference Vorbis implementation uses: sample * 32768 (for 16 bit) let int_value = sample * factor as f32; + // https://doc.rust-lang.org/nomicon/casts.html: casting float to integer + // rounds towards zero, then saturates. Ideally halves should round to even to + // prevent any bias, but since it is extremely unlikely that a float has + // *exactly* .5 as fraction, this should be more than precise enough. match self.ditherer { Some(ref mut d) => int_value + d.noise(int_value), None => int_value, @@ -62,10 +66,6 @@ impl Converter { int_value } - // https://doc.rust-lang.org/nomicon/casts.html: casting float to integer - // rounds towards zero, then saturates. Ideally halves should round to even to - // prevent any bias, but since it is extremely unlikely that a float has - // *exactly* .5 as fraction, this should be more than precise enough. pub fn f32_to_s32(&mut self, samples: &[f32]) -> Vec { samples .iter() diff --git a/playback/src/decoder/libvorbis_decoder.rs b/playback/src/decoder/libvorbis_decoder.rs deleted file mode 100644 index 23e66583..00000000 --- a/playback/src/decoder/libvorbis_decoder.rs +++ /dev/null @@ -1,86 +0,0 @@ -#[cfg(feature = "with-tremor")] -use librespot_tremor as vorbis; - -use super::{AudioDecoder, AudioError, AudioPacket}; -use std::error; -use std::fmt; -use std::io::{Read, Seek}; - -pub struct VorbisDecoder(vorbis::Decoder); -pub struct VorbisError(vorbis::VorbisError); - -impl VorbisDecoder -where - R: Read + Seek, -{ - pub fn new(input: R) -> Result, VorbisError> { - Ok(VorbisDecoder(vorbis::Decoder::new(input)?)) - } -} - -impl AudioDecoder for VorbisDecoder -where - R: Read + Seek, -{ - #[cfg(not(feature = "with-tremor"))] - fn seek(&mut self, ms: i64) -> Result<(), AudioError> { - self.0.time_seek(ms as f64 / 1000f64)?; - Ok(()) - } - - #[cfg(feature = "with-tremor")] - fn seek(&mut self, ms: i64) -> Result<(), AudioError> { - self.0.time_seek(ms)?; - Ok(()) - } - - fn next_packet(&mut self) -> Result, AudioError> { - loop { - match self.0.packets().next() { - Some(Ok(packet)) => { - return Ok(Some(AudioPacket::Samples( - packet - .data - .iter() - .map(|sample| (*sample as f64 / 0x8000 as f64) as f32) - .collect(), - ))); - } - None => return Ok(None), - - Some(Err(vorbis::VorbisError::Hole)) => (), - Some(Err(err)) => return Err(err.into()), - } - } - } -} - -impl From for VorbisError { - fn from(err: vorbis::VorbisError) -> VorbisError { - VorbisError(err) - } -} - -impl fmt::Debug for VorbisError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.0, f) - } -} - -impl fmt::Display for VorbisError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(&self.0, f) - } -} - -impl error::Error for VorbisError { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - error::Error::source(&self.0) - } -} - -impl From for AudioError { - fn from(err: vorbis::VorbisError) -> AudioError { - AudioError::VorbisError(VorbisError(err)) - } -} diff --git a/playback/src/mixer/mappings.rs b/playback/src/mixer/mappings.rs index 6a274442..d47744d3 100644 --- a/playback/src/mixer/mappings.rs +++ b/playback/src/mixer/mappings.rs @@ -17,7 +17,7 @@ impl MappedCtrl for VolumeCtrl { // reach zero). if volume == 0 { return 0.0; - } else if volume == 1 { + } else if volume == Self::MAX_VOLUME { // And limit in case of rounding errors (as is the case for log). return 1.0; }