This commit is contained in:
Iscle 2022-09-13 02:16:31 +02:00
parent 3b905032eb
commit fcd7da0f13
4 changed files with 51 additions and 37 deletions

View File

@ -16,7 +16,7 @@ static float ANALOGX_HARMONICS[10] = {
}; };
AnalogX::AnalogX() { AnalogX::AnalogX() {
this->samplerate = DEFAULT_SAMPLERATE; this->samplingRate = DEFAULT_SAMPLERATE;
this->processingModel = 0; this->processingModel = 0;
this->enabled = false; this->enabled = false;
Reset(); Reset();
@ -32,7 +32,7 @@ void AnalogX::Process(float *samples, uint32_t size) {
int index = i % 2; int index = i % 2;
float tmp = this->highpass[index].ProcessSample(sample); float tmp = this->highpass[index].ProcessSample(sample);
tmp = this->harmonics[index].Process(tmp); tmp = this->harmonic[index].Process(tmp);
tmp = this->lowpass[index].ProcessSample(sample + tmp * this->gain); tmp = this->lowpass[index].ProcessSample(sample + tmp * this->gain);
tmp = this->peak->ProcessSample(tmp * 0.8f); tmp = this->peak->ProcessSample(tmp * 0.8f);
@ -40,51 +40,70 @@ void AnalogX::Process(float *samples, uint32_t size) {
samples[i] = tmp; samples[i] = tmp;
} }
if (this->freqRange < this->samplerate / 4) { if (this->freqRange < this->samplingRate / 4) {
this->freqRange += size; this->freqRange += size;
memset(samples, 0, 2 * size * sizeof(float)); memset(samples, 0, 2 * size * sizeof(float));
} }
} }
void AnalogX::Reset() { void AnalogX::Reset() {
this->highpass[0].RefreshFilter(FilterType::HIGHPASS, 0.f, 240.f, (float) this->samplerate, 0.717, false); for (auto &highpass : this->highpass) {
this->highpass[1].RefreshFilter(FilterType::HIGHPASS, 0.f, 240.f, (float) this->samplerate, 0.717, false); highpass.RefreshFilter(FilterType::HIGHPASS, 0.0f, 240.0f, (float) this->samplingRate, 0.717f, false);
}
this->peak[0].RefreshFilter(FilterType::PEAK, 0.58f, 633.f, (float) this->samplerate, 6.28, true); for (auto &peak : this->peak) {
this->peak[1].RefreshFilter(FilterType::PEAK, 0.58f, 633.f, (float) this->samplerate, 6.28, true); peak.RefreshFilter(FilterType::PEAK, 0.58f, 633.0f, (float) this->samplingRate, 6.28f, true);
}
this->harmonics[0].Reset(); for (auto &harmonic : this->harmonic) {
this->harmonics[1].Reset(); harmonic.Reset();
}
if (this->processingModel == 0) { if (this->processingModel == 0) {
this->harmonics[0].SetHarmonics(ANALOGX_HARMONICS); for (auto &harmonic : this->harmonic) {
this->harmonics[1].SetHarmonics(ANALOGX_HARMONICS); harmonic.SetHarmonics(ANALOGX_HARMONICS);
}
this->gain = 0.6f; this->gain = 0.6f;
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, 18233.f, (float) this->samplerate, 0.717f, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, 18233.f, (float) this->samplerate, 0.717f, false); for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 19650.0f, (float) this->samplingRate, 0.717f, false);
}
} else if (this->processingModel == 1) { } else if (this->processingModel == 1) {
this->harmonics[0].SetHarmonics(ANALOGX_HARMONICS); for (auto &harmonic : this->harmonic) {
this->harmonics[1].SetHarmonics(ANALOGX_HARMONICS); harmonic.SetHarmonics(ANALOGX_HARMONICS);
}
this->gain = 1.2f; this->gain = 1.2f;
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, 19650.f, (float) this->samplerate, 0.717f, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, 19650.f, (float) this->samplerate, 0.717f, false); for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 18233.0f, (float) this->samplingRate, 0.717f, false);
}
} else if (this->processingModel == 2) { } else if (this->processingModel == 2) {
this->harmonics[0].SetHarmonics(ANALOGX_HARMONICS); for (auto &harmonic : this->harmonic) {
this->harmonics[1].SetHarmonics(ANALOGX_HARMONICS); harmonic.SetHarmonics(ANALOGX_HARMONICS);
}
this->gain = 2.4f; this->gain = 2.4f;
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, 16307.f, (float) this->samplerate, 0.717f, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, 16307.f, (float) this->samplerate, 0.717f, false); for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 16307.0f, (float) this->samplingRate, 0.717f, false);
}
} }
this->freqRange = 0; this->freqRange = 0;
} }
void AnalogX::SetProcessingModel(int model) { void AnalogX::SetProcessingModel(int processingModel) {
this->processingModel = model; if (this->processingModel != processingModel) {
Reset(); this->processingModel = processingModel;
Reset();
}
} }
void AnalogX::SetSamplingRate(uint32_t samplerate) { void AnalogX::SetSamplingRate(uint32_t samplingRate) {
this->samplerate = samplerate; if (this->samplingRate != samplingRate) {
Reset(); this->samplingRate = samplingRate;
Reset();
}
} }

View File

@ -11,18 +11,18 @@ public:
void Process(float *samples, uint32_t size); void Process(float *samples, uint32_t size);
void Reset(); void Reset();
void SetProcessingModel(int model); void SetProcessingModel(int processingModel);
void SetSamplingRate(uint32_t samplerate); void SetSamplingRate(uint32_t samplingRate);
MultiBiquad highpass[2]; MultiBiquad highpass[2];
Harmonic harmonics[2]; Harmonic harmonic[2];
MultiBiquad lowpass[2]; MultiBiquad lowpass[2];
MultiBiquad peak[2]; MultiBiquad peak[2];
float gain; float gain;
uint32_t freqRange; uint32_t freqRange;
int processingModel; int processingModel;
uint32_t samplerate; uint32_t samplingRate;
bool enabled; bool enabled;
}; };

View File

@ -19,6 +19,7 @@ public:
void ScaleFrames(float scale); void ScaleFrames(float scale);
void SetBufferOffset(uint32_t offset); void SetBufferOffset(uint32_t offset);
private:
float *buffer; float *buffer;
uint32_t length; uint32_t length;
uint32_t offset; uint32_t offset;

View File

@ -1,10 +1,5 @@
//
// Created by mart on 7/27/21.
//
#pragma once #pragma once
enum FilterType { enum FilterType {
LOWPASS, LOWPASS,
HIGHPASS, HIGHPASS,
@ -16,7 +11,6 @@ enum FilterType {
HIGHSHELF HIGHSHELF
}; };
class MultiBiquad { class MultiBiquad {
public: public:
MultiBiquad(); MultiBiquad();