wav <> mp3 for flash(as3) - actionscript-3

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.

Related

Working with flash with Mercurial: how to handle the FLA?

How do teams do to work all at the same time on the same .fla file when working with version control?
We are a team of 2 working on a flash game right now and we found that, since it is a binary file, we can't work on the .fla file at the same time or one or the other will need to replace his file (because it's almost impossible to merge).
The best solution we could find for short term, is texting the other "lock" and "unlock" whenever we want to work on the file. Yes, it is very inconvenient, I agree. There has to be a clean solution to this.
So how do big teams manage a binary file with version control?
What would be our alternative?
We use flash cs5 along with bitbucket and TurtoiseHg, if that changes anything.
Thank you for your precious time.
refer a following site:
Flash CS5 and Version Control

What are some good ways to Save/Load files in AS3?

I am writing a game in ActionScript3 using Flixel as a base. I have been unable to find a good method for saving and loading files from the player's local hard drive. I know Flixel has a way to save game data to...I think...cookies that the player doesn't really have access to, and I want to avoid this.
I first learned programming in Java, and one thing I've seen a lot of is scanning (Scanner) and printing (PrintWriter) lines of strings to/from text files. Something like this for AS3 would be my ideal, but if there are other methods I'm open.
Does AS3 have anything in its basic library that can do this task well? Are there libraries I can download and include that do this well/better?
If your game is going to run on a webpage your options are limited. Due to security concerns Flash is limited to reading and writing files specifically selected by the user.
Should you be using Air to make a standalone game, you will have regular access to the filesystem and can write files much like with Java.
If not, you will be pretty much stuck with Flash cookie equivalent, SharedObject.

Adobe AIR application audio

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.

AS3 and hashing

Is it possible to hash flv videos so it is unplayable by itself and the format is unrecognizable by softwares, but i could actually de-hash them and play in my as3 script?
This is going to be realized on a CD so I can't use server scripts.
no, you can't. not with flv. you could however embed the video into an swf and encrypt the SWF. please note however, using a strong encryption for video data may lead to performance problems.
anyhow: you can load the binary data into a ByteArray, perform the decryption and then load the SWF from the ByteArray.
I'm assuming you mean that you'd like to do this "real time" in the app.
If so, there are two issues with that:
you will have to decrypt your custom video in software, so its going to run very slow. And depending on the end user's computer, unpredictably so.
As ALOToverflow previously mentioned, the key to your hashing algorithm will be in your .swf which can be simply be decompiled to reveal it.
Assuming you are using as3 with adobe AIR you could potentially ship your users "broken" flv's and then simply repair them before you attempt to play them back.
Depending on the resolution and length of the videos this might be a viable alternative.
(you'd utilize the FileStream Class for this.) http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html
FLV's all start with a standard header, so you could start by just breaking the header, and repairing it later. (I'm talking about getting down and dirty with the binary code btw.)
http://en.wikipedia.org/wiki/Flash_Video
I created a similar project once.
this is what I did:
I encrypt the videos somehow, does not mater how, put them into one single big file.
A bulk data file. Then I run the swf, NOT from browser but rather run it from a JAVA application, which can decrypt the bulk video-file waaay faster, than the Adobe swf interpreter.
In the Java app, I pass the decrypted video to the swf as a parameter.
It is good to use Java, because all the clients can open it. Mac users, Windows users, anyone. It is possible to do it with C++, but that would limit your user-base.
Of course anyone with decent knowledge can reverse-engineer the encryption process, but it is harder to get the encryption from a Java compiled software, than from an AS3 swf.
Use Blowfish, Twofish or DES. Do not use RSA, it is slow.
You have to make the Java app extremely fast and simple, so also it is advised, not to use external cryptography libraries.

Air - Unzipping file

Currently I am using nochump library for unzipping files. But its very slow(around 30 seconds for 2 mb file). Is there any other libraries available which are fast. Or is thaere any better way to unzip by communicating with os?
I have used FZip, but it wont work in mac. So cant use it.
Not that I'm aware of... AS3 is quite slow in these areas...
A possible workaround, if you are using zips for loading images, could be using a big JPEG with all of your images inside it (eventually using an aditional XML to determine dimentions, or maybe even custom metadata). Uncompressing images in Flash is quite fast (and asynchronous).
It might be possible using Alchemy (there are very fast Alchemy librairies to encode JPEG and PNG), but I can't find any existing one for unzipping.
Otherwise, you can use the AIR 2.0 beta (not great for production code... depends on your project) to call a native application which will do the job for you.
Anyway, it might get tricky to retrieve progression information if you need it.