GAUDIO

From uGFX Wiki
Revision as of 01:38, 4 July 2014 by Tectu (Talk | contribs) (GEVENT integration)

Jump to: navigation, search

The GAUDIO module provides high level API for handling audio in- and output. The module provides built-in decoders but does also allow to use external codecs. See #External decoder.

Several drivers are provided to play and record data through different hardware peripherals. Any thing from a simple PWM output up to an external codec is supported.

API reference

The API reference of the GAUDIO module can be found here.

Board file

The GAUDIO module requires a board file to communicate with the hardware. One board file is needed for audio output and one for audio input. See board file.

GDataBuffer

GDataBuffer is the container that is used to hold, manipulate and pass audio data. The buffer is provided and handled by the GQUEUE module. For more information, see GQUEUE#Buffer.

Play back

Before any audio can be played, the audio device has to be initialized using gaudioPlayInit(). Both, the sample format and the sample frequency are set by this function call.

After successful initialization, gaudioPlay() can be used to output audio data. The function takes a pointer to a GDataBuffer that holds the audio data to play in the format that has been set by the initialization call.

gaudioPause() can be used to pause any current audio output. Resuming after a pause is done calling gaudioPlay() without any sample buffer reference.

Calling gaudioStop() will completely stop a current audio playback.

gaudioPlayWait() is used to make sure that the playback is complete. The function will poll for the given timeout (parameter) and return TRUE as soon as nothing is playing anymore or FALSE as soon as the timeout is exceeded.

Volume

The playback volume can be adjusted using gaudioSetVolume(). However, not every driver might implement this feature. The function will return FALSE in that case.

For stereo devices, both channels are set to the same volume.

External decoder

If your audio output devices does have an internal processor to decode audio formats, use GAUDIO_PLAY_FORMAT_FILE as the third parameter for gaudioPlayInit(). The GAUDIO module will simply pass the audio data unmodified to the audio device.

GEVENT integration

The GAUDIO module can optionally be configured to send events through the GEVENT module. This feature is enabled by calling gaudioRecordGetSource(), the GAUDIO module will send the following events:

Event Description
GAUDIO_PLAY_PLAYING The audio output system has started to play.
GAUDIO_PLAY_FREEBLOCK An audio buffer has been free'd.
GAUDIO_PLAY_LOSTEVENT The last audio play event was lost.

Record

ToDo