Real-time pitch shifting (without change of duration)

After reading Lee Brimelow’s post about Adjusting audio pitch in Flash Player 10, I’ve thinked about a real pitch shifting solution (adjusting pitch without change of duration).

Then I found a great algorithm here: http://www.dspdimension.com/admin/pitch-shifting-using-the-ft/ and its C# port here http://sites.google.com/site/mikescoderama/pitch-shifting

I’ve ported the code to AS3 then heavily optimized it to get it running under 100% cpu use (of 1 cpu core). I get 45% cpu use with the default parameters on my 2.4GHz PC.

See it in action here (Flash Player 10 required):

pitch_shift.gif
click to open

You can download the source code here: http://iq12.com/files/pitch_shift/pitch_shift.zip

Music: More Frightened by CandyCash (with permission)

Comments (21)

Stephan BernseeAugust 25th, 2009 at 17:21

Running at 32% (default values) on my MacPro 2×2.8 GHz Quad Core Intel Xeon. Good job!! If I may make a recommendation – you should really add the 4096 frame size as it sounds so much better for complex signals like music. Thanks for sharing this! Cheers, –smb

Lee BrimelowAugust 25th, 2009 at 19:27

Nice dude!

Og2tAugust 25th, 2009 at 20:01

Very nice, I wish Flash had support for microphone recording already. I wonder how fast it would run in PixelBender – I might try that, the C++ code seems to be portable and it might be even easier to port it to PB than AS3 ;-)

fuAugust 25th, 2009 at 21:32

I’ve looked into PB and as far as I know there’s no way to get this working because it would require too much loop unrolling. Correct me if I’m wrong.

UmitSeptember 5th, 2009 at 12:44

Nice work. The volume gradually decreases and increases back, how can we fix this?

Luke MassoudApril 7th, 2010 at 03:36

Hi there,
I searched the whole internet and here is the only as3 pitchshift code in the world.
thank you so much for this. its fantastic work I read all the stuff on the dsp dimension in hope that I could make my own but my brain isnt big.
thank god for people like you , now im just using your code.
a couple of questions if you get the time :
Why do you create two pitch shifters ? (one for left and one for right) why dont you reuse the one pitch shifter ?
in other words
can I use the one pitchshift object to shift in turn left then right.
I cant see any reason why not but i thought I should i ask you.

also im having a strange problem after I implemented the pitchshift object the output is really wrong. if i pitch shift at 1 I hear nothing but if I pitch shift at 2 all i can hear is a faint tin like sound almost in audible.
I checked the outputted floats and it looks really wrong its like this:
0
0
0
0
4.023402340
3.230403249023
0.0000324234324
0.0003423423423
0.0023432423423
0.0034234234324

I am pitch shifting a sound of only 9 milliseconds I thought that may be the problem
so i tried a longer sound but it still causes the problem.

thank-you again
Luke

Luke MassoudApril 7th, 2010 at 07:30

actually I made the sound longer and it worked
but i need to pitch shift a small sound
I geuss im asking how can i pitch shift a 9 millisecond sound ?

Luke MassoudApril 7th, 2010 at 10:28

i mean 90ms

Luke MassoudApril 8th, 2010 at 03:46

actually it was 9.
i discovered that this isnt what i need to pitch a sound whilst retaining the formants
http://www.surroundsfx.com/forum/viewtopic.php?f=11&t=638

Jonas NyströmOctober 23rd, 2010 at 06:02

Any ideas about how Alchemy would work in this case?

fuOctober 23rd, 2010 at 15:00

that’s pure speculation but I think a x4 performance boost could be achieved

I might give it a try.

SebastianDecember 1st, 2010 at 14:45

Great got a project with a some facetrackign aswell where this will come in handy, thanks! gimme a shout lator this month if you wanne see the result

raviJanuary 27th, 2011 at 06:48

Hi,

any body help me about pitch shifting in actionscript2.0

WinstonFebruary 1st, 2011 at 19:31

Great work.
I would like to use something like this to correct pitch of mp4 video played at 1/2 and maybe 1/x speeds in Flash 10 player. Any help would be appreciated. Also would need to improve quality and CPU performance.

Thanks,

[...] PitchShifter - Real-time pitch shifting (without change of duration) http://iq12.com/blog/2009/08/25/real-time-pitch-shifting/ [...]

SantosJuly 13th, 2011 at 21:43

Hello there, great job on the code.

I’ve been trying to adapt something of sorts for microphone input in realtime for the last few days with no such luck. Though I can get it to pitch and keep the duration, the sound comes out choppy and really unusable. I think I might be handling the mic sampling unproperly, or iterating over the sample data without the correct “overlap factor”, as you call it in your example.

Do you know of anyway I can achieve this? A realtime microphone pitch without change in duration and quality results? Any help at all would be much apreciated.

YanniOctober 4th, 2011 at 05:15

Any one know of a good objective C example of this source code?

fuOctober 4th, 2011 at 07:43

You can check thé dspdimension source link to get their pure C code. Should be easy enough to use no?

AS3 Class LibraryOctober 22nd, 2012 at 03:49

[...] PitchShifter - Real-time pitch shifting (without change of duration) http://iq12.com/blog/2009/08/25/real-time-pitch-shifting/ [...]

Jose Ramon LeonDecember 4th, 2012 at 13:50

What percent do you think is one complete pitch up or complete pitch down? And half pitch?

Thanks for all!

Best regards,

J.R. Leon

[...] изменение скорости звука в реальном времени (КРУТО!!!). PitchShifter — изменение тональности звука, черз pitch-shifting (я думаю, [...]

Leave a comment

Your comment