changeset 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 4035c19073aa
children f2a59f3c4f8f
files src/cs/services/audio/audio_mode_load.c
diffstat 1 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/cs/services/audio/audio_mode_load.c	Mon Oct 31 00:18:16 2022 +0000
+++ b/src/cs/services/audio/audio_mode_load.c	Mon Oct 31 00:31:30 2022 +0000
@@ -98,6 +98,9 @@
                                               return(AUDIO_ERROR); \
                                             } \
 
+/* FreeCalypso added definition for old vs new mode file handling */
+#define	MODE_FILE_SIZE_NEWAEC	176
+
   /********************************************************************************/
   /*                                                                              */
   /*    Function Name:   audio_mode_load_send_status                              */
@@ -308,6 +311,28 @@
     return(AUDIO_OK);
   }
 
+  /* FreeCalypso added function */
+  static void set_default_aec(T_AUDIO_AEC_CFG *aec)
+  {
+    aec->aec_enable = 0;
+    #if (L1_NEW_AEC)
+      aec->continuous_filtering = 0;
+      aec->granularity_attenuation = 1;
+      aec->smoothing_coefficient = 0x7FFF;
+      aec->max_echo_suppression_level = AUDIO_MAX_ECHO_12dB;
+      aec->vad_factor = 0x4000;
+      aec->absolute_threshold = 0x32;
+      aec->factor_asd_filtering = 0x1000;
+      aec->factor_asd_muting = 0x1000;
+      aec->aec_visibility = 0;
+    #else
+      aec->aec_mode = 0;
+      aec->echo_suppression_level = 0;
+    #endif
+    aec->noise_suppression_enable = 0;
+    aec->noise_suppression_level = 0;
+  }
+
   /********************************************************************************/
   /*                                                                              */
   /*    Function Name:   audio_mode_load_manager                                  */
@@ -332,6 +357,7 @@
     T_AUDIO_SPEAKER_LEVEL audio_volume;
     T_RVF_MB_STATUS       mb_status;
     UINT8                 message_to_confirm;
+    T_FFS_SIZE            rdsize;
     #ifdef _WINDOWS
       INT8  *p_read, *p_write;
       UINT8 i;
@@ -343,7 +369,7 @@
       {
         /* allocate the buffer for the current Audio mode */
         mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
-                                 sizeof (T_AUDIO_MODE),
+                                 MODE_FILE_SIZE_NEWAEC,
                                  (T_RVF_BUFFER **) (&(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode)));
         /* If insufficient resources, then report a memory error and abort.               */
         if (mb_status == RVF_RED)
@@ -366,9 +392,10 @@
         #else
           /* Load the audio mode structure from the FFS */
 
-          if ( ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd,
-                         (void *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),
-                         sizeof(T_AUDIO_MODE)) < EFFS_OK )
+          rdsize = ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd,
+                             (void *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),
+                             MODE_FILE_SIZE_NEWAEC);
+          if ( rdsize < EFFS_OK )
           {
             AUDIO_SEND_TRACE("AUDIO MODE LOAD: impossible to load the current audio mode", RV_TRACE_LEVEL_ERROR);
 
@@ -383,6 +410,11 @@
             audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
             return;
           }
+          if ( rdsize != sizeof(T_AUDIO_MODE) )
+          {
+            /* wrong version - clear the AEC part */
+            set_default_aec(&p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode->audio_microphone_speaker_loop_setting.aec);
+          }
         #endif
 
         /* Set the audio mode structure */