luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 1 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2 | #include "ql/ql_audio.h" |
| 3 | #include "mbtk_log.h" |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 4 | #include "mbtk_audio2.h" |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 6 | typedef enum { |
| 7 | AUDIO_PLAY_STATE_STOP, |
| 8 | AUDIO_PLAY_STATE_RUNNING, |
| 9 | AUDIO_PLAY_STATE_PAUSE |
| 10 | } audio_play_state_enum; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 11 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 12 | #define AUDIO_HANDLE 1 |
| 13 | #define WAV_PLAY_BUFF 1024 |
| 14 | |
luojian | 82fd38a | 2024-07-25 14:20:51 +0800 | [diff] [blame] | 15 | #ifdef MBTK_AF_SUPPORT |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 16 | static mbtk_audio_handle player_hdl = NULL; |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 17 | static int player_hdl_1 = AUDIO_HANDLE; |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 18 | static _cb_onRecorder record_cb_fun = NULL; |
| 19 | static int Samprate = 8000; |
luojian | 82fd38a | 2024-07-25 14:20:51 +0800 | [diff] [blame] | 20 | #endif |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 21 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 22 | static int sample_rate = 8000; |
| 23 | static int play_handle = AUDIO_HANDLE; |
| 24 | static _cb_onPlayer play_cb_func = NULL; |
| 25 | static _cb_onRecorder recorder_cb_fun = NULL; |
| 26 | static int is_running = 0; |
| 27 | static audio_play_state_enum play_state = AUDIO_PLAY_STATE_STOP; |
| 28 | static int play_exit = 1; |
| 29 | |
| 30 | static void recorder_cb_func(void *data, uint32 data_len) |
| 31 | { |
| 32 | if(recorder_cb_fun) { |
| 33 | recorder_cb_fun(AUD_RECORDER_START, (unsigned char*)data, data_len); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | static int play_stream(unsigned char* pData, unsigned int length) |
| 38 | { |
| 39 | int rc, len, frames = 0; |
| 40 | int result = 0; |
| 41 | |
| 42 | play_state = AUDIO_PLAY_STATE_RUNNING; |
| 43 | play_exit = 0; |
| 44 | int data_send = 0; |
| 45 | |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 46 | if (mbtk_audio_pcm_play_start()) { |
| 47 | printf("%s: error opening output device.", __FUNCTION__); |
| 48 | return -1; |
| 49 | } |
| 50 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 51 | if(pData && length > 0) { |
| 52 | while (play_state != AUDIO_PLAY_STATE_STOP) { |
| 53 | if(play_state == AUDIO_PLAY_STATE_RUNNING) { |
| 54 | if (data_send >= length) { |
| 55 | LOGE("%s: Read pcm stream end.", __FUNCTION__); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | if(length - data_send > WAV_PLAY_BUFF) { |
| 60 | len = WAV_PLAY_BUFF; |
| 61 | } else { |
| 62 | len = length - data_send; |
| 63 | } |
| 64 | |
| 65 | if((rc = mbtk_audio_pcm_play_data_send(pData + data_send, len)) != len) { |
| 66 | LOGE("Send data %d/%d", rc, len); |
| 67 | result = -1; |
| 68 | goto thread_end; |
| 69 | } |
| 70 | |
| 71 | data_send += len; |
| 72 | |
| 73 | LOGD("%s: No.%d frame playback", __FUNCTION__, ++frames); |
| 74 | } else { |
| 75 | usleep(200000); |
| 76 | } |
| 77 | } |
| 78 | } else { |
| 79 | result = -1; |
| 80 | } |
| 81 | |
| 82 | play_state = AUDIO_PLAY_STATE_STOP; |
| 83 | |
luojian | 21604d9 | 2024-06-25 14:11:25 +0800 | [diff] [blame] | 84 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 85 | thread_end: |
| 86 | mbtk_audio_pcm_play_stop(); |
| 87 | play_exit = 1; |
| 88 | LOGD("%s: finished pcm playback.", __FUNCTION__); |
| 89 | return result; |
| 90 | } |
| 91 | |
| 92 | static int play_by_fd(int fd, int offset) |
| 93 | { |
| 94 | int rc, len, frames = 0; |
| 95 | int result = 0; |
| 96 | char buf[WAV_PLAY_BUFF]; |
| 97 | |
| 98 | play_state = AUDIO_PLAY_STATE_RUNNING; |
luojian | 21604d9 | 2024-06-25 14:11:25 +0800 | [diff] [blame] | 99 | if(play_cb_func) |
| 100 | play_cb_func(play_handle , AUDIO_PLAY_STATE_RUNNING); |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 101 | play_exit = 0; |
| 102 | if(fd > 0) { |
| 103 | if(offset > 0) { |
| 104 | lseek(fd, offset, SEEK_SET); |
| 105 | } |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 106 | |
| 107 | if (mbtk_audio_pcm_play_start()) { |
| 108 | printf("%s: error opening output device.", __FUNCTION__); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 113 | while (play_state != AUDIO_PLAY_STATE_STOP) { |
| 114 | if(play_state == AUDIO_PLAY_STATE_RUNNING) { |
| 115 | memset(buf, 0x00, sizeof(buf)); |
| 116 | len = read(fd, buf, WAV_PLAY_BUFF); |
| 117 | if (len == -1) { |
| 118 | LOGE("%s: error reading from file", __FUNCTION__); |
| 119 | result = -1; |
| 120 | goto thread_end; |
| 121 | } |
| 122 | |
| 123 | if (len == 0) { |
| 124 | /* reached EOF */ |
| 125 | LOGE("%s: Read wav file end.", __FUNCTION__); |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | if((rc = mbtk_audio_pcm_play_data_send(buf, len)) < len) { |
| 130 | LOGE("Send data %d/%d", rc, len); |
| 131 | result = -1; |
| 132 | goto thread_end; |
| 133 | } |
| 134 | |
| 135 | LOGD("%s: No.%d frame playback", __FUNCTION__, ++frames); |
| 136 | } else { |
| 137 | usleep(200000); |
| 138 | } |
| 139 | } |
| 140 | } else { |
| 141 | result = -1; |
| 142 | } |
| 143 | |
| 144 | play_state = AUDIO_PLAY_STATE_STOP; |
luojian | 21604d9 | 2024-06-25 14:11:25 +0800 | [diff] [blame] | 145 | if(play_cb_func) |
| 146 | play_cb_func(play_handle , AUDIO_PLAY_STATE_STOP); |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 147 | |
| 148 | thread_end: |
| 149 | mbtk_audio_pcm_play_stop(); |
| 150 | play_exit = 1; |
| 151 | LOGD("%s: finished pcm playback.", __FUNCTION__); |
| 152 | return result; |
| 153 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 154 | |
| 155 | /***************************************************************** |
| 156 | * Function: Ql_AudPlayer_Open |
| 157 | * |
| 158 | * Description: |
| 159 | * Open audio play device, and specify the callback function. |
| 160 | * This function can be called twice to play different audio sources. |
| 161 | * |
| 162 | * Parameters: |
| 163 | * device : a string that specifies the PCM device. |
| 164 | * NULL, means the audio will be played on the default PCM device. |
| 165 | * |
| 166 | * If you want to mixedly play audio sources, you can call this |
| 167 | * API twice with specifying different PCM device. |
| 168 | * The string devices available: |
| 169 | * "hw:0,0" (the default play device) |
| 170 | * "hw:0,13" (this device can mix audio and TTS) |
| 171 | * "hw:0,14" |
| 172 | * |
| 173 | * cb_func : callback function for audio player. |
| 174 | * The results of all operations on audio player |
| 175 | * are informed in callback function. |
| 176 | * |
| 177 | * Return: |
| 178 | * pcm device handle on success |
| 179 | * -1 for failure |
| 180 | *****************************************************************/ |
| 181 | int Ql_AudPlayer_Open(char* device, _cb_onPlayer cb_func) |
| 182 | { |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 183 | #ifdef MBTK_AF_SUPPORT |
| 184 | player_hdl = mbtk_audio_open_new(MBTK_AUTIO_TYPE_OUT, 1, Samprate, cb_func); |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 185 | if(player_hdl == NULL) |
| 186 | { |
| 187 | return -1; |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | return player_hdl_1 = AUDIO_HANDLE; |
| 192 | } |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 193 | #else |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 194 | if(is_running || mbtk_audio_pcm_init()) { |
| 195 | return -1; |
| 196 | } else { |
| 197 | play_cb_func = cb_func; |
| 198 | is_running = 1; |
| 199 | return play_handle; |
| 200 | } |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 201 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /*======================================================================== |
| 205 | FUNCTION: Ql_AudPlayer_Play |
| 206 | =========================================================================*/ |
| 207 | /** @brief |
| 208 | This function writes pcm data to pcm device to play. |
| 209 | |
| 210 | @param[in] hdl, the handle returned by Ql_AudPlayer_Open(). |
| 211 | @param[in] pData, pointer to the start address of pcm data. |
| 212 | @param[in] length, the length of pcm data. |
| 213 | |
| 214 | @return |
| 215 | on success, the return value is the number of bytes to play |
| 216 | on failure, the return value is -1; |
| 217 | |
| 218 | @dependencies |
| 219 | Ql_AudPlayer_Open() must be first called successfully. |
| 220 | */ |
| 221 | /*=======================================================================*/ |
| 222 | int Ql_AudPlayer_Play(int hdl, unsigned char* pData, unsigned int length) |
| 223 | { |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 224 | #ifdef MBTK_AF_SUPPORT |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 225 | if(hdl != player_hdl_1 || player_hdl == NULL){ |
| 226 | LOGE("Handle error : %d", hdl); |
| 227 | return -1; |
| 228 | } |
| 229 | return mbtk_audio_play_stream_new((void *)player_hdl, pData, length,50); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 230 | |
| 231 | #else |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 232 | if(!is_running || hdl != play_handle) { |
| 233 | LOGE("Handle error : %d", hdl); |
| 234 | return -1; |
| 235 | } |
| 236 | |
| 237 | return play_stream(pData, length); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 238 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /*======================================================================== |
| 242 | FUNCTION: Ql_AudPlayer_PlayFrmFile |
| 243 | =========================================================================*/ |
| 244 | /** @brief |
| 245 | This function plays the pcm data from the specified file. |
| 246 | |
| 247 | @param[in] hdl, the handle returned by Ql_AudPlayer_Open(). |
| 248 | @param[in] fd, a file descriptor that contains pcm data. |
| 249 | Note: |
| 250 | the file offset should be set to the start position of pcm |
| 251 | data region, which means you should move the file offset |
| 252 | skipping the file header (such as wave header, amr header). |
| 253 | @param[in] offset, file offset. Please set it to -1 if no need to use. |
| 254 | |
| 255 | @return |
| 256 | 0 on success |
| 257 | -1 on failure |
| 258 | |
| 259 | @dependencies |
| 260 | Ql_AudPlayer_Open() must be first called successfully. |
| 261 | */ |
| 262 | /*=======================================================================*/ |
zhangzh | 8711cea | 2023-10-20 10:47:43 +0800 | [diff] [blame] | 263 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 264 | int Ql_AudPlayer_PlayFrmFile(int hdl, int fd, int offset) |
| 265 | { |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 266 | #ifdef MBTK_AF_SUPPORT |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 267 | if(hdl != player_hdl_1 || player_hdl == NULL){ |
| 268 | LOGE("Handle error : %d", hdl); |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | return mbtk_audio_play_file_new((void *)player_hdl, fd, offset); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 273 | |
| 274 | #else |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 275 | if(!is_running || hdl != play_handle) { |
| 276 | LOGE("Handle error : %d", hdl); |
| 277 | return -1; |
| 278 | } |
| 279 | |
| 280 | return play_by_fd(fd, offset); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 281 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // |
| 285 | // Function: Ql_AudPlayer_Pause |
| 286 | // |
| 287 | // Description: |
| 288 | // Pause playing. |
| 289 | // @param hdl: |
| 290 | // Handle received from Ql_AudPlayer_Open(). |
| 291 | int Ql_AudPlayer_Pause(int hdl) |
| 292 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 293 | if(!is_running || hdl != play_handle) { |
| 294 | LOGE("Handle error : %d", hdl); |
| 295 | return -1; |
| 296 | } |
| 297 | |
| 298 | play_state = AUDIO_PLAY_STATE_PAUSE; |
| 299 | |
| 300 | while(!play_exit) { |
| 301 | usleep(10000); |
| 302 | } |
| 303 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 304 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // |
| 308 | // Function: Ql_AudPlayer_Resume |
| 309 | // |
| 310 | // Description: |
| 311 | // Resume playing. |
| 312 | // @param hdl: |
| 313 | // Handle received from Ql_AudPlayer_Open(). |
| 314 | int Ql_AudPlayer_Resume(int hdl) |
| 315 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 316 | if(!is_running || hdl != play_handle) { |
| 317 | LOGE("Handle error : %d", hdl); |
| 318 | return -1; |
| 319 | } |
| 320 | |
| 321 | play_state = AUDIO_PLAY_STATE_RUNNING; |
| 322 | |
| 323 | while(!play_exit) { |
| 324 | usleep(10000); |
| 325 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 326 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | // |
| 330 | // Function: Ql_AudPlayer_Stop |
| 331 | // |
| 332 | // Description: |
| 333 | // Stop playing audio |
| 334 | // hdl: |
| 335 | // Handle received from Ql_AudPlayer_Open(). |
| 336 | void Ql_AudPlayer_Stop(int hdl) |
| 337 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 338 | if(!is_running || hdl != play_handle) { |
| 339 | LOGE("Handle error : %d", hdl); |
| 340 | return; |
| 341 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 342 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 343 | play_state = AUDIO_PLAY_STATE_STOP; |
| 344 | |
| 345 | while(!play_exit) { |
| 346 | usleep(10000); |
| 347 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | // |
| 351 | // Function: Ql_AudPlayer_Close |
| 352 | // |
| 353 | // Description: |
| 354 | // Close player, and free the resource. |
| 355 | // @param hdl: |
| 356 | // Handle received from Ql_AudPlayer_Open(). |
| 357 | void Ql_AudPlayer_Close(int hdl) |
| 358 | { |
luojian | a567faa | 2024-07-25 11:45:02 +0800 | [diff] [blame] | 359 | #ifdef MBTK_AF_SUPPORT |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 360 | if(hdl != player_hdl_1 || player_hdl == NULL){ |
| 361 | LOGE("Handle error : %d", hdl); |
| 362 | return -1; |
| 363 | } |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 364 | |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 365 | mbtk_audio_close_new((void *)player_hdl); |
| 366 | player_hdl_1 = 0; |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 367 | |
luojian | a567faa | 2024-07-25 11:45:02 +0800 | [diff] [blame] | 368 | #else |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 369 | if(!is_running || hdl != play_handle) { |
| 370 | LOGE("Handle error : %d", hdl); |
| 371 | return; |
| 372 | } |
| 373 | play_state = AUDIO_PLAY_STATE_STOP; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 374 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 375 | while(!play_exit) { |
| 376 | usleep(10000); |
| 377 | } |
| 378 | |
| 379 | is_running = 0; |
| 380 | mbtk_audio_pcm_deinit(); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 381 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
| 385 | int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize) |
| 386 | { |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | int Ql_AudPlayer_get_freeSpace(int hdl) |
| 392 | { |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /***************************************************************** |
| 399 | * Function: Ql_AudRecorder_Open |
| 400 | * |
| 401 | * Description: |
| 402 | * Open audio record device, and specify the callback function. |
| 403 | * |
| 404 | * Parameters: |
| 405 | * device : not used. MUST be NULL. |
| 406 | * |
| 407 | * cb_func : callback function for audio player. |
| 408 | * The results of all operations on audio recorder |
| 409 | * are informed in callback function. |
| 410 | * |
| 411 | * Return: |
| 412 | * pcm device handle |
| 413 | * -1 for failure |
| 414 | *****************************************************************/ |
| 415 | int Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun) |
| 416 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 417 | if(is_running || mbtk_audio_pcm_init()) { |
| 418 | return -1; |
| 419 | } else { |
| 420 | is_running = 1; |
| 421 | recorder_cb_fun = cb_fun; |
| 422 | return play_handle; |
| 423 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | // |
| 427 | // Function: Ql_AudRecorder_StartRecord |
| 428 | // |
| 429 | // Description: |
| 430 | // Start to record. |
| 431 | // The record data is output in _cb_onRecorder. |
| 432 | // |
| 433 | // Return: |
| 434 | // 0 on success |
| 435 | // -1 on failure |
| 436 | int Ql_AudRecorder_StartRecord(void) |
| 437 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 438 | if(!is_running) { |
| 439 | LOGE("No open device."); |
| 440 | return -1; |
| 441 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 442 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 443 | return mbtk_audio_pcm_recorder_start(recorder_cb_func); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | // |
| 447 | // Function: Ql_AudRecorder_Pause |
| 448 | // |
| 449 | // Description: |
| 450 | // Pause recording |
| 451 | int Ql_AudRecorder_Pause(void) |
| 452 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 453 | if(!is_running) { |
| 454 | LOGE("No open device."); |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | return mbtk_audio_pcm_recorder_pause(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | // |
| 462 | // Function: Ql_AudRecorder_Resume |
| 463 | // |
| 464 | // Description: |
| 465 | // Resume recording |
| 466 | int Ql_AudRecorder_Resume(void) |
| 467 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 468 | if(!is_running) { |
| 469 | LOGE("No open device."); |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | return mbtk_audio_pcm_recorder_resume(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // |
| 477 | // Function: Ql_AudRecorder_Stop |
| 478 | // |
| 479 | // Description: |
| 480 | // Stop recording |
| 481 | void Ql_AudRecorder_Stop(void) |
| 482 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 483 | if(!is_running) { |
| 484 | LOGE("No open device."); |
| 485 | return; |
| 486 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 487 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 488 | mbtk_audio_pcm_recorder_stop(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | // |
| 492 | // Function: Ql_AudRecorder_Close |
| 493 | // |
| 494 | // Description: |
| 495 | // Close recorder, and free the resource |
| 496 | void Ql_AudRecorder_Close(void) |
| 497 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 498 | if(!is_running) { |
| 499 | LOGE("No open device."); |
| 500 | return; |
| 501 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 502 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 503 | is_running = 0; |
| 504 | mbtk_audio_pcm_deinit(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // |
| 508 | // Function: Ql_clt_set_mixer_value |
| 509 | // |
| 510 | // Description: |
| 511 | // Close recorder, and free the resource |
| 512 | boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value) |
| 513 | { |
| 514 | |
| 515 | return FALSE; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | int Ql_AudTone_Open(char* device, _cb_onPlayer cb)//cb not support now |
| 520 | { |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para) |
| 525 | { |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | void Ql_AudTone_Stop(int hdl) |
| 530 | { |
| 531 | |
| 532 | } |
| 533 | |
| 534 | void Ql_AudTone_Close(int hdl) |
| 535 | { |
| 536 | |
| 537 | } |
| 538 | |
| 539 | |
| 540 | //****************QL Codec API************************// |
| 541 | |
| 542 | // |
| 543 | // Function: Ql_AudCodec_Set_ALC5616_DRCAGC |
| 544 | // |
| 545 | // Description: |
| 546 | // Set ALC5616 DRC/AGC configuration |
| 547 | int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg) |
| 548 | { |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | // |
| 553 | // Function: Ql_Update_wav_size |
| 554 | // |
| 555 | // Description: |
| 556 | // update wav format file size in the header |
| 557 | // @param fd: |
| 558 | // wav file discriptor |
| 559 | // @param size: |
| 560 | // wav file size to update |
| 561 | int Ql_Update_wav_size(int fd, int size) |
| 562 | { |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | //add by grady, 2018-5-29 |
| 567 | /* |
| 568 | * describe : this function is use to open pcm device |
| 569 | * paras : |
| 570 | * device : this should be fix to hw:0,0 |
| 571 | * flags ; pcm play flags |
| 572 | * rate: sample rate |
| 573 | * channels : audio channal 1 or 2 |
| 574 | * format: format to play or record, 16bit line,MP3 |
| 575 | * hostless: if there is no file it is true |
| 576 | * return : |
| 577 | * pcm : pcm handle, use can use this handle to read write data |
| 578 | */ |
| 579 | struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless) |
| 580 | { |
| 581 | return NULL; |
| 582 | } |
| 583 | |
| 584 | /* |
| 585 | * describe : this function is use to close pcm handle |
| 586 | * paras : |
| 587 | * pcm : pcm handle to close |
| 588 | * return : |
| 589 | */ |
| 590 | int quec_pcm_close(struct pcm *pcm ) |
| 591 | { |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * describe : this function is use to read pcm buffer |
| 597 | * paras : |
| 598 | * pcm : pcm handle to write date |
| 599 | * buffer: data buffer |
| 600 | * lenth: data length |
| 601 | * return : |
| 602 | */ |
| 603 | int quec_read_pcm(struct pcm *pcm, void * buffer, int length) |
| 604 | { |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | * describe : this function is use to get pcm buffer lenth |
| 611 | * paras : |
| 612 | * lenth: data length |
| 613 | * return |
| 614 | * buffer length |
| 615 | */ |
| 616 | int quec_get_pem_buffer_len(struct pcm *pcm) |
| 617 | { |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | void dtmf_cb1(char dtmf) |
| 623 | { |
| 624 | printf("%s:%c\n", __FUNCTION__, dtmf); |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * @brief Set RX DSP Gain |
| 629 | * @details |
| 630 | * Gain support [-36,12] dB |
| 631 | * |
| 632 | * @param gain |
| 633 | * DSP gain |
| 634 | */ |
| 635 | |
| 636 | int Ql_Rxgain_Set(int value) |
| 637 | { |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 638 | #ifdef MBTK_AF_SUPPORT |
| 639 | int volume =0; |
luojian | de23623 | 2024-07-27 10:51:57 +0800 | [diff] [blame] | 640 | if(value < -36 || value > 13) |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 641 | { |
| 642 | volume = 0; |
| 643 | } |
| 644 | else |
| 645 | { |
| 646 | volume = value; |
| 647 | } |
| 648 | |
| 649 | if(player_hdl==NULL) |
| 650 | return 0; |
| 651 | |
| 652 | char databuf[1025]={0}; |
| 653 | memcpy(databuf, " ", 1024); |
| 654 | |
| 655 | mbtk_audio_play_stream_new(player_hdl, databuf, 1024, volume); |
| 656 | return 0; |
| 657 | #else |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 658 | mbtk_dsp_gain_set(1, value); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 659 | return 0; |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 660 | #endif |
| 661 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
| 665 | /** Ql_Playback_Samprate_Set |
| 666 | * @brief Set Playback PCM Samprate |
| 667 | * @details |
| 668 | * 0 for NB 1 for WB |
| 669 | * |
| 670 | * @param samprate |
| 671 | * samprate for PCM playback,default value is PCM NB |
| 672 | */ |
| 673 | int Ql_Playback_Samprate_Set(int samprate) |
| 674 | { |
| 675 | printf("samprate is %d \n",samprate); |
| 676 | if(samprate == 1) |
| 677 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 678 | sample_rate = 16000; |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 679 | mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_16000); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 680 | } |
| 681 | else{ |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 682 | mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_8000); |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 683 | sample_rate = 8000; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path) |
| 690 | { |
b.liu | c1064f8 | 2023-10-11 16:47:39 +0800 | [diff] [blame] | 691 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate) |
| 695 | { |
b.liu | c1064f8 | 2023-10-11 16:47:39 +0800 | [diff] [blame] | 696 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | //add by grady, 2018-6-2 |
| 700 | /* |
| 701 | * describe : this function is use to open mixer device |
| 702 | * paras : |
| 703 | * device: mixer device |
| 704 | * return |
| 705 | * mixer handle |
| 706 | */ |
| 707 | struct mixer *quec_mixer_open(const char *device) |
| 708 | { |
| 709 | |
| 710 | return NULL; |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | * describe : this function is use to close mixer device |
| 715 | * paras : |
| 716 | * mixer: mixer handle |
| 717 | * return |
| 718 | * none |
| 719 | */ |
| 720 | void quec_mixer_close(struct mixer *mixer) |
| 721 | { |
| 722 | |
| 723 | |
| 724 | } |
| 725 | |
| 726 | /* |
| 727 | * describe : this function is use to get mixer devie control |
| 728 | * paras : |
| 729 | * mixer: mixer handle |
| 730 | * name: mixer device |
| 731 | * index: mixer index |
| 732 | * return |
| 733 | * mixer control |
| 734 | */ |
| 735 | struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index) |
| 736 | { |
| 737 | |
| 738 | return NULL; |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | * describe : this function is use to set mulvalues |
| 743 | * paras : |
| 744 | * mixer: mixer handle |
| 745 | * count: count |
| 746 | * argv: data |
| 747 | * return : |
| 748 | * |
| 749 | */ |
| 750 | int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv) |
| 751 | { |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | |
| 757 | //end grady |
| 758 | |
| 759 | /***************************************************************** |
| 760 | * Function: Ql_AudPlayer_OpenExt |
| 761 | * |
| 762 | * Description: |
| 763 | * expend function from Ql_AudPlayer_OpenExt |
| 764 | * Open audio play device, and specify the callback function. |
| 765 | * This function can be called twice to play different audio sources. |
| 766 | * |
| 767 | * Parameters: |
| 768 | * device : a string that specifies the PCM device. |
| 769 | * NULL, means the audio will be played on the default PCM device. |
| 770 | * |
| 771 | * If you want to mixedly play audio sources, you can call this |
| 772 | * API twice with specifying different PCM device. |
| 773 | * The string devices available: |
| 774 | * "hw:0,0" (the default play device) |
| 775 | * "hw:0,13" (this device can mix audio and TTS) |
| 776 | * "hw:0,14" |
| 777 | * |
| 778 | * cb_func : callback function for audio player. |
| 779 | * The results of all operations on audio player |
| 780 | * are informed in callback function. |
| 781 | * |
| 782 | * flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP. |
| 783 | * |
| 784 | * channels: pcm sample channels. |
| 785 | * |
| 786 | * rate : pcm sample rate. |
| 787 | * |
| 788 | * format : pcm sample fromat |
| 789 | * |
| 790 | * Return: |
| 791 | * pcm device handle |
| 792 | * NULL, fail |
| 793 | *****************************************************************/ |
| 794 | int Ql_AudPlayer_OpenExt( |
| 795 | char *dev, |
| 796 | _cb_onPlayer cb_fun, |
| 797 | int flags, |
| 798 | int channels, |
| 799 | int rate, |
| 800 | int format) |
| 801 | { |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | /***************************************************************** |
| 806 | * Function: Ql_AudRecorder_Open |
| 807 | * |
| 808 | * Description: |
| 809 | * Open audio record device, and specify the callback function. |
| 810 | * |
| 811 | * Parameters: |
| 812 | * device : not used. MUST be NULL. |
| 813 | * |
| 814 | * cb_func : callback function for audio player. |
| 815 | * The results of all operations on audio recorder |
| 816 | * are informed in callback function. |
| 817 | * |
| 818 | * flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP. |
| 819 | * |
| 820 | * channels: pcm sample channels. |
| 821 | * |
| 822 | * rate : pcm sample rate. |
| 823 | * |
| 824 | * format : pcm sample fromat |
| 825 | * |
| 826 | * Return: |
| 827 | * pcm device handle |
| 828 | * NULL, fail |
| 829 | *****************************************************************/ |
| 830 | int Ql_AudRecorder_OpenExt( |
| 831 | char *dev, |
| 832 | _cb_onRecorder cb_fun, |
| 833 | int flags, |
| 834 | int channels, |
| 835 | int rate, |
| 836 | int format) |
| 837 | { |
| 838 | |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | /* |
| 844 | * Function: uac enable |
| 845 | * |
| 846 | * Description: |
| 847 | * uac enable |
| 848 | * |
| 849 | * Parameters: |
| 850 | * none |
| 851 | * Return: |
| 852 | * TURE or FALSE |
| 853 | */ |
| 854 | int ql_uac_enable(void) |
| 855 | { |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | /* |
| 861 | * Function: uac disable |
| 862 | * |
| 863 | * Description: |
| 864 | * uac disable |
| 865 | * |
| 866 | * Parameters: |
| 867 | * none |
| 868 | * Return: |
| 869 | * TURE or FALSE |
| 870 | */ |
| 871 | int ql_uac_disable(void) |
| 872 | { |
| 873 | |
| 874 | return 0; |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 875 | } |