-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: YIN algorithm #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: YIN algorithm #940
Conversation
|
Hi @siriak, can you check this pr when you get a chance? Thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the YIN algorithm for pitch detection in audio signals, adding a new signal_analysis module to the codebase. The YIN algorithm is a well-known pitch estimation technique that uses autocorrelation-based methods to detect fundamental frequencies in audio signals.
- Implements the complete YIN algorithm including difference function, cumulative mean normalized difference function, and parabolic interpolation for improved accuracy
- Adds comprehensive test coverage with various sine wave scenarios including harmonic and inharmonic combinations
- Integrates the new module into the project structure with proper exports and documentation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/signal_analysis/yin.rs | Implements the YIN pitch detection algorithm with Yin struct, YinResult struct, and supporting functions for signal analysis |
| src/signal_analysis/mod.rs | Module file that exports the Yin and YinResult types |
| src/lib.rs | Adds the signal_analysis module to the public API |
| DIRECTORY.md | Updates documentation to include the new YIN implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #940 +/- ##
==========================================
+ Coverage 95.39% 95.44% +0.04%
==========================================
Files 331 332 +1
Lines 21261 21496 +235
==========================================
+ Hits 20282 20516 +234
- Misses 979 980 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Please check comments |
…Result. This is necessary to communicate clearly that yin can fail if no argmin for CMNDF is found, for which get_frequency would return inf because the best lag would be 0. Added a test for this case.
|
I adjusted the relevant code as suggested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
YIN algorithm
Description
Implementation of the YIN algorithm for estimating the fundamental frequency of an audio signal. With optional parabolic interpretation for refining the result. I added the following files:
signal_analysis/yin.rssignal_analysis/mod.rsI added a new folder
signal_analysisbecause I felt the algorithm did not feat neatly into the other categories. Let me know if that's okay or I should put it somewhere else.I added
#[allow(clippy::needless_range_loop)]on the functiondifference_function_valuesbecause I felt that clippy's suggestion to use an iterator and enumerate decreases the readability of the function (especially for people new to Rust) for no substantial performance improvement.The YIN algorithm is based on: De Cheveigné, A., & Kawahara, H. (2002). YIN, a fundamental frequency estimator for speech and music. The Journal of the Acoustical Society of America, 111(4), 1917–1930. https://doi.org/10.1121/1.1458024
Closes #939
Type of change
Please delete options that are not relevant.
Checklist:
cargo clippy --all -- -D warningsjust before my last commit and fixed any issue that was found.cargo fmtjust before my last commit.cargo testjust before my last commit and all tests passed.mod.rsfile within its own folder, and in any parent folder(s).DIRECTORY.mdwith the correct link.COUNTRIBUTING.mdand my code follows its guidelines.