Beispiel #1
0
        public unsafe override void Run()
        {
            Span <char> display = stackalloc char[50];

            channel.Paused = false;

            System.GetDSPBufferSize(out var sampleLen, out _);

            do
            {
                OnUpdate();

                System.Update();

                bool bypass   = dsp.Bypass;
                var  volume   = dsp.GetParameterFloat(1);
                var  ptr      = dsp.GetParameterData(0, out var len);
                var  channels = dsp.GetParameterInt(2);

                var data = new ReadOnlySpan <float>(ptr, (int)len);

                string volstr = (volume * 100).ToString("N1");

                DrawText("==================================================");
                DrawText("Custom DSP Example.");
                DrawText("Copyright (c) Firelight Technologies 2004-2018.");
                DrawText("==================================================");
                DrawText();
                DrawText("Press 1 to toggle filter bypass");
                DrawText("Press 2 to decrease volume 10%");
                DrawText("Press 3 to increase volume 10%");
                DrawText("Press Esc to Quit");
                DrawText();
                DrawText("Filter is " + (bypass ? "inactive" : "active"));
                DrawText("Volume is " + volstr + "%");

                if (data.Length != 0)
                {
                    Debug.Assert((uint)channels <= 10);

                    float[] levels = DetermineChannelLevels(data, channels, (int)sampleLen);

                    for (int channel = 0; channel < levels.Length; ++channel)
                    {
                        display.Clear();

                        channel.TryFormat(display.Slice(0, 2), out _);

                        display.Slice(3, Math.Min((int)(levels[channel] * 40f), display.Length - 3)).Fill('=');

                        DrawText(display);
                    }
                }

                Sleep(50);
            }while (!ShouldEndExample);
        }