Class to modify the speed of a sound: AS3

For the game I am making, I needed a class to change the duration and frequency of a sound, as there is the possibility to slow down time.

My first solution was to use this code: http://www.mcfunkypants.com/2011/as3-pitch-shift-mp3/. But it came out being extremely hard to read and modify. I expended all my day (I think almost 9 hours) trying to simply add the capability of playing not-looping sounds, wich this class didn’t include. That was because of how unclear the code was to me: it has almost no comments at all, and the loop inside the onSampleData event is just unreadable.

I must add that, althought the code was supposed to play sound effects in a game, it’s very poor in performance, so when you play more than one FrequencyChangeSound at the same time, your game could get some low FPSs.  I’ll program a sound player class to do one single onSampleData event (instead of one for each sound), and get better performance.

 

So here’s the code:

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: