views:

373

answers:

2

I'm trying to playback some sample data through the new real-time audio capabilities of Flash Player 10. I started with the example given at the bottom of this page on livedocs, which seems to work fine and plays a crystal clear tone.

I assume that the two writeFloat's in the example write to the left and right audio channels respectively and that the data being written is 32 bit (because of the float).

However. I seem to be having trouble converting my old 8 bit audio data to a format that is understood by this interface. When I playback my sample data I can vaguely hear the sound I'm expecting but it is massively distorted. My sample data consists of raw 8 bit samples that ranges from 0..255 where 127 is silence.

I've been trying different conversion formulas but I seem to be missing some vital information regarding this conversion.

Any help greatly appreciated.

UPDATE:

The correct formula turns out to be:

f = (sample.data.readByte() - 127) / 255
+2  A: 

Try the conversion var newSample:Number = (Number(oldSample)-127.0)/127.0;

+1  A: 

Make sure you are reading in your 8-bit data correctly. If you are using the ByteArray-class then use readUnsignedByte (instead of readByte) to get a value between 0-255. Then use the formula suggested by MontyGomery.

Ville Krumlinde