Click here for the API reference documentation.
Open/Close an Audio Interface
Control an Audio Stream
Create Audio connectors
Specifying audio formats
Play and record audio
Code samples
The Audio API handles audio interfaces including play or listen supported formats.
A Legato device can use several audio interfaces. You choose the input and output interfaces to tie together. The Audio stream related to a particular interface is represented with an 'Audio Stream Reference'.
You can create your own audio path by connecting several audio streams together using audio connectors.
An audio path can support more than two audio interfaces. You can have a basic output audio path of a voice call to connect the Modem Voice Received interface with the Speaker interface, and at the same time, the Modem Voice Received interface can be also connected to a Recorder Device interface.
The following functions let you select the desired interface:
le_audio_OpenMic()
: returns an Audio Stream Reference of the analog audio signal coming from the microphone input.le_audio_OpenSpeaker()
: returns an Audio Stream Reference of the analog audio signal routed to the Speaker output.le_audio_OpenUsbRx()
: returns an Audio Stream Reference of the digitized audio signal coming from an external device connected via USB Audio Class.le_audio_OpenUsbTx()
: returns an Audio Stream Reference of the digitized audio signal routed to an external device connected via USB Audio Class.le_audio_OpenPcmRx()
: it returns an Audio Stream Reference of the digitized audio signal coming from an external device connected via the PCM interface.le_audio_OpenPcmTx()
: it returns an Audio Stream Reference of the digitized audio signal routed to an external device connected via the PCM interface.le_audio_OpenI2sRx()
: it returns an Audio Stream Reference of the digitized audio signal coming from an external device connected via the I2S interface.le_audio_OpenI2sTx()
: it returns an Audio Stream Reference of the digitized audio signal routed to an external device connected via the I2S interface.le_audio_OpenModemVoiceRx()
: returns an Audio Stream Reference of the digitized audio signal coming from a voice call. The audio format is negotiated with the network when the call is established.le_audio_OpenModemVoiceTx()
: returns an Audio Stream Reference of the digitized audio signal routed to a voice call. The audio format is negotiated with the network when the call is established.Multiple users can own the same stream at the same time.
le_audio_GetFormat()
can be called to get the audio format of an input or output stream.
Call le_audio_Close()
to release it. If several users own the same, corresponding stream reference, the interface will close only after the last user releases the audio stream.
Once the users get an Audio Stream reference, they can control it with the following functions:
le_audio_SetGain()
: allows the user to adjust the gain of an audio stream (0 means 'muted', 100 is the maximum gain value).le_audio_GetGain()
: allows the User to retrieve the gain of an audio stream (0 means 'muted', 100 is the maximum gain value).le_audio_Mute()
: allows the user to mute an audio stream.le_audio_Unmute()
: allows the user to unmute an audio stream.You can create your own audio path by connecting several audio streams together.
le_audio_CreateConnector()
function creates a reference to an audio connector.
You can tie an audio stream to a connector by calling the le_audio_Connect() function.
You can remove an audio stream from a connector by calling the le_audio_Disconnect() function.
When finished with it, delete it using the le_audio_DeleteConnector()
function.
The encoding audio format can be specified to (or retrieved from) the audio interfaces that support this option. The format parameter is a string containing the IANA specified encoding format name for Real-Time protocol (RTP).
The complete list of the audio encoding format names can be found on the IANA organization web site (http://www.iana.org).
Function that gets the current audio format for an open interface is:
Some examples of audio formats:
An audio file can be played to any active output interfaces.
You must open a "File Playback" interface by calling:
le_audio_OpenFilePlayback()
: returns an Audio Stream Reference for file playback. The audio file is played on the local audio interface like Speaker, USB Tx, PCM Tx, I2S Tx or on the remote audio interface Modem Voice Tx depending the kind of connector (input or output) is tied to.A "File Playback" interface can be opened only on an active output audio path. For instance, the "I2S Tx" and "Modem Voice Rx" must be previously connected before opening and connecting the "File Playback" interface on the same connector.
Audio file recording can be done from any active input interfaces.
You must open a "File Recording" interface by calling:
le_audio_OpenFileRecording()
: returns an Audio Stream Reference for file recording. The local audio interface like Microphone, USB Rx, PCM Rx, I2S Rx is recorded into an audio file; or the Modem Voice Rx remote audio interface is recorded into an audio file, depending the kind of connector (input or output) is tied to.A "File Recording" interface can be opened only on an active input audio path. For instance, the "I2S Rx" and "Modem Voice Tx" must be previously connected before opening and connecting the "File Recording" interface on the same connector.
The function below is an example of how a file can be played to the Modem Voice Tx output interface. The audio of the voice call is redirected to the I2S interfaces. This function simply plays a voice prompt to the remote party when the voice call is established.
The following two code samples show how to create different audio paths for an incoming voice call.
The first example has the audio path depending on an USB Audio handset. The ConnectVoiceCallAudio() function creates this audio path. A USB Audio handset plugged in and fully operationnal, will redirect the call audio to the handset; otherwise, it will redirect the call to the default microphone and speaker.
Use DisconnectVoiceCallAudio()
to delete the audio path.
The next code sample uses specific functions to deal with a new 'Incoming call' event during a call already in progress.
If no call is in progress, use the ConnectVoiceCallAudio()
function to redirect the call audio to the in-built Microphone and Speaker.
If a new call is incoming, and considered a high priority call, you must mute the audio of the first call, and then connect the new call to your current audio path. Use SwitchVoiceCallAudio()
for these actions.
When the high priority call terminates, you can return back to your previous call and reactivate its audio with the SwitchBackVoiceCallAudio()
function.
Copyright (C) Sierra Wireless, Inc. 2014. Use of this work is subject to license.
If a LE_VOICECALL_EVENT_TERMINATED event is received, application can get the termination reason by using le_voicecall_GetTerminationReason().
An Incoming voice call will be notified by an LE_VOICECALL_EVENT_INCOMING event on state handler with a Call reference le_voicecall_CallRef_t().
Application can answer the call by using le_voicecall_Answer() or reject the call by using le_voicecall_End() passing the call reference le_voicecall_CallRef_t. Application should use le_voicecall_Delete() to release le_voicecall_CallRef_t voice call reference object.
Some applications may have voice call requirements that are not met by the default voice call (e.g., use a least cost voice call link or disable roaming on mobile networks). You can do this by:
le_voicecall_AddStateHandler() , le_voicecall_End() and le_voicecall_Delete() APIs can continue to be used, as described above.
Copyright (C) Sierra Wireless, Inc. 2014. Use of this work is subject to license.