|
| 1 | +/** |
| 2 | + * @file audio.h |
| 3 | + * @brief Audio APIs for modules based on RDA8910 chipset. |
| 4 | + * @date 2023-12-15 |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef INC_AUDIO_H_ |
| 9 | +#define INC_AUDIO_H_ |
| 10 | + |
| 11 | +#include <stdint.h> |
| 12 | + |
| 13 | +#ifdef __cplusplus |
| 14 | +extern "C" { |
| 15 | +#endif |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Audio output channel list |
| 19 | + * |
| 20 | + */ |
| 21 | +enum audio_out_e { |
| 22 | + AUDIO_OUTPUT_RECEIVER = 0, /**< receiver */ |
| 23 | + AUDIO_OUTPUT_HEADPHONE = 1, /**< headphone */ |
| 24 | + AUDIO_OUTPUT_SPEAKER = 2, /**< speaker */ |
| 25 | +}; |
| 26 | + |
| 27 | +/** |
| 28 | + * @brief Audio input channel list |
| 29 | + * |
| 30 | + */ |
| 31 | +enum audio_in_e { |
| 32 | + AUDIO_INPUT_MAINMIC = 0, /**< main mic */ |
| 33 | + AUDIO_INPUT_AUXMIC = 1, /**< auxilary mic */ |
| 34 | + AUDIO_INPUT_DUALMIC = 2, /**< dual mic */ |
| 35 | + AUDIO_INPUT_HPMIC_L = 3, /**< headphone mic left */ |
| 36 | + AUDIO_INPUT_HPMIC_R = 4, /**< headphone mic right */ |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * @brief Audio playback path select |
| 41 | + * |
| 42 | + */ |
| 43 | +enum audio_play_e { |
| 44 | + AUDIO_PLAY_LOCAL = 1, /**< Play to local audio path */ |
| 45 | + AUDIO_PLAY_VOICE = 2, /**< Play to uplink remote during voice call */ |
| 46 | +}; |
| 47 | + |
| 48 | +/** |
| 49 | + * @brief Audio recorder path select |
| 50 | + * |
| 51 | + */ |
| 52 | +enum audio_rec_e { |
| 53 | + AUDIO_REC_TYPE_MIC = 1, /**< Record from microphone. */ |
| 54 | + AUDIO_REC_TYPE_VOICE = 2, /**< Record for voice call. The recorded stream is the mixed with uplink and downlink channels */ |
| 55 | +}; |
| 56 | + |
| 57 | +enum audio_qual_e { |
| 58 | + AUDIO_QUALITY_LOW, /**< quality low */ |
| 59 | + AUDIO_QUALITY_MEDIUM, /**< quality medium */ |
| 60 | + AUDIO_QUALITY_HIGH, /**< quality high */ |
| 61 | + AUDIO_QUALITY_BEST, /**< quality best */ |
| 62 | +}; |
| 63 | + |
| 64 | +/** |
| 65 | + * @brief Audio event callback |
| 66 | + * |
| 67 | + */ |
| 68 | +typedef void (*audio_statuscb_f)(int ev); |
| 69 | + |
| 70 | +/** |
| 71 | + * @brief Set output channel for Audio playback |
| 72 | + * |
| 73 | + * @param ch output channel @ref audio_out_e |
| 74 | + * @return 0 for success, error code otherwise |
| 75 | + */ |
| 76 | +int audio_set_outputchannel(uint32_t ch); |
| 77 | + |
| 78 | +/** |
| 79 | + * @brief Get current output channel @ref audio_out_e |
| 80 | + * |
| 81 | + * @return output channel |
| 82 | + */ |
| 83 | +int audio_get_outputchannel(void); |
| 84 | + |
| 85 | +/** |
| 86 | + * @brief Set audio input channel for recording |
| 87 | + * |
| 88 | + * @param ch input channel value @ref audio_in_e |
| 89 | + * @return 0 for success, error code otherwise |
| 90 | + */ |
| 91 | +int audio_set_inputchannel(uint32_t ch); |
| 92 | + |
| 93 | +/** |
| 94 | + * @brief Get current input channel for recording @ref audio_in_e |
| 95 | + * |
| 96 | + * @return audio input channel |
| 97 | + */ |
| 98 | +int audio_get_inputchannel(void); |
| 99 | + |
| 100 | +/** |
| 101 | + * @brief Set playback volume. Volume level should in [0, 100]. |
| 102 | + * 0 is the minimal volume, and 100 is the maximum volume. |
| 103 | + * It is possible that the supported volume levels is not 100. |
| 104 | + * And then the output is the same for multiple vol. |
| 105 | + * |
| 106 | + * @param vol Volume level between 0 to 100 |
| 107 | + * @return 0 for success, error code otherwise |
| 108 | + */ |
| 109 | +int audio_set_volume(int vol); |
| 110 | + |
| 111 | +/** |
| 112 | + * @brief Get current playback volume level. |
| 113 | + * |
| 114 | + * @return volume level between 0 to 100 |
| 115 | + */ |
| 116 | +int audio_get_volume(void); |
| 117 | + |
| 118 | +/** |
| 119 | + * @brief Set volume level for voice call between 0 to 100. |
| 120 | + * 0 is the minimal volume, and 100 is the maximum volume. |
| 121 | + * It is possible that the supported volume levels is not 100. |
| 122 | + * And then the output is the same for multiple vol. |
| 123 | + * |
| 124 | + * @param vol volume level between 0 to 100 |
| 125 | + * @return 0 for success, error code otherwise |
| 126 | + */ |
| 127 | +int audio_set_callvolume(int vol); |
| 128 | + |
| 129 | +/** |
| 130 | + * @brief Get current voice call volume. |
| 131 | + * |
| 132 | + * @return volume level between 0 to 100 |
| 133 | + */ |
| 134 | +int audio_get_callvolume(void); |
| 135 | + |
| 136 | +/** |
| 137 | + * @brief mute or unmute audio output device. This setting |
| 138 | + * won't be stored, the initial value is always unmute. |
| 139 | + * |
| 140 | + * @param mute true for mute, false for unmute |
| 141 | + * @return 0 for success, error code otherwise |
| 142 | + */ |
| 143 | +int audio_set_mute(int mute); |
| 144 | + |
| 145 | +/** |
| 146 | + * @brief check whether audio output device is muted |
| 147 | + * |
| 148 | + * @return true if mute, false if unmute |
| 149 | + */ |
| 150 | +int audio_get_mute(void); |
| 151 | + |
| 152 | +/** |
| 153 | + * @brief Play DTMF tone |
| 154 | + * |
| 155 | + * @param tone DTMF string with valid DTMF characters (0-9,*,#,A,B,C,D) |
| 156 | + * @param duration Duration of DTMF tone in milliseconds, 100 to 1000ms. |
| 157 | + * @param block True to block till playback finishes, false for non-blocking call |
| 158 | + * @param cb Callback function for playback status events |
| 159 | + * @return 0 for success, error code otherwise |
| 160 | + */ |
| 161 | +int audio_play_dtmf(const char *tone, unsigned duration, int block, audio_statuscb_f cb); |
| 162 | + |
| 163 | +/** |
| 164 | + * @brief Play audio file. Supported audio file types: |
| 165 | + * Raw PCM file |
| 166 | + * Wav file |
| 167 | + * MP3 audio file |
| 168 | + * AMR audio file |
| 169 | + * |
| 170 | + * @param file Filesystem path of audio file to play |
| 171 | + * @param path Aduio output path @ref audio_play_e |
| 172 | + * @param cb Callback function for playback status events |
| 173 | + * @return 0 for success, error code otherwise |
| 174 | + */ |
| 175 | +int audio_file_play(const char *file, int path, audio_statuscb_f cb); |
| 176 | + |
| 177 | +/** |
| 178 | + * @brief Pause audio file player |
| 179 | + * |
| 180 | + * @return 0 for success, error code otherwise |
| 181 | + */ |
| 182 | +int audio_file_pause(void); |
| 183 | + |
| 184 | +/** |
| 185 | + * @brief Resume audio file player |
| 186 | + * |
| 187 | + * @return 0 for success, error code otherwise |
| 188 | + */ |
| 189 | +int audio_file_resume(void); |
| 190 | + |
| 191 | +/** |
| 192 | + * @brief Stop audio file player |
| 193 | + * |
| 194 | + * @return 0 for success, error code otherwise |
| 195 | + */ |
| 196 | +int audio_file_stop(void); |
| 197 | + |
| 198 | +/** |
| 199 | + * @brief Start audio recorder. |
| 200 | + * |
| 201 | + * @param fname Filename to store |
| 202 | + * @param path Audio recorder path @ref audio_rec_e |
| 203 | + * @param quality Audio encoder quality @ref audio_qual_e |
| 204 | + * @param duration duration of recording in ms, 0 for continuous recording until stopped or call ends |
| 205 | + * @param cb Callback function for recorder status events |
| 206 | + * @return 0 for success, error code otherwise |
| 207 | + */ |
| 208 | +int audio_record_start(const char *fname, int path, int quality, int duration, audio_statuscb_f cb); |
| 209 | + |
| 210 | +/** |
| 211 | + * @brief Pause audio recorder |
| 212 | + * |
| 213 | + * @return 0 for success, error code otherwise |
| 214 | + */ |
| 215 | +int audio_record_pause(void); |
| 216 | + |
| 217 | +/** |
| 218 | + * @brief Resume audio recorder |
| 219 | + * |
| 220 | + * @return 0 for success, error code otherwise |
| 221 | + */ |
| 222 | +int audio_record_resume(void); |
| 223 | + |
| 224 | +/** |
| 225 | + * @brief Stop audio recorder |
| 226 | + * |
| 227 | + * @return 0 for success, error code otherwise |
| 228 | + */ |
| 229 | +int audio_record_stop(void); |
| 230 | + |
| 231 | +#ifdef __cplusplus |
| 232 | +} |
| 233 | +#endif |
| 234 | + |
| 235 | +#endif /* INC_AUDIO_H_ */ |
0 commit comments