Adobe AIR application audio - actionscript-3

I have a quick question relating to Actionscript 3 / AIR. I have looked through the site, but may be searching for the wrong thing or terms.
Is it possible to get an application wide audio stream from an AIR application?
I am trying to create a local audio file containing everything (all channels) played in an AIR app.
Does anybody have any ideas or suggestions?
Kind regards,
Phil
Update:
I have tried using the SoundMixer.computeSpectrum() function, but it returns a bytearray (size 2480) full of zeros...
It looks like it isn't reading the audio data correctly... I am playing a swf loaded using a SwfLoader and it is playing the sound out...
Odd... Anybody got an idea..?

There is SoundMixer.computeSpectrum, which will give you the global waveform or frequency data for the app. Unfortunately, it is fairly unreliable, and if you are trying to piece together the entire accurate audio stream, it is probably insufficient. But it might be enough to suit your needs if you are making, say, a visualizer or something else that only wants to know the current state of the audio stream.

Have you looked at SoundMixer Class? It has a computeSpectrum method that can get all playing sounds into a ByteArray, if I'm not totally misinterpreting the docs there.

Related

Flash SWF taking up too much RAM - crashing unexpectedly?

I have created a game in Adobe Flash CS6 which uses a lot of video files. As a result it seems that when I try and publish the game I manage to get to the 4th question and the game just crashes. I have looked into the processes on my system and whilst playing the .swf file my RAM increases to 3GB! Surely this isn't right? Is there a possible way of making it so the file doesn't take up so much RAM so it can work all the way through?
I hope somebody can help me! Thanks
The videos, are they local? Such as, are they imported to flash, or does flash use the url command to retrieve the video?
are the videos optimized?

Encode video from any format to .flv format in AS3

Is there any library in Action Script that be able to convert any video format to .FLV?
I've been looking for it with no success. I thought that as3 had functions for that purposes but not found.
I want to give the possibility that in my site, users can upload any video, so I need to convert it to a standard and compress it to a fixed resolution.
Thanks in advance.
There's a FLV encoder AS3 library. As far as I remember it requires image bytes and audio bytes for a frame. But you will have to get image data and sound data somewhere. You could either
play the video in flash and grab 'screenshots'
decode it and get actual data
In the first case you'll end with a mp4/flv -> flv converter which I guess is not what you need. In the second case you will have to decode videos somehow. So you either will have to implement decoding algorythms in AS3 or use Alchemy and existing C/C++ solutions.
Adobe is messing up with Alchemy at the moment, so I guess it is not an option anyway.
But everyone in their mind uses a server-side script to convert videos. There are tons of articles in the web. This will be the simplest, fastest and least painful solution.

create a composite from bitmap and video file with FFmpeg or other binary via as3 frontend

After receiving much help with reading all the great stackoverflow topics in the past, I finally have to post a question myself.
For a client I need to create some sort of video-editor for dummies,
which has to generate a video file as output.
The editor has to load a movie-file scale and rotate it to a certain degree, and generate a composite video of a background bitmap and the rotated and placed video.
The frontend will be done in Flash/AS3 and has to use some background tools for processing the video.
Can I use FFmpeg to generate such a composite? Or is there any other good background task available?
edit:
update 19.12. ... still did not find a solution... any ideas from others?
thanks!
I don't think ffmpeg is the best tool for compositing. Instead, you could simply have Flash do the compositing, create the frames (as BitmapData objects) and upload them to some server-side script.
Then once all the frames have been uploaded, use Flash to call a second script that will build the video using ffmpeg.

Decoding Audio / Audio Playback (AS3)

I'm interested in learning how to decode and playback audio in ActionScript 3. I understand how to write bytes to a Sound object using the SAMPLE_DATA event, so that's not really a problem. What I want to understand is how I could implement alternate audio formats for native playback inside of Flash Player.
I guess what I'm asking is: how do I take something in X format and "convert/decode" it to WAV format and write the bytes to a Sound object, playing back the audio? I'm interested in writing a decoder for FLAC audio and possibly OGG audio, as these seem to be some of the most widely used open source audio formats.
Can anyone give me any advice on this?
If you want to write a decoder, the first thing you should probably look at is the spec for the format you want to decode.
The ogg/vorbis spec can be found here: http://xiph.org/vorbis/doc/Vorbis_I_spec.html.
Also, it could be of help to take a look (or maybe port) some other open source library that already does this (I'm not aware of any written in Actionscript), such as this, in Java: http://www.jcraft.com/jorbis/ (I don't know this library, I've just found it googling "ogg vorbis open source".
At any rate, you'll have to put some work to get it working and I don't mean this to discourage you, but I'm not sure Actionscript is fast enough for real time audio decoding.
You can try, but you're not going to have much grunt left to do other stuff. Prior to Flash 10, I wrote an article detailing a hack to feed PCM data into sound output in Flash. Someone got in touch because they had written an AS3 Ogg decoder, but... even after fully optimzing the code, it was found that AVM2 is really not that much up to the job. Basically, it's rather slow and decoding OGG is quite processor intensive. I can't see that things will have changed that much in the years since, because CPUs have become "wider" and not really that much faster. ActionScript is single threaded, so you can't offload to another core.
Probably worth checking out this... maybe performance has improved.
EDIT: Having said all that, as Juan has said, don't be discouraged by this answer. I suspect the computational demands of FLAC decoding are probably considerably less than OGG, and if DSP gets you excited, taking the time to figure all this stuff out is 100% worth it, even if the Flash route (possibly) leads to disappointment. Personally I think that the MediaStreamSource for Silverlight looks really promising,but haven't really dabbled that much.

wav <> mp3 for flash(as3)

I'm wondering about MP3 decoding/encoding, and I was hoping to pull this off in Flash using AS3
I'm sure it'll be a right pain...
I have no idea where to start, can anyone offer any pointers? reference material?
----much later---
Thank you all very much for your input... It seems I have a long road ahead of me yet!
You could also theoretically do this as a PixelBender filter, and should get significantly better performance than using a pure ActionScript 3 implementation.
More info on PixelBender here:
http://labs.adobe.com/wiki/index.php/Pixel_Bender_Toolkit
mike chambers
mesh#adobe.com
this would help
http://labs.adobe.com/technologies/alchemy/
See LAME MP3 Encoder. You can checkout their source code and their link page. Mpeg.org should have documents too.
I've got a project converting WAV files (actually Asterisk voice mails) into MP3's. If I remember correctly there are some oddities about Lame's license, so I've downloaded and compiled first LAME, then SOX by hand.
I have a web process written in PHP to actually convert the files from WAV to MP3 on the web server's local file system (actually PHP is just supervising the command-line sox tool via exec()). Then I attach all the metadata the MP3 needs using the PEAR Mp3_Id package.
Then I move the newly constructed MP3 file into a folder Apache is sharing, and point the outstanding SoundManager2 flash-based MP3 player at it.
For small transactions this works very well -- converting a minute or two voice mail does not add any appreciable lag to actually rendering and returning the rest of the page. As I get more users on a single server, it will probably eventually become necessary to write a cron job or something to do the conversion before the user actually asks for the file the first time.
It's going to be VERY slow doing this in AS3. You really need a C/C++ implementation if you care at all about how long it will take.
Andre Michelle and the Hobnox guys pulled off something similar with their Hobnox AudioTool, they ported a Java Vorbis encoder to AS3. They supposedly ended up with encoding taking twice the time of the audio duration.
Don't know what your use case is, but in the Hobnox tool apparently audio is created at the client side, encoded as Vorbis, sent to the server, converted to mp3 and stored in the users library.