Sound.extract() Speed

Hello Kirupites,

Please forgive me if this has been answered before - a search didn’t turn up anything relevant, so I thought I’d pick your collective brain…

I’m trying to use sound.extract() to draw the waveform of an mp3 when it is loaded in. The problem I have is twofold:

  1. Sound.extract() can take a long time to run, during which time the program is completely unresponsive. Accessing the ByteArray afterwards can take even longer (as even a 2-minute song contains over 50,000,000 samples). Added up this means the program either hangs, or the process times out after 15 seconds.

  2. When I try to access data using ByteArray.readFloat() from the ByteArray created using sound.extract() it just returns a load of zeros. However, if I use ByteArray[value] I do get a number - I’m just not sure what this number is!

Here is my code for an example:

package {
	import flash.events.Event;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	import flash.display.Sprite;
	
	public class WaveTest2 extends Sprite {
		
		public function WaveTest2()  {
			
			//Create new sound object
			var customSong: Sound = new Sound;
			customSong.load(new URLRequest("the_wall.mp3"));
			customSong.addEventListener(Event.COMPLETE, completeListener);
			
			function completeListener(e: Event): void {
			
				//Create an array to hold samples from MP3
				var songSamples : ByteArray = new ByteArray;
				
				//Extract data from the input sound.
				var totalSamples: int = Math.floor ((customSong.length / 1000) * 44100)
				customSong.extract(songSamples, totalSamples);
				
				//Reset to beginning of ByteArray
				songSamples.position = 0;
				
				for (var i:int = 0; i < totalSamples; i += 1000) {
					
					//Returns 0 for every entry of songSamples.readFloat()
					trace("At " + i + ": " + songSamples.readFloat());
					
					//Returns a +ve number between 0 and 189
					trace("At " + i + ": " + songSamples*);
				}
			}
		}	
	}
}

What I would like to know is:

  1. Is there any way of working with sound.extract() and the massive ByteArray it creates without causing the program to slow down or hang?

  2. Why does songSamples.readFloat() always return 0?

  3. What is the number returned by songSamples*?

Thanks very much in advance for your help, it’s really appreciated!