xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * @file voice_api.c
|
| 3 | * @brief Implementation of the public APIs of libvoice.
|
| 4 | *
|
| 5 | * Copyright (C) 2023 Sanechips Technology Co., Ltd.
|
| 6 | * @author
|
| 7 | *
|
| 8 | * This program is free software; you can redistribute it and/or modify
|
| 9 | * it under the terms of the GNU General Public License version 2 as
|
| 10 | * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
|
| 11 | *
|
| 12 | */
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 | #include <stdio.h>
|
| 17 | #include <unistd.h>
|
| 18 | #include <string.h>
|
| 19 | #include <stdlib.h>
|
| 20 |
|
| 21 | #include <stdint.h>
|
| 22 | //#include "volte_drv.h"
|
| 23 | #include <linux/volte_drv.h>
|
| 24 |
|
| 25 | #include <sys/ioctl.h>
|
| 26 | #include <fcntl.h>
|
| 27 | #include <tinyalsa/audio_mixer_ctrl.h>
|
| 28 | #include "voice_lib.h"
|
| 29 |
|
| 30 | #define VOCIE_SND_CARD_NUM 0
|
| 31 |
|
| 32 |
|
| 33 | extern int mix_set_voice_vol(struct mixer *mixer, int volume);
|
| 34 | extern int mix_get_voice_vol(struct mixer *mixer, int *volume);
|
| 35 | extern int mix_set_tx_voice_vol(struct mixer *mixer, int volume);
|
| 36 | extern int mix_get_tx_voice_vol(struct mixer *mixer, int *volume);
|
| 37 | extern int mix_set_voice_mute(struct mixer *mixer, bool enable);
|
| 38 | extern int mix_get_voice_mute(struct mixer *mixer, int *enable);
|
| 39 | extern int mix_set_rx_voice_mute(struct mixer *mixer, bool enable);
|
| 40 | extern int mix_get_rx_voice_mute(struct mixer *mixer, int *enable);
|
| 41 | extern int mix_set_voice_path(struct mixer *mixer, int path);
|
| 42 | extern int mix_set_vp_path(struct mixer *mixer, char path);
|
| 43 | extern int mix_get_vp_path(struct mixer *mixer, int *path);
|
| 44 | extern int mix_get_voice_path(struct mixer *mixer, int *path);
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 | #define VOCIE_SND_CARD_NUM 0
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 | //设置voiceé³é¢è®¾å¤æ¨¡å¼ dev_modeï¼handset,speaker,headset 0 表示æåï¼?å
¶å®è¡¨ç¤ºæéè¯?
|
| 53 | int set_voice_device_mode(int dev_mode)
|
| 54 | {
|
| 55 |
|
| 56 | struct mixer *voice_mixer = NULL;
|
| 57 | printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
|
| 58 |
|
| 59 | if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
|
| 60 | printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
|
| 61 | return -1;
|
| 62 | }
|
| 63 |
|
| 64 | //open mixer dev for control
|
| 65 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 66 | if (!voice_mixer) {
|
| 67 | printf("voice_mixer open failed!\n");
|
| 68 | return -1;
|
| 69 | }
|
| 70 |
|
| 71 | //config mixer dev
|
| 72 | mix_set_voice_path(voice_mixer, dev_mode);
|
| 73 |
|
| 74 | //close mixer
|
| 75 | mixer_close(voice_mixer);
|
| 76 | voice_mixer = NULL;
|
| 77 |
|
| 78 |
|
| 79 | return 0;
|
| 80 |
|
| 81 |
|
| 82 | }
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | int sc_audio_set_voice_device_mode(int dev_mode)
|
| 87 | {
|
| 88 |
|
| 89 | struct mixer *voice_mixer = NULL;
|
| 90 | printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
|
| 91 |
|
| 92 | if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
|
| 93 | printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
|
| 94 | return -1;
|
| 95 | }
|
| 96 |
|
| 97 | //open mixer dev for control
|
| 98 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 99 | if (!voice_mixer) {
|
| 100 | printf("voice_mixer open failed!\n");
|
| 101 | return -1;
|
| 102 | }
|
| 103 | #ifdef _ALSA_CODEC_IN_CAP
|
| 104 | mix_set_vp_path(voice_mixer,dev_mode);
|
| 105 |
|
| 106 | #else
|
| 107 | //config mixer dev
|
| 108 | mix_set_voice_path(voice_mixer, dev_mode);
|
| 109 | #endif
|
| 110 |
|
| 111 |
|
| 112 | //close mixer
|
| 113 | mixer_close(voice_mixer);
|
| 114 | voice_mixer = NULL;
|
| 115 |
|
| 116 |
|
| 117 | return 0;
|
| 118 |
|
| 119 |
|
| 120 | }
|
| 121 |
|
| 122 |
|
| 123 | int sc_audio_get_voice_device_mode(int *p_dev_mode)
|
| 124 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 125 | int ret = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 126 | struct mixer *voice_mixer = NULL;
|
| 127 | printf("%s: start!\n",__func__);
|
| 128 |
|
| 129 | //open mixer dev for control
|
| 130 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 131 | if (!voice_mixer) {
|
| 132 | printf("voice_mixer open failed!\n");
|
| 133 | return -1;
|
| 134 | }
|
| 135 |
|
| 136 | //config mixer dev
|
| 137 | mix_get_vp_path(voice_mixer, p_dev_mode);
|
| 138 |
|
| 139 |
|
| 140 | if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
|
| 141 | printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 142 | ret = -1;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 143 | }
|
| 144 | printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
|
| 145 |
|
| 146 | //close mixer
|
| 147 | mixer_close(voice_mixer);
|
| 148 | voice_mixer = NULL;
|
| 149 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 150 | return ret;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 151 |
|
| 152 | }
|
| 153 |
|
| 154 |
|
| 155 | int sc_audio_set_rx_voice_vol(int vol)
|
| 156 | {
|
| 157 | struct mixer *voice_mixer = NULL;
|
| 158 | printf("%s: start vol=%d!\n",__func__, vol);
|
| 159 |
|
| 160 | if ((vol < 0 ) ||(vol > 11)){
|
| 161 | printf("%s: vol not support, vol=%d!\n",__func__, vol);
|
| 162 | return -1;
|
| 163 | }
|
| 164 |
|
| 165 | //open mixer dev for control
|
| 166 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 167 | if (!voice_mixer) {
|
| 168 | printf("voice_mixer open failed!\n");
|
| 169 | return -1;
|
| 170 | }
|
| 171 |
|
| 172 | //config mixer dev
|
| 173 | mix_set_voice_vol(voice_mixer, vol);
|
| 174 |
|
| 175 | //close mixer
|
| 176 | mixer_close(voice_mixer);
|
| 177 | voice_mixer = NULL;
|
| 178 |
|
| 179 |
|
| 180 | return 0;
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 | }
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 | int sc_audio_get_rx_voice_vol(int * p_vol)
|
| 190 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 191 | int ret = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 192 | struct mixer *voice_mixer = NULL;
|
| 193 |
|
| 194 | printf("%s: start!\n",__func__);
|
| 195 |
|
| 196 | //open mixer dev for control
|
| 197 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 198 | if (!voice_mixer) {
|
| 199 | printf("voice_mixer open failed!\n");
|
| 200 | return -1;
|
| 201 | }
|
| 202 |
|
| 203 | //config mixer dev
|
| 204 | mix_get_voice_vol(voice_mixer, p_vol);
|
| 205 |
|
| 206 |
|
| 207 | if ((*p_vol < 0 ) ||(*p_vol > 11)){
|
| 208 | printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 209 | ret = -1;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 210 | }
|
| 211 | printf("%s: *p_vol=%d!\n",__func__, *p_vol);
|
| 212 |
|
| 213 | //close mixer
|
| 214 | mixer_close(voice_mixer);
|
| 215 | voice_mixer = NULL;
|
| 216 |
|
| 217 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 218 | return ret;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 219 |
|
| 220 |
|
| 221 |
|
| 222 | }
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 | int sc_audio_set_tx_voice_vol(int vol)
|
| 227 | {
|
| 228 | struct mixer *voice_mixer = NULL;
|
| 229 | printf("%s: start vol=%d!\n",__func__, vol);
|
| 230 |
|
| 231 | if ((vol < 0 ) ||(vol > 11)){
|
| 232 | printf("%s: vol not support, vol=%d!\n",__func__, vol);
|
| 233 | return -1;
|
| 234 | }
|
| 235 |
|
| 236 | //open mixer dev for control
|
| 237 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 238 | if (!voice_mixer) {
|
| 239 | printf("voice_mixer open failed!\n");
|
| 240 | return -1;
|
| 241 | }
|
| 242 |
|
| 243 | //config mixer dev
|
| 244 | mix_set_tx_voice_vol(voice_mixer, vol);
|
| 245 |
|
| 246 | //close mixer
|
| 247 | mixer_close(voice_mixer);
|
| 248 | voice_mixer = NULL;
|
| 249 |
|
| 250 |
|
| 251 | return 0;
|
| 252 |
|
| 253 |
|
| 254 | }
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 | int sc_audio_get_tx_voice_vol(int *p_vol)
|
| 259 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 260 | int ret = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 261 | struct mixer *voice_mixer = NULL;
|
| 262 | printf("%s: start!\n",__func__);
|
| 263 |
|
| 264 |
|
| 265 | //open mixer dev for control
|
| 266 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 267 | if (!voice_mixer) {
|
| 268 | printf("voice_mixer open failed!\n");
|
| 269 | return -1;
|
| 270 | }
|
| 271 |
|
| 272 | //config mixer dev
|
| 273 | mix_get_tx_voice_vol(voice_mixer, p_vol);
|
| 274 |
|
| 275 |
|
| 276 | if((*p_vol < 0 ) ||(*p_vol > 5)){
|
| 277 | printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 278 | ret = -1;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 279 | }
|
| 280 | printf("%s: *p_vol=%d!\n",__func__, *p_vol);
|
| 281 |
|
| 282 | //close mixer
|
| 283 | mixer_close(voice_mixer);
|
| 284 | voice_mixer = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 285 | return ret;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 286 | }
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 | int sc_audio_set_tx_voice_mute_state(int mute )
|
| 291 | {
|
| 292 | struct mixer *voice_mixer = NULL;
|
| 293 | printf("%s: start mute=%d!\n",__func__, mute);
|
| 294 |
|
| 295 | if((mute != 0 ) &&(mute != 1)) {
|
| 296 | printf("%s: mute not support, mute=%d!\n",__func__, mute);
|
| 297 | return -1;
|
| 298 | }
|
| 299 |
|
| 300 | //open mixer dev for control
|
| 301 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 302 | if (!voice_mixer) {
|
| 303 | printf("voice_mixer open failed!\n");
|
| 304 | return -1;
|
| 305 | }
|
| 306 |
|
| 307 | //config mixer dev
|
| 308 | mix_set_voice_mute(voice_mixer, mute);
|
| 309 |
|
| 310 | //close mixer
|
| 311 | mixer_close(voice_mixer);
|
| 312 | voice_mixer = NULL;
|
| 313 | return 0;
|
| 314 |
|
| 315 | }
|
| 316 |
|
| 317 | int sc_audio_get_tx_voice_mute_state(int *p_mute)
|
| 318 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 319 | int ret = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 320 | struct mixer *voice_mixer = NULL;
|
| 321 |
|
| 322 | printf("%s: start!\n",__func__);
|
| 323 |
|
| 324 | //open mixer dev for control
|
| 325 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 326 | if (!voice_mixer) {
|
| 327 | printf("voice_mixer open failed!\n");
|
| 328 | return -1;
|
| 329 | }
|
| 330 |
|
| 331 | //config mixer dev
|
| 332 | mix_get_voice_mute(voice_mixer, p_mute);
|
| 333 |
|
| 334 |
|
| 335 | if((*p_mute != 0 ) &&(*p_mute != 1)) {
|
| 336 | printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 337 |
|
| 338 | ret = -1;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 339 | }
|
| 340 | printf("%s: *p_mute=%d!\n",__func__, *p_mute);
|
| 341 |
|
| 342 | //close mixer
|
| 343 | mixer_close(voice_mixer);
|
| 344 | voice_mixer = NULL;
|
| 345 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 346 | return ret;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 347 | }
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 | int sc_audio_set_rx_voice_mute_state(int mute)
|
| 356 | {
|
| 357 | struct mixer *voice_mixer = NULL;
|
| 358 | printf("%s: start mute=%d!\n",__func__, mute);
|
| 359 |
|
| 360 | if((mute != 0 ) &&(mute != 1)) {
|
| 361 | printf("%s: mute not support, mute=%d!\n",__func__, mute);
|
| 362 | return -1;
|
| 363 | }
|
| 364 |
|
| 365 | //open mixer dev for control
|
| 366 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 367 | if (!voice_mixer) {
|
| 368 | printf("voice_mixer open failed!\n");
|
| 369 | return -1;
|
| 370 | }
|
| 371 |
|
| 372 | //config mixer dev
|
| 373 | mix_set_rx_voice_mute(voice_mixer, mute);
|
| 374 |
|
| 375 | //close mixer
|
| 376 | mixer_close(voice_mixer);
|
| 377 | voice_mixer = NULL;
|
| 378 | return 0;
|
| 379 |
|
| 380 | }
|
| 381 |
|
| 382 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 383 | int sc_audio_get_rx_voice_mute_state(int *p_mute)
|
| 384 | {
|
| 385 | int ret = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 386 | struct mixer *voice_mixer = NULL;
|
| 387 |
|
| 388 | printf("%s: start!\n",__func__);
|
| 389 |
|
| 390 | //open mixer dev for control
|
| 391 | voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
|
| 392 | if (!voice_mixer) {
|
| 393 | printf("voice_mixer open failed!\n");
|
| 394 | return -1;
|
| 395 | }
|
| 396 |
|
| 397 | //config mixer dev
|
| 398 | mix_get_rx_voice_mute(voice_mixer, p_mute);
|
| 399 |
|
| 400 | if((*p_mute != 0 ) &&(*p_mute != 1)) {
|
| 401 |
|
| 402 | printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 403 | ret = -1;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 404 | }
|
| 405 | printf("%s: *p_mute=%d!\n",__func__, *p_mute);
|
| 406 |
|
| 407 | //close mixer
|
| 408 | mixer_close(voice_mixer);
|
| 409 | voice_mixer = NULL;
|
| 410 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 411 | return ret;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 412 |
|
| 413 | }
|
| 414 |
|
| 415 | int sc_audio_set_loopback_enable_state(int enable)
|
| 416 | {
|
| 417 | return 0;
|
| 418 | }
|
| 419 |
|
| 420 | int sc_audio_get_loopback_enable_state(int *p_enable)
|
| 421 | {
|
| 422 | return 0;
|
| 423 | }
|
| 424 |
|