diff --git a/dnn/common.h b/dnn/common.h index 1e24a28f7de48d3ddd5ab62acbe543ba4bb847eb..b2e9a20799b2497150e6f9d9b48197436ed7f1ac 100644 --- a/dnn/common.h +++ b/dnn/common.h @@ -3,14 +3,38 @@ #ifndef COMMON_H #define COMMON_H -#include "stdlib.h" -#include "string.h" +#include <stdlib.h> +#include <string.h> +#include <math.h> #define RNN_INLINE inline #define OPUS_INLINE inline float lpc_from_cepstrum(float *lpc, const float *cepstrum); +static RNN_INLINE float ulaw2lin(float u) +{ + float s; + float scale_1 = 32768.f/255.f; + u = u - 128; + s = u >= 0 ? 1 : -1; + u = fabs(u); + return s*scale_1*(exp(u/128.*log(256))-1); +} + +static RNN_INLINE int lin2ulaw(float x) +{ + float u; + float scale = 255.f/32768.f; + int s = x >= 0 ? 1 : -1; + x = fabs(x); + u = (s*(128*log(1+scale*x)/log(256))); + u = 128 + u; + if (u < 0) u = 0; + if (u > 255) u = 255; + return (int)floor(.5 + u); +} + /** RNNoise wrapper for malloc(). To do your own dynamic allocation, all you need t o do is replace this function and rnnoise_free */ diff --git a/dnn/dump_data.c b/dnn/dump_data.c index 5ec671f2bb3943013cf85472f339722b7f5fecd4..3ca46c4b9881c366f07b45b7525d9cc24ffbf273 100644 --- a/dnn/dump_data.c +++ b/dnn/dump_data.c @@ -55,13 +55,9 @@ typedef struct { float analysis_mem[OVERLAP_SIZE]; float cepstral_mem[CEPS_MEM][NB_BANDS]; - int memid; float pitch_buf[PITCH_BUF_SIZE]; - float pitch_enh_buf[PITCH_BUF_SIZE]; float last_gain; int last_period; - float mem_hp_x[2]; - float lastg[NB_BANDS]; } DenoiseState; static int rnnoise_get_size() { diff --git a/dnn/lpcnet.c b/dnn/lpcnet.c index 10898e0af3a067eab01f190128ffe88029fb3055..afe14c27cdce73135b7670a5772b0d55a8ce2138 100644 --- a/dnn/lpcnet.c +++ b/dnn/lpcnet.c @@ -56,29 +56,6 @@ struct LPCNetState { }; -static float ulaw2lin(float u) -{ - float s; - float scale_1 = 32768.f/255.f; - u = u - 128; - s = u >= 0 ? 1 : -1; - u = fabs(u); - return s*scale_1*(exp(u/128.*log(256))-1); -} - -static int lin2ulaw(float x) -{ - float u; - float scale = 255.f/32768.f; - int s = x >= 0 ? 1 : -1; - x = fabs(x); - u = (s*(128*log(1+scale*x)/log(256))); - u = 128 + u; - if (u < 0) u = 0; - if (u > 255) u = 255; - return (int)floor(.5 + u); -} - #if 0 static void print_vector(float *x, int N) {