Re: [Audacity-devel] Autocorrelation for tuner ?
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
|
From: Dominic M. <do...@mi...> - 2001-12-24 05:41:32
|
Dan,
Glad that our code is of use to you. Your tuner sounds
like a great idea!
Please credit "Tolonen and Karjalainen" with the basic idea for
the enhanced autocorrelation. The Audacity implementation
is mine.
It sounds like you've got everything working correctly already.
If you recorded a sample rate of 44100 Hz, that means that each
sample is 1/44100 of a second.
So a peak of 63 samples means 63/44100 = 0.00143 seconds.
Take the reciprocal of that to get frequency: 700 Hz.
Does there look like there's a peak at more like 100 samples?
That's what 440 Hz would correspond to.
By the way, I normally use an FFT size of at least 512.
The other thing I think you're missing is the cubic
interpolation. The resolution of the FFT is not great
enough to figure out the tuning with better accuracy than
a single half-step. To get more accuracy, you pretend
that the output of the AutoCorrelation near the peak is
a cubic polynomial, and find its maximum using calculus.
You can borrow that code from Audacity too.
Anyway, what that will do is take a possible peak such
as 63 and change that to 62.73 (or something like that),
based on the neighboring values.
I'm running Linux now so I haven't checked out your code yet;
give this stuff a try and then let me know how it goes.
- Dominic
Daniel Frankowski wrote:
> Folks,
>
> **** THE APP:
>
> I am trying to steal your code to use it for a tuner program. :-) The
> app: play a note into a microphone, and the program will say what the
> pitch is, and how close you are to it. There are 17 million guitar
> tuners out there (fixed-pitch), but I have not found one that I can
> play my trumpet into (picks out the note on the fly), hence the app.
> I hope this is okay with you folks-- if I get it in shape to release,
> it'll be open source, like Audacity, with full credit to you guys,
> etc. etc.
>
> Anyway, I am trying to use your "Enhanced Autocorrelation" to detect
> the pitch, just like in Audacity's spectrum window. I am getting
> different results in the Audacity spectrum window when I set "Enhanced
> Autocorrelation" and in my app ("tuner"), so I have probably plugged
> things together wrong, or just don't understand the output.
>
>
> **** THE PROBLEM:
>
> - Audacity's ok: I sing A440 into Audacity for 5 seconds, and "Plot
> Spectrum". I choose "Enhanced Autocorrelation", "Hanning Window",
> "256", and "Linear Frequency", and when I move the cursor in the
> window, I get a peak detected at 0.0023 seconds, it says 440 Hz, all
> is well.
>
> - My app appears broken: I run "tuner", sing A440 into it for 5
> seconds, and it prints out a "spect.txt" which I then plot in Excel.
> If I choose a window size of 256, it has a peak at point 63 or so, not
> 440 or 0.0023 or something.
>
>
> **** THE CODE:
>
> Basically, I tried to combine portaudio's patest_record.c (which
> records 5 seconds of audio and plays it back) and a pared-down version
> of FreqWindow::Recalc(), which I call "Autocorrelation()", which lives
> in my own Spectrum.cpp (borrowed and modified from yours).
>
> See code snippets below my sig, or the entire project is in a zip file
> at
>
> http://www.winternet.com/~dfrankow/tuner/tuner.zip
>
> Right now, it only builds on Windows. I figure I'll tackle
> multi-platform later if there's demand. I also am trying to use gcc
> instead of VC++, just because I don't have VC++ and I figure I'll try
> free first. :-)
>
> Any advice is appreciated.
>
> Dan
>
|