[T106][ZXW-198][audio] Add audio interface to play PCM buffer
Only Configure: No
Affected branch: master
Affected module: audio
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: Yes
Change-Id: I79520549a6346faba89ada617c693e134e2e4e3e
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
index 63ce463..a43b1a4 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
@@ -207,6 +207,96 @@
}
/********************************************************************
+* @brief: qser_AudPlayer_Play_Pcmbuf, play audio from PCM buffer
+* @param period_size [IN]: int, size of the period for the PCM buffer, use default value if -1
+* @param period_count [IN]: int, count of the period for the PCM buffer, use default value if -1
+* @param num_channels [IN]: int, number of audio channels, use default value if -1
+* @param sample_rate [IN]: int, sample rate for the audio, use default value if -1
+* @param ownerid [IN]: int, ID of the audio owner, use default value if not in valid range
+* @return : success 0, failed -1
+* @todo: NA
+* @see: NA
+* @warning: NA
+*********************************************************************/
+int qser_AudPlayer_PlayPcmBuf(const unsigned char *pcm_data, int data_size, int period_size, \
+ int period_count, int num_channels, int sample_rate, int ownerid)
+{
+ if (pcm_data == NULL)
+ {
+ LYINFLOG("Error: pcm_data parameter is a null pointer \n");
+ return -1;
+ }
+
+ int error_line;
+ int audio_is_init = 0;
+
+ sc_audio_pcm_config_t pcm_config;
+ int ret = 0;
+ sc_audio_owner_id owner_id;
+
+ if(ownerid <= SC_AUDIO_OWNER_ID_NONE || ownerid >= SC_AUDIO_OWNER_ID_MAX)
+ {
+ owner_id = SC_AUDIO_OWNER_ID_PLAYER;
+ } else
+ {
+ owner_id = ownerid;
+ }
+
+ playback_handle = sc_audio_playback_open(SC_AUDIO_FE_PCM_DEV_MULTIMEDIA2,SC_AUDIO_FE_PCM_DEV_MIN, owner_id);
+ if (SC_AUDIO_INVALID_HANDLE == playback_handle)
+ {
+ error_line = __LINE__;
+ goto exit;
+ }
+
+ if(-1 == period_size || -1 == period_count || -1 == num_channels || -1 == sample_rate)
+ {
+ ret = sc_audio_playback_stream_prepare(playback_handle, NULL, playback_state_cb, NULL);
+ } else
+ {
+ pcm_config.period_size = period_size;
+ pcm_config.period_count = period_count;
+ pcm_config.flags = 0;
+ pcm_config.num_channels = num_channels;
+ pcm_config.sample_rate = sample_rate;
+ pcm_config.pcm_format = 2;
+
+ ret = sc_audio_playback_stream_prepare(playback_handle, &pcm_config, playback_state_cb, NULL);
+ }
+
+ if (SC_ERR_SUCCESS != ret)
+ {
+ error_line = __LINE__;
+ goto exit;
+ }
+
+ ret = sc_audio_playback_push_stream(playback_handle, (void *)pcm_data, data_size);
+ if (SC_ERR_SUCCESS != ret)
+ {
+ error_line = __LINE__;
+ goto exit;
+ }
+
+ ret = sc_audio_playback_play(playback_handle);
+ if (SC_ERR_SUCCESS != ret)
+ {
+ error_line = __LINE__;
+ goto exit;
+ }
+
+ return 0;
+
+exit:
+ if (SC_AUDIO_INVALID_HANDLE != playback_handle)
+ {
+ sc_audio_playback_close(playback_handle);
+ }
+
+ LYINFLOG("player_playback_play_pcmbuf error_line=%d\n",error_line);
+ return -1;
+}
+
+/********************************************************************
* @brief: qser_AudRecorder_StartRecord_Custom, used to capture audio from a file and play it
* @param file [IN]: char*, the path of the audio file
* @param period_size [IN]: int, the period size of the PCM buffer