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.
All the functions of this API are provided by the audioService foundation service.
Here's a code sample binding to audio services:
bindings: { clientExe.clientComponent.le_audio -> audioService.le_audio }
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.
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:
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.
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.
A PCM configuration must be set with:
An AMR configuration must be set with:
le_audio_Stop(): can be called to stop a play/record. The playback/record is stopped playing/recording, the read/write position indicator associated with the file stream is rewound to the beginning of the file. A new file can be played/recorded using le_audio_PlayFile()/le_audio_PlaySamples()/le_audio_RecordFile()/le_audio_GetSamples().
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 users have also the possibility to register a handler function to catch some media-related notifications such as errors or audio events.
le_audio_AddMediaHandler() function installs a handler for player/recorder stream notifications.
le_audio_RemoveMediaHandler() function removes the player/recorder handler function.
The code sample below shows how the User can install a file's event handler.
The le_audio_PlayDtmf() function allows the application to play one or several DTMF on a playback stream. The duration and the pause of the DTMFs must also be specified with the input parameters.
The le_audio_PlaySignallingDtmf() function allows the application to ask the Mobile Network to generate on the remote audio party the DTMFs. Compared with le_audio_PlayDtmf(), le_audio_PlaySignallingDtmf() function may offer a better signal quality, but the the duration and the pause timings may be less accurate.
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.