2022-09-25 01:28:56 +02:00
|
|
|
#include <cstring>
|
2023-01-08 01:11:46 +01:00
|
|
|
#include <cmath>
|
2022-08-30 00:39:15 +02:00
|
|
|
#include "SoftwareLimiter.h"
|
2022-09-06 17:57:23 +02:00
|
|
|
|
|
|
|
SoftwareLimiter::SoftwareLimiter() {
|
2022-09-25 01:28:56 +02:00
|
|
|
this->ready = false;
|
|
|
|
this->unknown4 = 0;
|
|
|
|
this->unknown2 = 1.0;
|
|
|
|
this->gate = 0.999999;
|
|
|
|
this->unknown3 = 1.0;
|
|
|
|
this->unknown1 = 1.0;
|
2023-03-01 19:49:26 +01:00
|
|
|
|
|
|
|
Reset();
|
2022-09-06 17:57:23 +02:00
|
|
|
}
|
|
|
|
|
2022-10-06 03:37:22 +02:00
|
|
|
float SoftwareLimiter::Process(float sample) {
|
2023-01-08 01:11:46 +01:00
|
|
|
bool bVar1;
|
|
|
|
uint uVar3;
|
|
|
|
uint uVar4;
|
|
|
|
int iVar5;
|
|
|
|
uint uVar6;
|
|
|
|
uint uVar8;
|
|
|
|
float fVar9;
|
|
|
|
float fVar10;
|
2023-03-01 19:49:26 +01:00
|
|
|
float abs_sample;
|
2023-01-08 01:11:46 +01:00
|
|
|
|
2023-03-01 19:49:26 +01:00
|
|
|
abs_sample = std::abs(sample);
|
2023-03-10 22:54:33 +01:00
|
|
|
if (abs_sample < this->gate) {
|
2023-01-08 01:11:46 +01:00
|
|
|
if (this->ready) goto LAB_0006d86c;
|
|
|
|
uVar8 = this->unknown4;
|
2023-03-01 19:49:26 +01:00
|
|
|
}
|
|
|
|
else {
|
2023-01-08 01:11:46 +01:00
|
|
|
if (!this->ready) {
|
2023-03-10 22:54:33 +01:00
|
|
|
memset(this->arr512, 0, sizeof(this->arr512));
|
|
|
|
this->ready = true;
|
2023-01-08 01:11:46 +01:00
|
|
|
}
|
|
|
|
LAB_0006d86c:
|
|
|
|
uVar3 = 8;
|
2023-03-10 22:54:33 +01:00
|
|
|
uVar8 = this->unknown4;
|
2023-01-08 01:11:46 +01:00
|
|
|
uVar4 = uVar8;
|
|
|
|
do {
|
|
|
|
iVar5 = 2 << (uVar3 & 0xff);
|
|
|
|
uVar6 = uVar4 ^ 1;
|
2023-03-10 22:54:33 +01:00
|
|
|
this->arr512[512 + uVar4 - iVar5] = abs_sample;
|
|
|
|
uVar4 = uVar4 / 2;
|
|
|
|
if (abs_sample < this->arr512[512 + uVar6 - iVar5]) {
|
|
|
|
abs_sample = this->arr512[512 + uVar6 - iVar5];
|
2023-01-08 01:11:46 +01:00
|
|
|
}
|
|
|
|
uVar3 = uVar3 - 1;
|
|
|
|
} while (uVar3 != 0);
|
2023-03-10 22:54:33 +01:00
|
|
|
if (this->gate < abs_sample) {
|
2023-03-01 19:49:26 +01:00
|
|
|
bVar1 = this->ready;
|
|
|
|
fVar10 = this->unknown1;
|
2023-03-10 22:54:33 +01:00
|
|
|
uVar4 = (uVar8 + 1) % 256;
|
2023-01-08 01:11:46 +01:00
|
|
|
this->arr256[uVar8] = sample;
|
|
|
|
this->unknown4 = uVar4;
|
2023-03-01 19:49:26 +01:00
|
|
|
if (bVar1) {
|
2023-03-10 22:54:33 +01:00
|
|
|
fVar10 = this->gate / abs_sample;
|
2023-03-01 19:49:26 +01:00
|
|
|
}
|
2023-01-08 01:11:46 +01:00
|
|
|
abs_sample = this->arr256[uVar4];
|
|
|
|
goto LAB_0006d8fc;
|
|
|
|
}
|
|
|
|
this->ready = false;
|
|
|
|
}
|
|
|
|
fVar10 = this->unknown1;
|
|
|
|
this->arr256[uVar8] = sample;
|
2023-03-10 22:54:33 +01:00
|
|
|
uVar8 = (uVar8 + 1) % 256;
|
2023-01-08 01:11:46 +01:00
|
|
|
this->unknown4 = uVar8;
|
|
|
|
abs_sample = this->arr256[uVar8];
|
|
|
|
LAB_0006d8fc:
|
|
|
|
fVar9 = this->unknown2 * 0.9999 + 0.0001;
|
|
|
|
fVar10 = fVar10 * 0.0999 + this->unknown3 * 0.8999;
|
|
|
|
bVar1 = fVar10 < fVar9;
|
|
|
|
this->unknown3 = fVar10;
|
|
|
|
if (bVar1) {
|
|
|
|
fVar9 = fVar10;
|
|
|
|
}
|
|
|
|
if (bVar1) {
|
|
|
|
this->unknown2 = fVar10;
|
|
|
|
}
|
|
|
|
if (!bVar1) {
|
|
|
|
this->unknown2 = fVar9;
|
|
|
|
}
|
|
|
|
fVar9 = abs_sample * fVar9;
|
2023-03-01 19:49:26 +01:00
|
|
|
fVar10 = std::abs(fVar9);
|
2023-03-10 22:54:33 +01:00
|
|
|
if (this->gate <= fVar10) {
|
|
|
|
fVar9 = this->gate / std::abs(abs_sample);
|
2023-03-01 19:49:26 +01:00
|
|
|
}
|
2023-03-10 22:54:33 +01:00
|
|
|
if (this->gate <= fVar10) {
|
2023-01-08 01:11:46 +01:00
|
|
|
this->unknown2 = fVar9;
|
|
|
|
fVar9 = abs_sample * fVar9;
|
|
|
|
}
|
|
|
|
return fVar9;
|
2022-09-06 17:57:23 +02:00
|
|
|
}
|
|
|
|
|
2023-03-01 19:49:26 +01:00
|
|
|
void SoftwareLimiter::Reset() {
|
|
|
|
memset(this->arr256, 0, sizeof(this->arr256));
|
|
|
|
memset(this->arr512, 0, sizeof(this->arr512));
|
2022-09-25 01:28:56 +02:00
|
|
|
this->ready = false;
|
|
|
|
this->unknown4 = 0;
|
|
|
|
this->unknown2 = 1.0;
|
|
|
|
this->unknown3 = 1.0;
|
2022-09-06 17:57:23 +02:00
|
|
|
}
|
|
|
|
|
2022-09-25 01:28:56 +02:00
|
|
|
void SoftwareLimiter::SetGate(float gate) {
|
|
|
|
this->gate = gate;
|
2022-09-06 17:57:23 +02:00
|
|
|
}
|