darksv / rusty-chromaprint

Chromaprint for Rust
18 stars 5 forks source link

Not clear how to properly use project #2

Closed qarmin closed 1 year ago

qarmin commented 1 year ago

When trying to test this project, I noticed few problems

Most of examples how to use this, I found directly in tests inside code in src folder instead examples

Music file with invalid numbers of channel, crashes internally instead returning error

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', /home/rafal/.cargo/registry/src/github.com-1ecc6299db9ec823/rusty-chromaprint-0.1.1/src/audio_processor.rs:129:9
stack backtrace:

Number of channels returned by lofty sometimes cause crashes(so or lofty or this library not properly handle number of channels)

Sample rate is 11025 which seems to be 44100 / 4, but why not just 44100? Also looks that this value cannot be regulated per file

I tested some music files(remixes etc.) with this library(11025 sample rate, 1 channel - to not have crash, multiple configurations) but always results were similar for each compared music files(usually results - completely different songs and also remixes - differs in max ~1)

5.28021978021978   ---   "01 - Call Of The Wild.mp3" "02 - Free Falling.mp3"
5.316801619433198   ---   "03 - Every Inch.mp3" "Florrie - Human.mp3"
5.3403284671532845   ---   "07 - Left Too Late (Florrie Edit).mp3" "Florrie - What If I\'m Wrong.mp3"
5.344478216818643   ---   "02 - I’m Gonna Get You Back.mp3" "Florrie - Human.mp3"
5.34469696969697   ---   "01 - Call Of The Wild.mp3" "03 - What You Doing This For_.mp3"
5.345717234262126   ---   "Florrie - Human.mp3" "07 - Left Too Late (Florrie Edit).mp3"
5.373559322033898   ---   "04 - Left Too Late.mp3" "03 - Every Inch.mp3"
5.376   ---   "03 - What You Doing This For_.mp3" "Florrie - Unstable.mp3"
5.380552220888355   ---   "02 - Free Falling.mp3" "Florrie - Walk Away.mp3"
5.382126348228043   ---   "Florrie - Sunday Girl.mp3" "Florrie - Unstable.mp3"
5.383695652173913   ---   "Florrie - Live a Little.mp3" "Florrie - Walk Away.mp3"
5.384436701509872   ---   "04 - Left Too Late.mp3" "Florrie - Unstable.mp3"
5.393723252496434   ---   "Florrie - Sunday Girl.mp3" "Florrie - What If I\'m Wrong.mp3"
5.394444444444445   ---   "03 - Every Inch.mp3" "Florrie - Too Young to Remember.mp3"
5.396   ---   "Florrie - Too Young to Remember.mp3" "Florrie - Unstable.mp3"
5.398502495840266   ---   "06 - She Always Gets What She Wants.mp3" "Florrie - Too Young to Remember.mp3"
5.411873840445269   ---   "Florrie - Too Young to Remember.mp3" "Florrie - Walk Away.mp3"
5.413756613756614   ---   "03 - Every Inch.mp3" "Falling Back To You.mp3"
5.416225749559083   ---   "04 - Left Too Late.mp3" "Florrie - Street Lights.mp3"
5.4225641025641025   ---   "Florrie - Human.mp3" "Florrie - Unstable.mp3"
5.429   ---   "Florrie - Unstable.mp3" "Florrie - Walk Away.mp3"
5.429062768701634   ---   "01 - Call Of The Wild.mp3" "Florrie - Too Young to Remember.mp3"
5.43   ---   "Florrie - Unstable.mp3" "07 - Left Too Late (Florrie Edit).mp3"
5.43010752688172   ---   "02 - Free Falling.mp3" "01 - Speed of Light.mp3"
5.435744680851064   ---   "01 - Call Of The Wild.mp3" "01 - Speed of Light.mp3"

Project which I used to test TestRustyChromaprint.zip

darksv commented 1 year ago

Hello! Thanks for trying out this library!

