This personal project is a Digital Audio Equaliser written purely using C++ STL (no external libraries) for processing audio signals. The equaliser reads in a .wav audio file and allows users to apply various gains to 5 frequency bands (sub-bass, bass, midrange, upper midrange, treble). It can also process stereo audio and save the result into a .wav file.
Note: I could have used any of the many good libraries out there, which are possibly even more efficient in terms of implementation than my code, or I could have written it all in Python. But I chose to write it all from scratch in C++ to have full control over the implementation details and to gain a better understanding of signal processing and C++ STL.
The equaliser uses digital IIR filters that are logarithmically spaced to align with the sensitivity of human hearing, ensuring a natural and intuitive audio adjustment experience. These filters were first designed and tested using MATLAB to allow for precise tuning of filter coefficients before implementing them in C++.
As a prototype, I first designed a real-time equaliser in MATLAB before implementing it from scratch in C++. In MATLAB, the gain adjustment dynamically updates the filter parameters, directly influencing the time-domain signal. These adjustments span a wide range of gain levels, from subtle to significant, which can be observed in the time graph. To ensure smooth processing, a sliding window buffer is used to handle real-time audio data, continuously updating the signal as the sliders are adjusted. This buffer allows for efficient management of the audio stream, ensuring that the filter coefficients are recalculated in real-time. Updates to the frequency response and spectrogram occur in real-time, with minimal latency, providing seamless transitions and a smooth audio experience as the frequency spectrum is adjusted.
The C++ equaliser begins by reading a .wav file and parsing its header to extract the metadata, including file size, sampling frequency, bit depth, and channel information. The implementation supports .wav files with any sampling frequency and can handle both mono and stereo audio formats. This process involves manually decoding the WAV file format's RIFF header structure. The raw audio data is then read into memory for processing.
Users can specify gain adjustments for any of the five predefined frequency bands (sub-bass, bass, midrange, upper midrange, treble). The system applies zero-phase filtering to each band by performing forward and reverse digital filtering, ensuring no phase distortion. This filtering and gain adjustment are performed independently for each channel in stereo files. After processing, the modified audio data is recombined and can be saved back to a .wav file, preserving the original format and metadata.
Additionally, users can apply dynamic range compression to control the audio signal's amplitude. This allows for precise adjustments to the threshold, which determines the level at which compression starts, the compression ratio, which defines the amount of reduction applied once the signal exceeds the threshold, and the make-up gain, which compensates for any volume loss caused by compression.
The C++ code is in my GitHub. However, if you would like access to the MATLAB real-time equaliser source code, please feel free to contact me.