Audio APIs
Note
Audio interface is currently only supported on RDA8910 chipset.
Example Usage
#include <audio.h>
/* Play an MP3 file from sdcard */
audio_file_play("/sd/file.mp3", AUDIO_PLAY_LOCAL, NULL);
/* Play an MP3 file from sdcard during call */
audio_file_play("/sd/file.mp3", AUDIO_PLAY_VOICE, NULL);
/* set volume */
audio_set_volume(100);
/* play DTMF tone */
audio_play_dtmf("1234", 500, false, NULL);
/* Record from MIC */
audio_record_start("/fs/record.amr", AUDIO_REC_TYPE_MIC, AUDIO_QUALITY_MEDIUM, 5000, NULL);
/* Record voice call */
audio_record_start("/fs/call_record.amr", AUDIO_REC_TYPE_VOICE, AUDIO_QUALITY_MEDIUM, 0, NULL);
API Reference
Header File
Source: include/audio.h
#include <audio.h>
Functions
-
int audio_set_outputchannel(uint32_t ch)
Set output channel for Audio playback.
- Parameters:
ch – output channel audio_out_e
- Returns:
0 for success, error code otherwise
-
int audio_get_outputchannel(void)
Get current output channel audio_out_e.
- Returns:
output channel
-
int audio_set_inputchannel(uint32_t ch)
Set audio input channel for recording.
- Parameters:
ch – input channel value audio_in_e
- Returns:
0 for success, error code otherwise
-
int audio_get_inputchannel(void)
Get current input channel for recording audio_in_e.
- Returns:
audio input channel
-
int audio_set_volume(int vol)
Set playback volume. Volume level should in [0, 100]. 0 is the minimal volume, and 100 is the maximum volume. It is possible that the supported volume levels is not 100. And then the output is the same for multiple vol.
- Parameters:
vol – Volume level between 0 to 100
- Returns:
0 for success, error code otherwise
-
int audio_get_volume(void)
Get current playback volume level.
- Returns:
volume level between 0 to 100
-
int audio_set_callvolume(int vol)
Set volume level for voice call between 0 to 100. 0 is the minimal volume, and 100 is the maximum volume. It is possible that the supported volume levels is not 100. And then the output is the same for multiple vol.
- Parameters:
vol – volume level between 0 to 100
- Returns:
0 for success, error code otherwise
-
int audio_get_callvolume(void)
Get current voice call volume.
- Returns:
volume level between 0 to 100
-
int audio_set_mute(int mute)
mute or unmute audio output device. This setting won’t be stored, the initial value is always unmute.
- Parameters:
mute – true for mute, false for unmute
- Returns:
0 for success, error code otherwise
-
int audio_get_mute(void)
check whether audio output device is muted
- Returns:
true if mute, false if unmute
-
int audio_play_dtmf(const char *tone, unsigned duration, int block, audio_statuscb_f cb)
Play DTMF tone.
- Parameters:
tone – DTMF string with valid DTMF characters (0-9,*,#,A,B,C,D)
duration – Duration of DTMF tone in milliseconds, 100 to 1000ms.
block – True to block till playback finishes, false for non-blocking call
cb – Callback function for playback status events
- Returns:
0 for success, error code otherwise
-
int audio_file_play(const char *file, int path, audio_statuscb_f cb)
Play audio file. Supported audio file types: Raw PCM file Wav file MP3 audio file AMR audio file.
- Parameters:
file – Filesystem path of audio file to play
path – Aduio output path audio_play_e
cb – Callback function for playback status events
- Returns:
0 for success, error code otherwise
-
int audio_file_pause(void)
Pause audio file player.
- Returns:
0 for success, error code otherwise
-
int audio_file_resume(void)
Resume audio file player.
- Returns:
0 for success, error code otherwise
-
int audio_file_stop(void)
Stop audio file player.
- Returns:
0 for success, error code otherwise
-
int audio_record_start(const char *fname, int path, int quality, int duration, audio_statuscb_f cb)
Start audio recorder.
- Parameters:
fname – Filename to store
path – Audio recorder path audio_rec_e
quality – Audio encoder quality audio_qual_e
duration – duration of recording in ms, 0 for continuous recording until stopped or call ends
cb – Callback function for recorder status events
- Returns:
0 for success, error code otherwise
-
int audio_record_pause(void)
Pause audio recorder.
- Returns:
0 for success, error code otherwise
-
int audio_record_resume(void)
Resume audio recorder.
- Returns:
0 for success, error code otherwise
-
int audio_record_stop(void)
Stop audio recorder.
- Returns:
0 for success, error code otherwise
Type Definitions
-
typedef void (*audio_statuscb_f)(int ev)
Audio event callback.
Enumerations
-
enum audio_out_e
Audio output channel list.
Values:
-
enumerator AUDIO_OUTPUT_RECEIVER
receiver
-
enumerator AUDIO_OUTPUT_HEADPHONE
headphone
-
enumerator AUDIO_OUTPUT_SPEAKER
speaker
-
enumerator AUDIO_OUTPUT_RECEIVER
-
enum audio_in_e
Audio input channel list.
Values:
-
enumerator AUDIO_INPUT_MAINMIC
main mic
-
enumerator AUDIO_INPUT_AUXMIC
auxilary mic
-
enumerator AUDIO_INPUT_DUALMIC
dual mic
-
enumerator AUDIO_INPUT_HPMIC_L
headphone mic left
-
enumerator AUDIO_INPUT_HPMIC_R
headphone mic right
-
enumerator AUDIO_INPUT_MAINMIC
-
enum audio_play_e
Audio playback path select.
Values:
-
enumerator AUDIO_PLAY_LOCAL
Play to local audio path
-
enumerator AUDIO_PLAY_VOICE
Play to uplink remote during voice call
-
enumerator AUDIO_PLAY_LOCAL
