mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2024-12-22 22:47:25 +08:00
NoiseSharpening
This commit is contained in:
parent
7fabac795e
commit
5d83c1356c
@ -36,6 +36,7 @@ set(FILES
|
||||
src/utils/IIR_NOrder_BW_BP.cpp
|
||||
src/utils/IIR_NOrder_BW_LH.cpp
|
||||
src/utils/MultiBiquad.cpp
|
||||
src/utils/NoiseSharpening.cpp
|
||||
src/utils/PassFilter.cpp
|
||||
src/utils/PolesFilter.cpp
|
||||
src/utils/TimeConstDelay.cpp
|
||||
|
56
src/utils/NoiseSharpening.cpp
Normal file
56
src/utils/NoiseSharpening.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by mart on 7/28/21.
|
||||
//
|
||||
|
||||
#include "NoiseSharpening.h"
|
||||
#include "../constants.h"
|
||||
|
||||
NoiseSharpening::NoiseSharpening() {
|
||||
this->samplerate = DEFAULT_SAMPLERATE;
|
||||
this->gain = 0.f;
|
||||
Reset();
|
||||
}
|
||||
|
||||
void NoiseSharpening::Process(float *buffer, uint32_t size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
float sampleLeft = buffer[i*2];
|
||||
float sampleRight = buffer[i*2+1];
|
||||
float prevLeft = this->in[0];
|
||||
float prevRight = this->in[1];
|
||||
this->in[0] = sampleLeft;
|
||||
this->in[1] = sampleRight;
|
||||
float diffLeft = (sampleLeft - prevLeft) * this->gain;
|
||||
float diffRight = (sampleRight - prevRight) * this->gain;
|
||||
|
||||
float sampleLeftIn = sampleLeft + diffLeft;
|
||||
float sampleRightIn = sampleRight + diffRight;
|
||||
|
||||
float hist = (sampleLeftIn) * this->filters[0].b1;
|
||||
float left = this->filters[0].prevSample + (sampleLeftIn) * this->filters[0].b0;
|
||||
this->filters[0].prevSample = (sampleLeftIn) * this->filters[0].a1 + hist;
|
||||
|
||||
hist = (sampleRightIn) * this->filters[1].b1;
|
||||
float right = this->filters[1].prevSample + (sampleRightIn) * this->filters[1].b0;
|
||||
this->filters[1].prevSample = (sampleRightIn) * this->filters[1].a1 + hist;
|
||||
|
||||
buffer[i*2] = left;
|
||||
buffer[i*2+1] = right;
|
||||
}
|
||||
}
|
||||
|
||||
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].Mute();
|
||||
this->in[i] = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
void NoiseSharpening::SetGain(float gain) {
|
||||
this->gain = gain;
|
||||
}
|
||||
|
||||
void NoiseSharpening::SetSamplingRate(uint32_t samplerate) {
|
||||
this->samplerate = samplerate;
|
||||
Reset();
|
||||
}
|
26
src/utils/NoiseSharpening.h
Normal file
26
src/utils/NoiseSharpening.h
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by mart on 7/28/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "IIR_1st.h"
|
||||
|
||||
class NoiseSharpening {
|
||||
public:
|
||||
NoiseSharpening();
|
||||
|
||||
void Process(float* buffer, uint32_t size);
|
||||
void Reset();
|
||||
void SetGain(float gain);
|
||||
void SetSamplingRate(uint32_t samplerate);
|
||||
|
||||
IIR_1st filters[2];
|
||||
float in[2];
|
||||
int32_t samplerate;
|
||||
float gain;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user