mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-08 02:29:40 +08:00
Make ViPERBass stereo :)
This commit is contained in:
parent
86b50169a0
commit
a947fd7f79
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// Iscle: Verified with the latest version at 13/12/2022
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
ViPERBass::ViPERBass() {
|
ViPERBass::ViPERBass() : polyphase(2), waveBuffer(2, 4096) {
|
||||||
this->speaker = 60;
|
this->speaker = 60;
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
this->processMode = ProcessMode::NATURAL_BASS;
|
this->processMode = ProcessMode::NATURAL_BASS;
|
||||||
@ -11,24 +11,15 @@ ViPERBass::ViPERBass() {
|
|||||||
this->bassFactor = 0.0;
|
this->bassFactor = 0.0;
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
this->samplingRatePeriod = 1.0 / VIPER_DEFAULT_SAMPLING_RATE;
|
this->samplingRatePeriod = 1.0 / VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
this->polyphase = new Polyphase(2);
|
|
||||||
this->biquad = new Biquad();
|
|
||||||
this->subwoofer = new Subwoofer();
|
|
||||||
this->waveBuffer = new WaveBuffer(1, 4096);
|
|
||||||
|
|
||||||
this->biquad->Reset();
|
for (auto &biquad : this->biquad) {
|
||||||
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
biquad.Reset();
|
||||||
this->subwoofer->SetBassGain(this->samplingRate, 0.0);
|
biquad.SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
|
}
|
||||||
|
this->subwoofer.SetBassGain(this->samplingRate, 0.0);
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
ViPERBass::~ViPERBass() {
|
|
||||||
delete this->polyphase;
|
|
||||||
delete this->biquad;
|
|
||||||
delete this->subwoofer;
|
|
||||||
delete this->waveBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViPERBass::Process(float *samples, uint32_t size) {
|
void ViPERBass::Process(float *samples, uint32_t size) {
|
||||||
if (!this->enable) return;
|
if (!this->enable) return;
|
||||||
if (size == 0) return;
|
if (size == 0) return;
|
||||||
@ -48,49 +39,46 @@ void ViPERBass::Process(float *samples, uint32_t size) {
|
|||||||
switch (this->processMode) {
|
switch (this->processMode) {
|
||||||
case ProcessMode::NATURAL_BASS: {
|
case ProcessMode::NATURAL_BASS: {
|
||||||
for (uint32_t i = 0; i < size * 2; i += 2) {
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
double sample = ((double) samples[i] + (double) samples[i + 1]) / 2.0;
|
samples[i] += (float) this->biquad[0].ProcessSample(samples[i]) * this->bassFactor;
|
||||||
float x = (float) this->biquad->ProcessSample(sample) * this->bassFactor;
|
samples[i + 1] += (float) this->biquad[1].ProcessSample(samples[i + 1]) * this->bassFactor;
|
||||||
samples[i] += x;
|
|
||||||
samples[i + 1] += x;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ProcessMode::PURE_BASS_PLUS: {
|
case ProcessMode::PURE_BASS_PLUS: {
|
||||||
if (this->waveBuffer->PushSamples(samples, size)) {
|
if (this->waveBuffer.PushSamples(samples, size)) {
|
||||||
float *buffer = this->waveBuffer->GetBuffer();
|
float *buffer = this->waveBuffer.GetBuffer();
|
||||||
uint32_t bufferOffset = this->waveBuffer->GetBufferOffset();
|
uint32_t bufferOffset = this->waveBuffer.GetBufferOffset();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < size * 2; i += 2) {
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
double sample = ((double) samples[i] + (double) samples[i + 1]) / 2.0;
|
buffer[bufferOffset - size + i] = (float) this->biquad[0].ProcessSample(samples[i]);
|
||||||
auto x = (float) this->biquad->ProcessSample(sample);
|
buffer[bufferOffset - size + i + 1] = (float) this->biquad[1].ProcessSample(samples[i + 1]);
|
||||||
buffer[bufferOffset - size + i / 2] = x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->polyphase->Process(samples, size) == size) {
|
if (this->polyphase.Process(samples, size) == size) {
|
||||||
for (uint32_t i = 0; i < size * 2; i += 2) {
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
float x = buffer[i / 2] * this->bassFactor;
|
samples[i] += buffer[i] * this->bassFactor;
|
||||||
samples[i] += x;
|
samples[i + 1] += buffer[i + 1] * this->bassFactor;
|
||||||
samples[i + 1] += x;
|
|
||||||
}
|
}
|
||||||
this->waveBuffer->PopSamples(size, true);
|
this->waveBuffer.PopSamples(size, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ProcessMode::SUBWOOFER: {
|
case ProcessMode::SUBWOOFER: {
|
||||||
this->subwoofer->Process(samples, size);
|
this->subwoofer.Process(samples, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViPERBass::Reset() {
|
void ViPERBass::Reset() {
|
||||||
this->polyphase->SetSamplingRate(this->samplingRate);
|
this->polyphase.SetSamplingRate(this->samplingRate);
|
||||||
this->polyphase->Reset();
|
this->polyphase.Reset();
|
||||||
this->waveBuffer->Reset();
|
this->waveBuffer.Reset();
|
||||||
this->waveBuffer->PushZeros(this->polyphase->GetLatency());
|
this->waveBuffer.PushZeros(this->polyphase.GetLatency());
|
||||||
this->subwoofer->SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
this->subwoofer.SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
||||||
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
this->biquad[0].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
|
this->biquad[1].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
this->samplingRatePeriod = 1.0f / (float) this->samplingRate;
|
this->samplingRatePeriod = 1.0f / (float) this->samplingRate;
|
||||||
this->antiPop = 0.0f;
|
this->antiPop = 0.0f;
|
||||||
}
|
}
|
||||||
@ -98,7 +86,7 @@ void ViPERBass::Reset() {
|
|||||||
void ViPERBass::SetBassFactor(float bassFactor) {
|
void ViPERBass::SetBassFactor(float bassFactor) {
|
||||||
if (this->bassFactor != bassFactor) {
|
if (this->bassFactor != bassFactor) {
|
||||||
this->bassFactor = bassFactor;
|
this->bassFactor = bassFactor;
|
||||||
this->subwoofer->SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
this->subwoofer.SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,15 +108,17 @@ void ViPERBass::SetSamplingRate(uint32_t samplingRate) {
|
|||||||
if (this->samplingRate != samplingRate) {
|
if (this->samplingRate != samplingRate) {
|
||||||
this->samplingRate = samplingRate;
|
this->samplingRate = samplingRate;
|
||||||
this->samplingRatePeriod = 1.0f / (float) samplingRate;
|
this->samplingRatePeriod = 1.0f / (float) samplingRate;
|
||||||
this->polyphase->SetSamplingRate(this->samplingRate);
|
this->polyphase.SetSamplingRate(this->samplingRate);
|
||||||
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
this->biquad[0].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
this->subwoofer->SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
this->biquad[1].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
|
this->subwoofer.SetBassGain(this->samplingRate, this->bassFactor * 2.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViPERBass::SetSpeaker(uint32_t speaker) {
|
void ViPERBass::SetSpeaker(uint32_t speaker) {
|
||||||
if (this->speaker != speaker) {
|
if (this->speaker != speaker) {
|
||||||
this->speaker = speaker;
|
this->speaker = speaker;
|
||||||
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
this->biquad[0].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
|
this->biquad[1].SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,10 @@ public:
|
|||||||
void SetSpeaker(uint32_t speaker);
|
void SetSpeaker(uint32_t speaker);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Polyphase *polyphase;
|
Polyphase polyphase;
|
||||||
Biquad *biquad;
|
Biquad biquad[2];
|
||||||
Subwoofer *subwoofer;
|
Subwoofer subwoofer;
|
||||||
WaveBuffer *waveBuffer;
|
WaveBuffer waveBuffer;
|
||||||
bool enable;
|
bool enable;
|
||||||
ProcessMode processMode;
|
ProcessMode processMode;
|
||||||
uint32_t samplingRate;
|
uint32_t samplingRate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user