Music file with invalid numbers of channel, crashes internally instead returning error

This was fixed for a while now when I implemented resampling, but wasn't published to crates.io - I've just released a new version including some bugfixes.

Sample rate is 11025 which seems to be 44100 / 4, but why not just 44100? Also looks that this value cannot be regulated per file

11025 is used in the original implementation and may not be easy to change since there are some hardcoded parameters that would require tuning. However, resampling is implemented now so it should work with any sample rate.

When it comes to your test application, the Fingerprinter::consume accepts a slice of samples so you need another crate to decode your file first. Symphonia is pure Rust and supports many formats, including MP3s. I created a small example using it here.

I improved the documentation slightly and I hope to extend it further this weekend.

qarmin commented 1 year ago

I updated to latest version, but cannot test output quality due crash, music files which cause this - test.zip

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `358`,
 right: `492`', /home/rafal/.cargo/git/checkouts/rusty-chromaprint-a12bb360ca835070/96a9591/chromaprint/src/fingerprint_matcher.rs:213:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: rusty_chromaprint::fingerprint_matcher::match_fingerprints
   5: test::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

https://github.com/darksv/rusty-chromaprint/blob/96a9591616ac623daf13e7ebc15cf5d81277b8b7/chromaprint/src/fingerprint_matcher.rs#L213

https://github.com/darksv/rusty-chromaprint/tree/main/compare - should be available as crate feature, because for now I just copy paste calc_fingerprint into project(I don't really see a reason, why I would need to reimplement this function)

darksv commented 1 year ago

@qarmin, sorry for late respond, but I didn't manage to work on this last week.

I updated to latest version, but cannot test output quality due crash

This panic should be fixed now. I checked your test files and it seems to work. Thanks.

https://github.com/darksv/rusty-chromaprint/tree/main/compare - should be available as crate feature, because for now I just copy paste calc_fingerprint into project(I don't really see a reason, why I would need to reimplement this function)

Sure. I can add this function in the future version.

qarmin commented 1 year ago

This two songs Music.zip - crashes with preset_test4 and preset_test5 in calc_fingerprint

(source code TestRustyChromaprint.zip )

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/rafal/.cargo/git/checkouts/rusty-chromaprint-a12bb360ca835070/ad1a81c/chromaprint/src/fingerprint_calculator.rs:14:78
stack backtrace:
darksv commented 1 year ago

thread '' panicked at 'called Option::unwrap() on a None value', /home/rafal/.cargo/git/checkouts/rusty-chromaprint-a12bb360ca835070/ad1a81c/chromaprint/src/fingerprint_calculator.rs:14:78

Thanks, I'll look into this.

Configuration presets in calc_fingerprint and match fingerprints should be same or can be different?

Right now it doesn't matter, because the config is not used in match_fingerprints. It might change at some point, so it should be the same.

If I understand correctly - 0 means almost no difference between fingerprints and 32(or 10) means maximum diff? (In documentation there is number 32, but in reality I only get max 9.99)

Segments with score above 10 are automatically rejected. I probably should make it configurable, though.

How to deal with false positives? A lot of music files returns 0 when comparing them with each other(like this two from above), but they are completely different (tested with test_preset_2 with other presets numbers are still quite low ~1.5)

For these two files I got a single segment that is 2 seconds long, so I'd say there is not much similarity between them. Ideally for two different files with the same song you'll get a single segment that lasts as long as that song.

qarmin commented 1 year ago

For these two files I got a single segment that is 2 seconds long, so I'd say there is not much similarity between them. Ideally for two different files with the same song you'll get a single segment that lasts as long as that song.

Where can I find info about segment length?

Segment { offset1: 1631, offset2: 1499, items_count: 16, score: 0.0 }
darksv commented 1 year ago

Use Segment::duration. It converts items_count to seconds based on the configuration.

qarmin commented 1 year ago

I already started to use this library, so initial sentence that I don't know how to use it, is no more valid