diff options
author | Jan Buethe <jbuethe@amazon.de> | 2023-12-18 11:51:47 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2023-12-20 07:01:34 +0300 |
commit | 9b9822a4758f2c95ecd106d96a21519b66d14b90 (patch) | |
tree | 72993893607a9042b0c23b306b91525d6702aa87 | |
parent | aa91747da015edcf6d7626c3de3d920d6ee3753b (diff) |
removed on-the-fly window initialization
-rw-r--r-- | dnn/adaconvtest.c | 15 | ||||
-rw-r--r-- | dnn/nndsp.c | 30 | ||||
-rw-r--r-- | dnn/nndsp.h | 2 | ||||
-rw-r--r-- | dnn/osce.c | 11 |
4 files changed, 25 insertions, 33 deletions
diff --git a/dnn/adaconvtest.c b/dnn/adaconvtest.c index ce28f5c8..722e4aff 100644 --- a/dnn/adaconvtest.c +++ b/dnn/adaconvtest.c @@ -3,11 +3,15 @@ #include "osce.h" #include "nndsp.h" + #include <stdlib.h> #include <stdio.h> #include <math.h> +extern const WeightArray lacelayers_arrays[]; +extern const WeightArray nolacelayers_arrays[]; + void adaconv_compare( const char * prefix, int num_frames, @@ -36,8 +40,10 @@ void adaconv_compare( float x_in[512]; float x_out_ref[512]; float x_out[512]; + float window[40]; init_adaconv_state(hAdaConv); + compute_overlap_window(window, 40); FILE *f_features, *f_x_in, *f_x_out; @@ -93,7 +99,7 @@ void adaconv_compare( adaconv_process_frame(hAdaConv, x_out, x_in, features, kernel_layer, gain_layer, feature_dim, frame_size, overlap_size, in_channels, out_channels, kernel_size, left_padding, - filter_gain_a, filter_gain_b, shape_gain, NULL, 0); + filter_gain_a, filter_gain_b, shape_gain, window, 0); mse = 0; for (i_sample = 0; i_sample < frame_size * out_channels; i_sample ++) @@ -136,8 +142,10 @@ void adacomb_compare( float x_out_ref[512]; float x_out[512]; int pitch_lag; + float window[40]; init_adacomb_state(hAdaComb); + compute_overlap_window(window, 40); FILE *f_features, *f_x_in, *f_p_in, *f_x_out; @@ -208,7 +216,7 @@ void adacomb_compare( } adacomb_process_frame(hAdaComb, x_out, x_in, features, kernel_layer, gain_layer, global_gain_layer, - pitch_lag, feature_dim, frame_size, overlap_size, kernel_size, left_padding, filter_gain_a, filter_gain_b, log_gain_limit, NULL, 0); + pitch_lag, feature_dim, frame_size, overlap_size, kernel_size, left_padding, filter_gain_a, filter_gain_b, log_gain_limit, window, 0); mse = 0; @@ -438,5 +446,4 @@ int main() return 0; } - -//gcc -DVAR_ARRAYS -I ../include -I ../silk -I . -I ../celt adaconvtest.c nndsp.c lace_data.c nolace_data.c nnet.c nnet_default.c ../celt/pitch.c ../celt/celt_lpc.c parse_lpcnet_weights.c -lm -o adaconvtest
\ No newline at end of file +/* gcc -DVAR_ARRAYS -DENABLE_OSCE -I ../include -I ../silk -I . -I ../celt adaconvtest.c nndsp.c lace_data.c nolace_data.c nnet.c nnet_default.c ../celt/pitch.c ../celt/celt_lpc.c parse_lpcnet_weights.c -lm -o adaconvtest */
\ No newline at end of file diff --git a/dnn/nndsp.c b/dnn/nndsp.c index 4fbe5346..6d987872 100644 --- a/dnn/nndsp.c +++ b/dnn/nndsp.c @@ -39,7 +39,7 @@ #include <math.h> #ifndef M_PI -#define M_PI 3.141592653 +#define M_PI 3.141592653589793f #endif #define SET_ZERO(x) memset(x, 0, sizeof(x)) @@ -60,6 +60,15 @@ void init_adashape_state(AdaShapeState *hAdaShape) OPUS_CLEAR(hAdaShape, 1); } +void compute_overlap_window(float *window, int overlap_size) +{ + int i_sample; + for (i_sample=0; i_sample < overlap_size; i_sample++) + { + window[i_sample] = 0.5f + 0.5f * cos(M_PI * (i_sample + 0.5f) / overlap_size); + } +} + #ifdef DEBUG_NNDSP void print_float_vector(const char* name, const float *vec, int length) { @@ -169,15 +178,6 @@ void adaconv_process_frame( print_float_vector("x_in", x_in, in_channels * frame_size); #endif - if (window == NULL) - { - for (i_sample=0; i_sample < overlap_size; i_sample++) - { - window_buffer[i_sample] = 0.5f + 0.5f * cos(M_PI * (i_sample + 0.5f) / overlap_size); - } - window = &window_buffer[0]; - } - /* prepare input */ for (i_in_channels=0; i_in_channels < in_channels; i_in_channels ++) { @@ -280,16 +280,6 @@ void adacomb_process_frame( SET_ZERO(kernel_buffer); SET_ZERO(input_buffer); - - if (window == NULL) - { - for (i_sample=0; i_sample < overlap_size; i_sample++) - { - window_buffer[i_sample] = 0.5f + 0.5f * cos(M_PI * (i_sample + 0.5f) / overlap_size); - } - window = &window_buffer[0]; - } - OPUS_COPY(input_buffer, hAdaComb->history, kernel_size + ADACOMB_MAX_LAG); OPUS_COPY(input_buffer + kernel_size + ADACOMB_MAX_LAG, x_in, frame_size); p_input = input_buffer + kernel_size + ADACOMB_MAX_LAG; diff --git a/dnn/nndsp.h b/dnn/nndsp.h index a35d8dda..f00094b6 100644 --- a/dnn/nndsp.h +++ b/dnn/nndsp.h @@ -81,6 +81,8 @@ void init_adacomb_state(AdaCombState *hAdaComb); void init_adashape_state(AdaShapeState *hAdaShape); +void compute_overlap_window(float *window, int overlap_size); + void adaconv_process_frame( AdaConvState* hAdaConv, float *x_out, @@ -91,10 +91,7 @@ static int init_lace(LACE *hLACE, const WeightArray *weights) ret = init_lacelayers(&hLACE->layers, weights); - for (i = 0; i < LACE_OVERLAP_SIZE; i ++) - { - hLACE->window[i] = 0.5f + 0.5f * cos(M_PI * (i + 0.5f) / LACE_OVERLAP_SIZE); - } + compute_overlap_window(hLACE->window, LACE_OVERLAP_SIZE); return ret; } @@ -357,13 +354,9 @@ static int init_nolace(NoLACE *hNoLACE, const WeightArray *weights) OPUS_CLEAR(hNoLACE, 1); celt_assert(weights != NULL); - ret = init_nolacelayers(&hNoLACE->layers, weights); - for (i = 0; i < NOLACE_OVERLAP_SIZE; i ++) - { - hNoLACE->window[i] = 0.5f + 0.5f * cos(M_PI * (i + 0.5f) / LACE_OVERLAP_SIZE); - } + compute_overlap_window(hNoLACE->window, NOLACE_OVERLAP_SIZE); return ret; } |