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 audio profile can be set with the le_audio_SetProfile() function. The pre-configured profiles are defined with le_audio_Profile_t enumeration type.
The audio profile in use can be retrieved with the le_audio_GetProfile() function.
Then, the following functions let you enable or disable the audio settings on the selected audio interface:
The following functions let you select the desired interface:
Multiple users can own the same stream at the same time.
le_audio_GetDefaultPcmTimeSlot() can be called to get the default PCM time slot used on the current platform.
le_audio_GetDefaultI2sMode() can be called to get the default I2s channel mode slot used on the current platform.
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.
You can configure the PCM interface with the le_audio_SetPcmSamplingRate(), le_audio_SetPcmSamplingResolution() and le_audio_SetPcmCompanding() functions. This function must be called before activating an audio path with the PCM interface, in other words you must call this function before connecting the PCM Stream to a connector.
In addition, the le_audio_GetPcmSamplingRate(), le_audio_GetPcmSamplingResolution() and le_audio_GetPcmCompanding() functions allows you to retrieve the PCM interface configuration.
Once the users get an Audio Stream reference, they can control it with the following functions:
The users have also the possibility to register a handler function to catch some stream-related notifications such as errors or audio file's events:
le_audio_AddStreamEventHandler() function installs a handler for stream notifications. You can specify the types of events to notify by passing a bit mask as a parameter (cf. le_audio_StreamEventBitMask_t).
le_audio_RemoveStreamEventHandler() function removes the stream handler function.
Once the stream event handler is called, the user can call the different functions to retrieve the event's value:
The code sample below shows how the User can install a file's event handler.
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 player interface by calling:
Audio file recording can be done from any active input interfaces.
You must open a "File Recording" interface by calling:
A play can be done only on a connected stream. For instance, the "I2S Tx", "Modem Voice Rx" and "Player" must be previously connected before playing a file.
A record can be done only on a connected stream. For instance, the "I2S Rx", "Modem Voice Tx" and "Recorder" must be previously connected before recording a file.
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 application must register a handler function to detect incoming DTMF characters on a specific input audio stream. The le_audio_AddDtmfDetectorHandler() function installs a handler for DTMF detection.
The le_audio_RemoveDtmfDetectorHandler() function uninstalls the handler function.
The DTMFs are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, *, #, A, B, C, D. Not case sensitive.
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. Use of this work is subject to license.