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 | a567faa | 2024-07-25 11:45:02 +0800 | [diff] [blame^] | 342 | #ifdef MBTK_AF_SUPPORT |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 343 | mbtk_audio_close_new((void *)hdl); |
| 344 | |
| 345 | |
luojian | a567faa | 2024-07-25 11:45:02 +0800 | [diff] [blame^] | 346 | #else |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 347 | if(!is_running || hdl != play_handle) { |
| 348 | LOGE("Handle error : %d", hdl); |
| 349 | return; |
| 350 | } |
| 351 | play_state = AUDIO_PLAY_STATE_STOP; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 352 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 353 | while(!play_exit) { |
| 354 | usleep(10000); |
| 355 | } |
| 356 | |
| 357 | is_running = 0; |
| 358 | mbtk_audio_pcm_deinit(); |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 359 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | |
| 363 | int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize) |
| 364 | { |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | int Ql_AudPlayer_get_freeSpace(int hdl) |
| 370 | { |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | /***************************************************************** |
| 377 | * Function: Ql_AudRecorder_Open |
| 378 | * |
| 379 | * Description: |
| 380 | * Open audio record device, and specify the callback function. |
| 381 | * |
| 382 | * Parameters: |
| 383 | * device : not used. MUST be NULL. |
| 384 | * |
| 385 | * cb_func : callback function for audio player. |
| 386 | * The results of all operations on audio recorder |
| 387 | * are informed in callback function. |
| 388 | * |
| 389 | * Return: |
| 390 | * pcm device handle |
| 391 | * -1 for failure |
| 392 | *****************************************************************/ |
| 393 | int Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun) |
| 394 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 395 | if(is_running || mbtk_audio_pcm_init()) { |
| 396 | return -1; |
| 397 | } else { |
| 398 | is_running = 1; |
| 399 | recorder_cb_fun = cb_fun; |
| 400 | return play_handle; |
| 401 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // |
| 405 | // Function: Ql_AudRecorder_StartRecord |
| 406 | // |
| 407 | // Description: |
| 408 | // Start to record. |
| 409 | // The record data is output in _cb_onRecorder. |
| 410 | // |
| 411 | // Return: |
| 412 | // 0 on success |
| 413 | // -1 on failure |
| 414 | int Ql_AudRecorder_StartRecord(void) |
| 415 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 416 | if(!is_running) { |
| 417 | LOGE("No open device."); |
| 418 | return -1; |
| 419 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 420 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 421 | return mbtk_audio_pcm_recorder_start(recorder_cb_func); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | // |
| 425 | // Function: Ql_AudRecorder_Pause |
| 426 | // |
| 427 | // Description: |
| 428 | // Pause recording |
| 429 | int Ql_AudRecorder_Pause(void) |
| 430 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 431 | if(!is_running) { |
| 432 | LOGE("No open device."); |
| 433 | return -1; |
| 434 | } |
| 435 | |
| 436 | return mbtk_audio_pcm_recorder_pause(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // |
| 440 | // Function: Ql_AudRecorder_Resume |
| 441 | // |
| 442 | // Description: |
| 443 | // Resume recording |
| 444 | int Ql_AudRecorder_Resume(void) |
| 445 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 446 | if(!is_running) { |
| 447 | LOGE("No open device."); |
| 448 | return -1; |
| 449 | } |
| 450 | |
| 451 | return mbtk_audio_pcm_recorder_resume(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // |
| 455 | // Function: Ql_AudRecorder_Stop |
| 456 | // |
| 457 | // Description: |
| 458 | // Stop recording |
| 459 | void Ql_AudRecorder_Stop(void) |
| 460 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 461 | if(!is_running) { |
| 462 | LOGE("No open device."); |
| 463 | return; |
| 464 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 465 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 466 | mbtk_audio_pcm_recorder_stop(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | // |
| 470 | // Function: Ql_AudRecorder_Close |
| 471 | // |
| 472 | // Description: |
| 473 | // Close recorder, and free the resource |
| 474 | void Ql_AudRecorder_Close(void) |
| 475 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 476 | if(!is_running) { |
| 477 | LOGE("No open device."); |
| 478 | return; |
| 479 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 480 | |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 481 | is_running = 0; |
| 482 | mbtk_audio_pcm_deinit(); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | // |
| 486 | // Function: Ql_clt_set_mixer_value |
| 487 | // |
| 488 | // Description: |
| 489 | // Close recorder, and free the resource |
| 490 | boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value) |
| 491 | { |
| 492 | |
| 493 | return FALSE; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | int Ql_AudTone_Open(char* device, _cb_onPlayer cb)//cb not support now |
| 498 | { |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para) |
| 503 | { |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | void Ql_AudTone_Stop(int hdl) |
| 508 | { |
| 509 | |
| 510 | } |
| 511 | |
| 512 | void Ql_AudTone_Close(int hdl) |
| 513 | { |
| 514 | |
| 515 | } |
| 516 | |
| 517 | |
| 518 | //****************QL Codec API************************// |
| 519 | |
| 520 | // |
| 521 | // Function: Ql_AudCodec_Set_ALC5616_DRCAGC |
| 522 | // |
| 523 | // Description: |
| 524 | // Set ALC5616 DRC/AGC configuration |
| 525 | int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg) |
| 526 | { |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | // |
| 531 | // Function: Ql_Update_wav_size |
| 532 | // |
| 533 | // Description: |
| 534 | // update wav format file size in the header |
| 535 | // @param fd: |
| 536 | // wav file discriptor |
| 537 | // @param size: |
| 538 | // wav file size to update |
| 539 | int Ql_Update_wav_size(int fd, int size) |
| 540 | { |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | //add by grady, 2018-5-29 |
| 545 | /* |
| 546 | * describe : this function is use to open pcm device |
| 547 | * paras : |
| 548 | * device : this should be fix to hw:0,0 |
| 549 | * flags ; pcm play flags |
| 550 | * rate: sample rate |
| 551 | * channels : audio channal 1 or 2 |
| 552 | * format: format to play or record, 16bit line,MP3 |
| 553 | * hostless: if there is no file it is true |
| 554 | * return : |
| 555 | * pcm : pcm handle, use can use this handle to read write data |
| 556 | */ |
| 557 | struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless) |
| 558 | { |
| 559 | return NULL; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * describe : this function is use to close pcm handle |
| 564 | * paras : |
| 565 | * pcm : pcm handle to close |
| 566 | * return : |
| 567 | */ |
| 568 | int quec_pcm_close(struct pcm *pcm ) |
| 569 | { |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | /* |
| 574 | * describe : this function is use to read pcm buffer |
| 575 | * paras : |
| 576 | * pcm : pcm handle to write date |
| 577 | * buffer: data buffer |
| 578 | * lenth: data length |
| 579 | * return : |
| 580 | */ |
| 581 | int quec_read_pcm(struct pcm *pcm, void * buffer, int length) |
| 582 | { |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /* |
| 588 | * describe : this function is use to get pcm buffer lenth |
| 589 | * paras : |
| 590 | * lenth: data length |
| 591 | * return |
| 592 | * buffer length |
| 593 | */ |
| 594 | int quec_get_pem_buffer_len(struct pcm *pcm) |
| 595 | { |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | void dtmf_cb1(char dtmf) |
| 601 | { |
| 602 | printf("%s:%c\n", __FUNCTION__, dtmf); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * @brief Set RX DSP Gain |
| 607 | * @details |
| 608 | * Gain support [-36,12] dB |
| 609 | * |
| 610 | * @param gain |
| 611 | * DSP gain |
| 612 | */ |
| 613 | |
| 614 | int Ql_Rxgain_Set(int value) |
| 615 | { |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 616 | #ifdef MBTK_AF_SUPPORT |
| 617 | int volume =0; |
| 618 | if(value < -36 || value > 9) |
| 619 | { |
| 620 | volume = 0; |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | volume = value; |
| 625 | } |
| 626 | |
| 627 | if(player_hdl==NULL) |
| 628 | return 0; |
| 629 | |
| 630 | char databuf[1025]={0}; |
| 631 | memcpy(databuf, " ", 1024); |
| 632 | |
| 633 | mbtk_audio_play_stream_new(player_hdl, databuf, 1024, volume); |
| 634 | return 0; |
| 635 | #else |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 636 | mbtk_dsp_gain_set(1, value); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 637 | return 0; |
luojian | fee10dc | 2024-07-25 11:34:35 +0800 | [diff] [blame] | 638 | #endif |
| 639 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
| 643 | /** Ql_Playback_Samprate_Set |
| 644 | * @brief Set Playback PCM Samprate |
| 645 | * @details |
| 646 | * 0 for NB 1 for WB |
| 647 | * |
| 648 | * @param samprate |
| 649 | * samprate for PCM playback,default value is PCM NB |
| 650 | */ |
| 651 | int Ql_Playback_Samprate_Set(int samprate) |
| 652 | { |
| 653 | printf("samprate is %d \n",samprate); |
| 654 | if(samprate == 1) |
| 655 | { |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 656 | sample_rate = 16000; |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 657 | mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_16000); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 658 | } |
| 659 | else{ |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 660 | mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_8000); |
b.liu | c181beb | 2024-03-07 18:34:21 +0800 | [diff] [blame] | 661 | sample_rate = 8000; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path) |
| 668 | { |
b.liu | c1064f8 | 2023-10-11 16:47:39 +0800 | [diff] [blame] | 669 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate) |
| 673 | { |
b.liu | c1064f8 | 2023-10-11 16:47:39 +0800 | [diff] [blame] | 674 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | //add by grady, 2018-6-2 |
| 678 | /* |
| 679 | * describe : this function is use to open mixer device |
| 680 | * paras : |
| 681 | * device: mixer device |
| 682 | * return |
| 683 | * mixer handle |
| 684 | */ |
| 685 | struct mixer *quec_mixer_open(const char *device) |
| 686 | { |
| 687 | |
| 688 | return NULL; |
| 689 | } |
| 690 | |
| 691 | /* |
| 692 | * describe : this function is use to close mixer device |
| 693 | * paras : |
| 694 | * mixer: mixer handle |
| 695 | * return |
| 696 | * none |
| 697 | */ |
| 698 | void quec_mixer_close(struct mixer *mixer) |
| 699 | { |
| 700 | |
| 701 | |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * describe : this function is use to get mixer devie control |
| 706 | * paras : |
| 707 | * mixer: mixer handle |
| 708 | * name: mixer device |
| 709 | * index: mixer index |
| 710 | * return |
| 711 | * mixer control |
| 712 | */ |
| 713 | struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index) |
| 714 | { |
| 715 | |
| 716 | return NULL; |
| 717 | } |
| 718 | |
| 719 | /* |
| 720 | * describe : this function is use to set mulvalues |
| 721 | * paras : |
| 722 | * mixer: mixer handle |
| 723 | * count: count |
| 724 | * argv: data |
| 725 | * return : |
| 726 | * |
| 727 | */ |
| 728 | int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv) |
| 729 | { |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | |
| 735 | //end grady |
| 736 | |
| 737 | /***************************************************************** |
| 738 | * Function: Ql_AudPlayer_OpenExt |
| 739 | * |
| 740 | * Description: |
| 741 | * expend function from Ql_AudPlayer_OpenExt |
| 742 | * Open audio play device, and specify the callback function. |
| 743 | * This function can be called twice to play different audio sources. |
| 744 | * |
| 745 | * Parameters: |
| 746 | * device : a string that specifies the PCM device. |
| 747 | * NULL, means the audio will be played on the default PCM device. |
| 748 | * |
| 749 | * If you want to mixedly play audio sources, you can call this |
| 750 | * API twice with specifying different PCM device. |
| 751 | * The string devices available: |
| 752 | * "hw:0,0" (the default play device) |
| 753 | * "hw:0,13" (this device can mix audio and TTS) |
| 754 | * "hw:0,14" |
| 755 | * |
| 756 | * cb_func : callback function for audio player. |
| 757 | * The results of all operations on audio player |
| 758 | * are informed in callback function. |
| 759 | * |
| 760 | * flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP. |
| 761 | * |
| 762 | * channels: pcm sample channels. |
| 763 | * |
| 764 | * rate : pcm sample rate. |
| 765 | * |
| 766 | * format : pcm sample fromat |
| 767 | * |
| 768 | * Return: |
| 769 | * pcm device handle |
| 770 | * NULL, fail |
| 771 | *****************************************************************/ |
| 772 | int Ql_AudPlayer_OpenExt( |
| 773 | char *dev, |
| 774 | _cb_onPlayer cb_fun, |
| 775 | int flags, |
| 776 | int channels, |
| 777 | int rate, |
| 778 | int format) |
| 779 | { |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | /***************************************************************** |
| 784 | * Function: Ql_AudRecorder_Open |
| 785 | * |
| 786 | * Description: |
| 787 | * Open audio record device, and specify the callback function. |
| 788 | * |
| 789 | * Parameters: |
| 790 | * device : not used. MUST be NULL. |
| 791 | * |
| 792 | * cb_func : callback function for audio player. |
| 793 | * The results of all operations on audio recorder |
| 794 | * are informed in callback function. |
| 795 | * |
| 796 | * flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP. |
| 797 | * |
| 798 | * channels: pcm sample channels. |
| 799 | * |
| 800 | * rate : pcm sample rate. |
| 801 | * |
| 802 | * format : pcm sample fromat |
| 803 | * |
| 804 | * Return: |
| 805 | * pcm device handle |
| 806 | * NULL, fail |
| 807 | *****************************************************************/ |
| 808 | int Ql_AudRecorder_OpenExt( |
| 809 | char *dev, |
| 810 | _cb_onRecorder cb_fun, |
| 811 | int flags, |
| 812 | int channels, |
| 813 | int rate, |
| 814 | int format) |
| 815 | { |
| 816 | |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * Function: uac enable |
| 823 | * |
| 824 | * Description: |
| 825 | * uac enable |
| 826 | * |
| 827 | * Parameters: |
| 828 | * none |
| 829 | * Return: |
| 830 | * TURE or FALSE |
| 831 | */ |
| 832 | int ql_uac_enable(void) |
| 833 | { |
| 834 | |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | /* |
| 839 | * Function: uac disable |
| 840 | * |
| 841 | * Description: |
| 842 | * uac disable |
| 843 | * |
| 844 | * Parameters: |
| 845 | * none |
| 846 | * Return: |
| 847 | * TURE or FALSE |
| 848 | */ |
| 849 | int ql_uac_disable(void) |
| 850 | { |
| 851 | |
| 852 | return 0; |
luojian | a6a47a9 | 2024-05-23 13:42:21 +0800 | [diff] [blame] | 853 | } |