Add audio ap control
Change-Id: I96e94aa7ccd9916c2f4de5c61fcac5e09a2aed89
diff --git a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c b/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
index 9f2336d..e178b56 100755
--- a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
+++ b/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
@@ -22,6 +22,9 @@
static audio_inter_info_t *audio_info = NULL;
static pthread_t recorder_thread_play;
+static mbtk_audio_pa_switch_func audio_pa_switch_func = NULL;
+static mbtk_audio_volume_set_func audio_volume_set_func = NULL;
+static int audio_pcm_write_count = 0;
static int lock_get() {
int fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
@@ -246,6 +249,16 @@
return -1;
}
+void mbtk_audio_pa_func_set(mbtk_audio_pa_switch_func pa_switch_func)
+{
+ audio_pa_switch_func = pa_switch_func;
+}
+
+void mbtk_audio_volume_set_func_set(mbtk_audio_volume_set_func volume_set_func)
+{
+ audio_volume_set_func = volume_set_func;
+}
+
int mbtk_audio_pcm_sample_rate_set(mbtk_audio_sample_rate_enum sample_rate)
{
if(!audio_info) {
@@ -282,6 +295,7 @@
audio_info->direction = MBTK_AUDIO_DIRECTION_OUTPUT;
audio_info->info.play.buff_remain_len = 0;
+ audio_pcm_write_count = 0;
return 0;
play_start_fail:
@@ -327,6 +341,21 @@
goto send_fail;
}
+ if(audio_pcm_write_count < 3) {
+ audio_pcm_write_count++;
+ if(audio_pcm_write_count == 3) {
+ // Set audio volume.
+ if(audio_volume_set_func) {
+ audio_volume_set_func();
+ }
+
+ // Open PA
+ if(audio_pa_switch_func) {
+ audio_pa_switch_func(TRUE);
+ }
+ }
+ }
+
index += (audio_info->playback_size - audio_info->info.play.buff_remain_len);
audio_info->info.play.buff_remain_len = 0;
}
@@ -390,7 +419,12 @@
audio_info->info.play.buff_remain_len = 0;
}
- vcm_playback_drain(0);//wait for drain the AP audiostub queue.
+ // Close PA
+ if(audio_pa_switch_func) {
+ audio_pa_switch_func(FALSE);
+ }
+
+ vcm_playback_drain(80);//wait for drain the AP audiostub queue.
usleep(80000);//delay 80ms until DSP play out its buffered data.
audio_info->info.play.stream_out->common.standby(&(audio_info->info.play.stream_out->common));
audio_info->audio_ahw_dev_ubus->close_output_stream(audio_info->audio_ahw_dev_ubus, audio_info->info.play.stream_out);