Exemplo n.º 1
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        // var gen = (AudioStreamGenerator) GetNode<AudioStreamPlayer>("AudioStreamPlayer").Stream;
        var frames = buf.GetFramesAvailable();

        bufferdata = new Vector2[frames];

        short output = 0;

        for (int i = 0; i < frames; i++)
        {
            if (timeacc % Math.Floor(MixRate / 4410f) == 0)
            {
                output = update_synth(ops);
            }
            GetNode <Label>("Label").Text = output.ToString();
            bufferdata[i].x = (float)output / 0x8000f;
            bufferdata[i].y = bufferdata[i].x;

            timeacc++;
        }

        buf.PushBuffer(bufferdata);
        // var output = update_synth(ops);
        // GetNode<Label>("Label").Text = output.ToString();
    }
Exemplo n.º 2
0
        void fill_buffer()
        {
            int frames = buf.GetFramesAvailable();
            // var bufferdata = new List<Vector2[]>();  //frames from each channel
            var    bufferdata = new Vector2[channels.Length][]; //frames from each channel
            var    output     = new Vector2[frames];            //final output
            object _lock      = new object();


            //Get frame data for each channel.
            for (int i = 0; i < channels.Length; i++)
            {
                // Parallel.For(0, channels.Length, delegate(int i) {
                //     lock(_lock)
                {
                    // if (!channels[i].Empty)  //Fill the buffer for the channel.  If channel is 0, also process clock events.
                    bufferdata[i] = channels[i].request_samples(frames, ClockEvent, i);
                }
            } //);

            //Assemble each set of frame data into the final output buffer.
            // for(int i=0; i<frames; i++) {
            Parallel.For(0, frames, delegate(int i) {
                // lock(_lock)
                // {
                for (int j = 0; j < channels.Length; j++)     //Cycle each channel into j.
                {
                    output[i].x += bufferdata[j][i].x * 0.3f; //quiet each channel by 1/16 (0.0625)
                    output[i].y += bufferdata[j][i].y * 0.3f;
                }
                // }
            });

            buf.PushBuffer(output);
            // Clock.Iterate(frames, MixRate);
        }