Ejemplo 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();
    }
Ejemplo n.º 2
0
        public void FillBuffer()
        {
            float increment = (1.0f / (hz / pulse_hz));
            int   toFill    = AudioStreamGeneratorPlayback.GetFramesAvailable();

            for (uint i = 0; i < toFill; i++)
            {
                float foo = Godot.Mathf.Sin(phase * (Godot.Mathf.Pi * 2f));
                Vector2.Set(foo, foo);
                AudioStreamGeneratorPlayback.PushFrame(Vector2);
                phase = (phase + increment) % 1f;
            }
        }
Ejemplo n.º 3
0
    private void PrepFrames()
    {
        var sampleHz = 44100.0f;
        var periodHz = 3000.0f;

        var incr = (1.0f / (sampleHz / (GetViewport().GetMousePosition().x / GetViewportRect().Size.x *periodHz)));
        var amp  = 1.0f - (GetViewport().GetMousePosition().y / GetViewportRect().Size.y);

        var numOfAvailFrames = gen.GetFramesAvailable();

        while (numOfAvailFrames > 0)
        {
            gen.PushFrame(new Vector2(amp, amp) * (float)Math.Sin(currPhase * (Mathf.Pi * 2)));
            currPhase         = (float)(currPhase + incr) % 1;
            numOfAvailFrames -= 1;
        }
    }
Ejemplo n.º 4
0
        public OplPlayer FillBuffer()
        {
            int toFill = AudioStreamGeneratorPlayback.GetFramesAvailable() * (Opl.IsStereo ? 2 : 1);

            if (Buffer.Length < toFill)
            {
                Buffer = new short[toFill];
            }
            Opl.ReadBuffer(Buffer, 0, toFill);
            for (uint i = 0; i < toFill; i++)
            {
                float soundbite = Buffer[i] / 32767f; // Convert from 16 bit signed integer audio to 32 bit signed float audio
                Vector2.Set(soundbite, soundbite);
                AudioStreamGeneratorPlayback.PushFrame(Vector2);
            }
            return(this);
        }
Ejemplo n.º 5
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);
        }