Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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;
        }
    }
Exemplo n.º 3
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);
        }