DEV Community

孤高游侠
孤高游侠

Posted on

Algorithm for Normalizing Current Data Using Historical Data to Eliminate Sound Noise

When developing a music playback software, I chose to use an IIR filter to implement the audio equalizer functionality, as it is simpler for me to develop compared to other options. However, when adjusting the sound effects to extreme settings—such as having a very high gain for one frequency while keeping others low—it often produces noise. Even when testing other similar software (like Winamp), I found that this problem cannot be completely avoided.

After researching, I discovered two common handling methods. The first is to clip any data exceeding an absolute value of 1 to 1, but this only partially reduces noise and does not eliminate it entirely. The second method is to normalize based on the absolute maximum value of the current data group, but this can cause sudden changes in volume during playback, impacting user experience.

Therefore, I propose an improved solution: introduce a global absolute maximum value (denoted as α), with an initial value set to 1. Each time I process a group of audio data, I will first obtain the absolute maximum value of that group (denoted as β), and then assign the larger value between α and β to α, using this α value to normalize the audio data. If the user switches songs or readjusts the equalizer, α will be reset to 1. This approach can avoid the drawbacks of the previous methods, but the side effect is that the overall volume of the song may be slightly reduced, while switching to other songs may result in the volume returning to normal (with a very low probability). Nevertheless, from a user experience perspective, I think this remains the best solution available.

Top comments (0)