Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

NetStream and SAMPLE_DATA

Advisor ,
May 08, 2018 May 08, 2018

Hi,

is there a special way to use SampleDataEvent with NetStream.play() ?

I would like to apply my own audio effect to NetStream thanks

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

you probably want SoundMixer.computeSpectrum

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

hi Kglad,

apparently computeSpectrum is for graphic wave form only and offer a fragment of the full byte data chunk.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2018 May 08, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

Thanks for your example, but from a NetStream live object

impossible to get it, even with audioSampleAcces on server and client side.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

that's not true.  if a sound is playing, you can use the code i suggested.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

ok if you confirm it so I will give more tries.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

do you have an example to use the byteArray with netstream appendBytes?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

do you have code that's loading a netstream and playing a sound?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

are you playing a video or a sound?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

mp4 audio/video, but sometimes audio only

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

do you hear a sound when playing audio only?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

-- 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

that sounds like you’re creating a sound display.  is that what you’re doing?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 09, 2018 May 09, 2018

not really. the goal is to create a FLV on the fly frame by frame then save it locally or remotely

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines