public void TimerUpdateEventHandler(object sender, EventArgs eventArgs) { BassWasapi.GetData(null, (int)DataFlags.Available); // Note: The DataFlags seems to be offset by one (e.g. FFT256 only fills 128 entries) const int get256FftValues = (int)DataFlags.FFT512; // Get FFT data. Return value is -1 on error var result = BassWasapi.GetData(FftBuffer, get256FftValues); if (result < 0) { Log.Debug("No new Data"); return; } var level = BassWasapi.GetLevel(); // Required, because some programs hang the output. If the output hangs for a 75ms // this piece of code re initializes the output so it doesn't make a glitched sound for long. if (level == _lastLevel && level > 0) { //Log.Debug(" not changed"); if (_hangCounter++ > 10) { Log.Warning("Looks like sound got lost. Trying to restart."); _hangCounter = 0; Free(); InitBass(); _initialized = false; SetEnableWasapi(true); } return; } _lastLevel = level; _hangCounter = 0; }
private static int Process(IntPtr buffer, int length, IntPtr user) { var level = BassWasapi.GetLevel(); if (length < 3000) { return(length); } int resultCode; if (_fftUpdatesSinceLastFrame == 0) { resultCode = BassWasapi.GetData(AudioAnalysis.FftGainBuffer, (int)(AudioAnalysis.BassFlagForFftBufferSize | DataFlags.FFTRemoveDC)); } else { resultCode = BassWasapi.GetData(_fftIntermediate, (int)(AudioAnalysis.BassFlagForFftBufferSize | DataFlags.FFTRemoveDC)); if (resultCode >= 0) { for (var i = 0; i < AudioAnalysis.FftHalfSize; i++) { AudioAnalysis.FftGainBuffer[i] = MathF.Max(_fftIntermediate[i], AudioAnalysis.FftGainBuffer[i]); } } } if (resultCode < 0) { Log.Debug($"Can't get Wasapi FFT-Data: {Bass.LastError}"); } var audioLevel = level * 0.00001; _fftUpdatesSinceLastFrame++; //Log.Debug($"Process with {length} #{_fftUpdatesSinceLastFrame} L:{audioLevel:0.0} DevBufLen:{BassWasapi.Info.BufferLength}"); return(length); }