The band index was incorrectly calculated using pointer arithmetic on a local parameter address, which is meaningless. Now uses the band index passed as a parameter instead.
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "IAudioEffect.h"
|
|
#include <vector>
|
|
|
|
namespace XCEngine {
|
|
namespace Audio {
|
|
|
|
class Equalizer : public IAudioEffect {
|
|
public:
|
|
Equalizer();
|
|
~Equalizer() override;
|
|
|
|
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels) override;
|
|
|
|
void SetBandCount(uint32 count);
|
|
uint32 GetBandCount() const { return m_bandCount; }
|
|
|
|
void SetBandFrequency(uint32 band, float frequency);
|
|
float GetBandFrequency(uint32 band) const;
|
|
|
|
void SetBandGain(uint32 band, float gainDb);
|
|
float GetBandGain(uint32 band) const;
|
|
|
|
void SetBandQ(uint32 band, float q);
|
|
float GetBandQ(uint32 band) const;
|
|
|
|
void SetEnabled(bool enabled) override;
|
|
bool IsEnabled() const override { return m_enabled; }
|
|
|
|
void SetWetMix(float wetMix) override;
|
|
float GetWetMix() const override { return m_wetMix; }
|
|
|
|
private:
|
|
void ProcessBand(float* buffer, uint32 sampleCount, uint32 channel, uint32 band);
|
|
void ComputeCoefficients(uint32 band, float frequency, float q, float gainDb);
|
|
|
|
private:
|
|
uint32 m_bandCount = 4;
|
|
std::vector<float> m_frequencies;
|
|
std::vector<float> m_gains;
|
|
std::vector<float> m_qs;
|
|
std::vector<float> m_a0;
|
|
std::vector<float> m_a1;
|
|
std::vector<float> m_a2;
|
|
std::vector<float> m_b1;
|
|
std::vector<float> m_b2;
|
|
|
|
struct BandState {
|
|
float x1 = 0.0f;
|
|
float x2 = 0.0f;
|
|
float y1 = 0.0f;
|
|
float y2 = 0.0f;
|
|
};
|
|
|
|
std::vector<BandState> m_bandStates;
|
|
|
|
float m_wetMix = 1.0f;
|
|
bool m_enabled = true;
|
|
|
|
uint32 m_sampleRate = 48000;
|
|
};
|
|
|
|
} // namespace Audio
|
|
} // namespace XCEngine
|