Fix bug leading to empty chroma errors
This commit is contained in:
parent
b12773d52d
commit
43fbafa80b
4
.github/workflows/rust.yml
vendored
4
.github/workflows/rust.yml
vendored
|
@ -24,6 +24,8 @@ jobs:
|
|||
override: false
|
||||
- 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
|
||||
- name: Check format
|
||||
run: cargo fmt -- --check
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
|
@ -36,8 +38,6 @@ jobs:
|
|||
run: cargo build --examples --verbose --features=serde
|
||||
- name: Lint
|
||||
run: cargo clippy --examples --features=serde -- -D warnings
|
||||
- name: Check format
|
||||
run: cargo fmt -- --check
|
||||
|
||||
build-test-lint-windows:
|
||||
name: Windows - build, test and lint
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#Changelog
|
||||
|
||||
## 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
|
||||
there (`analyze_paths`, `closest_to_album_group`.
|
||||
* Rename `distance` module to `playlist`.
|
||||
|
|
|
@ -83,7 +83,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
analyzed_songs.extend_from_slice(&songs);
|
||||
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()
|
||||
.filter(|x| x == &first_song || paths.contains(&x.path.to_string_lossy().to_string()))
|
||||
.collect();
|
||||
|
|
|
@ -330,11 +330,14 @@ fn estimate_tuning(
|
|||
.map(|(x, y)| (n64(*x), n64(*y)))
|
||||
.unzip();
|
||||
|
||||
if pitch.is_empty() {
|
||||
return Ok(0.);
|
||||
}
|
||||
|
||||
let threshold: N64 = Array::from(filtered_mag.to_vec())
|
||||
.quantile_axis_mut(Axis(0), n64(0.5), &Midpoint)
|
||||
.map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?
|
||||
.into_scalar();
|
||||
|
||||
let mut pitch = filtered_pitch
|
||||
.iter()
|
||||
.zip(&filtered_mag)
|
||||
|
@ -486,6 +489,11 @@ mod test {
|
|||
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]
|
||||
fn test_estimate_tuning_decode() {
|
||||
let signal = Song::decode(Path::new("data/s16_mono_22_5kHz.flac"))
|
||||
|
|
|
@ -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
|
||||
/// using the `distance` metric.
|
||||
pub fn closest_to_first_song(
|
||||
first_song: &Song,
|
||||
songs: &mut Vec<Song>,
|
||||
distance: impl DistanceMetric,
|
||||
) {
|
||||
pub fn closest_to_first_song(first_song: &Song, songs: &mut [Song], distance: impl DistanceMetric) {
|
||||
songs.sort_by_cached_key(|song| n32(first_song.custom_distance(song, &distance)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user