mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-08 02:29:40 +08:00
Update
This commit is contained in:
parent
de2f2142fd
commit
b6ee869c04
@ -250,7 +250,7 @@ static int32_t Viper_ICommand(effect_handle_t self,
|
||||
return 0;
|
||||
}
|
||||
case EFFECT_CMD_DISABLE: {
|
||||
// pContext->viper->enabled = false;
|
||||
// pContext->viper->enable = false;
|
||||
*((int *) pReplyData) = 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
DiffSurround::DiffSurround() {
|
||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||
this->delayTime = 0.0f;
|
||||
this->enabled = false;
|
||||
this->enable = false;
|
||||
for (auto &buffer : this->buffers) {
|
||||
buffer = new WaveBuffer(1, 0x1000);
|
||||
}
|
||||
@ -19,10 +19,11 @@ DiffSurround::~DiffSurround() {
|
||||
}
|
||||
|
||||
void DiffSurround::Process(float *samples, uint32_t size) {
|
||||
if (!this->enable) return;
|
||||
|
||||
float *bufs[2];
|
||||
float *outbufs[2];
|
||||
|
||||
if (this->enabled) {
|
||||
bufs[0] = this->buffers[0]->PushZerosGetBuffer(size);
|
||||
bufs[1] = this->buffers[1]->PushZerosGetBuffer(size);
|
||||
|
||||
@ -39,7 +40,6 @@ void DiffSurround::Process(float *samples, uint32_t size) {
|
||||
|
||||
this->buffers[0]->PopSamples(size, false);
|
||||
this->buffers[1]->PopSamples(size, false);
|
||||
}
|
||||
}
|
||||
|
||||
void DiffSurround::Reset() {
|
||||
@ -56,12 +56,12 @@ void DiffSurround::SetDelayTime(float delayTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void DiffSurround::SetEnable(bool enabled) {
|
||||
if (this->enabled != enabled) {
|
||||
if (!this->enabled) {
|
||||
void DiffSurround::SetEnable(bool enable) {
|
||||
if (this->enable != enable) {
|
||||
if (!this->enable) {
|
||||
Reset();
|
||||
}
|
||||
this->enabled = enabled;
|
||||
this->enable = enable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,11 @@ public:
|
||||
void Process(float *samples, uint32_t size);
|
||||
void Reset();
|
||||
void SetDelayTime(float delayTime);
|
||||
void SetEnable(bool enabled);
|
||||
void SetEnable(bool enable);
|
||||
void SetSamplingRate(uint32_t samplingRate);
|
||||
|
||||
uint32_t samplingRate;
|
||||
bool enabled;
|
||||
bool enable;
|
||||
float delayTime;
|
||||
WaveBuffer *buffers[2];
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ void DynamicSystem::SetBassGain(float gain) {
|
||||
|
||||
void DynamicSystem::SetEnable(bool enable) {
|
||||
if (this->enable != enable) {
|
||||
if (!this->enable) {
|
||||
if (enable) {
|
||||
Reset();
|
||||
}
|
||||
this->enable = enable;
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "IIRFilter.h"
|
||||
#include "../constants.h"
|
||||
|
||||
// Iscle: Verified with latest version at 13/12/2022
|
||||
|
||||
IIRFilter::IIRFilter(uint32_t bands) {
|
||||
this->enable = false;
|
||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||
@ -40,8 +42,8 @@ void IIRFilter::Process(float *samples, uint32_t size) {
|
||||
double coeff3 = coeffs[k * 4 + 2];
|
||||
|
||||
double a = coeff3 * this->buf[bufIdx + ((this->unknown3 + 3) - this->unknown2)];
|
||||
double b = coeff2 * (sample - this->buf[bufIdx + (unknown4 - unknown2)]);
|
||||
double c = coeff1 * this->buf[bufIdx + ((unknown4 - unknown2) + 3)];
|
||||
double b = coeff2 * (sample - this->buf[bufIdx + (this->unknown4 - this->unknown2)]);
|
||||
double c = coeff1 * this->buf[bufIdx + ((this->unknown4 - this->unknown2) + 3)];
|
||||
|
||||
double tmp = (a + b) - c;
|
||||
|
||||
@ -67,7 +69,7 @@ void IIRFilter::Reset() {
|
||||
|
||||
void IIRFilter::SetBandLevel(uint32_t band, float level) {
|
||||
if (band > 30) return;
|
||||
double bandLevel = pow(10.0, level / 20.0);
|
||||
double bandLevel = pow(10.0, (double) level / 20.0);
|
||||
this->bandLevelsWithQ[band] = (float) (bandLevel * 0.636);
|
||||
}
|
||||
|
||||
@ -75,7 +77,7 @@ void IIRFilter::SetEnable(bool enable) {
|
||||
if (this->enable != enable) {
|
||||
this->enable = enable;
|
||||
if (enable) {
|
||||
this->Reset();
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,8 +86,8 @@ void IIRFilter::SetSamplingRate(uint32_t samplingRate) {
|
||||
if (this->samplingRate != samplingRate) {
|
||||
this->samplingRate = samplingRate;
|
||||
if (this->bands != 0) {
|
||||
this->minPhaseIirCoeffs.UpdateCoeffs(this->bands, this->samplingRate);
|
||||
this->minPhaseIirCoeffs.UpdateCoeffs(this->bands, samplingRate);
|
||||
}
|
||||
this->Reset();
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <cstdint>
|
||||
#include "../utils/MinPhaseIIRCoeffs.h"
|
||||
|
||||
// Iscle: Verified with latest version at 13/12/2022
|
||||
|
||||
class IIRFilter {
|
||||
public:
|
||||
IIRFilter(uint32_t bands);
|
||||
|
@ -17,7 +17,7 @@ PlaybackGain::PlaybackGain() {
|
||||
this->biquad2.SetBandPassParameter(2200.0,this->samplingRate,0.33);
|
||||
}
|
||||
|
||||
float PlaybackGain::AnalyseWave(float *samples, uint32_t size) {
|
||||
double PlaybackGain::AnalyseWave(float *samples, uint32_t size) {
|
||||
if (size == 0) return 0.0;
|
||||
|
||||
double tmpL = 0.0;
|
||||
@ -31,13 +31,51 @@ float PlaybackGain::AnalyseWave(float *samples, uint32_t size) {
|
||||
tmpR += tmpR2 * tmpR2;
|
||||
}
|
||||
|
||||
float tmp = tmpL;
|
||||
double tmp;
|
||||
if (tmpL > tmpR) {
|
||||
tmp = tmpL;
|
||||
} else {
|
||||
tmp = tmpR;
|
||||
}
|
||||
|
||||
return tmp / (float) size;
|
||||
return tmp / (double) size;
|
||||
}
|
||||
|
||||
void PlaybackGain::Process(float *samples, uint32_t size) {
|
||||
//static float PlaybackGain::ProcessSingle(float sample) {
|
||||
//
|
||||
//}
|
||||
|
||||
void PlaybackGain::Process(float *samples, uint32_t size) {
|
||||
if (!this->enable) return;
|
||||
if (size == 0) return;
|
||||
|
||||
double analyzed = AnalyseWave(samples, size);
|
||||
double a = log(analyzed);
|
||||
|
||||
if (this->counterTo100 < 100) {
|
||||
this->counterTo100++;
|
||||
}
|
||||
|
||||
double b = a * this->unknown1 * 10.0 + 23.0;
|
||||
double c = ((double) this->counterTo100 / 100.0) * (b * this->ratio2 - b);
|
||||
double d = c / 100.0;
|
||||
double e = pow(10.0, (c - d * d * 50.0) / 20.0);
|
||||
uint32_t f;
|
||||
if (size < this->samplingRate / 40) {
|
||||
f = this->samplingRate / 40;
|
||||
} else {
|
||||
f = size;
|
||||
}
|
||||
|
||||
double unk2 = this->unknown2;
|
||||
double g = (e * this->volume - this->unknown2) / f;
|
||||
if (g >= 0.0) {
|
||||
g *= 0.0625;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackGain::Reset() {
|
||||
@ -50,10 +88,10 @@ void PlaybackGain::Reset() {
|
||||
|
||||
void PlaybackGain::SetEnable(bool enable) {
|
||||
if (this->enable != enable) {
|
||||
this->enable = enable;
|
||||
if (enable) {
|
||||
Reset();
|
||||
}
|
||||
this->enable = enable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ class PlaybackGain {
|
||||
public:
|
||||
PlaybackGain();
|
||||
|
||||
float AnalyseWave(float *samples, uint32_t size);
|
||||
double AnalyseWave(float *samples, uint32_t size);
|
||||
void Process(float *samples, uint32_t size);
|
||||
void Reset();
|
||||
void SetEnable(bool enable);
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "../constants.h"
|
||||
#include <cmath>
|
||||
|
||||
// Iscle: Verified with latest version at 13/12/2022
|
||||
|
||||
static const float MIN_PHASE_IIR_COEFFS_FREQ_10BANDS[] = {
|
||||
31.0,
|
||||
62.0,
|
||||
@ -107,8 +109,8 @@ MinPhaseIIRCoeffs::~MinPhaseIIRCoeffs() {
|
||||
|
||||
void MinPhaseIIRCoeffs::Find_F1_F2(double param_2, double param_3, double *param_4, double *param_5) {
|
||||
double x = pow(2.0, param_3 / 2.0);
|
||||
*param_5 = param_2 / x;
|
||||
*param_4 = param_2 * x;
|
||||
*param_4 = param_2 / x;
|
||||
*param_5 = param_2 * x;
|
||||
}
|
||||
|
||||
double *MinPhaseIIRCoeffs::GetCoefficients() {
|
||||
@ -132,7 +134,7 @@ float MinPhaseIIRCoeffs::GetIndexFrequency(uint32_t index) {
|
||||
|
||||
int MinPhaseIIRCoeffs::SolveRoot(double param_2, double param_3, double param_4, double *param_5) {
|
||||
double x = (param_4 - (param_3 * param_3) / (param_2 * 4.0)) / param_2;
|
||||
double y = param_3 / (param_2 * 2.0);
|
||||
double y = param_3 / (param_2 + param_2);
|
||||
|
||||
if (x >= 0.0) {
|
||||
return -1;
|
||||
@ -161,24 +163,24 @@ int MinPhaseIIRCoeffs::UpdateCoeffs(uint32_t bands, uint32_t samplingRate) {
|
||||
delete[] this->coeffs;
|
||||
this->coeffs = new double[bands * 4](); // TODO: Check this array size, original type: float
|
||||
|
||||
const float *coeffsArray;
|
||||
const float *bandFreqs;
|
||||
double tmp;
|
||||
|
||||
switch (bands) {
|
||||
case 10:
|
||||
coeffsArray = MIN_PHASE_IIR_COEFFS_FREQ_10BANDS;
|
||||
bandFreqs = MIN_PHASE_IIR_COEFFS_FREQ_10BANDS;
|
||||
tmp = 3.0 / 3.0;
|
||||
break;
|
||||
case 15:
|
||||
coeffsArray = MIN_PHASE_IIR_COEFFS_FREQ_15BANDS;
|
||||
bandFreqs = MIN_PHASE_IIR_COEFFS_FREQ_15BANDS;
|
||||
tmp = 2.0 / 3.0;
|
||||
break;
|
||||
case 25:
|
||||
coeffsArray = MIN_PHASE_IIR_COEFFS_FREQ_25BANDS;
|
||||
bandFreqs = MIN_PHASE_IIR_COEFFS_FREQ_25BANDS;
|
||||
tmp = 1.0 / 3.0;
|
||||
break;
|
||||
case 31:
|
||||
coeffsArray = MIN_PHASE_IIR_COEFFS_FREQ_31BANDS;
|
||||
bandFreqs = MIN_PHASE_IIR_COEFFS_FREQ_31BANDS;
|
||||
tmp = 1.0 / 3.0;
|
||||
break;
|
||||
}
|
||||
@ -187,9 +189,9 @@ int MinPhaseIIRCoeffs::UpdateCoeffs(uint32_t bands, uint32_t samplingRate) {
|
||||
double ret1;
|
||||
double ret2;
|
||||
|
||||
Find_F1_F2(coeffsArray[i], tmp, &ret1, &ret2);
|
||||
Find_F1_F2(bandFreqs[i], tmp, &ret2, &ret1);
|
||||
|
||||
double x = (2.0 * M_PI * (double) coeffsArray[i]) / (double) this->samplingRate;
|
||||
double x = (2.0 * M_PI * (double) bandFreqs[i]) / (double) this->samplingRate;
|
||||
double y = (2.0 * M_PI * ret2) / (double) this->samplingRate;
|
||||
|
||||
double cosX = cos(x);
|
||||
@ -197,20 +199,17 @@ int MinPhaseIIRCoeffs::UpdateCoeffs(uint32_t bands, uint32_t samplingRate) {
|
||||
double sinY = sin(y);
|
||||
|
||||
double a = cosX * cosY;
|
||||
double b = (cosX * cosX) / 2.0;
|
||||
double c = (sinY * sinY);
|
||||
double b = cosX * cosX / 2.0;
|
||||
double c = sinY * sinY;
|
||||
|
||||
// ((b - a) + 0.5) - c
|
||||
double d = ((b - a) + 0.5) - c;
|
||||
// c + (((b + (cosY * cosY)) - a) - 0.5)
|
||||
double e = c + (((b + (cosY * cosY)) - a) - 0.5);
|
||||
// (((cosX * cosX) / 8.0 - cosX * cosY / 4.0) + 0.125) - c / 4.0
|
||||
double e = c + (((b + cosY * cosY) - a) - 0.5);
|
||||
double f = (((cosX * cosX) * 0.125 - cosX * cosY * 0.25) + 0.125) - c * 0.25;
|
||||
|
||||
if (SolveRoot(d, e, f, &ret1) == 0) {
|
||||
this->coeffs[4 * i] = ret1 * 2.0;
|
||||
this->coeffs[4 * i + 1] = ((0.5 - ret1) * 0.5) * 2.0;
|
||||
this->coeffs[4 * i + 2] = ((ret1 + 0.5) * cosX) * 2.0;
|
||||
this->coeffs[i * 4] = ret1 + ret1;
|
||||
this->coeffs[i * 4 + 1] = 0.5 - ret1;
|
||||
this->coeffs[i * 4 + 2] = (ret1 + 0.5) * cosX * 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,18 +2,21 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Iscle: Verified with latest version at 13/12/2022
|
||||
|
||||
class MinPhaseIIRCoeffs {
|
||||
public:
|
||||
MinPhaseIIRCoeffs();
|
||||
~MinPhaseIIRCoeffs();
|
||||
|
||||
void Find_F1_F2(double param_2, double param_3, double *param_4, double *param_5);
|
||||
double *GetCoefficients();
|
||||
float GetIndexFrequency(uint32_t param_1);
|
||||
int SolveRoot(double param_2, double param_3, double param_4, double *param_5);
|
||||
int UpdateCoeffs(uint32_t bands, uint32_t samplingRate);
|
||||
|
||||
private:
|
||||
void Find_F1_F2(double param_2, double param_3, double *param_4, double *param_5);
|
||||
int SolveRoot(double param_2, double param_3, double param_4, double *param_5);
|
||||
|
||||
double *coeffs;
|
||||
uint32_t samplingRate;
|
||||
uint32_t bands;
|
||||
|
@ -59,13 +59,13 @@ int PConvSingle::LoadKernel(float *buf, int param_2, int segmentSize) {
|
||||
|
||||
int PConvSingle::LoadKernel(const float *param_2,float param_3,int param_4,int param_5) {
|
||||
// if (buf != nullptr && param_5 > 0 && segmentSize > 0 && segmentSize % 2 == 0) {
|
||||
// this->enabled = false;
|
||||
// this->enable = false;
|
||||
// ReleaseResources();
|
||||
//// this->data = new PConvData(); //(PConvData *) malloc(0x140); // TODO: Sizeof
|
||||
// this->segmentSize = segmentSize;
|
||||
// int n = ProcessKernel(1, param_2, param_4, param_5);
|
||||
// if (n != 0) {
|
||||
// this->enabled = true;
|
||||
// this->enable = true;
|
||||
// return n;
|
||||
// }
|
||||
// ReleaseResources();
|
||||
|
Loading…
x
Reference in New Issue
Block a user