Finding pitch shift coefficients

Algorithm development and general DSP issues

Moderator: frank

livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Finding pitch shift coefficients

Post by livingston »

AN-0001 gives this formula for finding pitch shift coefficients:
For pitch shifting up:
C = 2^14 * (2^N-1)
N = Desired amount of pitch shift in octaves
But I'm having trouble finding how we're supposed to express the target interval "in octaves". For example, to do an upward perfect fifth, the ratio is 1:1.498 or so, or in just intonation 3/2. However, putting 1.498 or 1.5 into that formula for N doesn't work. 2/3 also doesn't work.

I tried a few other possible things, such as: we know an octave is 16384, so divide by 12 to find one semitone and multiply by 7 to find a fifth. I know that this doesn't take into consideration the non-linear math of pitches, so it doesn't surprise me that it doesn't work.

So, how do we find N?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

If I remember correctly, it is:

N=((2^(1/12))^S)/2

Read as: The 12th root of 2 raised to the Sth power divided by 2

S is the number of semitones
Frank Thomson
Experimental Noize
djmalan
Posts: 36
Joined: Fri Mar 06, 2009 8:22 am

Post by djmalan »

Absolutely working,
for the 5th. the number is for wldr 5486,01617072184
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

djmalan wrote:Absolutely working,
for the 5th. the number is for wldr 5486,01617072184
Not exactly. That's the number for 5 semitones, but a perfect fifth is 7 semitones. 5 semitones is a fourth (blame the dastardly inventors of the diatonic scale).

Thanks for that formula Frank. Will have to make a little spreadsheet to do this for me. Then I'll have to work out how translate the SOF statement of the pot-controlled ramp speed directly into the interval. Darn math, I hate it. :evil:

D'oh: don't know how I missed this thread. Sorry to make you answer this twice, Frank.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Not a problem (actually forgot about that thread). I like answering and helping, just have not been able to as much lately. And if someone like Sean answers, I'll back off and read his posts and try to pick up a few new things myself.
Frank Thomson
Experimental Noize
djmalan
Posts: 36
Joined: Fri Mar 06, 2009 8:22 am

Post by djmalan »

Sorry , this is it 8164.26314754755
And I have list includes all formulas for every somitone as an (open office format like exel)ods. if you want ,I did it last summer and check with tuner.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Oops, if djmalan is correct my equation is wrong and should be:

N=((2^(1/12))^S) - 1
Frank Thomson
Experimental Noize
Aion
Posts: 33
Joined: Sat Mar 22, 2008 1:17 am

Post by Aion »

So let me summarize:

;For pitch shifting up:
;C = 2^14 * (2^N-1)
;where
;N=((2^(1/12))^S) - 1
;N = Desired amount of pitch shift in octaves
;S is the number of semitones

Is it OK?

How does this look for pitch shifting down?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

See page 8 of http://www.spinsemi.com/Products/appnot ... N-0001.pdf It has the equations for calculating C for up and down.
Frank Thomson
Experimental Noize
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

I'm having a pretty hard time with this.

Question #1

I'm starting by just putting the values into Excel to see how they all come out.

Using this calculation for # of octaves for a given # of semitones:

Octaves = POWER(2, (Semitones/12))/2
or equivalently,
Octaves = POWER(2, (Semitones/12) - 1)

The value comes out correctly, 1 octave for 12 semitones and 2 octaves for 24 semitones. However it gives 0 semitones = 0.5 octaves which is certainly wrong.

If instead I use:

Octaves =POWER(2, (Semitones/12)) - 1,

Then 0 semitones = 0 octaves and 12 semitones = 1 octave, however 24 semitones comes out at 3 octaves.

If I use:

Octaves = semitones/12, then all 3 are correct, however this isn't right either!

djmalan if you are still there I would appreciate some insight, as you said you worked it all out and checked it with a tuner!

Question #2
AN-001 shows that the correct WLDR value for +1 octave is 16384, and +2 octaves is 32767. However, it seems like the real correct value for +2 octaves should be 32768, however we are limited by the # of available bits to 32767. So we use 32767 instead of 32768, which is "good enough for rock and roll or possibly avant garde" music?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

This is all a bit odd since we are working with powers. The simple answer is:

#octaves = #semitones/12

But semitones are not evenly distributed in the octave, they follow a power curve so to calculate the the frequency multiplier:

=POWER(POWER(2,1/12),A1)

Where A1 is the cell in a spreadsheet that is the number of semitones of desired shift.

And yes, we are limited to 32767 on the coefficient so it is just short of 2 octaves up.
Frank Thomson
Experimental Noize
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Ultimately I'm trying to come up with a way to allow the user to enter semitones and cents to get accurate, repeatable pitch shifts. So, just for my own sanity, what is the parameter for WLDR for a positive pitch shift of one semitone?

Muchas gracias,

DL
slacker
Posts: 116
Joined: Tue Feb 01, 2011 1:13 pm

Post by slacker »

I think there might be some confusion here, you can't get 2 octaves up, WLDR of 32767 = about 19 semitones.

I use this which seems to be close enough for jazz, rock and roll is more forgiving :)

For up shifts:

WLDR=16,384*(2^(1/12*semitones)-1) so for one semitone up
you get 16384*(2^(1/12*1)-1) = 974.24 divide that by 32768 to get the decimal value for writing directly to rmpX_rate.

For down shifts:

WLDR = (-16384*(1-(1/2^(1/12*semitones))))*-1
Digital Larry
Posts: 338
Joined: Mon Nov 12, 2012 1:12 pm
Contact:

Post by Digital Larry »

Hi Slacker, thank you for coming to my emotional rescue (C)(P). You are my knight in shining armor. That reference simply is an indication of my age (cough).

Ah, so 32767 is NOT 2 octaves but only 12 + 7 = 19? That's an interesting development. Anyway thanks for your example. All I'm trying to do is come up with the proper math for my little program. I think that other than the nice sounding intervals, that very small shifts for the barberpole flange type of effect are probably the most useful application of this effect.

[Edit: Well, don't I feel silly now. I re-read the AN-0001 and I don't think that it is claimed anywhere that 32767 gives two octaves of pitch shift. Pardon me!]

Here's my table with all semitones calculated:

Code: Select all

Semitones	Octaves	RMP LFO frequency parameter
0	0	                0
1	0.0594630944	974
2	0.1224620483	2006
3	0.189207115	3100
4	0.2599210499	4259
5	0.3348398542	5486
6	0.4142135624	6786
7	0.4983070769	8164
8	0.587401052	9624
9	0.6817928305	11170
10	0.7817974363	12809
11	0.8877486254	14545
12	1	                16384
13	1.1189261887	18332
14	1.2449240966	20397
15	1.37841423	22584
16	1.5198420998	24901
17	1.6696797083	27356
18	1.8284271247	29957
19	1.9966141538	32713
Anyway, per this calculation, 19 semitones is in fact very close to two "octaves", which I may need some assistance in absorbing. Nevertheless it does allow me to proceed!

Cheers,

DL
slacker
Posts: 116
Joined: Tue Feb 01, 2011 1:13 pm

Post by slacker »

Your WLDR numbers look right but your octaves figures probably aren't what you want, looks like you've divided the WLDR value by 16384?
The Octaves figure you want is Semitones/12 that then give 19/12 = 1.58333 or 1 and 7/12 which is an octave and a fifth up.
Post Reply