0

I am developing an AIR application for desktop that simulate a drum set. Pressing the keyboard will result in a corresponding drum sound played in the application. I have placed music notes in the application so the user will try to play a particular song.

Now I want to record the whole performance and export it to a video file, say flv. I have already succeed in recording the video using this encoder:
http://www.zeropointnine.com/blog/updated-flv-encoder-alchem/

However, this encoder does not have the ability to record sound automatically. I need to find a way to get the sound in ByteArray at that particular frame, and pass it to the encoder. Each frame may have different Sound objects playing at the same time, so I need to get the bytes of the final sound.

I am aware that SoundMixer.computeSpectrum() can return the current sound in bytes. However, the ByteArray returned has a fixed length of 512, which does not fit in the requirement of the encoder. After a bit of testing, with a sample rate 44khz 8 bit stero, the encoder expects the audio byte data array to have a length of 5880. The data returned by SoundMixer.computeSpectrum() is much much shorter than the encoder required.

My application is running at 60FPS, and recording at 15FPS.

So my question is: Is there any way I can obtain the audio bytes in the current frame, which is mixed by more than one Sound objects, and has the data length enough for the encoder to work? If there is no API to do that, I will have to mix the audio and get the result bytes by myself, how can that be done?

Lawrence Choy
  • 6,088
  • 1
  • 20
  • 30
  • I don't believe you're able to get anything close to the amount of data actually being played by using the computeSpectrum method. It stores 512 floating point values, 256 left and 256 right if you multiply the 256 by 60fps, you're still getting at max 15360 samples per second which isn't even 22Khz (but not to far off at around 15, still this would require full 60fps running speed meaning <16ms for code execution/redrawing per frame). I feel like this may be a bit much for AS3, you're likely going to need to communicate with a separate process to handle the audio similar to the link you had – shaunhusain Mar 03 '13 at 18:57
  • I haven't tried using this library but looks like it should fit the bill to help get at the audio from a system level http://www.libsdl.org/ – shaunhusain Mar 03 '13 at 18:58
  • Hi there! Did you find a way to do your task? I have something similar and my question is [here](http://stackoverflow.com/q/17566485/645918). Thanks! – Art Jul 12 '13 at 08:41

0 Answers0