qahw: test: Set default preset and strength for effects

Modify test app to set default preset and strength for
every effect type.

Change-Id: If28f5e1feb0d24b4cad79a817c8e8b24c57af78a
diff --git a/qahw_api/test/qahw_effect_test.c b/qahw_api/test/qahw_effect_test.c
index 89c5d89..61b73a7 100644
--- a/qahw_api/test/qahw_effect_test.c
+++ b/qahw_api/test/qahw_effect_test.c
@@ -120,6 +120,9 @@
     int32_t                  rc;
     int                      reply_data;
     uint32_t                 reply_size = sizeof(int);
+    uint32_t array_size = sizeof(qahw_effect_param_t) + 2 * sizeof(int32_t);
+    uint32_t      buf32[array_size];
+    qahw_effect_param_t *values;
 
     pthread_mutex_lock(&thr_ctxt->mutex);
     while(!thr_ctxt->exit) {
@@ -154,6 +157,24 @@
             if (rc != 0) {
                 fprintf(stderr, "effect_command() returns %d\n", rc);
             }
+            if (thr_ctxt->default_flag && (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE)) {
+                if (thr_ctxt->default_value == -1)
+                    thr_ctxt->default_value = 600;
+
+                values = (qahw_effect_param_t *)buf32;
+                values->psize = sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = BASSBOOST_PARAM_STRENGTH;
+                memcpy((values->data + values->psize), &thr_ctxt->default_value, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }else {
+                     thr_ctxt->default_flag = false;
+                }
+            }
             break;
         case(EFFECT_PROC):
             //qahw_effect_process();
@@ -188,6 +209,9 @@
     int32_t                  rc;
     int                      reply_data;
     uint32_t                 reply_size = sizeof(int);
+    uint32_t array_size = sizeof(qahw_effect_param_t) + 2 * sizeof(int32_t);
+    uint32_t      buf32[array_size];
+    qahw_effect_param_t *values;
 
     pthread_mutex_lock(&thr_ctxt->mutex);
     while(!thr_ctxt->exit) {
@@ -222,6 +246,24 @@
             if (rc != 0) {
                 fprintf(stderr, "effect_command() returns %d\n", rc);
             }
+            if (thr_ctxt->default_flag && (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE)) {
+                if (thr_ctxt->default_value == -1)
+                    thr_ctxt->default_value = 600;
+
+                values = (qahw_effect_param_t *)buf32;
+                values->psize = sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = VIRTUALIZER_PARAM_STRENGTH;
+                memcpy((values->data + values->psize), &thr_ctxt->default_value, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }else {
+                     thr_ctxt->default_flag = false;
+                }
+            }
             break;
         case(EFFECT_PROC):
             //qahw_effect_process();
@@ -256,6 +298,9 @@
     int32_t                  rc;
     int                      reply_data;
     uint32_t                 reply_size = sizeof(int);
+    uint32_t array_size = sizeof(qahw_effect_param_t) + 2 * sizeof(int32_t);
+    uint32_t      buf32[array_size];
+    qahw_effect_param_t *values;
 
     pthread_mutex_lock(&thr_ctxt->mutex);
     while(!thr_ctxt->exit) {
@@ -290,6 +335,24 @@
             if (rc != 0) {
                 fprintf(stderr, "effect_command() returns %d\n", rc);
             }
+            if (thr_ctxt->default_flag && (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE)) {
+                if (thr_ctxt->default_value == -1)
+                    thr_ctxt->default_value = 2;
+
+                values = (qahw_effect_param_t *)buf32;
+                values->psize = sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = EQ_PARAM_CUR_PRESET;
+                memcpy((values->data + values->psize), &thr_ctxt->default_value, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }else {
+                     thr_ctxt->default_flag = false;
+                }
+            }
             break;
         case(EFFECT_PROC):
             //qahw_effect_process();
@@ -330,6 +393,9 @@
     int32_t                  rc;
     int                      reply_data;
     uint32_t                 reply_size = sizeof(int);
+    uint32_t array_size = sizeof(qahw_effect_param_t) + 2 * sizeof(int32_t);
+    uint32_t      buf32[array_size];
+    qahw_effect_param_t *values;
 
     pthread_mutex_lock(&thr_ctxt->mutex);
     while(!thr_ctxt->exit) {
@@ -364,6 +430,24 @@
             if (rc != 0) {
                 fprintf(stderr, "effect_command() returns %d\n", rc);
             }
+            if (thr_ctxt->default_flag && (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE)) {
+                if (thr_ctxt->default_value == -1)
+                    thr_ctxt->default_value = 2;
+
+                values = (qahw_effect_param_t *)buf32;
+                values->psize = sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = REVERB_PARAM_PRESET;
+                memcpy((values->data + values->psize), &thr_ctxt->default_value, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }else {
+                     thr_ctxt->default_flag = false;
+                }
+            }
             break;
         case(EFFECT_PROC):
             //qahw_effect_process();
@@ -402,7 +486,6 @@
     uint32_t      preset;
     int           level;
     uint16_t      band_idx;
-    int           enable;
     qahw_effect_param_t *param = (qahw_effect_param_t *)buf32;
     qahw_effect_param_t *param_2 = (qahw_effect_param_t *)buf32_2;
 
@@ -421,28 +504,10 @@
         cmd_key = get_key_from_name(fx_ctxt->who_am_i, cmd_str);
         switch (cmd_key) {
         case TTY_ENABLE:
-            enable = 1;
             notify_effect_command(fx_ctxt, EFFECT_CMD, QAHW_EFFECT_CMD_ENABLE, 0, NULL);
-            if (fx_ctxt->who_am_i == EFFECT_AUDIOSPHERE) {
-                param->psize = 2 * sizeof(int32_t);
-                *(int32_t *)param->data = ASPHERE_PARAM_ENABLE;
-                param->vsize = sizeof(int32_t);
-                memcpy((param->data + param->psize), &enable, param->vsize);
-
-                notify_effect_command(fx_ctxt, EFFECT_CMD, QAHW_EFFECT_CMD_SET_PARAM, size, param);
-            }
             break;
         case TTY_DISABLE:
-            enable = 0;
             notify_effect_command(fx_ctxt, EFFECT_CMD, QAHW_EFFECT_CMD_DISABLE, 0, NULL);
-            if (fx_ctxt->who_am_i == EFFECT_AUDIOSPHERE) {
-                param->psize = 2 * sizeof(int32_t);
-                *(int32_t *)param->data = ASPHERE_PARAM_ENABLE;
-                param->vsize = sizeof(int32_t);
-                memcpy((param->data + param->psize), &enable, param->vsize);
-
-                notify_effect_command(fx_ctxt, EFFECT_CMD, QAHW_EFFECT_CMD_SET_PARAM, size, param);
-            }
             break;
         case TTY_BB_SET_STRENGTH:
         case TTY_VT_SET_STRENGTH:
@@ -689,6 +754,10 @@
     int32_t                  rc;
     int                      reply_data;
     uint32_t                 reply_size = sizeof(int);
+    uint32_t array_size = sizeof(qahw_effect_param_t) + 2 * sizeof(int32_t);
+    uint32_t      buf32[array_size];
+    qahw_effect_param_t *values;
+    int enable;
 
     pthread_mutex_lock(&thr_ctxt->mutex);
     while(!thr_ctxt->exit) {
@@ -723,6 +792,37 @@
             if (rc != 0) {
                 fprintf(stderr, "effect_command() returns %d\n", rc);
             }
+            if (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE || thr_ctxt->cmd_code == QAHW_EFFECT_CMD_DISABLE) {
+                enable = ((thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE) ? 1 : 0);
+                values->psize = 2 * sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = ASPHERE_PARAM_ENABLE;
+                memcpy((values->data + values->psize), &enable, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }
+            }
+            if (thr_ctxt->default_flag && (thr_ctxt->cmd_code == QAHW_EFFECT_CMD_ENABLE)) {
+                if (thr_ctxt->default_value == -1)
+                    thr_ctxt->default_value = 600;
+
+                values = (qahw_effect_param_t *)buf32;
+                values->psize = sizeof(int32_t);
+                values->vsize = sizeof(int32_t);
+                *(int32_t *)values->data = ASPHERE_PARAM_STRENGTH;
+                memcpy((values->data + values->psize), &thr_ctxt->default_value, values->vsize);
+                rc = qahw_effect_command(effect_handle, QAHW_EFFECT_CMD_SET_PARAM,
+                                     array_size, (void *)values,
+                                     thr_ctxt->reply_size, thr_ctxt->reply_data);
+                if (rc != 0) {
+                    fprintf(stderr, "effect_command() returns %d\n", rc);
+                }else {
+                     thr_ctxt->default_flag = false;
+                }
+            }
             break;
         case(EFFECT_PROC):
             //qahw_effect_process();
diff --git a/qahw_api/test/qahw_effect_test.h b/qahw_api/test/qahw_effect_test.h
index 07557a5..ede65df 100644
--- a/qahw_api/test/qahw_effect_test.h
+++ b/qahw_api/test/qahw_effect_test.h
@@ -68,6 +68,8 @@
     void              *cmd_data;
     uint32_t          *reply_size;
     void              *reply_data;
+    int               default_value;
+    bool              default_flag;
 } thread_data_t;
 
 typedef struct cmd_data {
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index 6eb2bd8..b1b238f 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -62,6 +62,8 @@
 #define SUBCHUNK1_SIZE(x) ((8) + (x))
 #define SUBCHUNK2_SIZE 8
 
+#define DEFAULT_PRESET_STRENGTH -1
+
 static int get_wav_header_length (FILE* file_stream);
 static void init_streams(void);
 int pthread_cancel(pthread_t thread);
@@ -174,6 +176,7 @@
     bool flags_set;
     usb_mode_type_t usb_mode;
     int effect_index;
+    int effect_preset_strength;
     bool drift_query;
     bool drift_correction;
     bool play_later;
@@ -330,6 +333,7 @@
         stream_param[i].kvpair_values                       =   nullptr;
         stream_param[i].flags_set                           =   false;
         stream_param[i].usb_mode                            =   USB_MODE_DEVICE;
+        stream_param[i].effect_preset_strength              =   DEFAULT_PRESET_STRENGTH;
         stream_param[i].effect_index                        =   -1;
         stream_param[i].ethread_func                        =   nullptr;
         stream_param[i].ethread_data                        =   nullptr;
@@ -715,6 +719,7 @@
     bool exit = false;
     int32_t latency;
 
+
     if (is_offload) {
         fprintf(log_file, "stream %d: set callback for offload stream for playback usecase\n", params->stream_index);
         qahw_out_set_callback(params->out_handle, async_callback, params);
@@ -755,7 +760,9 @@
             // broadcast device info
             notify_effect_command(params->ethread_data, EFFECT_CMD, QAHW_EFFECT_CMD_SET_DEVICE, sizeof(audio_devices_t), &(params->output_device));
 
-            // enable effect
+            // Enable and Set default values
+            params->ethread_data->default_value = params->effect_preset_strength;
+            params->ethread_data->default_flag = true;
             notify_effect_command(params->ethread_data, EFFECT_CMD, QAHW_EFFECT_CMD_ENABLE, 0, NULL);
         }
     }
@@ -1540,6 +1547,8 @@
     printf(" -E  --event-trigger                       - Trigger DTMF event during playback\n");
     printf(" -e  --effect-type <effect type>           - Effect used for test\n");
     printf("                                             0:bassboost 1:virtualizer 2:equalizer 3:visualizer(NA) 4:reverb 5:audiosphere others:null\n\n");
+    printf(" -p  --effect-preset <effect preset type>  - Effect preset type for respective effect-type\n");
+    printf(" -S  --effect-strength <effect strength>   - Effect strength for respective effect-type\n");
     printf(" -A  --bt-addr <bt device addr>            - Required to set bt device adress for aptx decoder\n\n");
     printf(" -q  --drift query                         - Required for querying avtime vs hdmi drift\n");
     printf(" -Q  --drift query and correction          - Enable Drift query and correction\n");
@@ -1757,6 +1766,8 @@
         {"drift correction",   no_argument,     0, 'Q'},
         {"device-nodeurl",required_argument,    0, 'u'},
         {"mode",          required_argument,    0, 'm'},
+        {"effect-preset",   required_argument,    0, 'p'},
+        {"effect-strength", required_argument,    0, 'S'},
         {"help",          no_argument,          0, 'h'},
         {0, 0, 0, 0}
     };
@@ -1780,7 +1791,7 @@
 
     while ((opt = getopt_long(argc,
                               argv,
-                              "-f:r:c:b:d:s:v:l:t:a:w:k:PD:KF:Ee:A:u:m:qQh",
+                              "-f:r:c:b:d:s:v:l:t:a:w:k:PD:KF:Ee:A:u:m:S:p:qQh",
                               long_options,
                               &option_index)) != -1) {
 
@@ -1861,6 +1872,12 @@
                 stream_param[i].ethread_func = effect_thread_funcs[stream_param[i].effect_index];
             }
             break;
+        case 'p':
+            stream_param[i].effect_preset_strength = atoi(optarg);
+            break;
+        case 'S':
+            stream_param[i].effect_preset_strength = atoi(optarg);
+            break;
         case 'A':
             ba = optarg;
             break;