Audacity Bug Summary
••• Introduction •••
••• Keywords •••
    Audacity 3.0.3 development began 19th April 2021

Audacity Bugzilla



Bug 638 - Pitch detection in Change Pitch wildly inaccurate at high sample rates
Pitch detection in Change Pitch wildly inaccurate at high sample rates
Status: RESOLVED FIXED
Product: Audacity
Classification: Unclassified
Component: Built-in FX
unspecified
PC All
: P4 Repeatable
Assigned To: Default Assignee for New Bugs
: patch_ready
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-04-24 13:17 UTC by Steve Daulton
Modified: 2018-08-20 11:51 UTC (History)
5 users (show)

See Also:
Steps To Reproduce:
Set Project Rate to 192000. Generate a 261 Hz sine tone (middle C) Open "Change Pitch" effect. The detected pitch is 375 Hz F#
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00


Attachments
Auto size detection window according to sample rate (2.48 KB, patch)
2013-04-24 13:32 UTC, Steve Daulton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Daulton 2013-04-24 13:17:53 UTC
Detected note frequencies become increasing inaccurate at higher sample rates.

At a sample rate of 44100 Hz, pitch detection is reasonably accurate in the range 200 Hz to 5000 Hz.

At a sample rate of 96000 Hz, pitch detection is only reliable above about 500 Hz.

At 192000 Hz sample rate, it is only reliable above about 1 kHz.

As the name of the effect implies "musical pitch", the detection should be reasonably accurate for "notes" in the 200 Hz to 1000 Hz range at all popular sample rates.
Comment 1 Steve Daulton 2013-04-24 13:32:32 UTC
Created attachment 374 [details]
Auto size detection window according to sample rate

At higher sample rates (which are increasingly common these days) a fixed FFT window size of 1024 samples is inadequate for detecting "note" frequencies. This patch therefore adjusts the window size proportionally for high sample rates.

The total analysis period is also adjusted automatically to remain at around 0.2 seconds (as per the original effect) which should be suitable in most cases for detecting the first note of the selection.

As there may be non-musical applications where users require reasonable detection at very low sample rates (proposed by Gale), the minimum window size has be capped at 512 samples.

This patch has been tested at all preset Project rates from 2,000 Hz to 384,000 Hz and should be good down to around 100 Hz in each case. 
Middle C (261 Hz) and "A 440" are correctly detected at all these rates.

To assist with reviewing the patch, I have retained debug messages, which should be removed before committing.
Comment 2 Steve Daulton 2013-04-24 16:14:57 UTC
(In reply to comment #1)
> the minimum window size has be capped at 512 samples.

Oops. That should say "256 samples".
Comment 3 Gale Andrews 2013-04-25 21:33:28 UTC
(In reply to comment #1)
> This patch has been tested at all preset Project rates from 2,000 Hz to 384,000
> Hz and should be good down to around 100 Hz in each case. 
Marked as "patch_ready". 

It's recently been tested down to 1000 Hz project rate by me.

Also at low sample rates, detection down to and including 20 Hz frequency is very reasonable (and far better than now).
Comment 4 Vaughan Johnson 2013-05-18 00:29:29 UTC
(In reply to comment #3)

Generally looks good to me. 

Why the switch from

      float buffer[analyzeSize];

to 

      float *buffer;
      buffer = new float[analyzeSize];

, etc?
Comment 5 Steve Daulton 2013-05-18 06:05:30 UTC
(In reply to comment #4)
> Why the switch from
>       float buffer[analyzeSize];
> to 
>       float *buffer;
>       buffer = new float[analyzeSize];
> , etc?

That may not be necessary. It is not required on Linux. 

When working on this patch I has a_lot_of_trouble with Windows build errors. I think that just got put in as part of trying to get it to build on Windows (I don't have a Windows development machine so fixing Windows build errors was a royal pain).
Comment 6 Vaughan Johnson 2013-05-20 22:06:47 UTC
(In reply to comment #5)

> --- Comment #5 from Steve Daulton <stevethefiddle@gmail.com> 2013-05-18 06:05:30 EDT ---
> (In reply to comment #4)
>> Why the switch from
>>        float buffer[analyzeSize];
>> to
>>        float *buffer;
>>        buffer = new float[analyzeSize];
>> , etc?
> 
> That may not be necessary. It is not required on Linux.

Oops, I had done only a code review. You're right that it doesn't work in MSVC now that the array sizes are not constants.

Committed. 


> 
> When working on this patch I has a_lot_of_trouble with Windows build errors. I
> think that just got put in as part of trying to get it to build on Windows (I
> don't have a Windows development machine so fixing Windows build errors was a
> royal pain).
> 

Perhaps you should focus on getting your stuff working only on Linux. It seems that you like submitting a series of incremental patches, but Gale can build on Linux, I think, and most of the incremental responses are from him. When it's agreed ready on Linux, we can do the cross-platform details. Will that work?
Comment 7 Gale Andrews 2013-07-11 05:18:56 UTC
As far as I can see this is now fixed on all three platforms.