This commit is contained in:
Iscle 2022-09-23 04:15:43 +02:00
parent 64e356c7b7
commit e46f205779
47 changed files with 449 additions and 277 deletions

View File

@ -45,6 +45,7 @@ set(FILES
# Utils
src/cpp/viper/utils/AdaptiveBuffer.cpp
src/cpp/viper/utils/Biquad.cpp
src/cpp/viper/utils/CAllpassFilter.cpp
src/cpp/viper/utils/CCombFilter.cpp
src/cpp/viper/utils/CRevModel.cpp
@ -52,13 +53,13 @@ set(FILES
src/cpp/viper/utils/DepthSurround.cpp
src/cpp/viper/utils/DynamicBass.cpp
src/cpp/viper/utils/FIR.cpp
src/cpp/viper/utils/Biquad.cpp
src/cpp/viper/utils/Harmonic.cpp
src/cpp/viper/utils/HiFi.cpp
src/cpp/viper/utils/HighShelf.cpp
src/cpp/viper/utils/IIR_1st.cpp
src/cpp/viper/utils/IIR_NOrder_BW_BP.cpp
src/cpp/viper/utils/IIR_NOrder_BW_LH.cpp
src/cpp/viper/utils/MinPhaseIIRCoeffs.cpp
src/cpp/viper/utils/MultiBiquad.cpp
src/cpp/viper/utils/NoiseSharpening.cpp
src/cpp/viper/utils/PassFilter.cpp

View File

@ -48,11 +48,11 @@ void AnalogX::Process(float *samples, uint32_t size) {
void AnalogX::Reset() {
for (auto &highpass : this->highpass) {
highpass.RefreshFilter(FilterType::HIGHPASS, 0.0f, 240.0f, (float) this->samplingRate, 0.717f, false);
highpass.RefreshFilter(MultiBiquad::FilterType::HIGHPASS, 0.0f, 240.0f, (float) this->samplingRate, 0.717f, false);
}
for (auto &peak : this->peak) {
peak.RefreshFilter(FilterType::PEAK, 0.58f, 633.0f, (float) this->samplingRate, 6.28f, true);
peak.RefreshFilter(MultiBiquad::FilterType::PEAK, 0.58f, 633.0f, (float) this->samplingRate, 6.28f, true);
}
for (auto &harmonic : this->harmonic) {
@ -67,7 +67,7 @@ void AnalogX::Reset() {
this->gain = 0.6f;
for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 19650.0f, (float) this->samplingRate, 0.717f, false);
lowpass.RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0f, 19650.0f, (float) this->samplingRate, 0.717f, false);
}
} else if (this->processingModel == 1) {
for (auto &harmonic : this->harmonic) {
@ -77,7 +77,7 @@ void AnalogX::Reset() {
this->gain = 1.2f;
for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 18233.0f, (float) this->samplingRate, 0.717f, false);
lowpass.RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0f, 18233.0f, (float) this->samplingRate, 0.717f, false);
}
} else if (this->processingModel == 2) {
for (auto &harmonic : this->harmonic) {
@ -87,7 +87,7 @@ void AnalogX::Reset() {
this->gain = 2.4f;
for (auto &lowpass : this->lowpass) {
lowpass.RefreshFilter(FilterType::LOWPASS, 0.0f, 16307.0f, (float) this->samplingRate, 0.717f, false);
lowpass.RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0f, 16307.0f, (float) this->samplingRate, 0.717f, false);
}
}

View File

@ -30,9 +30,9 @@ void Cure::SetEnable(bool enabled) {
}
}
void Cure::SetSamplingRate(uint32_t samplerate) {
this->crossfeed.SetSamplingRate(samplerate);
this->pass.SetSamplingRate(samplerate);
void Cure::SetSamplingRate(uint32_t samplingRate) {
this->crossfeed.SetSamplingRate(samplingRate);
this->pass.SetSamplingRate(samplingRate);
}
uint16_t Cure::GetCutoff() {
@ -47,7 +47,7 @@ float Cure::GetLevelDelay() {
return this->crossfeed.GetLevelDelay();
}
preset_t Cure::GetPreset() {
struct Crossfeed::Preset Cure::GetPreset() {
return this->crossfeed.GetPreset();
}
@ -59,7 +59,7 @@ void Cure::SetFeedback(float feedback) {
this->crossfeed.SetFeedback(feedback);
}
void Cure::SetPreset(preset_t preset) {
void Cure::SetPreset(struct Crossfeed::Preset preset) {
this->crossfeed.SetPreset(preset);
}

View File

@ -12,14 +12,14 @@ public:
uint16_t GetCutoff();
float GetFeedback();
float GetLevelDelay();
preset_t GetPreset();
struct Crossfeed::Preset GetPreset();
void Process(float *buffer, uint32_t size);
void Reset();
void SetCutoff(uint16_t cutoff);
void SetEnable(bool enabled);
void SetFeedback(float feedback);
void SetPreset(preset_t preset);
void SetSamplingRate(uint32_t samplerate);
void SetPreset(struct Crossfeed::Preset preset);
void SetSamplingRate(uint32_t samplingRate);
Crossfeed crossfeed;
PassFilter pass;

View File

@ -3,7 +3,7 @@
#include "../constants.h"
DiffSurround::DiffSurround() {
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->delayTime = 0.0f;
this->enabled = false;
for (auto &buffer : this->buffers) {
@ -46,7 +46,7 @@ void DiffSurround::Reset() {
buffer->Reset();
}
this->buffers[1]->PushZeros((uint32_t) (this->delayTime / 1000.0f * (float) this->samplerate));
this->buffers[1]->PushZeros((uint32_t) (this->delayTime / 1000.0f * (float) this->samplingRate));
}
void DiffSurround::SetDelayTime(float delayTime) {
@ -65,9 +65,9 @@ void DiffSurround::SetEnable(bool enabled) {
}
}
void DiffSurround::SetSamplingRate(uint32_t samplerate) {
if (this->samplerate != samplerate) {
this->samplerate = samplerate;
void DiffSurround::SetSamplingRate(uint32_t samplingRate) {
if (this->samplingRate != samplingRate) {
this->samplingRate = samplingRate;
this->Reset();
}
}

View File

@ -12,9 +12,9 @@ public:
void Reset();
void SetDelayTime(float delayTime);
void SetEnable(bool enabled);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
uint32_t samplerate;
uint32_t samplingRate;
bool enabled;
float delayTime;
WaveBuffer *buffers[2];

View File

@ -3,8 +3,8 @@
DynamicSystem::DynamicSystem() {
this->enabled = false;
this->samplerate = DEFAULT_SAMPLERATE;
this->bass.SetSamplingRate(this->samplerate);
this->samplingRate = DEFAULT_SAMPLERATE;
this->bass.SetSamplingRate(this->samplingRate);
this->bass.Reset();
}
@ -15,7 +15,7 @@ void DynamicSystem::Process(float *samples, uint32_t size) {
}
void DynamicSystem::Reset() {
this->bass.SetSamplingRate(this->samplerate);
this->bass.SetSamplingRate(this->samplingRate);
this->bass.Reset();
}
@ -44,10 +44,10 @@ void DynamicSystem::SetYCoeffs(uint32_t low, uint32_t high) {
this->bass.SetFilterYPassFrequency(low, high);
}
void DynamicSystem::SetSamplingRate(uint32_t samplerate) {
if (this->samplerate != samplerate) {
this->samplerate = samplerate;
this->bass.SetSamplingRate(samplerate);
void DynamicSystem::SetSamplingRate(uint32_t samplingRate) {
if (this->samplingRate != samplingRate) {
this->samplingRate = samplingRate;
this->bass.SetSamplingRate(samplingRate);
}
}

View File

@ -12,13 +12,13 @@ public:
void Reset();
void SetBassGain(float gain);
void SetEnable(bool enable);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
void SetSideGain(float gainX, float gainY);
void SetXCoeffs(uint32_t low, uint32_t high);
void SetYCoeffs(uint32_t low, uint32_t high);
DynamicBass bass;
uint32_t samplerate;
uint32_t samplingRate;
bool enabled;
};

View File

@ -14,7 +14,7 @@ Reverberation::Reverberation() {
this->model.SetWet(0.f);
this->model.SetDry(0.5f);
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->enabled = false;
}
@ -61,7 +61,7 @@ void Reverberation::SetWidth(float value) {
}
void Reverberation::SetSamplingRate(uint32_t value) {
this->samplerate = value;
this->samplingRate = value;
this->model.Reset();
}

View File

@ -24,7 +24,7 @@ public:
float wet;
float dry;
CRevModel model;
uint32_t samplerate;
uint32_t samplingRate;
bool enabled;
};

View File

@ -2,7 +2,7 @@
#include "../constants.h"
SpeakerCorrection::SpeakerCorrection() {
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->enabled = false;
Reset();
}
@ -24,12 +24,12 @@ void SpeakerCorrection::Reset() {
this->bandpass[0].Reset();
this->bandpass[1].Reset();
this->highpass[0].RefreshFilter(FilterType::HIGHPASS, 0.f, 80.f, (float) this->samplerate, 1.f, false);
this->highpass[1].RefreshFilter(FilterType::HIGHPASS, 0.f, 80.f, (float) this->samplerate, 1.f, false);
this->lowpass[0].SetLowPassParameter(13500.f, this->samplerate, 1.0);
this->lowpass[1].SetLowPassParameter(13500.f, this->samplerate, 1.0);
this->bandpass[0].SetBandPassParameter(420.f, this->samplerate, 3.88f);
this->bandpass[1].SetBandPassParameter(420.f, this->samplerate, 3.88f);
this->highpass[0].RefreshFilter(MultiBiquad::FilterType::HIGHPASS, 0.f, 80.f, (float) this->samplingRate, 1.f, false);
this->highpass[1].RefreshFilter(MultiBiquad::FilterType::HIGHPASS, 0.f, 80.f, (float) this->samplingRate, 1.f, false);
this->lowpass[0].SetLowPassParameter(13500.f, this->samplingRate, 1.0);
this->lowpass[1].SetLowPassParameter(13500.f, this->samplingRate, 1.0);
this->bandpass[0].SetBandPassParameter(420.f, this->samplingRate, 3.88f);
this->bandpass[1].SetBandPassParameter(420.f, this->samplingRate, 3.88f);
}
void SpeakerCorrection::SetEnable(bool enabled) {
@ -39,8 +39,8 @@ void SpeakerCorrection::SetEnable(bool enabled) {
}
}
void SpeakerCorrection::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void SpeakerCorrection::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
Reset();
}

View File

@ -12,9 +12,9 @@ public:
void Process(float *samples, uint32_t size);
void Reset();
void SetEnable(bool enabled);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
uint32_t samplerate;
uint32_t samplingRate;
bool enabled;
MultiBiquad highpass[2];
Biquad lowpass[2];

View File

@ -15,7 +15,7 @@ static float SPECTRUM_HARMONICS[10] = {
};
SpectrumExtend::SpectrumExtend() {
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->referenceFreq = 7600;
this->enabled = false;
this->exciter = 0.f;
@ -38,14 +38,14 @@ void SpectrumExtend::Process(float *samples, uint32_t size) {
}
void SpectrumExtend::Reset() {
this->highpass[0].RefreshFilter(FilterType::HIGHPASS, 0.0, (float) this->referenceFreq, (float) this->samplerate,
this->highpass[0].RefreshFilter(MultiBiquad::FilterType::HIGHPASS, 0.0, (float) this->referenceFreq, (float) this->samplingRate,
0.717, false);
this->highpass[1].RefreshFilter(FilterType::HIGHPASS, 0.0, (float) this->referenceFreq, (float) this->samplerate,
this->highpass[1].RefreshFilter(MultiBiquad::FilterType::HIGHPASS, 0.0, (float) this->referenceFreq, (float) this->samplingRate,
0.717, false);
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
this->lowpass[0].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
(float) this->referenceFreq, 0.717, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
this->lowpass[1].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, (float) this->referenceFreq / 2.f - 2000.f,
(float) this->referenceFreq, 0.717, false);
this->harmonics[0].Reset();
@ -64,17 +64,17 @@ void SpectrumExtend::SetExciter(float value) {
}
void SpectrumExtend::SetReferenceFrequency(uint32_t freq) {
if (this->samplerate / 2 - 100 < freq) {
freq = this->samplerate / 2 - 100;
if (this->samplingRate / 2 - 100 < freq) {
freq = this->samplingRate / 2 - 100;
}
this->referenceFreq = freq;
Reset();
}
void SpectrumExtend::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
if (this->samplerate / 2 - 100 < this->referenceFreq) {
this->referenceFreq = this->samplerate / 2 - 100;
void SpectrumExtend::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
if (this->samplingRate / 2 - 100 < this->referenceFreq) {
this->referenceFreq = this->samplingRate / 2 - 100;
}
Reset();
}

View File

@ -14,13 +14,13 @@ public:
void SetEnable(bool enable);
void SetExciter(float value);
void SetReferenceFrequency(uint32_t freq);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
MultiBiquad highpass[2];
MultiBiquad lowpass[2];
Harmonic harmonics[2];
bool enabled;
uint32_t samplerate;
uint32_t samplingRate;
uint32_t referenceFreq;
float exciter;
};

View File

@ -5,7 +5,7 @@ VHE::VHE() {
enabled = false;
effectLevel = 0;
convSize = 0;
samplerate = DEFAULT_SAMPLERATE;
samplingRate = DEFAULT_SAMPLERATE;
bufA = new WaveBuffer(2, 0x1000);
bufB = new WaveBuffer(2, 0x1000);
@ -55,6 +55,6 @@ void VHE::SetEnable(bool enabled) {
}
void VHE::SetSamplingRate(uint32_t srate) {
this->samplerate = srate;
this->samplingRate = srate;
Reset();
}

View File

@ -18,7 +18,7 @@ public:
PConvSingle_F32 convLeft, convRight;
WaveBuffer *bufA, *bufB;
uint32_t samplerate;
uint32_t samplingRate;
bool enabled;
int effectLevel;
int convSize;

View File

@ -3,9 +3,9 @@
CAllpassFilter::CAllpassFilter() {
this->buffer = nullptr;
this->bufidx = 0;
this->bufsize = 0;
this->feedback = 0;
this->feedback = 0.0;
this->bufferIndex = 0;
this->bufferSize = 0;
}
float CAllpassFilter::GetFeedback() {
@ -13,22 +13,23 @@ float CAllpassFilter::GetFeedback() {
}
void CAllpassFilter::Mute() {
memset(this->buffer, 0, this->bufsize * sizeof(float));
memset(this->buffer, 0, this->bufferSize * sizeof(float));
}
float CAllpassFilter::Process(float sample) {
float outSample = this->buffer[this->bufidx];
this->buffer[this->bufidx] = sample + (outSample * this->feedback);
this->bufidx++;
if (this->bufidx >= this->bufsize) {
this->bufidx = 0;
float outSample = this->buffer[this->bufferIndex];
this->buffer[this->bufferIndex] = sample + outSample * this->feedback;
this->bufferIndex++;
if (this->bufferIndex >= this->bufferSize) {
this->bufferIndex = 0;
}
return outSample - sample;
}
void CAllpassFilter::SetBuffer(float *buffer, uint32_t size) {
this->buffer = buffer;
this->bufsize = size;
this->bufferSize = size;
this->bufferIndex = 0;
}
void CAllpassFilter::SetFeedback(float feedback) {

View File

@ -13,8 +13,8 @@ public:
void SetFeedback(float feedback);
private:
float *buffer;
uint32_t bufidx;
uint32_t bufsize;
float feedback;
float *buffer;
uint32_t bufferSize;
uint32_t bufferIndex;
};

View File

@ -2,11 +2,11 @@
#include <cstring>
CCombFilter::CCombFilter() {
this->feedback = 0.0;
this->buffer = nullptr;
this->size = 0;
this->bufidx = 0;
this->feedback = 0;
this->filterstore = 0;
this->bufferSize = 0;
this->bufferIndex = 0;
this->filterStore = 0.0;
this->damp = 0;
this->damp2 = 0;
}
@ -20,23 +20,24 @@ float CCombFilter::GetFeedback() {
}
void CCombFilter::Mute() {
memset(this->buffer, 0, this->size * sizeof(float));
memset(this->buffer, 0, this->bufferSize * sizeof(float));
}
float CCombFilter::Process(float sample) {
float output = this->buffer[this->bufidx];
this->filterstore = output * this->damp2 + this->filterstore * this->damp;
this->buffer[this->bufidx] = sample + this->filterstore * this->feedback;
this->bufidx++;
if (this->bufidx >= this->size) {
this->bufidx = 0;
float output = this->buffer[this->bufferIndex];
this->filterStore = output * this->damp2 + this->filterStore * this->damp;
this->buffer[this->bufferIndex] = sample + this->filterStore * this->feedback;
this->bufferIndex++;
if (this->bufferIndex >= this->bufferSize) {
this->bufferIndex = 0;
}
return output;
}
void CCombFilter::SetBuffer(float *buffer, uint32_t size) {
this->buffer = buffer;
this->size = size;
this->bufferSize = size;
this->bufferIndex = 0;
}
void CCombFilter::SetDamp(float damp) {

View File

@ -16,12 +16,12 @@ public:
private:
float feedback;
float filterstore;
float filterStore;
float damp;
float damp2;
float *buffer;
uint32_t size;
uint32_t bufidx;
uint32_t bufferSize;
uint32_t bufferIndex;
};

View File

@ -71,18 +71,18 @@ uint16_t Crossfeed::GetCutoff() {
}
float Crossfeed::GetFeedback() {
return (float) this->preset.feedback / 10.f;
return (float) this->preset.feedback / 10.0f;
}
float Crossfeed::GetLevelDelay() {
if (this->preset.cutoff <= 1800) {
return (18700.f / (float) this->preset.cutoff) * 10.f;
return (float) ((18700.0 / (double) this->preset.cutoff) * 10.0);
} else {
return 0.f;
return 0.0;
}
}
preset_t Crossfeed::GetPreset() {
struct Crossfeed::Preset Crossfeed::GetPreset() {
return this->preset;
}
@ -92,16 +92,16 @@ void Crossfeed::SetCutoff(uint16_t cutoff) {
}
void Crossfeed::SetFeedback(float feedback) {
this->preset.feedback = (uint16_t) (feedback * 10);
this->preset.feedback = (uint16_t) (feedback * 10.0f);
Reset();
}
void Crossfeed::SetPreset(preset_t preset) {
void Crossfeed::SetPreset(struct Crossfeed::Preset preset) {
this->preset = preset;
Reset();
}
void Crossfeed::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void Crossfeed::SetSamplingRate(uint32_t samplingRate) {
this->samplerate = samplingRate;
Reset();
}

View File

@ -1,15 +1,14 @@
#pragma once
#include <cstdint>
typedef struct {
uint16_t cutoff;
uint16_t feedback;
} preset_t;
class Crossfeed {
public:
struct Preset {
uint16_t cutoff;
uint16_t feedback;
};
Crossfeed();
void Reset();
@ -24,15 +23,15 @@ public:
float GetLevelDelay();
preset_t GetPreset();
struct Preset GetPreset();
void SetCutoff(uint16_t cutoff);
void SetFeedback(float feedback);
void SetPreset(preset_t preset);
void SetPreset(struct Preset preset);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
uint32_t samplerate;
float a0_lo, b1_lo;
@ -41,5 +40,5 @@ public:
struct {
float asis[2], lo[2], hi[2];
} lfs;
preset_t preset;
struct Preset preset;
};

View File

@ -1,5 +1,4 @@
#include "DepthSurround.h"
#include <cstring>
#include <cmath>
#include "../constants.h"
@ -22,15 +21,15 @@ void DepthSurround::Process(float *samples, uint32_t size) {
float sampleLeft = samples[2 * i];
float sampleRight = samples[2 * i + 1];
this->prev[0] = this->gain * this->delay[0].ProcessSample(sampleLeft + this->prev[1]);
this->prev[1] = this->gain * this->delay[1].ProcessSample(sampleRight + this->prev[0]);
this->prev[0] = this->gain * this->timeConstDelay[0].ProcessSample(sampleLeft + this->prev[1]);
this->prev[1] = this->gain * this->timeConstDelay[1].ProcessSample(sampleRight + this->prev[0]);
float l = this->prev[0] + sampleLeft;
float r = this->prev[1] + sampleRight;
float diff = (l - r) / 2.f;
float avg = (l + r) / 2.f;
float avgOut = this->highpass.ProcessSample(diff);
float avgOut = (float) this->highpass.ProcessSample(diff);
samples[2 * i] = avg + (diff - avgOut);
samples[2 * i + 1] = avg - (diff - avgOut);
}
@ -39,15 +38,15 @@ void DepthSurround::Process(float *samples, uint32_t size) {
float sampleLeft = samples[2 * i];
float sampleRight = samples[2 * i + 1];
this->prev[0] = this->gain * this->delay[0].ProcessSample(sampleLeft + this->prev[1]);
this->prev[1] = -this->gain * this->delay[1].ProcessSample(sampleRight + this->prev[0]);
this->prev[0] = this->gain * this->timeConstDelay[0].ProcessSample(sampleLeft + this->prev[1]);
this->prev[1] = -this->gain * this->timeConstDelay[1].ProcessSample(sampleRight + this->prev[0]);
float l = this->prev[0] + sampleLeft;
float r = this->prev[1] + sampleRight;
float diff = (l - r) / 2.f;
float avg = (l + r) / 2.f;
float avgOut = this->highpass.ProcessSample(diff);
float avgOut = (float) this->highpass.ProcessSample(diff);
samples[2 * i] = avg + (diff - avgOut);
samples[2 * i + 1] = avg - (diff - avgOut);
}
@ -59,20 +58,20 @@ void DepthSurround::RefreshStrength(short strength) {
this->strengthAtLeast500 = strength >= 500;
this->enabled = strength != 0;
if (strength != 0) {
float gain = powf(10.0f, ((strength / 1000.0f) * 10.0f - 15.0f) / 20.0f);
if (fabsf(gain) > 1.0f) {
gain = 1.0f;
float gain = (float) pow(10.0, ((strength / 1000.0) * 10.0 - 15.0) / 20.0);
if (gain > 1.0) {
gain = 1.0;
}
this->gain = gain;
this->gain = (float) gain;
} else {
this->gain = 0;
this->gain = 0.0;
}
}
void DepthSurround::SetSamplingRate(uint32_t samplerate) {
this->delay[0].SetParameters(samplerate, 0.02);
this->delay[1].SetParameters(samplerate, 0.014);
this->highpass.SetHighPassParameter(800.0f, samplerate, -11.0f, 0.72f, 0);
void DepthSurround::SetSamplingRate(uint32_t samplingRate) {
this->timeConstDelay[0].SetParameters(samplingRate, 0.02);
this->timeConstDelay[1].SetParameters(samplingRate, 0.014);
this->highpass.SetHighPassParameter(800.0f, samplingRate, -11.0f, 0.72f, 0.0);
for (auto &prev : this->prev) {
prev = 0.0f;
}

View File

@ -4,24 +4,21 @@
#include "Biquad.h"
#include "TimeConstDelay.h"
class DepthSurround {
public:
DepthSurround();
void Process(float *samples, uint32_t size);
void RefreshStrength(short strength);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
void SetStrength(short strength);
private:
short strength;
bool enabled;
bool strengthAtLeast500;
uint32_t gain;
float gain;
float prev[2];
TimeConstDelay delay[2];
TimeConstDelay timeConstDelay[2];
Biquad highpass;
};

View File

@ -10,17 +10,11 @@ DynamicBass::DynamicBass() {
this->lowFreqX = 120;
this->highFreqX = 80;
this->lowFreqY = 40;
this->highFreqY = (float) this->samplerate / 4.f;
this->highFreqY = (uint32_t) ((float) this->samplingRate / 4.0f);
this->filterX.SetPassFilter(this->lowFreqX, this->highFreqX);
this->filterY.SetPassFilter(this->lowFreqY, this->highFreqY);
this->lowPass.SetLowPassParameter(55.f, this->samplerate, this->qPeak / 666.f + 0.5f);
}
void DynamicBass::Reset() {
this->filterX.Reset();
this->filterY.Reset();
this->lowPass.SetLowPassParameter(55.f, this->samplerate, this->qPeak / 666.f + 0.5f);
this->lowPass.SetLowPassParameter(55.f, this->samplingRate, this->qPeak / 666.f + 0.5f);
}
void DynamicBass::FilterSamples(float *samples, uint32_t size) {
@ -28,7 +22,7 @@ void DynamicBass::FilterSamples(float *samples, uint32_t size) {
for (int i = 0; i < size; i++) {
float left = samples[2 * i];
float right = samples[2 * i + 1];
float avg = this->lowPass.ProcessSample(left + right);
float avg = (float) this->lowPass.ProcessSample(left + right);
samples[2 * i] = left + avg;
samples[2 * i + 1] = right + avg;
}
@ -47,18 +41,22 @@ void DynamicBass::FilterSamples(float *samples, uint32_t size) {
}
}
void DynamicBass::SetBassGain(float gain) {
this->bassGain = gain;
this->qPeak = (gain - 1.f) / 20.f * 1600.f;
if (this->qPeak > 1600.f) {
this->qPeak = 1600.f;
}
this->lowPass.SetLowPassParameter(55.f, this->samplerate, this->qPeak / 666.f + 0.5f);
void DynamicBass::Reset() {
this->filterX.Reset();
this->filterY.Reset();
this->lowPass.SetLowPassParameter(55.0, this->samplingRate, this->qPeak / 666.0f + 0.5f);
}
void DynamicBass::SetSideGain(float gainX, float gainY) {
this->sideGainX = gainX;
this->sideGainY = gainY;
void DynamicBass::SetBassGain(float gain) {
this->bassGain = gain;
double x = ((gain - 1.0) / 20.0) * 1600.0;
if (x > 1600.0) {
x = 1600.0;
}
this->qPeak = (float) x;
this->lowPass.SetLowPassParameter(55.0, this->samplingRate, this->qPeak / 666.0f + 0.5f);
}
void DynamicBass::SetFilterXPassFrequency(uint32_t low, uint32_t high) {
@ -66,8 +64,8 @@ void DynamicBass::SetFilterXPassFrequency(uint32_t low, uint32_t high) {
this->highFreqX = high;
this->filterX.SetPassFilter(low, high);
this->filterX.SetSamplingRate(this->samplerate);
this->lowPass.SetLowPassParameter(55.f, this->samplerate, this->qPeak / 666.f + 0.5f);
this->filterX.SetSamplingRate(this->samplingRate);
this->lowPass.SetLowPassParameter(55.0, this->samplingRate, this->qPeak / 666.0f + 0.5f);
}
void DynamicBass::SetFilterYPassFrequency(uint32_t low, uint32_t high) {
@ -75,13 +73,18 @@ void DynamicBass::SetFilterYPassFrequency(uint32_t low, uint32_t high) {
this->highFreqY = high;
this->filterY.SetPassFilter(low, high);
this->filterY.SetSamplingRate(this->samplerate);
this->lowPass.SetLowPassParameter(55.f, this->samplerate, this->qPeak / 666.f + 0.5f);
this->filterY.SetSamplingRate(this->samplingRate);
this->lowPass.SetLowPassParameter(55.0, this->samplingRate, this->qPeak / 666.0f + 0.5f);
}
void DynamicBass::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
this->filterX.SetSamplingRate(samplerate);
this->filterY.SetSamplingRate(samplerate);
this->lowPass.SetLowPassParameter(55.f, samplerate, this->qPeak / 666.f + 0.5f);
void DynamicBass::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
this->filterX.SetSamplingRate(samplingRate);
this->filterY.SetSamplingRate(samplingRate);
this->lowPass.SetLowPassParameter(55.0, samplingRate, this->qPeak / 666.0f + 0.5f);
}
void DynamicBass::SetSideGain(float gainX, float gainY) {
this->sideGainX = gainX;
this->sideGainY = gainY;
}

View File

@ -18,13 +18,13 @@ public:
void SetFilterYPassFrequency(uint32_t low, uint32_t high);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
void SetSideGain(float gainX, float gainY);
uint32_t lowFreqX, highFreqX;
uint32_t lowFreqY, highFreqY;
uint32_t samplerate;
uint32_t samplingRate;
float qPeak;
float bassGain;
float sideGainX, sideGainY;

View File

@ -3,7 +3,7 @@
HiFi::HiFi() {
this->gain = 1.f;
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
for (int i = 0; i < 2; i++) {
this->buffers[i] = new WaveBuffer(2, 0x800);
this->filters[i].lowpass = new IIR_NOrder_BW_LH(1);
@ -54,17 +54,17 @@ void HiFi::Process(float *samples, uint32_t size) {
void HiFi::Reset() {
for (int i = 0; i < 2; i++) {
this->filters[i].lowpass->setLPF(120.0, this->samplerate);
this->filters[i].lowpass->setLPF(120.0, this->samplingRate);
this->filters[i].lowpass->Mute();
this->filters[i].highpass->setHPF(1200.0, this->samplerate);
this->filters[i].highpass->setHPF(1200.0, this->samplingRate);
this->filters[i].highpass->Mute();
this->filters[i].bandpass->setBPF(120.f, 1200.f, this->samplerate);
this->filters[i].bandpass->setBPF(120.f, 1200.f, this->samplingRate);
this->filters[i].bandpass->Mute();
}
this->buffers[0]->Reset();
this->buffers[0]->PushZeros(this->samplerate / 400);
this->buffers[0]->PushZeros(this->samplingRate / 400);
this->buffers[1]->Reset();
this->buffers[1]->PushZeros(this->samplerate / 200);
this->buffers[1]->PushZeros(this->samplingRate / 200);
}
@ -72,7 +72,7 @@ void HiFi::SetClarity(float value) {
this->gain = value;
}
void HiFi::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void HiFi::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
Reset();
}

View File

@ -17,7 +17,7 @@ public:
void SetClarity(float value);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
WaveBuffer *buffers[2];
struct {
@ -26,7 +26,7 @@ public:
IIR_NOrder_BW_BP *bandpass;
} filters[2];
float gain;
uint32_t samplerate;
uint32_t samplingRate;
};

View File

@ -11,7 +11,6 @@ IIR_1st::IIR_1st() {
Mute();
}
void IIR_1st::Mute() {
this->prevSample = 0.f;
}
@ -22,18 +21,18 @@ void IIR_1st::SetCoefficients(float b0, float b1, float a1) {
this->a1 = a1;
}
#define angle(freq, samplerate) (expf(-1*(float)M_PI*(freq)/((float)(samplerate)/2.f)))
#define omega() (2.f * (float)M_PI * frequency / (float)samplerate)
#define omega_2() ((float)M_PI * frequency / (float)samplerate)
#define angle(freq, samplingRate) (expf(-1*(float)M_PI*(freq)/((float)(samplingRate)/2.f)))
#define omega() (2.f * (float)M_PI * frequency / (float)samplingRate)
#define omega_2() ((float)M_PI * frequency / (float)samplingRate)
void IIR_1st::setHPF_A(float frequency, uint32_t samplerate) {
this->a1 = angle(frequency, samplerate);
void IIR_1st::setHPF_A(float frequency, uint32_t samplingRate) {
this->a1 = angle(frequency, samplingRate);
float norm = (1 + a1) / 2.f;
this->b0 = norm;
this->b1 = -norm;
}
void IIR_1st::setHPF_BW(float frequency, uint32_t samplerate) {
void IIR_1st::setHPF_BW(float frequency, uint32_t samplingRate) {
float omega_2 = omega_2();
float tan_omega_2 = tanf(omega_2);
this->b0 = 1 / (1 + tan_omega_2);
@ -41,32 +40,32 @@ void IIR_1st::setHPF_BW(float frequency, uint32_t samplerate) {
this->a1 = (1 - tan_omega_2) / (1 + tan_omega_2);
}
void IIR_1st::setHPF_C(float frequency, uint32_t samplerate) {
this->b0 = (float) samplerate / ((float) samplerate + frequency);
void IIR_1st::setHPF_C(float frequency, uint32_t samplingRate) {
this->b0 = (float) samplingRate / ((float) samplingRate + frequency);
this->b1 = -1 * this->b0;
this->a1 = ((float) samplerate - frequency) / ((float) samplerate + frequency);
this->a1 = ((float) samplingRate - frequency) / ((float) samplingRate + frequency);
}
void IIR_1st::setHPFwLPS_A(float frequency, uint32_t samplerate) {
void IIR_1st::setHPFwLPS_A(float frequency, uint32_t samplingRate) {
this->a1 = -0.12f;
this->b0 = -1.f;
this->b1 = angle(frequency, samplerate);
this->b1 = angle(frequency, samplingRate);
float norm = (1 - this->a1) / fabsf(this->b0 + this->b1);
this->b0 *= norm;
this->b1 *= norm;;
}
void IIR_1st::setHSF_A(float f1, float f2, uint32_t samplerate) {
this->a1 = angle(f1, samplerate);
void IIR_1st::setHSF_A(float f1, float f2, uint32_t samplingRate) {
this->a1 = angle(f1, samplingRate);
this->b0 = -1.f;
this->b1 = angle(f2, samplerate);
this->b1 = angle(f2, samplingRate);
float norm = (1 - this->a1) / (this->b0 + this->b1);
this->b0 *= norm;
this->b1 *= norm;
}
void IIR_1st::setLPF_A(float frequency, uint32_t samplerate) {
this->a1 = angle(frequency, samplerate);
void IIR_1st::setLPF_A(float frequency, uint32_t samplingRate) {
this->a1 = angle(frequency, samplingRate);
this->b0 = 1.f;
this->b1 = 0.12f;
float norm = (1 + this->a1) / (this->b0 + this->b1);
@ -74,7 +73,7 @@ void IIR_1st::setLPF_A(float frequency, uint32_t samplerate) {
this->b1 *= norm;
}
void IIR_1st::setLPF_BW(float frequency, uint32_t samplerate) {
void IIR_1st::setLPF_BW(float frequency, uint32_t samplingRate) {
float omega_2 = omega_2();
float tan_omega_2 = tanf(omega_2);
this->a1 = (1 - tan_omega_2) / (1 + tan_omega_2);
@ -82,16 +81,16 @@ void IIR_1st::setLPF_BW(float frequency, uint32_t samplerate) {
this->b1 = this->b0;
}
void IIR_1st::setLPF_C(float frequency, uint32_t samplerate) {
this->b0 = frequency / ((float) samplerate + frequency);
void IIR_1st::setLPF_C(float frequency, uint32_t samplingRate) {
this->b0 = frequency / ((float) samplingRate + frequency);
this->b1 = this->b0;
this->a1 = ((float) samplerate - frequency) / ((float) samplerate + frequency);
this->a1 = ((float) samplingRate - frequency) / ((float) samplingRate + frequency);
}
void IIR_1st::setLSF_A(float f1, float f2, uint32_t samplerate) {
this->a1 = angle(f1, samplerate);
void IIR_1st::setLSF_A(float f1, float f2, uint32_t samplingRate) {
this->a1 = angle(f1, samplingRate);
this->b0 = -1.f;
this->b1 = angle(f2, samplerate);
this->b1 = angle(f2, samplingRate);
}
void IIR_1st::setPole(float a1) {
@ -100,7 +99,7 @@ void IIR_1st::setPole(float a1) {
this->b1 = 0.f;
}
void IIR_1st::setPoleHPF(float frequency, uint32_t samplerate) {
void IIR_1st::setPoleHPF(float frequency, uint32_t samplingRate) {
float omega = omega();
float cos_omega = cosf(omega);
float tmp = (2.f + cos_omega);
@ -110,7 +109,7 @@ void IIR_1st::setPoleHPF(float frequency, uint32_t samplerate) {
this->b1 = 0;
}
void IIR_1st::setPoleLPF(float frequency, uint32_t samplerate) {
void IIR_1st::setPoleLPF(float frequency, uint32_t samplingRate) {
float omega = omega();
float cos_omega = cosf(omega);
float tmp = (2.f - cos_omega);
@ -129,7 +128,7 @@ void IIR_1st::setZero(float b1) {
this->b1 *= norm;
}
void IIR_1st::setZeroHPF(float frequency, uint32_t samplerate) {
void IIR_1st::setZeroHPF(float frequency, uint32_t samplingRate) {
float omega = omega();
float cos_omega = cosf(omega);
float tmp = (1.f - 2.f * cos_omega);
@ -139,7 +138,7 @@ void IIR_1st::setZeroHPF(float frequency, uint32_t samplerate) {
this->b1 = -coeff / (1.f + coeff);
}
void IIR_1st::setZeroLPF(float frequency, uint32_t samplerate) {
void IIR_1st::setZeroLPF(float frequency, uint32_t samplingRate) {
float omega = omega();
float cos_omega = cosf(omega);
float tmp = (1.f + 2.f * cos_omega);

View File

@ -10,35 +10,35 @@ public:
void SetCoefficients(float b0, float b1, float a1);
void setHPF_A(float frequency, uint32_t samplerate);
void setHPF_A(float frequency, uint32_t samplingRate);
void setHPF_BW(float frequency, uint32_t samplerate);
void setHPF_BW(float frequency, uint32_t samplingRate);
void setHPF_C(float frequency, uint32_t samplerate);
void setHPF_C(float frequency, uint32_t samplingRate);
void setHPFwLPS_A(float frequency, uint32_t samplerate);
void setHPFwLPS_A(float frequency, uint32_t samplingRate);
void setHSF_A(float f1, float f2, uint32_t samplerate);
void setHSF_A(float f1, float f2, uint32_t samplingRate);
void setLPF_A(float frequency, uint32_t samplerate);
void setLPF_A(float frequency, uint32_t samplingRate);
void setLPF_BW(float frequency, uint32_t samplerate);
void setLPF_BW(float frequency, uint32_t samplingRate);
void setLPF_C(float frequency, uint32_t samplerate);
void setLPF_C(float frequency, uint32_t samplingRate);
void setLSF_A(float f1, float f2, uint32_t samplerate);
void setLSF_A(float f1, float f2, uint32_t samplingRate);
void setPole(float a1);
void setPoleHPF(float frequency, uint32_t samplerate);
void setPoleHPF(float frequency, uint32_t samplingRate);
void setPoleLPF(float frequency, uint32_t samplerate);
void setPoleLPF(float frequency, uint32_t samplingRate);
void setZero(float b1);
void setZeroHPF(float frequency, uint32_t samplerate);
void setZeroHPF(float frequency, uint32_t samplingRate);
void setZeroLPF(float frequency, uint32_t samplerate);
void setZeroLPF(float frequency, uint32_t samplingRate);
float b0, b1, a1;
float prevSample;

View File

@ -23,9 +23,9 @@ void IIR_NOrder_BW_BP::Mute() {
}
}
void IIR_NOrder_BW_BP::setBPF(float highCut, float lowCut, uint32_t samplerate) {
void IIR_NOrder_BW_BP::setBPF(float highCut, float lowCut, uint32_t samplingRate) {
for (int x = 0; x < this->order; x++) {
this->lowpass[x].setLPF_BW(lowCut, samplerate);
this->highpass[x].setHPF_BW(highCut, samplerate);
this->lowpass[x].setLPF_BW(lowCut, samplingRate);
this->highpass[x].setHPF_BW(highCut, samplingRate);
}
}

View File

@ -10,7 +10,7 @@ public:
void Mute();
void setBPF(float highCut, float lowCut, uint32_t samplerate);
void setBPF(float highCut, float lowCut, uint32_t samplingRate);
IIR_1st *lowpass;
IIR_1st *highpass;

View File

@ -19,14 +19,14 @@ void IIR_NOrder_BW_LH::Mute() {
}
}
void IIR_NOrder_BW_LH::setLPF(float frequency, uint32_t samplerate) {
void IIR_NOrder_BW_LH::setLPF(float frequency, uint32_t samplingRate) {
for (int x = 0; x < this->order; x++) {
this->filters[x].setLPF_BW(frequency, samplerate);
this->filters[x].setLPF_BW(frequency, samplingRate);
}
}
void IIR_NOrder_BW_LH::setHPF(float frequency, uint32_t samplerate) {
void IIR_NOrder_BW_LH::setHPF(float frequency, uint32_t samplingRate) {
for (int x = 0; x < this->order; x++) {
this->filters[x].setHPF_BW(frequency, samplerate);
this->filters[x].setHPF_BW(frequency, samplingRate);
}
}

View File

@ -10,9 +10,9 @@ public:
void Mute();
void setLPF(float frequency, uint32_t samplerate);
void setLPF(float frequency, uint32_t samplingRate);
void setHPF(float frequency, uint32_t samplerate);
void setHPF(float frequency, uint32_t samplingRate);
IIR_1st *filters;
uint32_t order;

View File

@ -1 +1,165 @@
#include "MinPhaseIIRCoeffs.h"
#include "../constants.h"
#include <cmath>
static const float MIN_PHASE_IIR_COEFFS_FREQ_10[] = {
31.0,
62.0,
125.0,
250.0,
500.0,
1000.0,
2000.0,
4000.0,
8000.0,
16000.0
};
static const float MIN_PHASE_IIR_COEFFS_FREQ_15[] = {
25.0,
40.0,
63.0,
100.0,
160.0,
250.0,
400.0,
630.0,
1000.0,
1600.0,
2500.0,
4000.0,
6300.0,
10000.0,
16000.0
};
static const float MIN_PHASE_IIR_COEFFS_FREQ_25[] = {
20.0,
31.5,
40.0,
50.0,
80.0,
100.0,
125.0,
160.0,
250.0,
315.0,
400.0,
500.0,
800.0,
1000.0,
1250.0,
1600.0,
2500.0,
3150.0,
4000.0,
5000.0,
8000.0,
10000.0,
12500.0,
16000.0,
20000.0
};
static const float MIN_PHASE_IIR_COEFFS_FREQ_31[] = {
20.0,
25.0,
31.5,
40.0,
50.0,
63.0,
80.0,
100.0,
125.0,
160.0,
200.0,
250.0,
315.0,
400.0,
500.0,
630.0,
800.0,
1000.0,
1250.0,
1600.0,
2000.0,
2500.0,
3150.0,
4000.0,
5000.0,
6300.0,
8000.0,
10000.0,
12500.0,
16000.0,
20000.0
};
MinPhaseIIRCoeffs::MinPhaseIIRCoeffs() {
this->coeffs = nullptr;
this->samplingRate = DEFAULT_SAMPLERATE;
this->freqs = 0;
}
MinPhaseIIRCoeffs::~MinPhaseIIRCoeffs() {
delete this->coeffs;
}
void MinPhaseIIRCoeffs::Find_F1_F2(double param_2, double param_3, double *parma_4, double *param_5) {
double x = pow(2.0, param_3 / 2.0);
*param_5 = param_2 / x;
*parma_4 = param_2 * x;
}
float *MinPhaseIIRCoeffs::GetCoefficients() {
return this->coeffs;
}
float MinPhaseIIRCoeffs::GetIndexFrequency(uint32_t index) {
switch (this->freqs) {
case 10:
return MIN_PHASE_IIR_COEFFS_FREQ_10[index];
case 15:
return MIN_PHASE_IIR_COEFFS_FREQ_15[index];
case 25:
return MIN_PHASE_IIR_COEFFS_FREQ_25[index];
case 31:
return MIN_PHASE_IIR_COEFFS_FREQ_31[index];
default:
return 0.0;
}
}
int MinPhaseIIRCoeffs::SolveRoot(double param_2, double param_3, double param_4, double *param_5) {
double x = (param_4 - pow(param_3, 2.0) / (param_2 * 4.0)) / param_2;
double y = param_3 / (param_2 * 2.0);
if (x >= 0.0) {
return -1;
}
double z = sqrt(-x);
double a = -y - z;
double b = z - y;
if (a > b) {
*param_5 = b;
} else {
*param_5 = a;
}
return 0;
}
int MinPhaseIIRCoeffs::UpdateCoeffs(uint32_t freqs, int samplingRate) {
if ((freqs != 10 && freqs != 15 && freqs != 25 && freqs != 31) || samplingRate != 44100) {
return 0;
}
this->freqs = freqs;
this->samplingRate = samplingRate;
delete this->coeffs;
this->coeffs = new float[freqs * 5];
return 0;
}

View File

@ -1,13 +1,20 @@
#pragma once
#include <cstdint>
class MinPhaseIIRCoeffs {
public:
MinPhaseIIRCoeffs();
~MinPhaseIIRCoeffs();
void Find_F1_F2(double a, double b, double *c, double *d);
void Find_F1_F2(double param_2, double param_3, double *parma_4, double *param_5);
float *GetCoefficients();
float *GetIndexFrequency();
int *SolveRoot(double a, double b, double c, double *d);
int UpdateCoeffs(int a, int samplingRate);
float GetIndexFrequency(uint32_t param_1);
int SolveRoot(double param_2, double param_3, double param_4, double *param_5);
int UpdateCoeffs(uint32_t freqs, int samplingRate);
private:
float *coeffs;
uint32_t samplingRate;
uint32_t freqs;
};

View File

@ -1,5 +1,5 @@
#include <cmath>
#include "MultiBiquad.h"
#include <cmath>
MultiBiquad::MultiBiquad() {
this->y_2 = 0;

View File

@ -1,18 +1,20 @@
#pragma once
enum FilterType {
LOWPASS = 0,
HIGHPASS = 1,
BANDPASS = 2,
BANDSTOP = 3,
ALLPASS = 4,
PEAK = 5,
LOWSHELF = 6,
HIGHSHELF = 7
};
#include <cstdint>
class MultiBiquad {
public:
enum FilterType {
LOWPASS = 0,
HIGHPASS = 1,
BANDPASS = 2,
BANDSTOP = 3,
ALLPASS = 4,
PEAK = 5,
LOWSHELF = 6,
HIGHSHELF = 7
};
MultiBiquad();
double ProcessSample(double sample);

View File

@ -2,7 +2,7 @@
#include "../constants.h"
NoiseSharpening::NoiseSharpening() {
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->gain = 0.f;
Reset();
}
@ -36,7 +36,7 @@ void NoiseSharpening::Process(float *buffer, uint32_t size) {
void NoiseSharpening::Reset() {
for (int i = 0; i < 2; i++) {
this->filters[i].setLPF_BW(this->samplerate / 2.f - 1000.f, this->samplerate);
this->filters[i].setLPF_BW(this->samplingRate / 2.f - 1000.f, this->samplingRate);
this->filters[i].Mute();
this->in[i] = 0.f;
}
@ -46,7 +46,7 @@ void NoiseSharpening::SetGain(float gain) {
this->gain = gain;
}
void NoiseSharpening::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void NoiseSharpening::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
Reset();
}

View File

@ -13,11 +13,11 @@ public:
void SetGain(float gain);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
IIR_1st filters[2];
float in[2];
int32_t samplerate;
int32_t samplingRate;
float gain;
};

View File

@ -6,7 +6,7 @@ PassFilter::PassFilter() {
this->filters[1] = new IIR_NOrder_BW_LH(3);
this->filters[2] = new IIR_NOrder_BW_LH(1);
this->filters[3] = new IIR_NOrder_BW_LH(1);
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
Reset();
}
@ -19,14 +19,14 @@ PassFilter::~PassFilter() {
void PassFilter::Reset() {
uint32_t cutoff;
if (this->samplerate < 44100) {
cutoff = this->samplerate - 100;
if (this->samplingRate < 44100) {
cutoff = this->samplingRate - 100;
} else {
cutoff = 18000;
}
this->filters[0]->setLPF((float) cutoff, this->samplerate);
this->filters[1]->setLPF((float) cutoff, this->samplerate);
this->filters[0]->setLPF((float) cutoff, this->samplingRate);
this->filters[1]->setLPF((float) cutoff, this->samplingRate);
this->filters[2]->setLPF(10.f, cutoff);
this->filters[3]->setLPF(10.f, cutoff);
@ -51,7 +51,7 @@ void PassFilter::ProcessFrames(float *buffer, uint32_t size) {
}
}
void PassFilter::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void PassFilter::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
Reset();
}

View File

@ -13,8 +13,8 @@ public:
void ProcessFrames(float *buffer, uint32_t size);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
IIR_NOrder_BW_LH *filters[4];
uint32_t samplerate;
uint32_t samplingRate;
};

View File

@ -4,7 +4,7 @@
#include <cmath>
PolesFilter::PolesFilter() {
this->samplerate = DEFAULT_SAMPLERATE;
this->samplingRate = DEFAULT_SAMPLERATE;
this->lower_freq = 160;
this->upper_freq = 8000;
UpdateCoeff();
@ -18,10 +18,10 @@ void PolesFilter::UpdateCoeff() {
memset(&this->channels[0], 0, sizeof(channel));
memset(&this->channels[1], 0, sizeof(channel));
this->channels[0].lower_angle = ((float) this->lower_freq * M_PI / (float) this->samplerate);
this->channels[1].lower_angle = ((float) this->lower_freq * M_PI / (float) this->samplerate);
this->channels[0].upper_angle = ((float) this->upper_freq * M_PI / (float) this->samplerate);
this->channels[1].upper_angle = ((float) this->upper_freq * M_PI / (float) this->samplerate);
this->channels[0].lower_angle = ((float) this->lower_freq * M_PI / (float) this->samplingRate);
this->channels[1].lower_angle = ((float) this->lower_freq * M_PI / (float) this->samplingRate);
this->channels[0].upper_angle = ((float) this->upper_freq * M_PI / (float) this->samplingRate);
this->channels[1].upper_angle = ((float) this->upper_freq * M_PI / (float) this->samplingRate);
}
inline void DoFilterSide(channel *side, float sample, float *out1, float *out2, float *out3) {
@ -59,7 +59,7 @@ void PolesFilter::SetPassFilter(uint32_t lower_freq, uint32_t upper_freq) {
UpdateCoeff();
}
void PolesFilter::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
void PolesFilter::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
UpdateCoeff();
}

View File

@ -26,12 +26,12 @@ public:
void SetPassFilter(uint32_t lower_freq, uint32_t upper_freq);
void SetSamplingRate(uint32_t samplerate);
void SetSamplingRate(uint32_t samplingRate);
channel channels[2];
uint32_t lower_freq;
uint32_t upper_freq;
uint32_t samplerate;
uint32_t samplingRate;
};

View File

@ -4,12 +4,12 @@
Subwoofer::Subwoofer() {
uint32_t samplingRate = DEFAULT_SAMPLERATE;
this->peak[0].RefreshFilter(FilterType::PEAK, 0.0, 37.0, samplingRate, 1.0, false);
this->peak[1].RefreshFilter(FilterType::PEAK, 0.0, 37.0, samplingRate, 1.0, false);
this->peakLow[0].RefreshFilter(FilterType::PEAK, 0.0, 75.0, samplingRate, 1.0, false);
this->peakLow[1].RefreshFilter(FilterType::PEAK, 0.0, 75.0, samplingRate, 1.0, false);
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, 200.0, samplingRate, 1.0, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, 200.0, samplingRate, 1.0, false);
this->peak[0].RefreshFilter(MultiBiquad::FilterType::PEAK, 0.0, 37.0, samplingRate, 1.0, false);
this->peak[1].RefreshFilter(MultiBiquad::FilterType::PEAK, 0.0, 37.0, samplingRate, 1.0, false);
this->peakLow[0].RefreshFilter(MultiBiquad::FilterType::PEAK, 0.0, 75.0, samplingRate, 1.0, false);
this->peakLow[1].RefreshFilter(MultiBiquad::FilterType::PEAK, 0.0, 75.0, samplingRate, 1.0, false);
this->lowpass[0].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, 200.0, samplingRate, 1.0, false);
this->lowpass[1].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, 200.0, samplingRate, 1.0, false);
}
void Subwoofer::Process(float *samples, uint32_t size) {
@ -27,10 +27,10 @@ void Subwoofer::SetBassGain(uint32_t samplingRate, float gainDb) {
float gain = 20.0f * log10( gainDb);
float gainLower = 20.0f * log10( gainDb / 8.0f);
this->peak[0].RefreshFilter(FilterType::PEAK, gain, 44.0, samplingRate, 0.75, true);
this->peak[1].RefreshFilter(FilterType::PEAK, gain, 44.0, samplingRate, 0.75, true);
this->peakLow[0].RefreshFilter(FilterType::PEAK, gainLower, 80.0, samplingRate, 0.2, true);
this->peakLow[1].RefreshFilter(FilterType::PEAK, gainLower, 80.0, samplingRate, 0.2, true);
this->lowpass[0].RefreshFilter(FilterType::LOWPASS, 0.0, 380.0, samplingRate, 0.6, false);
this->lowpass[1].RefreshFilter(FilterType::LOWPASS, 0.0, 380.0, samplingRate, 0.6, false);
this->peak[0].RefreshFilter(MultiBiquad::FilterType::PEAK, gain, 44.0, samplingRate, 0.75, true);
this->peak[1].RefreshFilter(MultiBiquad::FilterType::PEAK, gain, 44.0, samplingRate, 0.75, true);
this->peakLow[0].RefreshFilter(MultiBiquad::FilterType::PEAK, gainLower, 80.0, samplingRate, 0.2, true);
this->peakLow[1].RefreshFilter(MultiBiquad::FilterType::PEAK, gainLower, 80.0, samplingRate, 0.2, true);
this->lowpass[0].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, 380.0, samplingRate, 0.6, false);
this->lowpass[1].RefreshFilter(MultiBiquad::FilterType::LOWPASS, 0.0, 380.0, samplingRate, 0.6, false);
}

View File

@ -1,6 +1,5 @@
#include <cstdlib>
#include <cstring>
#include "TimeConstDelay.h"
#include <cstdlib>
TimeConstDelay::TimeConstDelay() {
this->samples = nullptr;
@ -19,11 +18,11 @@ float TimeConstDelay::ProcessSample(float sample) {
this->offset = (int) modf((float) this->offset + 1, (float *) &this->sampleCount); // TODO: check if this is correct
return val;
}
return 0.0f;
return 0.0;
}
void TimeConstDelay::SetParameters(uint32_t samplerate, float delay) {
this->sampleCount = (int) ((float) samplerate * delay * 0.5f);
void TimeConstDelay::SetParameters(uint32_t samplingRate, float delay) {
this->sampleCount = samplingRate * (uint32_t) ceil(delay);
delete this->samples;
this->samples = new float[this->sampleCount]();
this->offset = 0;

View File

@ -10,7 +10,7 @@ public:
float ProcessSample(float sample);
void SetParameters(uint32_t samplerate, float delay);
void SetParameters(uint32_t samplingRate, float delay);
float *samples;
uint32_t offset;