This commit is contained in:
Iscle 2022-09-19 04:30:07 +02:00
parent 36275e8fba
commit 2d185130a4
17 changed files with 254 additions and 152 deletions

View File

@ -28,7 +28,6 @@ Effect::Effect() {
Effect::~Effect() {
delete this->buffer;
this->buffer = nullptr;
}
int32_t Effect::process(audio_buffer_s *in, audio_buffer_s *out) {

View File

@ -67,7 +67,6 @@ ViPER::ViPER() {
this->viperBass->Reset();
this->viperClarity = new ViPERClarity();
this->viperClarity->SetEnable(false);
this->viperClarity->SetSamplingRate(this->sampleRate);
this->viperClarity->Reset();
@ -114,65 +113,26 @@ ViPER::ViPER() {
ViPER::~ViPER() {
delete this->adaptiveBuffer;
this->adaptiveBuffer = nullptr;
delete this->waveBuffer;
this->waveBuffer = nullptr;
delete this->convolver;
this->convolver = nullptr;
delete this->vhe;
this->vhe = nullptr;
delete this->viperDdc;
this->viperDdc = nullptr;
delete this->spectrumExtend;
this->spectrumExtend = nullptr;
delete this->iirFilter;
this->iirFilter = nullptr;
delete this->colorfulMusic;
this->colorfulMusic = nullptr;
delete this->reverberation;
this->reverberation = nullptr;
delete this->playbackGain;
this->playbackGain = nullptr;
delete this->fetCompressor;
this->fetCompressor = nullptr;
delete this->dynamicSystem;
this->dynamicSystem = nullptr;
delete this->viperBass;
this->viperBass = nullptr;
delete this->viperClarity;
this->viperClarity = nullptr;
delete this->diffSurround;
this->diffSurround = nullptr;
delete this->cure;
this->cure = nullptr;
delete this->tubeSimulator;
this->tubeSimulator = nullptr;
delete this->analogX;
this->analogX = nullptr;
delete this->speakerCorrection;
this->speakerCorrection = nullptr;
for (auto &softwareLimiter: this->softwareLimiters) {
delete softwareLimiter;
softwareLimiter = nullptr;
}
}

View File

@ -14,7 +14,6 @@ DiffSurround::DiffSurround() {
DiffSurround::~DiffSurround() {
for (auto &buffer : this->buffers) {
delete buffer;
buffer = nullptr;
}
}

View File

@ -21,16 +21,9 @@ ViPERBass::ViPERBass() {
ViPERBass::~ViPERBass() {
delete this->polyphase;
this->polyphase = nullptr;
delete this->biquad;
this->biquad = nullptr;
delete this->subwoofer;
this->subwoofer = nullptr;
delete this->waveBuffer;
this->waveBuffer = nullptr;
}
void ViPERBass::Process(float *samples, uint32_t size) {
@ -74,8 +67,9 @@ void ViPERBass::Process(float *samples, uint32_t size) {
if (this->polyphase->Process(samples, size) == size) {
for (uint32_t i = 0; i < size * 2; i += 2) {
samples[i] += buffer[i / 2] * this->bassFactor;
samples[i + 1] += buffer[i / 2] * this->bassFactor;
float x = buffer[i / 2] * this->bassFactor;
samples[i] += x;
samples[i + 1] += x;
}
this->waveBuffer->PopSamples(size, true);
}
@ -120,7 +114,7 @@ void ViPERBass::SetSamplingRate(uint32_t samplingRate) {
this->invertedSamplingRate = 1.0f / (float) samplingRate;
this->polyphase->SetSamplingRate(samplingRate);
this->biquad->SetLowPassParameter(this->speaker, samplingRate, 0.53);
this->subwoofer->SetBassGain(samplingRate, this->bassFactor * 2.5);
this->subwoofer->SetBassGain(samplingRate, this->bassFactor * 2.5f);
}
}

View File

@ -2,87 +2,75 @@
#include "../constants.h"
ViPERClarity::ViPERClarity() {
for (int i = 0; i < 2; i++) {
this->hiShelf[i].SetFrequency(12000.f);
// this->hiShelf[i].SetQuality(100.f);
this->hiShelf[i].SetGain(1.f);
this->hiShelf[i].SetSamplingRate(DEFAULT_SAMPLERATE);
for (auto &highShelf : this->highShelf) {
highShelf.SetFrequency(12000.0);
highShelf.SetGain(1.0);
highShelf.SetSamplingRate(DEFAULT_SAMPLERATE);
}
this->enabled = false;
this->processMode = ClarityMode::NATURAL;
this->clarityGainPercent = 0.f;
this->samplerate = DEFAULT_SAMPLERATE;
Reset();
this->samplingRate = DEFAULT_SAMPLERATE;
this->clarityGainPercent = 0.0;
this->Reset();
}
void ViPERClarity::Process(float *samples, uint32_t size) {
if (this->enabled) {
switch (this->processMode) {
case ClarityMode::NATURAL: {
this->sharp.Process(samples, size);
break;
}
case ClarityMode::OZONE: {
for (int i = 0; i < size * 2; i++) {
samples[i] = this->hiShelf[i % 2].Process(samples[i]);
}
break;
}
case ClarityMode::XHIFI: {
this->hifi.Process(samples, size);
break;
switch (this->processMode) {
case ClarityMode::NATURAL: {
this->noiseSharpening.Process(samples, size);
break;
}
case ClarityMode::OZONE: {
for (int i = 0; i < size * 2; i++) {
samples[i] = (float) this->highShelf[i % 2].Process(samples[i]);
}
break;
}
case ClarityMode::XHIFI: {
this->hifi.Process(samples, size);
break;
}
}
}
void ViPERClarity::Reset() {
this->sharp.SetSamplingRate(this->samplerate);
this->sharp.Reset();
SetClarityToFilter();
for (int i = 0; i < 2; i++) {
this->hiShelf[i].SetFrequency(8250.f);
// this->hiShelf[i].SetQuality(100.f);
this->hiShelf[i].SetSamplingRate(DEFAULT_SAMPLERATE);
this->noiseSharpening.SetSamplingRate(this->samplingRate);
this->noiseSharpening.Reset();
this->SetClarityToFilter();
for (auto &highShelf : this->highShelf) {
highShelf.SetFrequency(8250.0);
highShelf.SetSamplingRate(this->samplingRate);
}
this->hifi.SetSamplingRate(this->samplerate);
this->hifi.SetSamplingRate(this->samplingRate);
this->hifi.Reset();
}
void ViPERClarity::SetClarity(float gainPercent) {
this->clarityGainPercent = gainPercent;
if (this->processMode != ClarityMode::OZONE) {
SetClarityToFilter();
this->SetClarityToFilter();
} else {
Reset();
this->Reset();
}
}
void ViPERClarity::SetClarityToFilter() {
this->sharp.SetGain(this->clarityGainPercent);
this->hiShelf[0].SetGain(this->clarityGainPercent + 1.f);
this->hiShelf[1].SetGain(this->clarityGainPercent + 1.f);
this->hifi.SetClarity(this->clarityGainPercent + 1.f);
this->noiseSharpening.SetGain(this->clarityGainPercent);
this->highShelf[0].SetGain(this->clarityGainPercent + 1.0f);
this->highShelf[1].SetGain(this->clarityGainPercent + 1.0f);
this->hifi.SetClarity(this->clarityGainPercent + 1.0f);
}
void ViPERClarity::SetEnable(bool enabled) {
this->enabled = enabled;
if (this->enabled) {
Reset();
void ViPERClarity::SetProcessMode(ClarityMode processMode) {
if (this->processMode != processMode) {
this->processMode = processMode;
this->Reset();
}
}
void ViPERClarity::SetProcessMode(ClarityMode mode) {
this->processMode = mode;
Reset();
}
void ViPERClarity::SetSamplingRate(uint32_t samplerate) {
this->samplerate = samplerate;
Reset();
}
ViPERClarity::~ViPERClarity() {
void ViPERClarity::SetSamplingRate(uint32_t samplingRate) {
if (this->samplingRate != samplingRate) {
this->samplingRate = samplingRate;
this->Reset();
}
}

View File

@ -5,31 +5,29 @@
#include "../utils/HiFi.h"
#include "../utils/HighShelf.h"
enum ClarityMode {
NATURAL,
OZONE,
XHIFI
};
class ViPERClarity {
public:
enum ClarityMode {
NATURAL,
OZONE,
XHIFI
};
ViPERClarity();
~ViPERClarity();
void Process(float *samples, uint32_t size);
void Reset();
void SetClarity(float gainPercent);
void SetClarityToFilter();
void SetEnable(bool enabled);
void SetProcessMode(ClarityMode mode);
void SetSamplingRate(uint32_t samplerate);
void SetProcessMode(ClarityMode processMode);
void SetSamplingRate(uint32_t samplingRate);
NoiseSharpening sharp;
HighShelf hiShelf[2];
private:
NoiseSharpening noiseSharpening;
HighShelf highShelf[2];
HiFi hifi;
bool enabled;
ClarityMode processMode;
uint32_t samplerate;
uint32_t samplingRate;
float clarityGainPercent;
};

View File

@ -14,7 +14,6 @@ AdaptiveBuffer::AdaptiveBuffer(uint32_t channels, uint32_t length) {
AdaptiveBuffer::~AdaptiveBuffer() {
delete this->buffer;
this->buffer = nullptr;
}
void AdaptiveBuffer::FlushBuffer() {

View File

@ -28,11 +28,11 @@ void Biquad::Reset() {
this->y_2 = 0;
}
void Biquad::SetBandPassParameter(double frequency, double samplingRate, double qFactor) {
void Biquad::SetBandPassParameter(double frequency, double samplingRate, float qFactor) {
double x = (2.0 * M_PI * frequency) / samplingRate;
double sinX = sin(x);
double cosX = cos(x);
double y = sinX / (2.0 * qFactor);
double y = sinX / ((double) qFactor * 2.0);
double a0 = 1.0 + y;
double a1 = -cosX * 2.0;
@ -56,7 +56,7 @@ void Biquad::SetCoeffs(double a0, double a1, double a2, double b0, double b1, do
}
void
Biquad::SetHighPassParameter(double frequency, double samplingRate, double param_4, double qFactor, double param_6) {
Biquad::SetHighPassParameter(double frequency, double samplingRate, double param_4, float qFactor, double param_6) {
double x = (2.0 * M_PI * frequency) / samplingRate;
double sinX = sin(x);
double cosX = cos(x);
@ -64,7 +64,7 @@ Biquad::SetHighPassParameter(double frequency, double samplingRate, double param
double y = pow(10.0, param_4 / 40.0);
double sqrtY = sqrt(y);
double z = sinX / 2.0 * sqrt((1.0 / y + y) * (1.0 / qFactor - 1.0) + 2.0);
double z = sinX / 2.0 * sqrt((1.0 / y + y) * (1.0 / (double) qFactor - 1.0) + 2.0);
double a = (y - 1.0) * cosX;
double b = (y + 1.0) + a;
double c = (y + 1.0) * cosX;
@ -81,10 +81,10 @@ Biquad::SetHighPassParameter(double frequency, double samplingRate, double param
this->SetCoeffs(a0, a1, a2, b0, b1, b2);
}
void Biquad::SetLowPassParameter(double frequency, double samplingRate, double qFactor) {
void Biquad::SetLowPassParameter(double frequency, double samplingRate, float qFactor) {
double x = (2.0 * M_PI * frequency) / samplingRate;
double sinX = sin(x);
double y = sinX / (qFactor * 2.0);
double y = sinX / ((double) qFactor * 2.0);
double cosX = cos(x);
double z = 1.0 - cosX;

View File

@ -8,10 +8,10 @@ public:
double ProcessSample(double sample);
void Reset();
void SetBandPassParameter(double frequency, double samplingRate, double qFactor);
void SetBandPassParameter(double frequency, double samplingRate, float qFactor);
void SetCoeffs(double a0, double a1, double a2, double b0, double b1, double b2);
void SetHighPassParameter(double frequency, double samplingRate, double param_4, double qFactor, double param_6);
void SetLowPassParameter(double frequency, double samplingRate, double qFactor);
void SetHighPassParameter(double frequency, double samplingRate, double param_4, float qFactor, double param_6);
void SetLowPassParameter(double frequency, double samplingRate, float qFactor);
private:
double x_1;

View File

@ -14,7 +14,7 @@ void FIR::FilterSamples(int *samples, uint32_t size) {
this->FilterSamplesInterleaved(samples, size, 1);
}
void FIR::FilterSamplesInterleaved(int *samples, uint32_t size, uint32_t channels) {
void FIR::FilterSamplesInterleaved(float *samples, uint32_t size, uint32_t channels) {
}
@ -22,7 +22,7 @@ int FIR::GetBlockLength() {
return this->blockLength;
}
int FIR::LoadCoefficients(float *coeffs, uint32_t coeffsize, int blockLength) {
int FIR::LoadCoefficients(const float *coeffs, uint32_t coeffsize, int blockLength) {
return 0;
}

View File

@ -8,9 +8,9 @@ public:
~FIR();
void FilterSamples(int *samples, uint32_t size);
void FilterSamplesInterleaved(int *samples, uint32_t size, uint32_t channels);
void FilterSamplesInterleaved(float *samples, uint32_t size, uint32_t channels);
int GetBlockLength();
int LoadCoefficients(float *coeffs, uint32_t coeffsize, int blockLength);
int LoadCoefficients(const float *coeffs, uint32_t coeffsize, int blockLength);
void Reset();
private:

View File

@ -10,16 +10,16 @@ double HighShelf::Process(double sample) {
return out;
}
void HighShelf::SetFrequency(double freq) {
void HighShelf::SetFrequency(float freq) {
this->frequency = freq;
}
void HighShelf::SetGain(double gain) {
this->gain = log10(gain) * 20.0;
void HighShelf::SetGain(float gain) {
this->gain = 20.0 * log10((double) gain);
}
void HighShelf::SetSamplingRate(double samplingRate) {
double x = (2 * M_PI * this->frequency) / samplingRate;
void HighShelf::SetSamplingRate(uint32_t samplingRate) {
double x = (2 * M_PI * this->frequency) / (double) samplingRate;
double sinX = sin(x);
double cosX = cos(x);
double y = exp((this->gain * log(10.0)) / 40.0);
@ -38,7 +38,7 @@ void HighShelf::SetSamplingRate(double samplingRate) {
double f = (y - 1.0) - d;
this->a0 = 1.0 / c;
this->a1 = a * 2.0;
this->a1 = f * 2.0;
this->a2 = b - z;
this->b0 = (e + z) * y;
this->b1 = -y * 2.0 * ((y - 1.0) + d);

View File

@ -5,12 +5,12 @@
class HighShelf {
public:
double Process(double sample);
void SetFrequency(double freq);
void SetGain(double gain);
void SetSamplingRate(double samplingRate);
void SetFrequency(float freq);
void SetGain(float gain);
void SetSamplingRate(uint32_t samplingRate);
private:
double frequency;
float frequency;
double gain;
double x_1;
double x_2;

View File

@ -1,11 +1,161 @@
#include "Polyphase.h"
#include "../constants.h"
static const float POLYPHASE_COEFFICIENTS_2[] = {
-0.002339,
-0.002073,
-0.001940,
-0.001675,
-0.001515,
-0.001329,
-0.001223,
-0.001037,
-0.000904,
-0.000851,
-0.000532,
-0.000851,
-0.000106,
-0.001010,
0.000558,
-0.001435,
0.001302,
-0.001967,
0.002259,
-0.002605,
0.003216,
-0.003562,
0.004784,
-0.005475,
0.007655,
-0.008506,
0.017622,
-0.024639,
0.028679,
-0.017303,
-0.032507,
0.623321,
0.184702,
-0.166867,
0.025729,
-0.078490,
-0.015735,
-0.041199,
-0.023151,
-0.031524,
-0.020121,
-0.024985,
-0.017303,
-0.019616,
-0.015018,
-0.015204,
-0.012838,
-0.011881,
-0.010951,
-0.009516,
-0.009090,
-0.007788,
-0.007442,
-0.006353,
-0.006087,
-0.005183,
-0.004970,
-0.004253,
-0.003987,
-0.003482,
-0.003216,
-0.002871,
-0.002578
};
static const float POLYPHASE_COEFFICIENTS_OTHER[] = {
-0.014194,
-0.002339,
-0.006220,
-0.019722,
-0.020626,
-0.014885,
-0.012240,
-0.012386,
-0.011801,
-0.011376,
-0.016293,
-0.018845,
-0.018327,
-0.013902,
-0.014951,
-0.015895,
-0.019044,
-0.017928,
-0.020094,
-0.017715,
-0.018845,
-0.015377,
-0.018354,
-0.016665,
-0.018951,
-0.011416,
-0.019469,
-0.017250,
0.003549,
-0.076045,
0.288350,
0.267751,
-0.041212,
-0.005130,
-0.088418,
-0.089348,
-0.087686,
-0.065625,
-0.041305,
-0.013343,
0.001422,
0.010313,
0.005834,
-0.001170,
-0.014499,
-0.021822,
-0.030792,
-0.029331,
-0.031071,
-0.018407,
-0.027271,
-0.008373,
-0.010791,
-0.040680,
0.229171,
0.080324,
-0.070955,
0.021689,
-0.046607,
-0.025011,
-0.026886,
-0.027271,
-0.032919
};
Polyphase::Polyphase(int unknown1) {
this->samplingRate = DEFAULT_SAMPLERATE;
this->fir1 = new FIR();
this->fir2 = new FIR();
this->waveBuffer1 = new WaveBuffer(2, 0x1000);
this->waveBuffer2 = new WaveBuffer(2, 0x1000);
this->buffer = new float[0x7e0];
if (unknown1 == 2) {
this->fir1->LoadCoefficients(POLYPHASE_COEFFICIENTS_2, sizeof(POLYPHASE_COEFFICIENTS_2) / sizeof(float), 1008);
this->fir2->LoadCoefficients(POLYPHASE_COEFFICIENTS_2, sizeof(POLYPHASE_COEFFICIENTS_2) / sizeof(float), 1008);
} else if (unknown1 > 2) {
this->fir1->LoadCoefficients(POLYPHASE_COEFFICIENTS_OTHER, sizeof(POLYPHASE_COEFFICIENTS_OTHER) / sizeof(float), 1008);
this->fir2->LoadCoefficients(POLYPHASE_COEFFICIENTS_OTHER, sizeof(POLYPHASE_COEFFICIENTS_OTHER) / sizeof(float), 1008);
}
}
Polyphase::~Polyphase() {
delete this->fir1;
delete this->fir2;
delete this->waveBuffer1;
delete this->waveBuffer2;
delete this->buffer;
}
uint32_t Polyphase::GetLatency() {
@ -13,14 +163,33 @@ uint32_t Polyphase::GetLatency() {
}
uint32_t Polyphase::Process(float *samples, uint32_t size) {
if (this->waveBuffer1->PushSamples(samples, size) != 0) {
uint32_t bufferOffset = this->waveBuffer1->GetBufferOffset();
while (bufferOffset >= 1008) {
if (this->waveBuffer1->PopSamples(this->buffer, 1008, false) == 1008) {
this->fir1->FilterSamplesInterleaved(this->buffer, 1008, 2);
this->fir2->FilterSamplesInterleaved(this->buffer + 1, 1008, 2);
this->waveBuffer2->PushSamples(this->buffer, 1008);
}
bufferOffset = this->waveBuffer1->GetBufferOffset();
}
if (this->waveBuffer2->GetBufferOffset() >= size) {
this->waveBuffer2->PopSamples(samples, size, true);
}
}
return 0;
}
void Polyphase::Reset() {
this->fir1->Reset();
this->fir2->Reset();
this->waveBuffer1->Reset();
this->waveBuffer2->Reset();
}
void Polyphase::SetSamplingRate(uint32_t samplingRate) {
if (this->samplingRate != samplingRate) {
this->samplingRate = samplingRate;
}
}

View File

@ -19,9 +19,7 @@ private:
FIR *fir2;
WaveBuffer *waveBuffer1;
WaveBuffer *waveBuffer2;
int *unknown1;
bool enabled;
// 3 unknowns
float *buffer;
uint32_t samplingRate;
};

View File

@ -10,7 +10,6 @@ TimeConstDelay::TimeConstDelay() {
TimeConstDelay::~TimeConstDelay() {
delete this->samples;
this->samples = nullptr;
}
float TimeConstDelay::ProcessSample(float sample) {

View File

@ -10,7 +10,6 @@ WaveBuffer::WaveBuffer(int channels, uint32_t size) {
WaveBuffer::~WaveBuffer() {
delete this->buffer;
this->buffer = nullptr;
}
uint32_t WaveBuffer::GetBufferOffset() {