audio: There is no effect of post gain on headphone [1/1]

PD#TV-118468

Problem:
We do not use adev->eq_data.p_gain.headphone.

Solution:
adev->eq_data.p_gain.headphone is used to calculate the volume of hp.

Verify:
Yocto-t5w

Change-Id: Ia95b286d6215ce7d5da790b02e7fb0d6d84acd45
Signed-off-by: yayun.shi <yayun.shi@amlogic.com>
diff --git a/audio_hal/aml_audio_output.c b/audio_hal/aml_audio_output.c
index b5e022f..720e4ae 100644
--- a/audio_hal/aml_audio_output.c
+++ b/audio_hal/aml_audio_output.c
@@ -412,7 +412,7 @@
             int16_t *effect_tmp_buf;
             int32_t *spk_tmp_buf;
             int16_t *hp_tmp_buf = NULL;
-            int16_t *ps32SpdifTempBuffer = NULL;
+            int32_t *ps32SpdifTempBuffer = NULL;
             float gain_speaker = adev->eq_data.p_gain.speaker;
 
             /* handling audio effect process here */
@@ -428,13 +428,13 @@
 
                 adev->spk_output_buf = aml_audio_realloc(adev->spk_output_buf, bytes * 2);
                 if (!adev->spk_output_buf) {
-                    ALOGE ("realloc headphone buf failed size %zu format = %#x", bytes, output_format);
+                    ALOGE ("realloc speaker buf failed size %zu format = %#x", bytes * 2, output_format);
                     return -ENOMEM;
                 }
 
-                adev->spdif_output_buf = aml_audio_realloc(adev->spdif_output_buf, bytes);
+                adev->spdif_output_buf = aml_audio_realloc(adev->spdif_output_buf, bytes * 2);
                 if (!adev->spdif_output_buf) {
-                    ALOGE ("realloc spdif buf failed size %zu format = %#x", bytes, output_format);
+                    ALOGE ("realloc spdif buf failed size %zu format = %#x", bytes * 2, output_format);
                     return -ENOMEM;
                 }
 
@@ -459,8 +459,7 @@
                 memcpy(hp_tmp_buf, tmp_buffer, bytes);
             }
 
-            ps32SpdifTempBuffer = (int16_t *)adev->spdif_output_buf;
-            memcpy(ps32SpdifTempBuffer, hp_tmp_buf, bytes);
+            ps32SpdifTempBuffer = (int32_t *)adev->spdif_output_buf;
 #ifdef ENABLE_AVSYNC_TUNING
             tuning_spker_latency(adev, effect_tmp_buf, tmp_buffer, bytes);
 #else
@@ -503,7 +502,8 @@
             volume = gain_speaker * adev->sink_gain[OUTPORT_SPEAKER];
 
             apply_volume_16to32(volume, effect_tmp_buf, spk_tmp_buf, bytes);
-            apply_volume(adev->sink_gain[OUTPORT_HEADPHONE], hp_tmp_buf, sizeof(uint16_t), bytes);
+            apply_volume_16to32(adev->eq_data.p_gain.spdif_arc, hp_tmp_buf, ps32SpdifTempBuffer, bytes);
+            apply_volume(adev->sink_gain[OUTPORT_HEADPHONE] * adev->eq_data.p_gain.headphone, hp_tmp_buf, sizeof(uint16_t), bytes);
 
 #ifdef ADD_AUDIO_DELAY_INTERFACE
             aml_audio_delay_process(AML_DELAY_OUTPORT_SPEAKER, spk_tmp_buf,
@@ -536,8 +536,8 @@
                 for (i = 0; i < out_frames; i++) {
                     adev->tmp_buffer_8ch[8 * i + 0] = spk_tmp_buf[2 * i];
                     adev->tmp_buffer_8ch[8 * i + 1] = spk_tmp_buf[2 * i + 1];
-                    adev->tmp_buffer_8ch[8 * i + 2] = ps32SpdifTempBuffer[2 * i] << 16;
-                    adev->tmp_buffer_8ch[8 * i + 3] = ps32SpdifTempBuffer[2 * i + 1] << 16;
+                    adev->tmp_buffer_8ch[8 * i + 2] = ps32SpdifTempBuffer[2 * i];
+                    adev->tmp_buffer_8ch[8 * i + 3] = ps32SpdifTempBuffer[2 * i + 1];
                     adev->tmp_buffer_8ch[8 * i + 4] = hp_tmp_buf[2 * i] << 16;
                     adev->tmp_buffer_8ch[8 * i + 5] = hp_tmp_buf[2 * i + 1] << 16;
                     adev->tmp_buffer_8ch[8 * i + 6] = tmp_buffer[2 * i] << 16;
diff --git a/audio_hal/audio_hw.c b/audio_hal/audio_hw.c
index 47fffda..06cee26 100644
--- a/audio_hal/audio_hw.c
+++ b/audio_hal/audio_hw.c
@@ -8470,13 +8470,13 @@
     }
     memset(adev->spk_output_buf, 0, buffer_size * 2);
 
-    adev->spdif_output_buf = aml_audio_malloc(buffer_size);
+    adev->spdif_output_buf = aml_audio_malloc(buffer_size * 2);
     if (adev->spdif_output_buf == NULL) {
         ALOGE("no memory for spdif output buffer");
         ret = -ENOMEM;
         goto err_spk_buf;
     }
-    memset(adev->spdif_output_buf, 0, buffer_size);
+    memset(adev->spdif_output_buf, 0, buffer_size * 2);
 
     adev->hp_output_buf = aml_audio_malloc(buffer_size);
     if (adev->hp_output_buf == NULL) {