Copy link to clipboard
Copied
Hi,
is there a special way to use SampleDataEvent with NetStream.play() ?
I would like to apply my own audio effect to NetStream thanks
Copy link to clipboard
Copied
you probably want SoundMixer.computeSpectrum
Copy link to clipboard
Copied
hi Kglad,
apparently computeSpectrum is for graphic wave form only and offer a fragment of the full byte data chunk.
Copy link to clipboard
Copied
computeSpectrum can be used to get an envelope like display, but you can also just get the audio data. I've done apps that combine sections of audio, and play them back as a single sound. This article explains the modes:
Adobe ActionScript 3.0 * Accessing raw sound data
The part I don't know is whether that will work from a video stream audio, but it's worth a try.
Copy link to clipboard
Copied
Hi Colin,
I tried to use computSpectrum to put every fragment in a byteArray but unfortunately didn't reproduce every chunk of the audio
since computSpectrum grabs only 256 bits even with a very short interval no more than a small "clip" sound is heard.
Anyhow I'm going to try your example thanks... btw, I recall that I already tried it out without success.
same result of my example, little "clip" sound is heard, nothing else
Copy link to clipboard
Copied
there are several errors in your statements.
i recommend you read about and experiement with computeSpectrum before you decide it won't work for you.
Copy link to clipboard
Copied
I just recall I already did months ago since it's not a new issue but I have to go back these days to solve it.
if any of you have a working example of computeSpectrum grabbing audio sample in byteArray then
able to play it so I would be happy
Copy link to clipboard
Copied
var obj:Object=new Object();
var byteA:ByteArray=new ByteArray();
var sound1:Sound=new Sound();
var url:URLRequest=new URLRequest("whatever.mp3");
sound1.load(url);
var sc:SoundChannel=sound1.play();
var t:Timer=new Timer(50,0);
t.addEventListener(TimerEvent.TIMER,f);
t.start();
function f(evt:TimerEvent) {
SoundMixer.computeSpectrum(byteA,true,3);
delete obj.rightA;
delete obj.leftA;
obj.leftA=new Array();
obj.rightA=new Array();
for (var k:int=0; k<255; k++) {
obj.leftA.push(byteA.readFloat());
}
for (var m:int=0; m<255; m++) {
obj.rightA.push(byteA.readFloat());
}
// do whatever you want with obj.rightA and obj.leftA
}
Copy link to clipboard
Copied
Thanks for your example, but from a NetStream live object
impossible to get it, even with audioSampleAcces on server and client side.
Copy link to clipboard
Copied
that's not true. if a sound is playing, you can use the code i suggested.
Copy link to clipboard
Copied
ok if you confirm it so I will give more tries.
Copy link to clipboard
Copied
do you have an example to use the byteArray with netstream appendBytes?
Copy link to clipboard
Copied
do you have code that's loading a netstream and playing a sound?
Copy link to clipboard
Copied
it's a live NetStream so I should look for previous sample test I did months ago in my dev folder.
Briefly I did what your code do with NetStream.play("mp4:whatever"), then
I tried ENTER_FRAME with no success and a Timer at 33ms, same result,
with a global byteArray taking the data for around 10 sec and then
play it with another NetConnection with connect null and NetStram.appendBytes();
Copy link to clipboard
Copied
are you playing a video or a sound?
Copy link to clipboard
Copied
mp4 audio/video, but sometimes audio only
Copy link to clipboard
Copied
do you hear a sound when playing audio only?
Copy link to clipboard
Copied
-- do you hear a sound when playing audio only?
with the original NetStream yes. with the audio data grabbed from computeSpectrum()
I can hear a nano second of "clic" then silence. it Sounds like the audio grabbed is played so fast
that every bit is played without to care of the digital clock
Copy link to clipboard
Copied
I extracted the code from my class that manages various things not related to this topic and simplified it.
it's the best result I got from a microphone audio data btw, but not for NetStream audio.
this is a function running from a Timer at 33ms
function timerFrameAdd(event:TimerEvent):void{
while(mic1.bytesAvailable > 0){
var byte1:Number = (mic1.bytesAvailable > 0) ? mic1.readFloat() : null;
myMic.byteArray.writeFloat(byte1);
}
if(myMic.byteArray.length == 0){
for(var s:int=0;s<8192;s++){
myMic.byteArray.writeFloat(0);
}
}
baFlvEncoder.addFrame(videoFrame,myMic.byteArray);
myMic.byteArray.clear();
videoFrame = null;
}
I think I should make a clean test sample out of the project..
Copy link to clipboard
Copied
with the mic you can use the sampledataevent. that's one of its two uses.
using computeSpectrum does not affect the audio. if you're doing anything with the bytearray data from computeSpectrum that may or may not affect the audio.
if you're saving the data that can consume quite a bit of memory and that may affect playback.
what code are you using to play your netstream and save the bytearray data?
Copy link to clipboard
Copied
I planned to use a worker and next step crossbridge,
but for now I want to be sure the audio will be grabbed.
grabbing raw data from the mic is definitely working, grab audio from a live netStream is
really another story.
the NetStream can come from a NetConnection DIRECT_CONNECTION peerToPeer, or multicast, or unicast
and is pretty straight forward.
nc = new NetConnection();
nc.connect(URI,params...);
once connected:
ns = new NetStream(nc); // with options if peerTopeer
ns.play("mp4:whatever");
to save the byteArray I use multiple classes from FLVencoder (do you like I post all of them here?)
Copy link to clipboard
Copied
each call to computeSpectrum will generate 2^^9 ~20digit numbers. if you call that 2^^5/second for 2^^7 seconds, you're saving a lot of data.
why are you saving all that data?
Copy link to clipboard
Copied
probably because It's not correct .
the wish is to grab the audio from the netstream playing on enter_frame or timer function that also create a bitmapdata frame from the stage to the FLVencoder.
Copy link to clipboard
Copied
that sounds like you’re creating a sound display. is that what you’re doing?
Copy link to clipboard
Copied
not really. the goal is to create a FLV on the fly frame by frame then save it locally or remotely
Find more inspiration, events, and resources on the new Adobe Community
Explore Now