![]() |
1.11 |
This chapter discusses the audio support in EGT.
Playing audio in EGT is usually done with the egt::AudioPlayer class. This class is based on GStreamer, so it supports all of the expected features for playing various audio formats such as random seeking and pausing.
For quick, asynchronous sound playback, such as in response to a button press, the egt::SoundEffect class is more suitable than egt::AudioPlayer.
The egt::SoundEffect class utilizes the libsndfile library to read audio files. The supported formats depend on the version and compilation options of libsndfile in your distribution. For instance, MP3 support is optional and may not be available.
The egt::SoundEffect class uses ALSA for audio playback. Due to ALSA's limited abstraction, understanding your hardware is crucial.
Sound cards vary in their features, such as mixing capabilities, supported formats, channels and sample rates. EGT modifies the ALSA configuration to use ALSA plugins, creating EGT PCM devices with consistent features. The hardware PCM devices are wrapped in the dmix plugin for mixing capabilities and the plug plugin for channel, rate, and format conversion. This configuration only affects the EGT application process.
Upon the first instantiation of an egt::SoundEffect object, EGT detects all ALSA sound cards and modifies the ALSA configuration to create EGT PCM devices based on the hardware PCM devices.
PCM devices are identified by a card index and a device index, which can be retrieved using the aplay
command:
For example, to use the CLASSD sound card, the card index is 0 and the device index is 0.
You can also use alsactl info
command for more information.
EGT doesn't manage volume control due to the variability in sound card configurations. Channel names and the need to unmute some channels can differ between cards. Use alsamixer
to configure playback volume and alsa ctl store
to save the settings.
Audio file playback occurs in a separate thread. The play()
method starts playback, and the stop()
method interrupts it. If repeat mode is enabled using the repeat()
method, the sound file will continue to play until repeat mode is disabled or playback is stopped.