Spectrogram C++ library
It would be fairly easy to put together your own spectrogram. The steps are:
- window function (fairly trivial,
e.g. Hanning) - FFT (FFTW would be
a good choice but if licensing is an
issue then go for Kiss FFT or
similar) - calculate log magnitude
of frequency domain components
(trivial: log(sqrt(re * re + im *
im))
How do I display a spectrogram from a wav file in C++?
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.)
A C library for finding local maxima?
Peak finding is a fairly general problem. It has already been discussed once on SO as Peak detection of measured signal.
The answers provided include several viable heuristics.
Of course, I prefer my own answer if you need rigor, but ROOT is written in c++, and is almost certainly too heavy for your application, so you'll need to strip out just the code you want...
How to generate the audio spectrum using fft in C++?
There are quite a few similar/related questions on SO already which are well worth reading as the answers contain a lot of useful information and advice, but in essence you need to do this:
- Convert the audio data to the format required by FFT (e.g. int -> float, with separate L/R channels);
- Apply suitable window function (e.g. Hann aka Hanning window)
- Apply FFT (NB: if using typical complex-to-complex FFT then set all imaginary parts in the input array to zero);
- Calculate the magnitude of the first N/2 FFT output bins (
sqrt(re*re + im*im)
); - Optionally convert magnitude to dB (log) scale (
20 * log10(magnitude)
or10 * log10(re*re + im*im)
); - Plot N/2 (log) magnitude values.
Note that while FFTW is a very good and very fast FFT it may be a little overwhelming for a beginner - it's also very expensive if you want to include it as part of a commercial product. I recommend starting with KissFFT instead.
Plotting the spectrogram
If you want to stay with C++ and be reasonable cross-platform, you might want to consider Qt as UI and either Qwt or QCustomPlot ar scientific plots widget
Links
http://sourceforge.net/projects/qwt/
http://www.qcustomplot.com/
Related Topics
How to Perform a Pairwise Binary Operation Between the Elements of Two Containers
What Strategies Have You Used to Improve Build Times on Large Projects
Global Variable "Count" Ambiguous
Should I Return an Rvalue Reference (By Std::Move'Ing)
Propagate Constness to Data Pointed by Member Variables
Is Rebasing Dlls (Or Providing an Appropriate Default Load Address) Worth the Trouble
How to Install Llvm Toolchain for Eclipse Cdt
How to Pre-Allocate Space for a File in C/C++ on Windows
C++: Nested Template Classes Error "Explicit Specialization in Non-Namespace Scope"
How to Iterate Through a List of Objects in C++
Is C++ Considered Weakly Typed? Why
Why am I Not Provided with a Default Copy Constructor from a Volatile
Properties File Library for C (Or C++)
What Is Difference Between Const and Non Const Key
Understand Op Registration and Kernel Linking in Tensorflow
Are There Any Issues with Allocating Memory Within Constructor Initialization Lists