4

Based on the resource here (defining the structure of a WAV file), I was able to get the audio data between the 44th byte and near the end of the file (some extra meta-data exists at the end which is not necessary).

But I'm having trouble loading it with the new Sound.loadPCMFromByteArray() method available in Flash Player 11.

I get this error if I pass the number of samples:

_sound.loadPCMFromByteArray(pcm, pcm.length, "float", wav.isStereo, wav.sampleRate);
  • [Fault] exception, information=ArgumentError: Error #2084: The AMF encoding of the arguments cannot exceed 40K

However, if I divide the pcm.length by four (4), it seems to play "something" but isn't at all the sample that I passed it originally. Plus, it sounds like it's looping forever, is this the intended behavior? (I sure hope not!)

 //Dividing by 4 (# >> 2 is the same) is playable, but incorrect!
 _sound.loadPCMFromByteArray(pcm, pcm.length >> 2, "float", wav.isStereo, wav.sampleRate);

Does the ByteArray of WAV data need to be processed a certain way to conform to a readable PCM format? Do I need to insert an EOF character at the end so it knows when to stop the Sound file?

Should I use another format than "float"? Which ones are supported?

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
  • if the playback is funny, then I suspect that the the format of data is not what FP is expecting it to be. This function assumes 32bits/sample. I guess if your original file is encoded in something different, then you'd need to pre-process the data before passing it on to loadPCMFromByteArray – catholicon Feb 01 '12 at 23:03
  • it has something to do with "short" instead of "float". I will provide an elaborate answer later... – chamberlainpi Feb 02 '12 at 11:13
  • @bigp - were you able to accomplish this? Also, there are classes out there to save and load WAV files in Flash. Have you tried these? – 1.21 gigawatts Apr 01 '12 at 11:41
  • Hey gigawatts, No I wasn't able to successfully load PCM data. I gave up on this method after a few other developers reported the issue to Adobe and their response didn't seem like they considered it a high-priority (which sucks!). For the time being, I used Andre Michelle's Popforge library which works well enough to create SWF-Sound files at runtime. The loadPCMFromByteArray(...) method might be fixed when AS4 comes out, lets hope! – chamberlainpi Apr 01 '12 at 16:18
  • I think the classes you speak of are the ones in the Popforge library, yeah I gave those a try. What I'm mostly interested in though is create audio-processing algorithms. So working with raw PCM ByteArrays would be much faster (in theory). – chamberlainpi Apr 01 '12 at 16:21

0 Answers0