protected override void Update() { base.Update(); float[] levels = new float[2]; BassMix.ChannelGetLevel(ChannelHandle, levels, 1 / 1000f * sample_window, LevelRetrievalFlags.Stereo); float curPeakL = levels[0]; float curPeakR = levels[1]; float curPeak = (curPeakL + curPeakR) / 2f; if (curPeak > maxPeak || Clock.CurrentTime - lastMaxPeakTime > peak_hold_time) { lastMaxPeakTime = Clock.CurrentTime; maxPeak = float.MinValue; } maxPeak = Math.Max(maxPeak, curPeak); volBarL.ResizeHeightTo(curPeakL, sample_window * 4); volBarR.ResizeHeightTo(curPeakR, sample_window * 4); string peakDisplay = curPeak == 0 ? "-∞ " : $"{BassUtils.LevelToDb(curPeak):F}"; string maxPeakDisplay = maxPeak == 0 ? "-∞ " : $"{BassUtils.LevelToDb(maxPeak):F}"; peakText.Text = $"curr: {peakDisplay}dB"; maxPeakText.Text = $"peak: {maxPeakDisplay}dB"; peakText.Colour = BassUtils.LevelToDb(curPeak) > 0 ? Colour4.Red : Colour4.White; maxPeakText.Colour = BassUtils.LevelToDb(maxPeak) > 0 ? Colour4.Red : Colour4.White; }
public bool ChannelGetLevel(IBassAudioChannel channel, [In, Out] float[] levels, float length, LevelRetrievalFlags flags) => BassMix.ChannelGetLevel(channel.Handle, levels, length, flags) != -1;