A basic slicer

Part of the slicer

Part of the slicer

This is it! The first one: A slicer.

It loads and plays an MP3 file. But not only that. It divides the file in sixteen equal parts and you can change the order in which the parts are played.

When it’s loaded the slicer plays all the parts in the right order. Part 1, 2, 3 and up until part 16. With the buttons you can change the order and for example play part 4, then 3, 11, 8 and so on. With the right MP3 loop this will create all kinds of interesting rhythmic variations.

It works best if the MP3 file is a short piece of music with a steady rhythm that loops seamlessly (so the start and end of the sound fit together exactly). Then every slice has a little bit of rhythm in it. Just one or two sounds like a kick or snare drum.

Best to check it out for yourself. I will put the actual SWF files on the ‘Read more’ pages of the posts, so they won’t all be playing at the same time and use up each other’s CPU cycles.

The interface

It’s a matrix! Sixteen buttons wide for the time slots, sixteen high for the slices. So the bottom left button selects slice one to be played first, the top left button plays slice sixteen at position one. Just click around and you’ll get it.

The code

The main thing in this application is the Sound.extract() method. Once the MP3 is loaded the total amount of samples in the file is divided by sixteen. Then it can store the duration in samples of a slice and at which sample exactly each slice starts. So the file isn’t actually split into sixteen parts. It only stores the starting point of each slice within the loop.

One thing I didn’t know but found out trying is how to get the total amount of samples in an MP3 file: Use extract() and request a length longer than you know the MP3 file is. For example one hour. Then extract() will get as many samples as it can. Which are all the samples in the file, and it returns that number:

 

Get Adobe Flash player

var oneHour : uint = 44100 * 60 * 60;
var numSamples : uint = mp3File.extract(new ByteArray(), oneHour);

If you recognized the loop but thought it was somehow different: You’re right! It’s Mr Oizo’s “Bobby Can’t Dance” from his album “Analog Worms Attack” (1999). But speeded up to 120 BPM. I liked it a bit faster. (The speeding up wasn’t done with this slicer by the way. No advanced ActionScript 3.0 timestretching algorithm yet I’m afraid.)

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − six =