From ef53f705cf5708875a43fc314d741964ffa71637 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Mon, 26 Jul 2021 09:50:19 +0100 Subject: Update to be compatible with web --- WasmAudio/main.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 14 deletions(-) (limited to 'WasmAudio') diff --git a/WasmAudio/main.c b/WasmAudio/main.c index c8a5191..9ddf5ba 100644 --- a/WasmAudio/main.c +++ b/WasmAudio/main.c @@ -35,6 +35,13 @@ //#include #endif + +#ifdef __EMSCRIPTEN__ +#define KEEPALIVE EMSCRIPTEN_KEEPALIVE +#else +#define KEEPALIVE +#endif + #include "../FIR/firmath.h" #define SCREEN_WIDTH 320 @@ -53,6 +60,7 @@ //Maximum recording time #define MAX_RECORDING_SECONDS (RECORDING_BUFFER_SECONDS+2) +//SDL drawing recording int first_run=1; static int quit=0; static SDL_Window *window = NULL; @@ -63,7 +71,7 @@ static SDL_AudioDeviceID playbackDeviceId = 0; int audio_buf_position=0; int current_state=0; - +//audio buffer vars int audio_rec_buffer_size=-1; int audio_rec_buffer_max_size=-1; static uint8_t audio_rec_buffer_[BUFSIZE]; @@ -72,9 +80,16 @@ static double process_buf[PROCESS_BUF_SIZE+100]; static double process_buf2[PROCESS_BUF_SIZE+100]; uint8_t *audio_rec_buffer=NULL; +//FIR filter stuff FILE *f_1,*f_2; fir_t fir_lp; firw_t firw_lp; +const int N=200; +double h[N],w[N]; +int filter_N=60; +int filter_FS_hz=48000; +int filter_FC_hz=1000; +double filter_FC; void audio_recording_callback(void *data, uint8_t *insamples, int len) { if (audio_buf_position> 24)&0xff; - audio_rec_buffer[i+2] = ((int)i32>> 16)&0xff; - audio_rec_buffer[i+1] = ((int)i32>> 8)&0xff; + audio_rec_buffer[i+3] = ((int)i32>>24)&0xff; + audio_rec_buffer[i+2] = ((int)i32>>16)&0xff; + audio_rec_buffer[i+1] = ((int)i32>>8)&0xff; audio_rec_buffer[i+0] = ((int)i32&0xff); } //printf("\n"); - } @@ -146,6 +160,69 @@ void convert_f32_to_double() { } +int KEEPALIVE get_sample_rate() { + return filter_FS_hz; +} + +void set_sample_rate() { + +} + +void set_cutoff_freq(int cutoff) { + if (cutoff < 0) { + cutoff = 0; + filter_FC_hz = cutoff; + return; + } + + if (cutoff > filter_FS_hz/2) { + cutoff = filter_FS_hz/2; + filter_FC_hz = cutoff; + filter_FC=1.0*cutoff/filter_FS_hz; + return; + } +} + +int KEEPALIVE get_cutoff_freq() { + return filter_FC_hz; +} + +int KEEPALIVE get_tap_number() { + return filter_N; +} + +void set_tap_number(int tapN) { + if (tapN<10) { + tapN = 10; + return; + + } +} + +int KEEPALIVE recalculate_fir() { + int i = 0; + filter_FC=1.0*filter_FC_hz/filter_FS_hz; + fir_lp.num_taps =filter_N; + fir_lp.fir_coef = h; + firw_lp.num_taps = filter_N; + firw_lp.win_coef = w; + + for (i=0;i %d\n",audio_rec_want.freq,audio_rec_have.freq); @@ -545,5 +623,5 @@ int main(int argc, const char * argv[]) { fclose(f_1); fclose(f_2); - return 0; + //return 0; } -- cgit v1.2.3