FftProvider: GetFftData always returns 0 values

Jul 9, 2014 at 9:18 PM
Edited Jul 9, 2014 at 9:25 PM

I'm integrating CSCore in an existing audio player. I've successfully implemented all functions (play, stop, pause,...) but Im struggling with the visualizations (I'm using the spectrum analyzer provided by https://wpfsvl.codeplex.com/). This is the code I use to play a sound:
Dim soundSource As IWaveSource = GetSoundSource()
Dim soundOut As ISoundOut = GetSoundOut()

mFftProvider = New FftProvider(soundOut.WaveSource.WaveFormat.Channels, FftSize.Fft2048)
The visualization requires FFTData at regular intervals implementation of the spectrum player interface makes sure the function which returns FFTData is called when needed). In that function I'm calling CSCore's:
The returned fftDataBuffer is used by the visualization. However fftDataBuffer only contains 2048 "0" values.

What am I missing to get this to work and to calculata FFTData correctly?
Jul 10, 2014 at 12:17 AM
The usage of the FftProvider is basically correct. The only point you are missing is, that you have to add the samples which should be used for the FFT calculation.
You would have to change your code to something like this (not tested):
IWaveSource soundSource = GetSoundSource();
ISoundOut soundOut = GetSoundOut();

var notificationSource = new SingleBlockNotificationStream(soundSource);
mFftProvider = new FftProvider(notificationSource.WaveFormat.Channels, FftSize.Fft2048);

notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right); //eventhandler which actually adds the samples to the FftProvider.

soundOut.Initialize(notificationSource.ToWaveSource(16)); //initialize the soundOut which the notificationSource
Anyway, I am going to upload a few visualization samples soon.
Marked as answer by filoe on 7/24/2014 at 8:56 AM
Jul 10, 2014 at 4:32 AM
Thanks a lot for the code sample! I've got it to work in 10 minutes.