diff options
-rw-r--r-- | WasmAudio/main.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/WasmAudio/main.c b/WasmAudio/main.c index ab17933..5c9628a 100644 --- a/WasmAudio/main.c +++ b/WasmAudio/main.c @@ -87,7 +87,7 @@ firw_t firw_lp; //const int N=200; #define N (200) double h[N],w[N]; -int filter_N=60; +int filter_N=180; int filter_FS_hz=48000; int filter_FC_hz=1000; double filter_FC; @@ -105,6 +105,8 @@ void audio_playback_callback(void *data, uint8_t *outsamples, int len) { if (audio_buf_position<audio_rec_buffer_size) { memcpy( outsamples, audio_rec_buffer+audio_buf_position,len); audio_buf_position += len; + } else { + memset( outsamples, 0, len*sizeof(double)); } } @@ -346,6 +348,42 @@ void fir_filter(fir_t *fir, double *input, uint32_t ilength, double *output, uin memmove(&input[0], &input[ilength], (fir->num_taps-1)*sizeof(double)); } +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +void fir_filter2(fir_t *fir, double *input, uint32_t ilength, double *output, uint32_t olength) { + double acc; + double *coeffp; + double *inputp; + int i,j; + + //memcpy(&input[fir->num_taps-1], input, ilength*sizeof(double)); + /* + for (n=0; n<ilength; n++) + { + coeffp = fir->fir_coef; + inputp = &input[fir->num_taps - 1 + n]; + acc = 0; + + for (k=0;k<fir->num_taps;k++) + { + acc += (*coeffp++)*(*inputp--); + } + + output[n] = acc; + } + */ + for (i=0;i<ilength-fir->num_taps;i++) { + acc = 0.0f; + for (j=0;j<fir->num_taps;j++) { + acc = fir->fir_coef[j]*input[ilength-j-1]; + } + if (i<olength) { + output[i] = acc; + } + } + + //memmove(&input[0], &input[ilength], (fir->num_taps-1)*sizeof(double)); +} + uint32_t tick_start, tick_end,tick_1sec; #if __EMSCRIPTEN__ |