From 0ef67d5294bfa14312a4e7d7850e1f11372167b6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 20 Jul 2017 18:33:38 -0400 Subject: [PATCH] Adds analysis and synthesis --- src/common.h | 38 ++++++++++++++++++++++++++++++++- src/denoise.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/src/common.h b/src/common.h index 253cb9d..a9c2f0e 100644 --- a/src/common.h +++ b/src/common.h @@ -3,6 +3,42 @@ #ifndef COMMON_H #define COMMON_H -#define OPUS_INLINE inline +#define RNN_INLINE inline + + +/** RNNoise wrapper for malloc(). To do your own dynamic allocation, all you need t +o do is replace this function and rnnoise_free */ +#ifndef OVERRIDE_RNNOISE_ALLOC +static RNN_INLINE void *rnnoise_alloc (size_t size) +{ + return malloc(size); +} +#endif + +/** RNNoise wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and rnnoise_alloc */ +#ifndef OVERRIDE_RNNOISE_FREE +static RNN_INLINE void rnnoise_free (void *ptr) +{ + free(ptr); +} +#endif + +/** Copy n elements from src to dst. The 0* term provides compile-time type checking */ +#ifndef OVERRIDE_RNN_COPY +#define RNN_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) +#endif + +/** Copy n elements from src to dst, allowing overlapping regions. The 0* term + provides compile-time type checking */ +#ifndef OVERRIDE_RNN_MOVE +#define RNN_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) +#endif + +/** Set n elements of dst to zero */ +#ifndef OVERRIDE_RNN_CLEAR +#define RNN_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst)))) +#endif + + #endif diff --git a/src/denoise.c b/src/denoise.c index b03ef6a..bf961f2 100644 --- a/src/denoise.c +++ b/src/denoise.c @@ -2,6 +2,7 @@ #include #include #include "kiss_fft.h" +#include "common.h" #define FRAME_SIZE_SHIFT 2 #define FRAME_SIZE (120<analysis_mem, FRAME_SIZE); + for (i=0;ianalysis_mem, in, FRAME_SIZE); + apply_window(x); + forward_transform(y, x); + /* Do the actual processing here. */ + inverse_transform(x, y); + apply_window(x); + for (i=0;isynthesis_mem[i]; + RNN_COPY(st->synthesis_mem, &x[FRAME_SIZE], FRAME_SIZE); +} + int main() { int i; - float x[2*FRAME_SIZE]; - kiss_fft_cpx y[2*FRAME_SIZE]; - float bandE[NB_BANDS]; + float x[FRAME_SIZE]; + DenoiseState *st; + st = rnnoise_create(); memset(x, 0, sizeof(x)); x[0] = 1; - x[1] = 1; + x[1] = -1; //opus_fft(kfft, x, y, 0); - forward_transform(y, x); - compute_band_energy(bandE, y); - inverse_transform(x, y); + //forward_transform(y, x); + //compute_band_energy(bandE, y); + //inverse_transform(x, y); /*for (i=0;i<2*FRAME_SIZE;i++) printf("%f %f\n", y[i].r, y[i].i);*/ /*for (i=0;i