noise reduction work

This commit is contained in:
AlexandreRouma
2023-03-27 01:50:34 +02:00
parent a9f882e5b1
commit 75050347de
12 changed files with 52 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ namespace dsp::convert {
StereoToMono(stream<stereo_t>* in) { base_type::init(in); }
inline int process(int count, const stereo_t* in, float* out) {
static inline int process(int count, const stereo_t* in, float* out) {
for (int i = 0; i < count; i++) {
out[i] = (in[i].l + in[i].r) / 2.0f;
}

View File

@@ -37,21 +37,17 @@ namespace dsp::noise_reduction {
inline int process(int count, complex_t* in, complex_t* out) {
for (int i = 0; i < count; i++) {
// Get signal amplitude
// Get signal amplitude and pass value if null
float inAmp = in[i].amplitude();
// Update average amplitude
float gain = 1.0f;
if (inAmp != 0.0f) {
amp = (amp * _invRate) + (inAmp * _rate);
float excess = inAmp / amp;
if (excess > _level) {
gain = 1.0f / excess;
}
if (!inAmp) {
out[i] = in[i];
}
// Scale output by gain
out[i] = in[i] * gain;
// Update running average of amplitude
amp = (_rate*inAmp) + (_invRate*amp);
// Null out if spike (Note: ideally, it should try to guess the real data)
out[i] = (inAmp > _level*amp) ? complex_t{0.0f,0.0f} : in[i];
}
return count;
}