Get all pitches of a wav file

Apr 23, 2014 at 5:31 PM
Hi, I just start using Pitch Tracker. I wish to get all the pitch of a wav file that I opened. What I know is enabling history buffer by setting PitchTracker.RecordPitchRecords to true that shown in documentation there.
How I retrieve those pitches after I set PitchTracker.RecordPitchRecords to true?
Where should I locate so that I can retrieve all the values of pitch?
Thank you.
Coordinator
Apr 24, 2014 at 8:04 PM
Hi,

You need to do the following:
  1. Set PitchTracker.RecordPitchRecords to true.
  2. Set PitchTracker.PitchRecordHistorSize to 0 (for no limit).
  3. Once you it has processed some data, the pitch records will be in PitchTracker.PitchRecords.
Sorry I noticed some comments for some properties are wrong, but the above should give you what you want.
Marked as answer by skc on 5/2/2014 at 7:34 PM
Apr 25, 2014 at 1:41 PM
Thanks for the reply. I thought you wont replying. You did help me a lot. I able to get the pitch already. By the way, is that any way to clear the pitch for the next use? I mean dispose the value of the pitch so that I can call in other wav file and calculate another pitch value again. Thanks a lot
Apr 26, 2014 at 2:12 PM
and there is one more question, how do I store the PitchTracker.PitchRecords into one variable and pass it to other class. Can I know what is the data type of PitchRecords
Apr 26, 2014 at 2:22 PM
Edited Apr 26, 2014 at 2:45 PM
I cannot access to the value store inside PitchTracker.PitchRecords. How do I access the value like RecordIndex, Pitch, MidiNote and MidiCents?
Current, I store the PitchTracker.PitchRecords like this:

var pitchValues = pitch.PitchRecords;

However I cant access the Pitch inside it. How to get it? I cannot call pitchValues.Pitch. There is no method Pitch inside pitchValues.

But I can call currentPitch.Pitch when I assign

var currentPitch = pitch.CurrentPitchRecord;

How do I access Pitch in PitchRecords like I access Pitch in CurrentPitchRecord?
Thanks a lot.
Coordinator
Apr 26, 2014 at 6:44 PM
To reset the pitch history, call PitchTracker.Reset().

PitchTracker.PitchRecords is enumerable, so you can access the records like this:
var pitchRecords = pitch.PitchRecords;

foreach (var pitchRecord in pitchRecords)
{
    Debug.WriteLine("Pitch = " + pitchRecord.Pitch.ToString());
    // ... or whatever
}
Apr 30, 2014 at 9:13 AM
Thx for the reply. Your reply did help me a lot. The PitchTracker is using auto-correlation method right? Can I know which part of code is using auto-correlation method?
I tried find it out but do not know where it locate. Can you show me which part of code is calculating auto-correlation? Thanks a lot.
Apr 30, 2014 at 12:13 PM
Can you show how to use auto-correlation to process the float data? I need a better understanding on it because I doing some study on it. Thx a lot.
May 2, 2014 at 5:39 AM
Hi, can I know is the PitchTracker using auto-correlation algorithm to calculate the pitch? In documentation there, it mentioned about heavily modified. Is it still considered calculate the pitch based on auto-correlation algorithm? I tried look through the code and I cant find any part of code is related to auto-correlation. Can you please show me which part of code is using auto-correlation algorithm? I would like to study how auto-correlation perform the pitch calculating. Thanks a lot.
May 5, 2014 at 6:30 PM
Hi, would you mind to reply? I need some guide from you. Thank you.
Coordinator
May 5, 2014 at 7:18 PM
Edited May 5, 2014 at 7:25 PM
The pitch tracker is using a modified version of auto-correlation. By that I mean it uses a divide-and-conquer approach to speed up the process (it "zooms in" on the peak by initially skipping some tests, and then reduces the size of the skips as it gets closer to the peak). It also uses a low resolution phase and high resolution phase so that the high resolution phase only need to do a peak search in a small range, further speeding up the overall process.

The actual code is spread out over multiple methods, but it basically starts in PitchDsp.DetectPitchLo. If you step through that code, you will see how it processes the data to find the point where the auto-correlation causes the pitch to be revealed.

Another difference between the traditional auto-correlation algorithm and this one... Typically it searches for a dip, but in this version searches for a peak due to the way the math is done differently (so the curve is inverted in this version). It just made more sense for me to do it that way.

Yet another difference: The traditional auto-correlation algorithm uses integer step sizes, resulting in inferior resolution the higher the pitch is that it is trying to detect. This version does interpolation in order to do fractional steps, meaning the accuracy doesn't degrade when detecting higher frequencies.

However, even with all those improvements over the traditional auto-correlation algorithm, there are still some audio sources where it doesn't perform well. This is why I'm working on a completely different approach now that so far produces much better results. But as I said, that one is nowhere near ready to make publicly available.
Marked as answer by skc on 5/5/2014 at 12:14 PM
May 5, 2014 at 8:17 PM
Thanks a lot for the reply. Learn a lot from your clear explanation. Your code did help a lot for my study and research. Sorry for disturbing you so many times.
Anyway, thanks for your help.
Aug 22, 2015 at 4:47 PM
Hi,
Currently I'm doing a project related to Music Industry in c#. Actually it is comparison of two wave files.
I want to get the pitch of opened wave file and I want to print it. how can I do that??
sample code may help me a lot...