Clippy lints
This commit is contained in:
parent
9cf425a8ba
commit
266913ef13
12
.github/workflows/rust.yml
vendored
12
.github/workflows/rust.yml
vendored
|
@ -26,6 +26,8 @@ jobs:
|
||||||
run: sudo apt-get update && sudo apt-get install build-essential yasm libavutil-dev libavcodec-dev libavformat-dev libavfilter-dev libavfilter-dev libavdevice-dev libswresample-dev libfftw3-dev ffmpeg
|
run: sudo apt-get update && sudo apt-get install build-essential yasm libavutil-dev libavcodec-dev libavformat-dev libavfilter-dev libavfilter-dev libavdevice-dev libswresample-dev libfftw3-dev ffmpeg
|
||||||
- name: Check format
|
- name: Check format
|
||||||
run: cargo fmt -- --check
|
run: cargo fmt -- --check
|
||||||
|
- name: Lint
|
||||||
|
run: cargo clippy --examples --features=serde,library -- -D warnings
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --verbose
|
run: cargo build --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
|
@ -38,8 +40,6 @@ jobs:
|
||||||
run: cargo +nightly-2022-02-16 bench --verbose --features=bench --no-run
|
run: cargo +nightly-2022-02-16 bench --verbose --features=bench --no-run
|
||||||
- name: Build examples
|
- name: Build examples
|
||||||
run: cargo build --examples --verbose --features=serde,library
|
run: cargo build --examples --verbose --features=serde,library
|
||||||
- name: Lint
|
|
||||||
run: cargo clippy --examples --features=serde,library -- -D warnings
|
|
||||||
|
|
||||||
build-test-lint-windows:
|
build-test-lint-windows:
|
||||||
name: Windows - build, test and lint
|
name: Windows - build, test and lint
|
||||||
|
@ -70,11 +70,11 @@ jobs:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
- name: Build
|
|
||||||
run: cargo build --examples
|
|
||||||
- name: Test
|
|
||||||
run: cargo test --examples --features=serde
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: cargo clippy --examples --features=serde -- -D warnings
|
run: cargo clippy --examples --features=serde -- -D warnings
|
||||||
- name: Check format
|
- name: Check format
|
||||||
run: cargo fmt -- --check
|
run: cargo fmt -- --check
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --examples
|
||||||
|
- name: Test
|
||||||
|
run: cargo test --examples --features=serde
|
||||||
|
|
|
@ -9,9 +9,9 @@ use std::env;
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().skip(1).collect();
|
let args: Vec<String> = env::args().skip(1).collect();
|
||||||
for path in &args {
|
for path in &args {
|
||||||
match Song::from_path(&path) {
|
match Song::from_path(path) {
|
||||||
Ok(song) => println!("{}: {:?}", path, song.analysis),
|
Ok(song) => println!("{}: {:?}", path, song.analysis),
|
||||||
Err(e) => println!("{}: {}", path, e),
|
Err(e) => println!("{path}: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ fn main() -> Result<(), String> {
|
||||||
let first_path = paths.next().ok_or("Help: ./distance <song1> <song2>")?;
|
let first_path = paths.next().ok_or("Help: ./distance <song1> <song2>")?;
|
||||||
let second_path = paths.next().ok_or("Help: ./distance <song1> <song2>")?;
|
let second_path = paths.next().ok_or("Help: ./distance <song1> <song2>")?;
|
||||||
|
|
||||||
let song1 = Song::from_path(&first_path).map_err(|x| x.to_string())?;
|
let song1 = Song::from_path(first_path).map_err(|x| x.to_string())?;
|
||||||
let song2 = Song::from_path(&second_path).map_err(|x| x.to_string())?;
|
let song2 = Song::from_path(second_path).map_err(|x| x.to_string())?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"d({:?}, {:?}) = {}",
|
"d({:?}, {:?}) = {}",
|
||||||
|
|
|
@ -196,7 +196,7 @@ fn main() -> Result<()> {
|
||||||
.map(|s| s.bliss_song.path.to_string_lossy().to_string())
|
.map(|s| s.bliss_song.path.to_string_lossy().to_string())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
for song in song_paths {
|
for song in song_paths {
|
||||||
println!("{:?}", song);
|
println!("{song:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ fn main() -> Result<()> {
|
||||||
})
|
})
|
||||||
.collect::<Vec<(String, String)>>();
|
.collect::<Vec<(String, String)>>();
|
||||||
for (path, mime_type) in playlist {
|
for (path, mime_type) in playlist {
|
||||||
println!("{} <{}>", path, mime_type,);
|
println!("{path} <{mime_type}>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ fn main() -> Result<()> {
|
||||||
if let Some(m) = matches.value_of("output-playlist") {
|
if let Some(m) = matches.value_of("output-playlist") {
|
||||||
fs::write(m, playlist)?;
|
fs::write(m, playlist)?;
|
||||||
} else {
|
} else {
|
||||||
println!("{}", playlist);
|
println!("{playlist}");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,13 +53,7 @@ impl ChromaDesc {
|
||||||
*/
|
*/
|
||||||
pub fn do_(&mut self, signal: &[f32]) -> BlissResult<()> {
|
pub fn do_(&mut self, signal: &[f32]) -> BlissResult<()> {
|
||||||
let mut stft = stft(signal, ChromaDesc::WINDOW_SIZE, 2205);
|
let mut stft = stft(signal, ChromaDesc::WINDOW_SIZE, 2205);
|
||||||
let tuning = estimate_tuning(
|
let tuning = estimate_tuning(self.sample_rate, &stft, ChromaDesc::WINDOW_SIZE, 0.01, 12)?;
|
||||||
self.sample_rate as u32,
|
|
||||||
&stft,
|
|
||||||
ChromaDesc::WINDOW_SIZE,
|
|
||||||
0.01,
|
|
||||||
12,
|
|
||||||
)?;
|
|
||||||
let chroma = chroma_stft(
|
let chroma = chroma_stft(
|
||||||
self.sample_rate,
|
self.sample_rate,
|
||||||
&mut stft,
|
&mut stft,
|
||||||
|
@ -162,7 +156,7 @@ fn chroma_filter(
|
||||||
let n_chroma2 = (n_chroma_float / 2.0).round() as u32;
|
let n_chroma2 = (n_chroma_float / 2.0).round() as u32;
|
||||||
let n_chroma2_float = f64::from(n_chroma2);
|
let n_chroma2_float = f64::from(n_chroma2);
|
||||||
|
|
||||||
let frequencies = Array::linspace(0., f64::from(sample_rate), (n_fft + 1) as usize);
|
let frequencies = Array::linspace(0., f64::from(sample_rate), n_fft + 1);
|
||||||
|
|
||||||
let mut freq_bins = frequencies;
|
let mut freq_bins = frequencies;
|
||||||
hz_to_octs_inplace(&mut freq_bins, tuning, n_chroma);
|
hz_to_octs_inplace(&mut freq_bins, tuning, n_chroma);
|
||||||
|
@ -213,12 +207,12 @@ fn chroma_filter(
|
||||||
}
|
}
|
||||||
let mut b = Array::from(uninit)
|
let mut b = Array::from(uninit)
|
||||||
.into_shape(wts.dim())
|
.into_shape(wts.dim())
|
||||||
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?;
|
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {e}")))?;
|
||||||
b.slice_mut(s![-3.., ..]).assign(&wts.slice(s![..3, ..]));
|
b.slice_mut(s![-3.., ..]).assign(&wts.slice(s![..3, ..]));
|
||||||
b.slice_mut(s![..-3, ..]).assign(&wts.slice(s![3.., ..]));
|
b.slice_mut(s![..-3, ..]).assign(&wts.slice(s![3.., ..]));
|
||||||
|
|
||||||
wts = b;
|
wts = b;
|
||||||
let non_aliased = (1 + n_fft / 2) as usize;
|
let non_aliased = 1 + n_fft / 2;
|
||||||
Ok(wts.slice_move(s![.., ..non_aliased]))
|
Ok(wts.slice_move(s![.., ..non_aliased]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +302,7 @@ fn pitch_tuning(
|
||||||
}
|
}
|
||||||
let max_index = counts
|
let max_index = counts
|
||||||
.argmax()
|
.argmax()
|
||||||
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?;
|
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {e}")))?;
|
||||||
|
|
||||||
// Return the bin with the most reoccuring frequency.
|
// Return the bin with the most reoccuring frequency.
|
||||||
Ok((-50. + (100. * resolution * max_index as f64)) / 100.)
|
Ok((-50. + (100. * resolution * max_index as f64)) / 100.)
|
||||||
|
@ -336,7 +330,7 @@ fn estimate_tuning(
|
||||||
|
|
||||||
let threshold: N64 = Array::from(filtered_mag.to_vec())
|
let threshold: N64 = Array::from(filtered_mag.to_vec())
|
||||||
.quantile_axis_mut(Axis(0), n64(0.5), &Midpoint)
|
.quantile_axis_mut(Axis(0), n64(0.5), &Midpoint)
|
||||||
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?
|
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {e}")))?
|
||||||
.into_scalar();
|
.into_scalar();
|
||||||
let mut pitch = filtered_pitch
|
let mut pitch = filtered_pitch
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -534,7 +534,7 @@ impl<Config: AppConfigTrait> Library<Config> {
|
||||||
G: DistanceMetric + Copy,
|
G: DistanceMetric + Copy,
|
||||||
{
|
{
|
||||||
let first_song: LibrarySong<T> = self.song_from_path(song_path).map_err(|_| {
|
let first_song: LibrarySong<T> = self.song_from_path(song_path).map_err(|_| {
|
||||||
BlissError::ProviderError(format!("song '{}' has not been analyzed", song_path))
|
BlissError::ProviderError(format!("song '{song_path}' has not been analyzed"))
|
||||||
})?;
|
})?;
|
||||||
let mut songs = self.songs_from_library()?;
|
let mut songs = self.songs_from_library()?;
|
||||||
sort_by(&first_song, &mut songs, distance, |s: &LibrarySong<T>| {
|
sort_by(&first_song, &mut songs, distance, |s: &LibrarySong<T>| {
|
||||||
|
@ -886,8 +886,7 @@ impl<Config: AppConfigTrait> Library<Config> {
|
||||||
pb.inc(1);
|
pb.inc(1);
|
||||||
}
|
}
|
||||||
pb.finish_with_message(format!(
|
pb.finish_with_message(format!(
|
||||||
"Analyzed {} song(s) successfully. {} Failure(s).",
|
"Analyzed {success_count} song(s) successfully. {failure_count} Failure(s).",
|
||||||
success_count, failure_count
|
|
||||||
));
|
));
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -1059,8 +1058,7 @@ impl<Config: AppConfigTrait> Library<Config> {
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
BlissError::ProviderError(format!(
|
BlissError::ProviderError(format!(
|
||||||
"song has more or less than {} features",
|
"song has more or less than {NUMBER_FEATURES} features",
|
||||||
NUMBER_FEATURES
|
|
||||||
))
|
))
|
||||||
})?,
|
})?,
|
||||||
};
|
};
|
||||||
|
|
|
@ -268,7 +268,7 @@ pub fn closest_album_to_group(group: Vec<Song>, pool: Vec<Song>) -> BlissResult<
|
||||||
analysis
|
analysis
|
||||||
.push_row(song.analysis.as_arr1().view())
|
.push_row(song.analysis.as_arr1().view())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::ProviderError(format!("while computing distances: {}", e))
|
BlissError::ProviderError(format!("while computing distances: {e}"))
|
||||||
})?;
|
})?;
|
||||||
} else {
|
} else {
|
||||||
let mut array = Array::zeros((1, song.analysis.as_arr1().len()));
|
let mut array = Array::zeros((1, song.analysis.as_arr1().len()));
|
||||||
|
@ -370,7 +370,7 @@ where
|
||||||
analysis
|
analysis
|
||||||
.push_row(song.analysis.as_arr1().view())
|
.push_row(song.analysis.as_arr1().view())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::ProviderError(format!("while computing distances: {}", e))
|
BlissError::ProviderError(format!("while computing distances: {e}"))
|
||||||
})?;
|
})?;
|
||||||
} else {
|
} else {
|
||||||
let mut array = Array::zeros((1, song.analysis.as_arr1().len()));
|
let mut array = Array::zeros((1, song.analysis.as_arr1().len()));
|
||||||
|
|
|
@ -158,7 +158,7 @@ impl fmt::Debug for Analysis {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut debug_struct = f.debug_struct("Analysis");
|
let mut debug_struct = f.debug_struct("Analysis");
|
||||||
for feature in AnalysisIndex::iter() {
|
for feature in AnalysisIndex::iter() {
|
||||||
debug_struct.field(&format!("{:?}", feature), &self[feature]);
|
debug_struct.field(&format!("{feature:?}"), &self[feature]);
|
||||||
}
|
}
|
||||||
debug_struct.finish()?;
|
debug_struct.finish()?;
|
||||||
f.write_str(&format!(" /* {:?} */", &self.as_vec()))
|
f.write_str(&format!(" /* {:?} */", &self.as_vec()))
|
||||||
|
@ -657,8 +657,7 @@ fn resample_frame(
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::DecodingError(format!(
|
BlissError::DecodingError(format!(
|
||||||
"while trying to allocate resampling context: {:?}",
|
"while trying to allocate resampling context: {e:?}",
|
||||||
e
|
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
let mut resampled = ffmpeg::frame::Audio::empty();
|
let mut resampled = ffmpeg::frame::Audio::empty();
|
||||||
|
@ -680,7 +679,7 @@ fn resample_frame(
|
||||||
resample_context
|
resample_context
|
||||||
.run(&decoded, &mut resampled)
|
.run(&decoded, &mut resampled)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::DecodingError(format!("while trying to resample song: {:?}", e))
|
BlissError::DecodingError(format!("while trying to resample song: {e:?}"))
|
||||||
})?;
|
})?;
|
||||||
push_to_sample_array(&resampled, &mut sample_array);
|
push_to_sample_array(&resampled, &mut sample_array);
|
||||||
}
|
}
|
||||||
|
@ -691,7 +690,7 @@ fn resample_frame(
|
||||||
// `resampled` again?
|
// `resampled` again?
|
||||||
loop {
|
loop {
|
||||||
match resample_context.flush(&mut resampled).map_err(|e| {
|
match resample_context.flush(&mut resampled).map_err(|e| {
|
||||||
BlissError::DecodingError(format!("while trying to resample song: {:?}", e))
|
BlissError::DecodingError(format!("while trying to resample song: {e:?}"))
|
||||||
})? {
|
})? {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
push_to_sample_array(&resampled, &mut sample_array);
|
push_to_sample_array(&resampled, &mut sample_array);
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl BPMDesc {
|
||||||
sample_rate,
|
sample_rate,
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::AnalysisError(format!("error while loading aubio tempo object: {}", e))
|
BlissError::AnalysisError(format!("error while loading aubio tempo object: {e}"))
|
||||||
})?,
|
})?,
|
||||||
bpms: Vec::new(),
|
bpms: Vec::new(),
|
||||||
})
|
})
|
||||||
|
@ -56,7 +56,7 @@ impl BPMDesc {
|
||||||
|
|
||||||
pub fn do_(&mut self, chunk: &[f32]) -> BlissResult<()> {
|
pub fn do_(&mut self, chunk: &[f32]) -> BlissResult<()> {
|
||||||
let result = self.aubio_obj.do_result(chunk).map_err(|e| {
|
let result = self.aubio_obj.do_result(chunk).map_err(|e| {
|
||||||
BlissError::AnalysisError(format!("aubio error while computing tempo {}", e))
|
BlissError::AnalysisError(format!("aubio error while computing tempo {e}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if result > 0. {
|
if result > 0. {
|
||||||
|
|
|
@ -125,23 +125,20 @@ impl SpectralDesc {
|
||||||
centroid_aubio_desc: SpecDesc::new(SpecShape::Centroid, SpectralDesc::WINDOW_SIZE)
|
centroid_aubio_desc: SpecDesc::new(SpecShape::Centroid, SpectralDesc::WINDOW_SIZE)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::AnalysisError(format!(
|
BlissError::AnalysisError(format!(
|
||||||
"error while loading aubio centroid object: {}",
|
"error while loading aubio centroid object: {e}",
|
||||||
e
|
|
||||||
))
|
))
|
||||||
})?,
|
})?,
|
||||||
rolloff_aubio_desc: SpecDesc::new(SpecShape::Rolloff, SpectralDesc::WINDOW_SIZE)
|
rolloff_aubio_desc: SpecDesc::new(SpecShape::Rolloff, SpectralDesc::WINDOW_SIZE)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::AnalysisError(format!(
|
BlissError::AnalysisError(format!(
|
||||||
"error while loading aubio rolloff object: {}",
|
"error while loading aubio rolloff object: {e}",
|
||||||
e
|
|
||||||
))
|
))
|
||||||
})?,
|
})?,
|
||||||
phase_vocoder: PVoc::new(SpectralDesc::WINDOW_SIZE, SpectralDesc::HOP_SIZE).map_err(
|
phase_vocoder: PVoc::new(SpectralDesc::WINDOW_SIZE, SpectralDesc::HOP_SIZE).map_err(
|
||||||
|e| {
|
|e| {
|
||||||
BlissError::AnalysisError(format!(
|
BlissError::AnalysisError(
|
||||||
"error while loading aubio pvoc object: {}",
|
format!("error while loading aubio pvoc object: {e}",),
|
||||||
e
|
)
|
||||||
))
|
|
||||||
},
|
},
|
||||||
)?,
|
)?,
|
||||||
values_centroid: Vec::new(),
|
values_centroid: Vec::new(),
|
||||||
|
@ -163,7 +160,7 @@ impl SpectralDesc {
|
||||||
self.phase_vocoder
|
self.phase_vocoder
|
||||||
.do_(chunk, fftgrain.as_mut_slice())
|
.do_(chunk, fftgrain.as_mut_slice())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::AnalysisError(format!("error while processing aubio pv object: {}", e))
|
BlissError::AnalysisError(format!("error while processing aubio pv object: {e}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let bin = self
|
let bin = self
|
||||||
|
@ -171,8 +168,7 @@ impl SpectralDesc {
|
||||||
.do_result(fftgrain.as_slice())
|
.do_result(fftgrain.as_slice())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
BlissError::AnalysisError(format!(
|
BlissError::AnalysisError(format!(
|
||||||
"error while processing aubio centroid object: {}",
|
"error while processing aubio centroid object: {e}",
|
||||||
e
|
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn stft(signal: &[f32], window_length: usize, hop_length: usize) -> A
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn mean<T: Clone + Into<f32>>(input: &[T]) -> f32 {
|
pub(crate) fn mean<T: Clone + Into<f32>>(input: &[T]) -> f32 {
|
||||||
input.iter().map(|x| x.clone().into() as f32).sum::<f32>() / input.len() as f32
|
input.iter().map(|x| x.clone().into()).sum::<f32>() / input.len() as f32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait Normalize {
|
pub(crate) trait Normalize {
|
||||||
|
@ -112,8 +112,7 @@ pub(crate) fn geometric_mean(input: &[f32]) -> f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
let n = input.len() as u32;
|
let n = input.len() as u32;
|
||||||
((((mantissas as f32).log2() + exponents as f32) as f32) / n as f32 - (1023. + 500.) / 8.)
|
(((mantissas as f32).log2() + exponents as f32) / n as f32 - (1023. + 500.) / 8.).exp2()
|
||||||
.exp2()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn hz_to_octs_inplace(
|
pub(crate) fn hz_to_octs_inplace(
|
||||||
|
@ -121,7 +120,7 @@ pub(crate) fn hz_to_octs_inplace(
|
||||||
tuning: f64,
|
tuning: f64,
|
||||||
bins_per_octave: u32,
|
bins_per_octave: u32,
|
||||||
) -> &mut Array1<f64> {
|
) -> &mut Array1<f64> {
|
||||||
let a440 = 440.0 * (2_f64.powf(tuning / f64::from(bins_per_octave)) as f64);
|
let a440 = 440.0 * 2_f64.powf(tuning / f64::from(bins_per_octave));
|
||||||
|
|
||||||
*frequencies /= a440 / 16.;
|
*frequencies /= a440 / 16.;
|
||||||
frequencies.mapv_inplace(f64::log2);
|
frequencies.mapv_inplace(f64::log2);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user