How do I play back a WAV in ActionScript?

Posted by Jeremy White on Stack Overflow See other posts from Stack Overflow or by Jeremy White
Published on 2010-05-29T00:44:36Z Indexed on 2010/05/29 0:52 UTC
Read the original article Hit count: 489

Filed under:
|
|

Please see the class I have created at http://textsnip.com/51013f for parsing a WAVE file in ActionScript 3.0.

This class is correctly pulling apart info from the file header & fmt chunks, isolating the data chunk, and creating a new ByteArray to store the data chunk. It takes in an uncompressed WAVE file with a format tag of 1. The WAVE file is embedded into my SWF with the following Flex embed tag:

[Embed(source="some_sound.wav", mimeType="application/octet-stream")]
public var sound_class:Class;
public var wave:WaveFile = new WaveFile(new sound_class());

After the data chunk is separated, the class attempts to make a Sound object that can stream the samples from the data chunk. I'm having issues with the streaming process, probably because I'm not good at math and don't really know what's happening with the bits/bytes, etc.

Here are the two documents I'm using as a reference for the WAVE file format: http://www.lightlink.com/tjweber/StripWav/Canon.html https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Right now, the file IS playing back! In real time, even! But...the sound is really distorted. What's going on?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about audio