1

I'm streaming music from Spotify with C# wrapper ohLibSpotify and play it with NAudio. Now I'm trying to create a spectrum visualization for the data i receive.

When i get data from libspotify, following callback gets called:

public void MusicDeliveryCallback(SpotifySession session, AudioFormat format, IntPtr frames, int num_frames)
{
    //handle received music data from spotify for streaming
    //format: audio format for streaming
    //frames: pointer to the byte-data in storage

    var size = num_frames * format.channels * 2;
    if (size != 0)
    {
        _copiedFrames = new byte[size];
        Marshal.Copy(frames, _copiedFrames, 0, size);   //Copy Pointer Bytes to _copiedFrames
        _bufferedWaveProvider.AddSamples(_copiedFrames, 0, size);    //adding bytes from _copiedFrames as samples
    }
}

Is it possible to analyze the data i pass to the BufferedWaveProvider to create a realtime visualization? And can somebody explain how?

freakimkaefig
  • 409
  • 5
  • 19

1 Answers1

1

The standard tool for transforming time-domain signals like audio samples into a frequency domain information is the Fourier transform.

Grab the fast Fourier transform library of your choice and throw it at your data; you will get a decomposition of the signal into its constituent frequencies. You can then take that data and visualize however you like. Spectrograms are particularly easy; you just need to plot the magnitude of each frequency component versus the frequency and time.

nimish
  • 4,755
  • 3
  • 24
  • 34
  • I've managed the FFT and received a double[] containing values from -1 to 1. Can you explain in more detail what "plot the magnitude of each frequency component versus the frequency and time" means and how you would code that part? – freakimkaefig Apr 02 '14 at 13:26
  • 1
    This answer has tips for interpreting the output of a Fourier transform: http://stackoverflow.com/questions/604453/analyze-audio-using-fast-fourier-transform – nimish Apr 03 '14 at 09:10