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