Sound
Sound playback
There are two possibilities to play sounds with EiffelMedia Audio Library. It is recommended to play sounds using EM_SOUND_PLAYER (see Players: Instant audio for further informations). The second solution is described in this document.
Loading sounds
If you want to load sounds, you need an open mixer device. You may then inherit from EM_SHARED_AUDIO_FACTORY to be able to access the singleton audio_factory, which allows you to load sounds using several techniques. Sound file may be one of the formats WAVE, AIFF, RIFF, OGG or VOC files.
Most of the time one will use create_sound_from_file, which takes the filename as an argument. Only slightly different is create_sound_from_file_pointer, which takes a valid filepointer to load the sound file.
Another set of loading features support loading files directly from memory. create_sound_from_pointer reassigns an EM_SOUND file from a POINTER. The two features create_wav_sound_from_memory and create_raw_sound_from_memory also create sound files from memory. Both functions need the sound data in a format corresponding to the current mixer settings (see Audio Initialization for more informations). create_wav_sound_from_memory may load WAVE and RIFF files whereas create_raw_sound_from_memory only can load RAW data.
Playing sounds
Sounds may not be played directly. You need to play your sound file using an EM_CHANNEL or by accessing EM_CHANNELS, which holds several channels. Please have a look at Channels for more detailed usage informations.
To play your sound file on a channel, use play, play_timed, fade_in or fade_in_timed. You may also pause, resume, stop and fade_out a playing soundfile. Another possibility comes with EM_CHANNELS. There one may find play_on_first_free_channel, play_timed_on_first_free_channel, fade_in_on_first_free_channel and fade_in_timed_on_first_free_channel. In these cases, your file will be played on the first unused channel found (if there is any).
Notes
Loading sounds from memory happens with very little error checking. Only use it, if you're 100% sure what you're doing.
As one perhaps already experienced, only create_sound_from_file sets the filename of the newly created EM_SOUND. For easier locating the sound in containers like a list, you should set the filename manually using set_filename.
Fading sounds is non-blocking. Be sure you don't interupt fading for example when quitting your application. You should always block fading using a loop halting when EM_CHANNEL.is_fading equals to False.