Pitching MP3 (Not PitchShift!) is possible since Flash10s new Sound API. Today I saw Lee Brimelow’s post about doing so, providing some source code. Cause we spend a lot of time to keep things running more smoothly in the AudioTool, I created another version which has some advantages.
- 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
(no preloader – music by basic channel) – Thanks Lee for pointing me!
Seriously cool! Can’t believe the source code is so small and easy to follow.
Already looking forward to your FOTB talk. Hope they put you in the room with the decent soundsystem ;-)
Awesome! Love your work, thanks for this example!
Very nice use of Basic Channel…
Been meaning to do some audio work, something like pitching is a great place to start.
wow nett – basic channel rockt und das script auch.
wann programmierst du traktor dj studio in actionscript nach? ;)
grüße aus berlin
Aber es pitched doch gar nicht, es speeded … ;-)
Geht das auch mit pitchshift und harmonic correction?
Nicely done! Now we just need to figure out how to get the music pitch changed but with the music playing at a constant speed …
bekomm leider den folgenden fehler?!
TypeError: Error #2007: Parameter type darf nicht ‘null’ sein.
at flash.events::EventDispatcher/addEventListener()
at components::MP3Pitch()[/Users/aM/Documents/workspace/audiotool/team/andre.michelle/fdt/session/Audio2009/src/components/MP3Pitch.as:36]
at ExampleMP3Pitch()[/Users/aM/Documents/workspace/audiotool/team/andre.michelle/fdt/session/Audio2009/src/ExampleMP3Pitch.as:29]
@Philipp:
Neusten Flashplayer installiert? Klingt als hättest du noch den Betaplayer.
Always a fan :)
I did something quite similar there:
http://guillaume.boit.free.fr/flash/scratch/bin/
(long preloader, just wait)
Sad thing it’s not very reactive.
Great stuff… Keep up the great work.
@Kodiak nice turntable.
AwESoMe …
could this code (modified) used for video?
:-)
That sounds amazing Andre!
@vidme unfortunately there is no current way to get to the bytes of audio from a Flash video file.
@dVyper
you just estimate the pitch and slice the sample accordingly and then overlap+add
@andre
not sure if it matters in AS3, but you could save a multiplication in
( 1.0 – alpha ) * l0 + alpha * l1 )
->
l0 – alpha* l0 + alpha * l1
->
l0+alpha*(l1-l0)
but maybe the compiler does already these kind of optimizations.. do you happen to know if this is the case?
Dont know if it’s the same thing but check it out http://wonderfl.kayac.com/code/d1eb34ea56d0b2671a0b85ce78b75896dba8573f (2009/05/20)
omg, I love it! Nice add adobe!!! = ]
@E.G Thanks for sharing. I have updated the source code with your optimization.
Andre you rock! Your implentation of mp3 speed shifting is very elegant.
I’m wondering, is it possible to use sound.extract() and then manipulate the raw sound data without waiting that the song is completely loaded ?
Good work !
Keep up great staff!
> you just estimate the pitch and slice the sample accordingly and then overlap+add
Could you perhaps elaborate on how to time shift without shifting pitch? Or better yet, update this example so that pitch is not effected? :)
@Adrien W. – yes, it seems you can start extracting before the file completely loads.
In addition to the Speed control, would it be possible to create a second slider to control the pitch? I suppoe it would be similar to what E.G. suggested, but I’m not sure how to code the second slider. Has anyone done both rate and pitch sliders using the Sound API and SampleDataEvent?
@Doug, @jazzairwaves, @dVyper
I’ve started porting a C++ library (SoundTouch) that does the overlap+add for time-stretching/pitch shifting. It’s pretty rough, but it works and is promising:
Here’s a demo http://static.ryanberdeen.com/projects/soundtouch-as3/demo/player/stretch.swf
You can adjust the tempo by dragging the slider. It sounds OK when the tempo is increased. Decreasing the tempo could use some work.
The source is here: http://github.com/also/soundtouch-as3
Ryan
@Ryan – that’s exceedingly cool! And even without decreasing tempo, it’s a lot further along than my attempted port of this FFT based routine:
http://downloads.dspdimension.com/smbPitchShift.cpp
I seem to be having trouble with very basic AS Number issues – the output has some relation to the input, but there are many artifacts… Will post if I figure it out. Please update if you get lower tempos working. Wouldn’t it be a matter of overlapping copies of each frame?
Hi, how to pitch a mp3 loop ?
Hi, so I find the way, but it’s not perfect
http://stealth35.free.fr/flash/Looper.as
@Ryan
Major respect, that’s the most impressive thing I’ve seen in audio with AS3 !
Looks very promising indeed :)
Hi,
Anyone know how can i put the buffer when i play dynamic sound(it’s generate from raw sound(mp3 file))
Thanks
Bechar
Andre, yet again you rock \m/ \m/
it keeps getting better , thanks for this
hey Andre,
great stuff as always!
any chance you could point me in the direction to do BPM (Beats Per Minute) analysis for a batch of MP3 files?
FP 10 is fine too.
Thanks in advance
Just in case anyone is looking to extend this example to do note based pitch shifting, this formula might be handy:
_playbackSpeed = Math.exp((Math.log(2)* SEMITONE_SHIFT)/12);
Hope that helps,
atom
@Ryan – Superb example of the type of audio control we’ve been struggling to create in Flash for a long time. Thank you for providing the source! Excellent work!
those chain reaction / bacis channel classics still sound good after all these years :)
Hi,
Anyone know how can i put the buffer when i play dynamic sound(it’s generate from raw sound(mp3 file))
Thanks
Bechar
Maybe this will help someone else, the _position variable is the Byte position, not millisecond = \ sometimes I spent way to much time not noticing that
Hi Andre,
your work is awesome!
How to pitch a loop mp3?
This is also pretty cool, as the tempo stays constant when you change pitch: http://iq12.com/blog/2009/08/25/real-time-pitch-shifting/
Really great work!
Im not good at this soundstuff. Is there a way to use this on soundfiles with lower samplerate or any samplerate?
//Olof
@leef you can get the percent played like this: var percentPlayed:Number = (_position/(_mp3.length*44.1));
Great work! Thanks for sharing!
if anybody else would like to play the sound from a certain start position you have to set the position to something like this:
_position = startTime * 44.1;
note that the startTime will be the time the mp3 should start playing in milliseconds.
hope that helps.
Awesome!
Does anyone know how to play the mp3 in reverse smoothly? Right now I have changed the startposition:
_position = startTime*44.1;
and the sound position:
_position -= scaledBlockSize;
But it doesn’t play smoothly…
Thanks