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); }
private void AddFloatControl(Dsp dsp, ref DspParameterDesc info, int index) { var floatPanel = new FloatParameterPanel { ParameterUnit = info.Label, ParameterDescription = info.Description }; floatPanel.TrackBarControl.Maximum = info.FloatDescription.Maximum; floatPanel.TrackBarControl.Minimum = info.FloatDescription.Minimum; floatPanel.TrackBarControl.TickFactor = 20; floatPanel.TrackBarControl.Value = dsp.GetParameterFloat(index); floatPanel.Anchor = AnchorStyles.Left | AnchorStyles.Right; floatPanel.ValueChanged += (s, e) => dsp.SetParameterFloat(index, floatPanel.Value); flowPanel.Controls.Add(floatPanel, 0, index); }
private static void AdjustVolume(Dsp dsp, float adjustment) { dsp.SetParameterFloat(1, Math.Clamp(dsp.GetParameterFloat(1) + adjustment, 0, 1)); }