Adjusting audio pitch in Flash Player 10

Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre!

Here is another sound example that shows how to adjust the pitch of an external sound. This is an extension of the example that can be found in the documentation for the Sound.extract method. Now this example does adjust the pitch but it also speeds the song up as well. This is because you need to skip some samples in order to increase the pitch. Now there are ways to increase the pitch of sounds without speeding them up but I have no idea how to do it. Do you?

Click on the image below to see the example. It uses my throw slider which you can toss back and forth. It may take a minute for the song to load so please be patient. You can download the FLA file if you want to see how it was done.

Lee


Commentary

  1. samBrown says:

    very cool, thanks for the insight. checkin under the hood…

  2. Denis says:

    How to force flash player to clear buffer while streaming sound? For example, streaming online radio.

  3. Subb says:

    Well, time-stretching can be done by splitting the sample into small parts and moving those parts closer or further away, filling the gap (if any) by repeating the part.

    High-Quality example:

    10101010101…

    can be stretched to
    110011001100…

    or
    1111111…

    Implementing this can be relatively simple (just drop or duplicate every X sample), but the sound quality may not be the best (tho it creates an interesting effect).

  4. nacho says:

    very good and music perfect, thank

  5. hristo says:

    Are you all that sure about time-stretching being all that simple? What about groups of samples, for example 16 bits or something

  6. Paras says:

    Great tutorial, Lee.

    Sorry for a slightly irrelevant question.

    Does anyone know how to find BPM (Beats Per Minute) information from external MP3 file(s)?

    I don’t want to play them all straightaway. Its a bit like iTunes – show a play list of all the mp3 from a specified file structure and BPM next to it. This is for an AIR application I am currently working on.

    Any help is appreciated. Thanks.

  7. gordee says:

    This is great, I have been looking into how to manipulate sound in Flash lately and had almost come to the conclusion that I was wasting my time. Great choice of song too!

  8. Paul says:

    Looks like Andre Michelle wrote a post in response to this one pretty quickly.

    http://blog.andre-michelle.com/2009/pitch-mp3/

    He improves the example in these ways:
    * No objects are created in runtime (memory usage)
    * The SampleDataEvent is receiving a static blocksize (steady latency)
    * Linear interpolation (sound quality)
    * Speed can go down to zero

    Personally I find this stuff really exciting and I’m looking forward to learning something new today.

  9. leef says:

    that is so fresh! I can’t wait to try that out

  10. personman says:

    The slider turned all the way up reminds me of Foamy the squirrel.

  11. joshspoon says:

    Is there anywhere where there is community of Flash developers working on audio manipulation stuff? Anyone?

  12. Joeflash says:

    The chipmunks were hippies? Far out man…

    This had my wife cracking up. Nice work Lee.

  13. Basically, the pitch or tone depends on the sampling frequency, and the sampling frequency depends on the time of the wave.
    That’s why if we modify our sampling frequency, we modify our time.
    The only way is by skipping samples from X time to time in the time domain, so the frequency wave form wouldn’t be affected. If we just rise the sampling frequency without modifying our samples, the result is that the Fourier transform domain (frequency) is not the same, so that the sound changes its velocity.

    The way to rise the pitch without rising the velocity is not by skipping samples, you just have to copy such as samples as frequency-multiple you want to rise the pitch.
    (Such as: 100111010 –(rising pitch in a 3 ratio) –> 111000000111111111000111000), as you can see, 3 times every sample to solve the 3times rised freq.
    That’s what it does Soundbooth when you just rise the pitch ;)

    I have just studied Digital Audio in Telecomunicatios, I got a 9 over 10.

    Keep on ;)

  14. Lewis says:

    I’ve been playing around with this for awhile and have a basic demo of some DJ turntables.

    http://idontdance.co.uk/lab/flashdj/FlashDJ.swf

    Lewis

  15. tommy says:

    very funny to play with.. could sit here for days.

  16. Dejanseo says:

    Ah, very cool I was starting to this that this wasn’t possible. I need this for my next viral! :)

  17. Pim says:

    i find this sound, sampledata, writefloats etc stuff so freaking hard to understand, but yet it’s so cool :D So i’m going to lock myself up and see if i can get to understand it :P
    Thanks for the tutorial Lee!

  18. Benny says:

    Would it be possible to pitch a youtube stream?

  19. Dave Bleeker says:

    I have seen this example on the Adobe website, but the bouncing slider really adds something very cool and creative.

  20. Dave Bleeker says:

    btw. If you want to see and hear something that really blows your mind with working with audio in Flash, for those who doesn’t seen it yet:

    http://www.hobnox.com/index.1056.en.html

  21. Gerardo says:

    Hi Lewis how are you.. I’m trying to do something similar to your project FlashDJ.. I’m wondering if you can share with me your source file (.fla)

    I’ll appreciate your help

    Thanks a lot…

    If you can contact me my e-mail address is ghernandez@orugafilms.com

  22. p2man says:

    There’s a company creating dynamic sound in Flash AS3 called Sonoflash.

    http://www.sonoflash.com/sounds/

    Their stuff is pretty lightweight!

  1. [... Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre! Here is ...]

  2. [... Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre! Here is ...]

  3. [... Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre! Here is ...]

Leave a Comment