From e4619445203c9b17788cbcedeac4f4918b2ac2b3 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 22 Jul 2021 09:40:38 +0100 Subject: clean the code --- WasmAudio/main.c | 110 ++++++++++++++++--------------------------------------- 1 file changed, 31 insertions(+), 79 deletions(-) (limited to 'WasmAudio/main.c') diff --git a/WasmAudio/main.c b/WasmAudio/main.c index 38f5e1a..2ab9449 100644 --- a/WasmAudio/main.c +++ b/WasmAudio/main.c @@ -61,18 +61,15 @@ static SDL_Renderer *renderer = NULL; static SDL_AudioDeviceID recordingDeviceId = 0; static SDL_AudioDeviceID playbackDeviceId = 0; int audio_buf_position=0; -//uint8_t *audio_play_buffer=NULL; int current_state=0; int audio_rec_buffer_size=-1; int audio_rec_buffer_max_size=-1; -//int audio_play_buffer_size=-1; -//int audio_play_buffer_max_size=-1; static uint8_t audio_rec_buffer_[BUFSIZE]; const int process_buf_size = BUFSIZE4; -static double process_buf[process_buf_size*4]; -static double process_buf2[process_buf_size*4]; +static double process_buf[process_buf_size+100]; +static double process_buf2[process_buf_size+100]; uint8_t *audio_rec_buffer=NULL; @@ -111,56 +108,42 @@ enum RecordingState void convert_double_to_f32() { int i=0; - printf("float sizeof=%lu\n",sizeof(float)); - printf("double sizeof=%lu\n",sizeof(double)); for (i=0;i BUFSIZE4) { + printf("Buffer overflow convert_double_to_f32"); + exit(1); + } float f = d; - //printf("%f ",f); - //f = f*2147483647.0; int32_t *i32_ = &f,i32=*i32_; - //printf("%d %f\n",i32,f); - - //audio_rec_buffer[i+0] = ((int)i32>> 24)&0xff; - //audio_rec_buffer[i+1] = ((int)i32>> 16)&0xff; - //audio_rec_buffer[i+2] = ((int)i32>> 8)&0xff; - //audio_rec_buffer[i+3] = ((int)i32&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); - - //audio_rec_buffer[i+0] = ((int)f>> 24)&0xff; - //audio_rec_buffer[i+1] = ((int)f>> 16)&0xff; - //audio_rec_buffer[i+2] = ((int)f>> 8)&0xff; - //audio_rec_buffer[i+3] = ((int)f&0xff); - - //memcpy(&f,&audio_rec_buffer[i],4); + } //printf("\n"); - for (i=0;i<100;i+=4) { - fprintf(f_2, "%d %02x %02x %02x %02x\n", i/4,audio_rec_buffer[i],audio_rec_buffer[i+1],audio_rec_buffer[i+2],audio_rec_buffer[i+3]); - } } void convert_f32_to_double() { int i=0; - for (i=0;i<100;i+=4) { - fprintf(f_1, "%d %02x %02x %02x %02x\n", i/4,audio_rec_buffer[i],audio_rec_buffer[i+1],audio_rec_buffer[i+2],audio_rec_buffer[i+3]); - } for (i=0;i