comparison src/cs/services/audio/audio_mode_load.c @ 212:7f3266e247d6

audio mode load: gracefully handle mode files of wrong AEC version Irrespective of which AEC policy we adopt for FC Selenite (keep L1_NEW_AEC disabled like in Magnetite or enable it like in Tourmaline), we MUST gracefully handle the case of wrong AEC version on audio mode load: disable AEC instead of loading garbage. Therefore, we apply the same change to src/cs/services/audio/audio_mode_load.c as we made in Tourmaline and Magnetite last year.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 31 Oct 2022 00:31:30 +0000
parents 1eb391057168
children
comparison
equal deleted inserted replaced
211:4035c19073aa 212:7f3266e247d6
96 #define CHECK_STATUS(function, param) if ( (function(&(param))) == AUDIO_ERROR ) \ 96 #define CHECK_STATUS(function, param) if ( (function(&(param))) == AUDIO_ERROR ) \
97 { \ 97 { \
98 return(AUDIO_ERROR); \ 98 return(AUDIO_ERROR); \
99 } \ 99 } \
100 100
101 /* FreeCalypso added definition for old vs new mode file handling */
102 #define MODE_FILE_SIZE_NEWAEC 176
103
101 /********************************************************************************/ 104 /********************************************************************************/
102 /* */ 105 /* */
103 /* Function Name: audio_mode_load_send_status */ 106 /* Function Name: audio_mode_load_send_status */
104 /* */ 107 /* */
105 /* Purpose: This function sends the audio mdoe load status to the entity. */ 108 /* Purpose: This function sends the audio mdoe load status to the entity. */
306 CHECK_STATUS(audio_mode_speaker_volume_write, *p_audio_volume) 309 CHECK_STATUS(audio_mode_speaker_volume_write, *p_audio_volume)
307 310
308 return(AUDIO_OK); 311 return(AUDIO_OK);
309 } 312 }
310 313
314 /* FreeCalypso added function */
315 static void set_default_aec(T_AUDIO_AEC_CFG *aec)
316 {
317 aec->aec_enable = 0;
318 #if (L1_NEW_AEC)
319 aec->continuous_filtering = 0;
320 aec->granularity_attenuation = 1;
321 aec->smoothing_coefficient = 0x7FFF;
322 aec->max_echo_suppression_level = AUDIO_MAX_ECHO_12dB;
323 aec->vad_factor = 0x4000;
324 aec->absolute_threshold = 0x32;
325 aec->factor_asd_filtering = 0x1000;
326 aec->factor_asd_muting = 0x1000;
327 aec->aec_visibility = 0;
328 #else
329 aec->aec_mode = 0;
330 aec->echo_suppression_level = 0;
331 #endif
332 aec->noise_suppression_enable = 0;
333 aec->noise_suppression_level = 0;
334 }
335
311 /********************************************************************************/ 336 /********************************************************************************/
312 /* */ 337 /* */
313 /* Function Name: audio_mode_load_manager */ 338 /* Function Name: audio_mode_load_manager */
314 /* */ 339 /* */
315 /* Purpose: This function manages the audio mode load services. */ 340 /* Purpose: This function manages the audio mode load services. */
330 void audio_mode_load_manager (T_RV_HDR *p_message) 355 void audio_mode_load_manager (T_RV_HDR *p_message)
331 { 356 {
332 T_AUDIO_SPEAKER_LEVEL audio_volume; 357 T_AUDIO_SPEAKER_LEVEL audio_volume;
333 T_RVF_MB_STATUS mb_status; 358 T_RVF_MB_STATUS mb_status;
334 UINT8 message_to_confirm; 359 UINT8 message_to_confirm;
360 T_FFS_SIZE rdsize;
335 #ifdef _WINDOWS 361 #ifdef _WINDOWS
336 INT8 *p_read, *p_write; 362 INT8 *p_read, *p_write;
337 UINT8 i; 363 UINT8 i;
338 #endif 364 #endif
339 365
341 { 367 {
342 case AUDIO_MODE_LOAD_IDLE: 368 case AUDIO_MODE_LOAD_IDLE:
343 { 369 {
344 /* allocate the buffer for the current Audio mode */ 370 /* allocate the buffer for the current Audio mode */
345 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal, 371 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
346 sizeof (T_AUDIO_MODE), 372 MODE_FILE_SIZE_NEWAEC,
347 (T_RVF_BUFFER **) (&(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode))); 373 (T_RVF_BUFFER **) (&(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode)));
348 /* If insufficient resources, then report a memory error and abort. */ 374 /* If insufficient resources, then report a memory error and abort. */
349 if (mb_status == RVF_RED) 375 if (mb_status == RVF_RED)
350 { 376 {
351 AUDIO_SEND_TRACE("AUDIO MODE LOAD: not enough memory to allocate the audio mode buffer", RV_TRACE_LEVEL_ERROR); 377 AUDIO_SEND_TRACE("AUDIO MODE LOAD: not enough memory to allocate the audio mode buffer", RV_TRACE_LEVEL_ERROR);
364 } 390 }
365 #endif 391 #endif
366 #else 392 #else
367 /* Load the audio mode structure from the FFS */ 393 /* Load the audio mode structure from the FFS */
368 394
369 if ( ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd, 395 rdsize = ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd,
370 (void *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode), 396 (void *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),
371 sizeof(T_AUDIO_MODE)) < EFFS_OK ) 397 MODE_FILE_SIZE_NEWAEC);
398 if ( rdsize < EFFS_OK )
372 { 399 {
373 AUDIO_SEND_TRACE("AUDIO MODE LOAD: impossible to load the current audio mode", RV_TRACE_LEVEL_ERROR); 400 AUDIO_SEND_TRACE("AUDIO MODE LOAD: impossible to load the current audio mode", RV_TRACE_LEVEL_ERROR);
374 401
375 /* Close the files */ 402 /* Close the files */
376 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd); 403 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd);
380 rvf_free_buf((T_RVF_BUFFER *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode)); 407 rvf_free_buf((T_RVF_BUFFER *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode));
381 408
382 /* send the status message */ 409 /* send the status message */
383 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path); 410 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
384 return; 411 return;
412 }
413 if ( rdsize != sizeof(T_AUDIO_MODE) )
414 {
415 /* wrong version - clear the AEC part */
416 set_default_aec(&p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode->audio_microphone_speaker_loop_setting.aec);
385 } 417 }
386 #endif 418 #endif
387 419
388 /* Set the audio mode structure */ 420 /* Set the audio mode structure */
389 if ( (audio_mode_set((p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode), 421 if ( (audio_mode_set((p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),