From dc3592147cb36970777adf59fd28f80065e55753 Mon Sep 17 00:00:00 2001 From: Polochon_street Date: Thu, 28 Dec 2023 19:01:26 +0100 Subject: [PATCH] Cleanup deps --- Cargo.lock | 53 ++++----------------------- Cargo.toml | 6 ++-- src/cue.rs | 6 ++-- src/lib.rs | 6 ++-- src/library.rs | 13 ++++--- src/song.rs | 98 ++++++++++++++++++++------------------------------ 6 files changed, 62 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a0aea7..eec8c11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + [[package]] name = "ahash" version = "0.8.6" @@ -114,10 +120,10 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" name = "bliss-audio" version = "0.6.10" dependencies = [ + "adler32", "anyhow", "bliss-audio-aubio-rs", "clap", - "crossbeam", "dirs", "ffmpeg-next", "ffmpeg-sys-next", @@ -129,10 +135,8 @@ dependencies = [ "ndarray-npy", "ndarray-stats", "noisy_float", - "num_cpus", "pretty_assertions", "rcue", - "ripemd", "rusqlite", "rustfft", "serde", @@ -292,30 +296,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eb9105919ca8e40d437fc9cbb8f1975d916f1bd28afe795a48aae32a2cc8920" -dependencies = [ - "cfg-if", - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.4" @@ -338,16 +318,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc6598521bb5a83d491e8c1fe51db7296019d2ca3cb93cc6c2a20369a4d78a2" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.18" @@ -1250,15 +1220,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest", -] - [[package]] name = "rusqlite" version = "0.28.0" diff --git a/Cargo.toml b/Cargo.toml index 3540ae1..7dd4290 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,15 +39,15 @@ serde = ["dep:serde"] # Until https://github.com/aubio/aubio/issues/336 is somehow solved # Hopefully we'll be able to use the official aubio-rs at some point. bliss-audio-aubio-rs = "0.2.1" -crossbeam = "0.8.2" ffmpeg-next = "6.1.0" ffmpeg-sys-next = { version = "6.1.0", default-features = false } log = "0.4.17" +# `rayon` is used only by `par_mapv_inplace` in chroma.rs. +# TODO: is the speed gain that substantial? ndarray = { version = "0.15.6", features = ["rayon"] } -num_cpus = "1.15.0" ndarray-stats = "0.5.1" noisy_float = "0.2.0" -ripemd = "0.1.3" +adler32 = "1.0.2" rustfft = "6.1.0" thiserror = "1.0.40" strum = "0.24.1" diff --git a/src/cue.rs b/src/cue.rs index 616899b..390b140 100644 --- a/src/cue.rs +++ b/src/cue.rs @@ -160,8 +160,8 @@ impl BlissCueFile { let mut songs = Vec::new(); for (index, tuple) in (self.tracks[..]).windows(2).enumerate() { let (current_track, next_track) = (tuple[0].to_owned(), tuple[1].to_owned()); - if let Some((_, start_current)) = current_track.indices.get(0) { - if let Some((_, end_current)) = next_track.indices.get(0) { + if let Some((_, start_current)) = current_track.indices.first() { + if let Some((_, end_current)) = next_track.indices.first() { let start_current = (start_current.as_secs_f32() * SAMPLE_RATE as f32) as usize; let end_current = (end_current.as_secs_f32() * SAMPLE_RATE as f32) as usize; let duration = Duration::from_secs_f32( @@ -176,7 +176,7 @@ impl BlissCueFile { } // Take care of the last track, since the windows iterator doesn't. if let Some(last_track) = self.tracks.last() { - if let Some((_, start_current)) = last_track.indices.get(0) { + if let Some((_, start_current)) = last_track.indices.first() { let start_current = (start_current.as_secs_f32() * SAMPLE_RATE as f32) as usize; let duration = Duration::from_secs_f32( (self.sample_array.len() - start_current) as f32 / SAMPLE_RATE as f32, diff --git a/src/lib.rs b/src/lib.rs index e9ad3b4..abfc207 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,8 +75,6 @@ mod temporal; mod timbral; mod utils; -extern crate crossbeam; -extern crate num_cpus; #[cfg(feature = "serde")] #[macro_use] extern crate serde; @@ -155,7 +153,7 @@ pub type BlissResult = Result; pub fn analyze_paths, F: IntoIterator>( paths: F, ) -> mpsc::IntoIter<(PathBuf, BlissResult)> { - let cores = NonZeroUsize::new(num_cpus::get()).unwrap(); + let cores = thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap()); analyze_paths_with_cores(paths, cores) } @@ -203,7 +201,7 @@ pub fn analyze_paths_with_cores, F: IntoIterator>( paths: F, number_cores: NonZeroUsize, ) -> mpsc::IntoIter<(PathBuf, BlissResult)> { - let mut cores = NonZeroUsize::new(num_cpus::get()).unwrap(); + let mut cores = thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap()); if cores > number_cores { cores = number_cores; } diff --git a/src/library.rs b/src/library.rs index e227b62..3fa8efa 100644 --- a/src/library.rs +++ b/src/library.rs @@ -138,6 +138,7 @@ use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::sync::Mutex; +use std::thread; use crate::Song; use crate::FEATURES_VERSION; @@ -277,8 +278,9 @@ impl BaseConfig { } }; - let number_cores = - number_cores.unwrap_or_else(|| NonZeroUsize::new(num_cpus::get()).unwrap()); + let number_cores = number_cores.unwrap_or_else(|| { + thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap()) + }); Ok(Self { config_path, @@ -3010,7 +3012,7 @@ mod test { library.config.base_config().config_path.display(), library.config.base_config().database_path.display(), FEATURES_VERSION, - num_cpus::get(), + thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap()), ) ); } @@ -3183,7 +3185,10 @@ mod test { ignore_wav_files: true, }; - assert_eq!(config.get_number_cores().get(), num_cpus::get()); + assert_eq!( + config.get_number_cores().get(), + usize::from(thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap())), + ); let base_config = BaseConfig::new(Some(config_file), Some(database_file), Some(nzus(1))).unwrap(); diff --git a/src/song.rs b/src/song.rs index 3c63e45..673c7bc 100644 --- a/src/song.rs +++ b/src/song.rs @@ -7,7 +7,6 @@ //! For implementation of plug-ins for already existing audio players, //! a look at Library is instead recommended. -extern crate crossbeam; extern crate ffmpeg_next as ffmpeg; extern crate ndarray; @@ -23,7 +22,6 @@ use crate::{BlissError, BlissResult, SAMPLE_RATE}; use crate::{CHANNELS, FEATURES_VERSION}; use ::log::warn; use core::ops::Index; -use crossbeam::thread; use ffmpeg_next::codec::threading::{Config, Type as ThreadingType}; use ffmpeg_next::util::channel_layout::ChannelLayout; use ffmpeg_next::util::error::Error; @@ -40,7 +38,7 @@ use std::path::Path; use std::path::PathBuf; use std::sync::mpsc; use std::sync::mpsc::Receiver; -use std::thread as std_thread; +use std::thread; use std::time::Duration; use strum::{EnumCount, IntoEnumIterator}; use strum_macros::{EnumCount, EnumIter}; @@ -331,16 +329,16 @@ impl Song { * * If you *do* want to use this with a song already decoded by yourself, * the sample format of `sample_array` should be f32le, one channel, and - * the sampling rate 22050 Hz. Anything other thant that will yield aberrant + * the sampling rate 22050 Hz. Anything other than that will yield aberrant * results. * To double-check that your sample array has the right format, you could run - * `ffmpeg -i path_to_your_song.flac -ar 22050 -ac 1 -c:a pcm_f32le -f hash -hash ripemd160 -`, - * which will give you the ripemd160 hash of the sample array if the song - * has been decoded properly. You can then compute the ripemd160 hash of your sample - * array (see `_test_decode` in the tests) and make sure both hashes are the same. + * `ffmpeg -i path_to_your_song.flac -ar 22050 -ac 1 -c:a pcm_f32le -f hash -hash addler32 -`, + * which will give you the addler32 checksum of the sample array if the song + * has been decoded properly. You can then compute the addler32 checksum of your sample + * array (see `_test_decode` in the tests) and make sure both are the same. * * (Running `ffmpeg -i path_to_your_song.flac -ar 22050 -ac 1 -c:a pcm_f32le` will simply give - * you the raw sample array as it should look like, if you're not into computing hashes) + * you the raw sample array as it should look like, if you're not into computing checksums) **/ pub fn analyze(sample_array: &[f32]) -> BlissResult { let largest_window = vec![ @@ -358,8 +356,8 @@ impl Song { ))); } - thread::scope(|s| { - let child_tempo: thread::ScopedJoinHandle<'_, BlissResult> = s.spawn(|_| { + thread::scope(|s| -> BlissResult { + let child_tempo = s.spawn(|| { let mut tempo_desc = BPMDesc::new(SAMPLE_RATE)?; let windows = sample_array .windows(BPMDesc::WINDOW_SIZE) @@ -371,17 +369,14 @@ impl Song { Ok(tempo_desc.get_value()) }); - let child_chroma: thread::ScopedJoinHandle<'_, BlissResult>> = s.spawn(|_| { + let child_chroma = s.spawn(|| { let mut chroma_desc = ChromaDesc::new(SAMPLE_RATE, 12); chroma_desc.do_(sample_array)?; Ok(chroma_desc.get_values()) }); #[allow(clippy::type_complexity)] - let child_timbral: thread::ScopedJoinHandle< - '_, - BlissResult<(Vec, Vec, Vec)>, - > = s.spawn(|_| { + let child_timbral = s.spawn(|| { let mut spectral_desc = SpectralDesc::new(SAMPLE_RATE)?; let windows = sample_array .windows(SpectralDesc::WINDOW_SIZE) @@ -395,22 +390,21 @@ impl Song { Ok((centroid, rolloff, flatness)) }); - let child_zcr: thread::ScopedJoinHandle<'_, BlissResult> = s.spawn(|_| { + let child_zcr = s.spawn(|| { let mut zcr_desc = ZeroCrossingRateDesc::default(); zcr_desc.do_(sample_array); Ok(zcr_desc.get_value()) }); - let child_loudness: thread::ScopedJoinHandle<'_, BlissResult>> = - s.spawn(|_| { - let mut loudness_desc = LoudnessDesc::default(); - let windows = sample_array.chunks(LoudnessDesc::WINDOW_SIZE); + let child_loudness = s.spawn(|| { + let mut loudness_desc = LoudnessDesc::default(); + let windows = sample_array.chunks(LoudnessDesc::WINDOW_SIZE); - for window in windows { - loudness_desc.do_(window); - } - Ok(loudness_desc.get_value()) - }); + for window in windows { + loudness_desc.do_(window); + } + Ok(loudness_desc.get_value()) + }); // Non-streaming approach for that one let tempo = child_tempo.join().unwrap()?; @@ -434,7 +428,6 @@ impl Song { })?; Ok(Analysis::new(array)) }) - .unwrap() } pub(crate) fn decode(path: &Path) -> BlissResult { @@ -548,7 +541,7 @@ impl Song { let (tx, rx) = mpsc::channel(); let in_codec_format = decoder.format(); let in_codec_rate = decoder.rate(); - let child = std_thread::spawn(move || { + let child = thread::spawn(move || { resample_frame( rx, in_codec_format, @@ -752,8 +745,8 @@ fn push_to_sample_array(frame: &ffmpeg::frame::Audio, sample_array: &mut Vec