mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-08 02:29:40 +08:00
Fix SpectrumExtend
This commit is contained in:
parent
6550d6e58b
commit
3edf47a26d
@ -3,22 +3,22 @@
|
|||||||
|
|
||||||
static const float SPECTRUM_HARMONICS[10] = {
|
static const float SPECTRUM_HARMONICS[10] = {
|
||||||
0.02f,
|
0.02f,
|
||||||
0.f,
|
0.0f,
|
||||||
0.02f,
|
0.02f,
|
||||||
0.f,
|
0.0f,
|
||||||
0.02f,
|
0.02f,
|
||||||
0.f,
|
0.0f,
|
||||||
0.02f,
|
0.02f,
|
||||||
0.f,
|
0.0f,
|
||||||
0.02f,
|
0.02f,
|
||||||
0.f,
|
0.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
SpectrumExtend::SpectrumExtend() {
|
SpectrumExtend::SpectrumExtend() {
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
this->referenceFreq = 7600;
|
this->referenceFreq = 7600;
|
||||||
this->enabled = false;
|
this->enabled = false;
|
||||||
this->exciter = 0.f;
|
this->exciter = 0.0;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,15 +27,20 @@ SpectrumExtend::~SpectrumExtend() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumExtend::Process(float *samples, uint32_t size) {
|
void SpectrumExtend::Process(float *samples, uint32_t size) {
|
||||||
if (this->enabled) {
|
if (!this->enabled) return;
|
||||||
for (uint32_t i = 0; i < size * 2; i++) {
|
|
||||||
float sample = samples[i];
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
int index = i % 2;
|
double tmp;
|
||||||
float tmp = this->highpass[index].ProcessSample(sample);
|
|
||||||
tmp = this->harmonics[index].Process(tmp);
|
tmp = this->highpass[0].ProcessSample(samples[i]);
|
||||||
tmp = this->lowpass[index].ProcessSample(tmp * this->exciter);
|
tmp = this->harmonics[0].Process(tmp);
|
||||||
samples[i] = samples[i] + tmp;
|
tmp = this->lowpass[0].ProcessSample(tmp * this->exciter);
|
||||||
}
|
samples[i] = samples[i] + (float) tmp;
|
||||||
|
|
||||||
|
tmp = this->highpass[1].ProcessSample(samples[i + 1]);
|
||||||
|
tmp = this->harmonics[1].Process(tmp);
|
||||||
|
tmp = this->lowpass[1].ProcessSample(tmp * this->exciter);
|
||||||
|
samples[i + 1] = samples[i + 1] + (float) tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,10 +50,10 @@ void SpectrumExtend::Reset() {
|
|||||||
this->highpass[1].RefreshFilter(MultiBiquad::FilterType::HIGH_PASS, 0.0, (float) this->referenceFreq, this->samplingRate,
|
this->highpass[1].RefreshFilter(MultiBiquad::FilterType::HIGH_PASS, 0.0, (float) this->referenceFreq, this->samplingRate,
|
||||||
0.717, false);
|
0.717, false);
|
||||||
|
|
||||||
this->lowpass[0].RefreshFilter(MultiBiquad::FilterType::LOW_PASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
|
this->lowpass[0].RefreshFilter(MultiBiquad::FilterType::LOW_PASS, 0.0, (float) this->samplingRate / 2.0f - 2000.0f,
|
||||||
this->referenceFreq, 0.717, false);
|
this->samplingRate, 0.717, false);
|
||||||
this->lowpass[1].RefreshFilter(MultiBiquad::FilterType::LOW_PASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
|
this->lowpass[1].RefreshFilter(MultiBiquad::FilterType::LOW_PASS, 0.0, (float) this->samplingRate / 2.0f - 2000.0f,
|
||||||
this->referenceFreq, 0.717, false);
|
this->samplingRate, 0.717, false);
|
||||||
|
|
||||||
this->harmonics[0].Reset();
|
this->harmonics[0].Reset();
|
||||||
this->harmonics[1].Reset();
|
this->harmonics[1].Reset();
|
||||||
@ -58,8 +63,13 @@ void SpectrumExtend::Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumExtend::SetEnable(bool enable) {
|
void SpectrumExtend::SetEnable(bool enable) {
|
||||||
|
if (this->enabled != enable) {
|
||||||
|
if (enable) {
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
this->enabled = enable;
|
this->enabled = enable;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SpectrumExtend::SetExciter(float value) {
|
void SpectrumExtend::SetExciter(float value) {
|
||||||
this->exciter = value;
|
this->exciter = value;
|
||||||
@ -74,9 +84,11 @@ void SpectrumExtend::SetReferenceFrequency(uint32_t freq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumExtend::SetSamplingRate(uint32_t samplingRate) {
|
void SpectrumExtend::SetSamplingRate(uint32_t samplingRate) {
|
||||||
|
if (this->samplingRate != samplingRate) {
|
||||||
this->samplingRate = samplingRate;
|
this->samplingRate = samplingRate;
|
||||||
if (this->samplingRate / 2 - 100 < this->referenceFreq) {
|
if (samplingRate / 2 - 100 < this->referenceFreq) {
|
||||||
this->referenceFreq = this->samplingRate / 2 - 100;
|
this->referenceFreq = samplingRate / 2 - 100;
|
||||||
}
|
}
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -16,6 +16,7 @@ public:
|
|||||||
void SetReferenceFrequency(uint32_t freq);
|
void SetReferenceFrequency(uint32_t freq);
|
||||||
void SetSamplingRate(uint32_t samplingRate);
|
void SetSamplingRate(uint32_t samplingRate);
|
||||||
|
|
||||||
|
private:
|
||||||
MultiBiquad highpass[2];
|
MultiBiquad highpass[2];
|
||||||
MultiBiquad lowpass[2];
|
MultiBiquad lowpass[2];
|
||||||
Harmonic harmonics[2];
|
Harmonic harmonics[2];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user