#bcf #detection #bacf #auto-correlation #acf

pitch

Quickly and accurately determine the pitch and volume of a sound sample

4 releases

Uses old Rust 2015

0.1.3 Jun 16, 2018
0.1.2 Jun 14, 2018
0.1.1 Jun 12, 2018
0.1.0 Jun 12, 2018

#671 in Audio

Download history 12/week @ 2024-02-26 3/week @ 2024-03-04 15/week @ 2024-03-11 3/week @ 2024-03-18 51/week @ 2024-04-01

70 downloads per month

BSL-1.0 license

9KB
115 lines

"pitch" by Plop Grizzly

Quickly and accurately determine the pitch and volume of a sound sample.

This crate uses a Bitstream Autocorrelation Function (BCF) invented by Joel de Guzman to determine the pitch of the sound sample.

Features

  • Determine pitch of an audio wave using Bitstream Autocorrelation (BCF)

Contributing

Roadmap to 1.0 (Future Features)

  • Try using BACF, the updated version of BCF, which uses peaks rather than zero-crossings. Evaluate Speed vs accuracy benifits / downfalls. Method differences described here

Change Log

0.1

  • Initial release.

lib.rs:

Quickly and accurately determine the pitch and volume of a sound sample.

This crate uses a Bitstream Autocorrelation Function (BCF) invented by Joel de Guzman to determine the pitch of the sound sample.

How to use

It is really quite simple. Just write:

let (hz, amplitude) = pitch::detect(&samples)

samples is a fixed-size array of f32s. I use 2,048 for the array length. The length of the array should be 2 times the period of the lowest note you want to pick up (because of math and some theories). So 2,048 gives us notes up to 1,024 samples per period, which in 48,000Hz is about 47Hz (48,000Hz / 1,024 Samples). For reference, the lowest sine wave that a human can hear is 20Hz (a little more than an octave lower).

Example

Example code can be found in test.rs. The audio files I used were me playing my trombone on notes A1, A2, A3, and A4, and generating sine, saw, and square waves with Audacity on the note A4 (making sure to set 48,000hz sample rate). Here is my example output (Note: I didn't tune my trombone beforehand since this program is a tuner, and may give different results than other tuners):

A1: 55.422962 Hz, 0.7379681 Vl
A2: 107.865166 Hz, 0.43305764 Vl
A3: 215.78847 Hz, 0.69536424 Vl
A4: 436.30658 Hz, 0.117435224 Vl
SINE_A4: 439.99805 Hz, 0.8001343 Vl
SAW_A4: 439.99167 Hz, 0.8001343 Vl
SQUARE_A4: 434.3891 Hz, 0.80022585 Vl

No runtime deps