From a402265b87c89ca3ab73c49fb1575b7b8f6ac04d Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Fri, 30 Jul 2021 09:39:22 +0100 Subject: Fixed few glitches --- WasmAudio/main.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'WasmAudio/main.c') diff --git a/WasmAudio/main.c b/WasmAudio/main.c index 4cb9f2e..86d307f 100644 --- a/WasmAudio/main.c +++ b/WasmAudio/main.c @@ -51,7 +51,7 @@ //Maximum recording time plus padding -#define RECORDING_BUFFER_SECONDS (2) +#define RECORDING_BUFFER_SECONDS (1) //Maximum recording time #define MAX_RECORDING_SECONDS (RECORDING_BUFFER_SECONDS) #define RECORDING_BUFFER_CHANNELS (2) @@ -78,6 +78,7 @@ static SDL_AudioDeviceID recordingDeviceId = 0; static SDL_AudioDeviceID playbackDeviceId = 0; int audio_buf_position=0; int current_state=0; +int audio_buf_full=0; //FIR filter stuff FILE *f_1,*f_2; @@ -97,27 +98,30 @@ int audio_rec_buffer_max_size=-1; static uint8_t audio_rec_buffer_[BUFSIZE]; #define PROCESS_BUF_SIZE (BUFSIZE) uint8_t *audio_rec_buffer=NULL; -static double process_buf[PROCESS_BUF_SIZE+200]; -static double process_buf2[PROCESS_BUF_SIZE+200]; +static double process_buf[PROCESS_BUF_SIZE]; +static double process_buf2[PROCESS_BUF_SIZE]; void audio_recording_callback(void *data, uint8_t *insamples, int len) { - if (audio_buf_position BUFSIZE4) { printf("Buffer overflow convert_double_to_f32"); @@ -158,7 +162,7 @@ void convert_double_to_f32() { void convert_f32_to_double() { int i=0; - for (i=0;i audio_rec_buffer_size ) + if( (audio_buf_position > audio_rec_buffer_size) || (audio_buf_full) ) { //Stop recording audio SDL_PauseAudioDevice( recordingDeviceId, SDL_TRUE ); @@ -500,7 +506,7 @@ int main_tick() { SDL_LockAudioDevice( playbackDeviceId ); //Finished playback printf("audio_buf_position=%d\n",audio_buf_position); - if( audio_buf_position > audio_rec_buffer_size ) + if( (audio_buf_position > audio_rec_buffer_size) || (audio_buf_full) ) { //Stop playing audio //SDL_Delay(500); @@ -563,7 +569,7 @@ void main_loop() if (current_state == RECORDING) { SDL_LockAudioDevice( recordingDeviceId ); //printf("recording=%d\n",audio_buf_position); - if( audio_buf_position > audio_rec_buffer_size ) + if( (audio_buf_position > audio_rec_buffer_size) || (audio_buf_full) ) { //Stop recording audio SDL_PauseAudioDevice( recordingDeviceId, SDL_TRUE ); @@ -576,7 +582,7 @@ void main_loop() SDL_LockAudioDevice( playbackDeviceId ); //Finished playback //printf("audio_buf_position=%d audio_rec_buffer_size=%d\n",audio_buf_position,audio_rec_buffer_size); - if( audio_buf_position >= (audio_rec_buffer_size-SDL_CALLBACK_USED_BUFSIZE) ) + if( (audio_buf_position >= (audio_rec_buffer_size-SDL_CALLBACK_USED_BUFSIZE)) || (audio_buf_full) ) { //Stop playing audio SDL_PauseAudioDevice( playbackDeviceId, SDL_TRUE ); -- cgit v1.2.3