Fix equalizer peak updates (#7038)

Fix the peak update of the LMMS equalizer which accidentally used the same sample twice.

Simplify the `gain` method by removing repeated deferences which made the code hard to read.

Use `std::max` to update the peak values to the maximum of the buffer.
This commit is contained in:
Michael Gregorius
2023-12-31 15:52:24 +01:00
committed by GitHub
parent 36cb0ed7ca
commit 1868fa170a

View File

@@ -28,6 +28,9 @@
#include "EqControls.h"
#include "EqFilter.h"
#include <algorithm>
namespace lmms
{
@@ -42,23 +45,20 @@ public:
{
return &m_eqControls;
}
inline void gain( sampleFrame * buf, const fpp_t frames, float scale, sampleFrame * peak )
inline void gain( sampleFrame * buf, const fpp_t frames, float scale, sampleFrame * peak )
{
peak[0][0] = 0.0f; peak[0][1] = 0.0f;
for( fpp_t f = 0; f < frames; ++f )
{
buf[f][0] *= scale;
buf[f][1] *= scale;
auto & sf = buf[f];
if( fabs( buf[f][0] ) > peak[0][0] )
{
peak[0][0] = fabs( buf[f][0] );
}
if( fabs( buf[f][1] ) > peak[0][1] )
{
peak[0][1] = fabs( buf[f][0] );
}
// Apply gain to sample frame
sf[0] *= scale;
sf[1] *= scale;
// Update peaks
peak[0][0] = std::max(peak[0][0], (float)fabs(sf[0]));
peak[0][1] = std::max(peak[0][1], (float)fabs(sf[1]));
}
}