mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Fix clippy warnings
This commit is contained in:
parent
a576194b0e
commit
b4f9ae31e2
12 changed files with 44 additions and 52 deletions
|
@ -36,24 +36,21 @@ macro_rules! convert_samples_to {
|
|||
};
|
||||
}
|
||||
|
||||
pub struct SamplesConverter {}
|
||||
impl SamplesConverter {
|
||||
pub fn to_s32(samples: &[f32]) -> Vec<i32> {
|
||||
convert_samples_to!(i32, samples)
|
||||
}
|
||||
|
||||
pub fn to_s24(samples: &[f32]) -> Vec<i32> {
|
||||
convert_samples_to!(i32, samples, 8)
|
||||
}
|
||||
|
||||
pub fn to_s24_3(samples: &[f32]) -> Vec<i24> {
|
||||
Self::to_s32(samples)
|
||||
.iter()
|
||||
.map(|sample| i24::pcm_from_i32(*sample))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn to_s16(samples: &[f32]) -> Vec<i16> {
|
||||
convert_samples_to!(i16, samples)
|
||||
}
|
||||
pub fn to_s32(samples: &[f32]) -> Vec<i32> {
|
||||
convert_samples_to!(i32, samples)
|
||||
}
|
||||
|
||||
pub fn to_s24(samples: &[f32]) -> Vec<i32> {
|
||||
convert_samples_to!(i32, samples, 8)
|
||||
}
|
||||
|
||||
pub fn to_s24_3(samples: &[f32]) -> Vec<i24> {
|
||||
to_s32(samples)
|
||||
.iter()
|
||||
.map(|sample| i24::pcm_from_i32(*sample))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn to_s16(samples: &[f32]) -> Vec<i16> {
|
||||
convert_samples_to!(i16, samples)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod convert;
|
||||
pub mod convert;
|
||||
mod decrypt;
|
||||
mod fetch;
|
||||
|
||||
|
@ -24,7 +24,6 @@ pub use passthrough_decoder::{PassthroughDecoder, PassthroughError};
|
|||
|
||||
mod range_set;
|
||||
|
||||
pub use convert::{i24, SamplesConverter};
|
||||
pub use decrypt::AudioDecrypt;
|
||||
pub use fetch::{AudioFile, StreamLoaderController};
|
||||
pub use fetch::{
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Open for AlsaSink {
|
|||
|
||||
Self {
|
||||
pcm: None,
|
||||
format: format,
|
||||
format,
|
||||
device: name,
|
||||
buffer: vec![],
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ impl SinkAsBytes for AlsaSink {
|
|||
.extend_from_slice(&data[processed_data..processed_data + data_to_buffer]);
|
||||
processed_data += data_to_buffer;
|
||||
if self.buffer.len() == self.buffer.capacity() {
|
||||
self.write_buf().expect("could not append to buffer");
|
||||
self.write_buf();
|
||||
self.buffer.clear();
|
||||
}
|
||||
}
|
||||
|
@ -156,14 +156,12 @@ impl SinkAsBytes for AlsaSink {
|
|||
}
|
||||
|
||||
impl AlsaSink {
|
||||
fn write_buf(&mut self) -> io::Result<()> {
|
||||
fn write_buf(&mut self) {
|
||||
let pcm = self.pcm.as_mut().unwrap();
|
||||
let io = pcm.io_bytes();
|
||||
match io.writei(&self.buffer) {
|
||||
Ok(_) => (),
|
||||
Err(err) => pcm.try_recover(err, false).unwrap(),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ impl Open for JackSink {
|
|||
}
|
||||
info!("Using JACK sink with format {:?}", AudioFormat::F32);
|
||||
|
||||
let client_name = client_name.unwrap_or("librespot".to_string());
|
||||
let client_name = client_name.unwrap_or_else(|| "librespot".to_string());
|
||||
let (client, _status) =
|
||||
Client::new(&client_name[..], ClientOptions::NO_START_SERVER).unwrap();
|
||||
let ch_r = client.register_port("out_0", AudioOut::default()).unwrap();
|
||||
|
|
|
@ -26,25 +26,25 @@ fn mk_sink<S: Sink + Open + 'static>(device: Option<String>, format: AudioFormat
|
|||
macro_rules! sink_as_bytes {
|
||||
() => {
|
||||
fn write(&mut self, packet: &AudioPacket) -> io::Result<()> {
|
||||
use crate::audio::{i24, SamplesConverter};
|
||||
use crate::audio::convert::{self, i24};
|
||||
use zerocopy::AsBytes;
|
||||
match packet {
|
||||
AudioPacket::Samples(samples) => match self.format {
|
||||
AudioFormat::F32 => self.write_bytes(samples.as_bytes()),
|
||||
AudioFormat::S32 => {
|
||||
let samples_s32: &[i32] = &SamplesConverter::to_s32(samples);
|
||||
let samples_s32: &[i32] = &convert::to_s32(samples);
|
||||
self.write_bytes(samples_s32.as_bytes())
|
||||
}
|
||||
AudioFormat::S24 => {
|
||||
let samples_s24: &[i32] = &SamplesConverter::to_s24(samples);
|
||||
let samples_s24: &[i32] = &convert::to_s24(samples);
|
||||
self.write_bytes(samples_s24.as_bytes())
|
||||
}
|
||||
AudioFormat::S24_3 => {
|
||||
let samples_s24_3: &[i24] = &SamplesConverter::to_s24_3(samples);
|
||||
let samples_s24_3: &[i24] = &convert::to_s24_3(samples);
|
||||
self.write_bytes(samples_s24_3.as_bytes())
|
||||
}
|
||||
AudioFormat::S16 => {
|
||||
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
|
||||
let samples_s16: &[i16] = &convert::to_s16(samples);
|
||||
self.write_bytes(samples_s16.as_bytes())
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use super::{Open, Sink};
|
||||
use crate::audio::{AudioPacket, SamplesConverter};
|
||||
use crate::audio::{convert, AudioPacket};
|
||||
use crate::config::AudioFormat;
|
||||
use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
|
||||
use portaudio_rs;
|
||||
use portaudio_rs::device::{get_default_output_index, DeviceIndex, DeviceInfo};
|
||||
use portaudio_rs::stream::*;
|
||||
use std::io;
|
||||
|
@ -157,11 +156,11 @@ impl<'a> Sink for PortAudioSink<'a> {
|
|||
write_sink!(ref mut stream, samples)
|
||||
}
|
||||
Self::S32(stream, _parameters) => {
|
||||
let samples_s32: &[i32] = &SamplesConverter::to_s32(samples);
|
||||
let samples_s32: &[i32] = &convert::to_s32(samples);
|
||||
write_sink!(ref mut stream, samples_s32)
|
||||
}
|
||||
Self::S16(stream, _parameters) => {
|
||||
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
|
||||
let samples_s16: &[i16] = &convert::to_s16(samples);
|
||||
write_sink!(ref mut stream, samples_s16)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ use cpal::traits::{DeviceTrait, HostTrait};
|
|||
use thiserror::Error;
|
||||
|
||||
use super::Sink;
|
||||
use crate::audio::{AudioPacket, SamplesConverter};
|
||||
use crate::audio::{convert, AudioPacket};
|
||||
use crate::config::AudioFormat;
|
||||
use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
|
||||
|
||||
|
@ -189,7 +189,7 @@ impl Sink for RodioSink {
|
|||
self.rodio_sink.append(source);
|
||||
}
|
||||
AudioFormat::S16 => {
|
||||
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
|
||||
let samples_s16: &[i16] = &convert::to_s16(samples);
|
||||
let source = rodio::buffer::SamplesBuffer::new(
|
||||
NUM_CHANNELS as u16,
|
||||
SAMPLE_RATE,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{Open, Sink};
|
||||
use crate::audio::{AudioPacket, SamplesConverter};
|
||||
use crate::audio::{convert, AudioPacket};
|
||||
use crate::config::AudioFormat;
|
||||
use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
|
||||
use sdl2::audio::{AudioQueue, AudioSpecDesired};
|
||||
|
@ -97,12 +97,12 @@ impl Sink for SdlSink {
|
|||
queue.queue(samples)
|
||||
}
|
||||
Self::S32(queue) => {
|
||||
let samples_s32: &[i32] = &SamplesConverter::to_s32(samples);
|
||||
let samples_s32: &[i32] = &convert::to_s32(samples);
|
||||
drain_sink!(queue, AudioFormat::S32.size());
|
||||
queue.queue(samples_s32)
|
||||
}
|
||||
Self::S16(queue) => {
|
||||
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
|
||||
let samples_s16: &[i16] = &convert::to_s16(samples);
|
||||
drain_sink!(queue, AudioFormat::S16.size());
|
||||
queue.queue(samples_s16)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::audio::i24;
|
||||
use crate::audio::convert::i24;
|
||||
use std::convert::TryFrom;
|
||||
use std::mem;
|
||||
use std::str::FromStr;
|
||||
|
|
|
@ -33,13 +33,12 @@ impl AlsaMixer {
|
|||
let mixer = alsa::mixer::Mixer::new(&config.card, false)?;
|
||||
let sid = alsa::mixer::SelemId::new(&config.mixer, config.index);
|
||||
|
||||
let selem = mixer.find_selem(&sid).expect(
|
||||
format!(
|
||||
let selem = mixer.find_selem(&sid).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Couldn't find simple mixer control for {},{}",
|
||||
&config.mixer, &config.index,
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
});
|
||||
let (min, max) = selem.get_playback_volume_range();
|
||||
let (min_db, max_db) = selem.get_playback_db_range();
|
||||
let hw_mix = selem
|
||||
|
|
|
@ -206,11 +206,11 @@ pub struct NormalisationData {
|
|||
|
||||
impl NormalisationData {
|
||||
pub fn db_to_ratio(db: f32) -> f32 {
|
||||
return f32::powf(10.0, db / DB_VOLTAGE_RATIO);
|
||||
f32::powf(10.0, db / DB_VOLTAGE_RATIO)
|
||||
}
|
||||
|
||||
pub fn ratio_to_db(ratio: f32) -> f32 {
|
||||
return ratio.log10() * DB_VOLTAGE_RATIO;
|
||||
ratio.log10() * DB_VOLTAGE_RATIO
|
||||
}
|
||||
|
||||
fn parse_from_file<T: Read + Seek>(mut file: T) -> io::Result<NormalisationData> {
|
||||
|
@ -1161,7 +1161,7 @@ impl PlayerInternal {
|
|||
}
|
||||
|
||||
if self.config.normalisation
|
||||
&& (normalisation_factor != 1.0
|
||||
&& (f32::abs(normalisation_factor - 1.0) < f32::EPSILON
|
||||
|| self.config.normalisation_method != NormalisationMethod::Basic)
|
||||
{
|
||||
for sample in data.iter_mut() {
|
||||
|
|
|
@ -322,7 +322,7 @@ fn setup(args: &[String]) -> Setup {
|
|||
.opt_str("format")
|
||||
.as_ref()
|
||||
.map(|format| AudioFormat::try_from(format).expect("Invalid output format"))
|
||||
.unwrap_or(AudioFormat::default());
|
||||
.unwrap_or_default();
|
||||
|
||||
let device = matches.opt_str("device");
|
||||
if device == Some("?".into()) {
|
||||
|
@ -470,7 +470,7 @@ fn setup(args: &[String]) -> Setup {
|
|||
bitrate,
|
||||
gapless: !matches.opt_present("disable-gapless"),
|
||||
normalisation: matches.opt_present("enable-volume-normalisation"),
|
||||
normalisation_method: normalisation_method,
|
||||
normalisation_method,
|
||||
normalisation_type: gain_type,
|
||||
normalisation_pregain: matches
|
||||
.opt_str("normalisation-pregain")
|
||||
|
|
Loading…
Reference in a new issue