Ibrahim
Ibrahim

Reputation: 1289

How do I display a spectrogram from a wav file in C++?

I am doing a project in which I want to embed images into a .wav file so that when one sees the spectrogram using certain parameters, they will see the hidden image. My question is, in C++, how can I use the data in a wav file to display a spectrogram without using any signal processing libraries?

An explanation of the math (especially the Hanning window) will also be of great help, I am fairly new to signal processing. Also, since this is a very broad question, detailed steps are preferable over actual code.


Example:

above: output spectrogram; below: input audio waveform (.wav file)

above: output spectrogram; below: input audio waveform

Upvotes: 2

Views: 3042

Answers (1)

hotpaw2
hotpaw2

Reputation: 70743

Some of the steps (write C code for each):

Convert the data into a numeric sample array.

Chop sample array into some size of chunks, (usually) overlapped.

(usually) Window with some window function.

FFT each chunk.

Take the Magnitude.

(usually) Take the Log.

Assemble all the 1D FFT result vectors into a 2D matrix.

Scale.

Color the matrix.

Render the 2D bitmap.

(optional) (optimize by rolling some of the above into a loop.)

Add plot decorations (scale, grid marks, etc.)

Upvotes: 2

Related Questions