Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:07:52+00:00 2026-05-23T00:07:52+00:00

so this the code with it i am able to mix several tracks with

  • 0

so this the code with it i am able to mix several tracks
with a Shader done in pixel bender.
the problem here i don’t know when the mixing is finish or all the sound reache their end
to be able to save the bytearray into a file any Event or something like that

help plz ?

package  
{
    import flash.display.*;
    import flash.media.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;
    import fl.controls.Slider;
    import org.bytearray.micrecorder.encoder.WaveEncoder;

    [SWF(width='500', height='380', frameRate='24')]

    public class AudioMixer extends Sprite{

        [Embed(source = "sound2.mp3")] private var Track1:Class;        
        [Embed(source = "sound1.mp3")] private var Track2:Class;        

        [Embed(source = "mix.pbj",mimeType = "application/octet-stream")]
        private var EmbedShader:Class;

        private var shader:Shader = new Shader(new EmbedShader());

        private var sound:Vector.<Sound> = new Vector.<Sound>();    
        private var bytes:Vector.<ByteArray> = new Vector.<ByteArray>();
        private var sliders:Vector.<Slider> = new Vector.<Slider>();
        private var graph:Vector.<Shape> = new Vector.<Shape>();
        private var recBA:ByteArray = new ByteArray();
        private var BUFFER_SIZE:int = 0x800;
        public var playback:Sound = new Sound();
        public var container:Sprite = new Sprite();
        public var isEvent:Boolean = false;
        public function AudioMixer():void{
            container.y = stage.stageHeight * .5;
            addChild(container);

            sound.push(new Track1(), new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2());

            for(var i:int = 0; i < sound.length; i++){
                var slider:Slider = new Slider();
                slider.maximum = 1;
                slider.minimum = 0;
                slider.snapInterval = 0.025;
                slider.value = 0.8;
                slider.rotation += -90;
                slider.x  = i * 40 + 25;
                container.addChild(slider);
                sliders.push(slider);

                var line:Shape = new Shape();
                line.graphics.lineStyle(1, 0x888888);
                line.graphics.drawRect(i * 40 + 14, 0, 5, -80);
                line.graphics.endFill();
                container.addChild(line);   

                var shape:Shape = new Shape();      
                shape.graphics.beginFill(0x00cc00);
                shape.graphics.drawRect(i * 40 + 15, 0, 3, -80);
                shape.graphics.endFill();
                container.addChild(shape);
                graph.push(shape);
            }           

            playback.addEventListener(SampleDataEvent.SAMPLE_DATA, onSoundData);
            playback.play();

        }

        private function onSoundData(event:SampleDataEvent):void {

            for(var i:int = 0; i < sound.length; i++){
                bytes[i] = new ByteArray();
                bytes[i].length = BUFFER_SIZE * 4 * 2;
                sound[i].extract(bytes[i], BUFFER_SIZE);                

                var volume:Number = 0;
                bytes[i].position = 0;  

                for(var j:int = 0; j < BUFFER_SIZE; j++){
                    volume += Math.abs(bytes[i].readFloat());
                    volume += Math.abs(bytes[i].readFloat());                   
                }

                volume = (volume / (BUFFER_SIZE * .5)) * sliders[i].value;              

                shader.data['track' + (i + 1)].width    = BUFFER_SIZE / 1024;
                shader.data['track' + (i + 1)].height   = 512;
                shader.data['track' + (i + 1)].input    = bytes[i];
                shader.data['vol'   + (i + 1)].value    = [sliders[i].value];

                graph[i].scaleY = volume;
            }

            var shaderJob:ShaderJob = new ShaderJob(shader,event.data,BUFFER_SIZE / 1024,512);

            shaderJob.start(true);
            var shaderJob2:ShaderJob = new ShaderJob(shader,recBA,BUFFER_SIZE / 1024,512);
            shaderJob2.start(true);

        }       

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:07:53+00:00Added an answer on May 23, 2026 at 12:07 am

    You can tell when a shader has completed it’s job using the ShaderEvent.COMPLETE listener. Like so:

    shaderJob.addEventListener(ShaderEvent.COMPLETE, onShaderComplete);
    
    private function onShaderComplete(e:Event):void
    {
        //Do Something here
    }
    

    See this link for more details.

    One thing about your code though. You’re doing this shader job inside of a sampleDataEvent and I can see this being problematic (possibly) in the sense that your mixing may be out of sync with your playback (that is, if you plan on mixing live and writing the mixed data back into the sound stream). Anyway that’s perhaps an issue for a new question. This should solve your problem with needing to know when the mixing is complete.

    Note you also need to add “false” to the shaderJob.start(false) function. From the documentation about the ShaderEvent.COMPLETE:

    “Dispatched when a ShaderJob that executes asynchronously finishes processing the data using the shader. A ShaderJob instance executes asynchronously when the start() method is called with a false value for the waitForCompletion parameter.”

    Update

    In response to your inquiry about how to only process inside the sampleDataEvent if the sound isnt being processed:

    private var isProcessing:Boolean = false;
    
    private function onSoundData(event:SampleDataEvent):void {
    
    if(isProcessing != true){
    
                for(var i:int = 0; i < sound.length; i++){
                    bytes[i] = new ByteArray();
                    bytes[i].length = BUFFER_SIZE * 4 * 2;
                    sound[i].extract(bytes[i], BUFFER_SIZE);                
    
                    var volume:Number = 0;
                    bytes[i].position = 0;  
    
                    for(var j:int = 0; j < BUFFER_SIZE; j++){
                        volume += Math.abs(bytes[i].readFloat());
                        volume += Math.abs(bytes[i].readFloat());                   
                    }
    
                    volume = (volume / (BUFFER_SIZE * .5)) * sliders[i].value;              
    
                    shader.data['track' + (i + 1)].width    = BUFFER_SIZE / 1024;
                    shader.data['track' + (i + 1)].height   = 512;
                    shader.data['track' + (i + 1)].input    = bytes[i];
                    shader.data['vol'   + (i + 1)].value    = [sliders[i].value];
    
                    graph[i].scaleY = volume;
                }
    
                var shaderJob:ShaderJob = new ShaderJob(shader,event.data,BUFFER_SIZE / 1024,512);
    
                shaderJob.start(false);
    shaderJob.addEventListener(ShaderEvent.COMPLETE, onShaderComplete);
                var shaderJob2:ShaderJob = new ShaderJob(shader,recBA,BUFFER_SIZE / 1024,512);
                shaderJob2.start(false);
    
    }
    
            }    
    
    private function onShaderComplete(e:ShaderEvent):void
    {
        //Do something here
        isProcessing = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In code: //I know that to get this effect (being able to use it
This code is supposed to be able to sort the items in self.array based
I have this code, which works fine, but I would like to be able
All the automated, online converters weren't able to convert this code. Unfortunately my brief
I have this piece of code which I'm hoping will be able to tell
I would like to see how this example of existing code would be able
I have this code and I'd really liek to be able to get the
everyone.. I'm on the way to find out why this code is not able
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.