Merge pull request #37 from Polochon-street/fix-empty-chroma

Fix bug leading to empty chroma errors
This commit is contained in:
Polochon-street 2022-04-11 18:09:22 +02:00 committed by GitHub
commit c08fd3d703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 9 deletions

View File

@ -24,6 +24,8 @@ jobs:
override: false override: false
- name: Packages - name: Packages
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
run: cargo fmt -- --check
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
- name: Run tests - name: Run tests
@ -36,8 +38,6 @@ jobs:
run: cargo build --examples --verbose --features=serde run: cargo build --examples --verbose --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
run: cargo fmt -- --check
build-test-lint-windows: build-test-lint-windows:
name: Windows - build, test and lint name: Windows - build, test and lint

View File

@ -1,6 +1,7 @@
#Changelog #Changelog
## bliss 0.5.0 ## bliss 0.5.0
* Fix a bug in `estimate_tuning` that led to empty chroma errors.
* Remove the unusued Library trait, and extract a few useful functions from * Remove the unusued Library trait, and extract a few useful functions from
there (`analyze_paths`, `closest_to_album_group`. there (`analyze_paths`, `closest_to_album_group`.
* Rename `distance` module to `playlist`. * Rename `distance` module to `playlist`.

View File

@ -83,7 +83,7 @@ fn main() -> Result<()> {
} }
analyzed_songs.extend_from_slice(&songs); analyzed_songs.extend_from_slice(&songs);
let serialized = serde_json::to_string(&analyzed_songs).unwrap(); let serialized = serde_json::to_string(&analyzed_songs).unwrap();
let mut songs_to_chose_from = analyzed_songs let mut songs_to_chose_from: Vec<_> = analyzed_songs
.into_iter() .into_iter()
.filter(|x| x == &first_song || paths.contains(&x.path.to_string_lossy().to_string())) .filter(|x| x == &first_song || paths.contains(&x.path.to_string_lossy().to_string()))
.collect(); .collect();

View File

@ -330,11 +330,14 @@ fn estimate_tuning(
.map(|(x, y)| (n64(*x), n64(*y))) .map(|(x, y)| (n64(*x), n64(*y)))
.unzip(); .unzip();
if pitch.is_empty() {
return Ok(0.);
}
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()
.zip(&filtered_mag) .zip(&filtered_mag)
@ -486,6 +489,11 @@ mod test {
assert!(0.000001 > (-0.09999999999999998 - tuning).abs()); assert!(0.000001 > (-0.09999999999999998 - tuning).abs());
} }
#[test]
fn test_chroma_estimate_tuning_empty_fix() {
assert!(0. == estimate_tuning(22050, &Array2::zeros((8192, 1)), 8192, 0.01, 12).unwrap());
}
#[test] #[test]
fn test_estimate_tuning_decode() { fn test_estimate_tuning_decode() {
let signal = Song::decode(Path::new("data/s16_mono_22_5kHz.flac")) let signal = Song::decode(Path::new("data/s16_mono_22_5kHz.flac"))

View File

@ -39,11 +39,7 @@ pub fn cosine_distance(a: &Array1<f32>, b: &Array1<f32>) -> f32 {
/// Sort `songs` in place by putting songs close to `first_song` first /// Sort `songs` in place by putting songs close to `first_song` first
/// using the `distance` metric. /// using the `distance` metric.
pub fn closest_to_first_song( pub fn closest_to_first_song(first_song: &Song, songs: &mut [Song], distance: impl DistanceMetric) {
first_song: &Song,
songs: &mut Vec<Song>,
distance: impl DistanceMetric,
) {
songs.sort_by_cached_key(|song| n32(first_song.custom_distance(song, &distance))); songs.sort_by_cached_key(|song| n32(first_song.custom_distance(song, &distance)));
} }