Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify sound in real-time with SampleDataEvent for audio within NetStream

I'm streaming audio using NetConnection and NetStream. I know that you can modify sample data in real-time with the Sound object, however I cannot find the SampleDataEvent for audio playing with the NetStream object. Is there a way to pass the audio from the NetStream object to a Sound object and modify the sound at that object instead?

Edit: I'm willing to do any kind of crazy hacks, so any solution is OK!

like image 436
Johan Avatar asked Oct 13 '22 17:10

Johan


2 Answers

you need to access the bytecode of the sound, if using netstream it's possible only by passing it to (requesting it by) NetStream.send() / NetConnection.call() in addition to the data being streamed. else you'll need something like a direct url for a Sound or URLStream

like image 168
www0z0k Avatar answered Oct 25 '22 05:10

www0z0k


Depending on the quality you're looking for, it you can sacrifice it down to a mono signal with low-bitrate, you may be able to stream it to obtain it as a URLStream on the client side, and then feed the data of that URLStream to a SampleDataEvent of an empty Sound object, progressively at runtime.

The extra work would mostly be on the server side, decompressing your MP3 to a Waveform stream of floating-numbers (a stream of a single-channel [mono] signal or a blend of the two combined to mono) and then pushing that out to your client side application.

As the URLStream gets loaded, append it's downloaded bytes to the ByteArray available on the Sound's SampleDataEvent (also give it some buffer "time" to load sufficient waveform data). For each mono-sample's read from the URLStream, you should write the same value twice to the SampleDataEvent.data object (once to the Left channel, once to the Right).

All this being said, downgrading the WAV-like sound stream to mono may not be sufficient to cut down on bandwidth and reach a wide target audience. Perhaps a look at an OGG library for AS3 (which should exists) would be a better alternative, and should certainly support decoding partially downloaded streams.

like image 25
chamberlainpi Avatar answered Oct 25 '22 05:10

chamberlainpi