Reggae tutorial: Playing a sound from file

From MorphOS Library

Revision as of 14:31, 26 January 2010 by Krashan (talk | contribs) (The first section.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Playing a sound file from disk is one of most common tasks. Reggae can perform it with a few lines of code. Using Reggae for audio playback has several advantages:

  • Wide range of supported audio formats. A codec is selected and loaded by Reggae automatically.
  • Playback is asynchronous. Reggae offloads decoding and playback to a dedicated process. The main application may perform other tasks during playback. It gets informed when the playback ends.
  • Reggae streams audio from disk, so it does not load the whole file to memory. Doublebuffering is fully automatic.
  • Audio is played through selected unit of AHI. Multiple sounds (up to 32, depending on user settings of AHI) may be played simultaneously.

Playing audio directly from disk is best suited for long sounds without low latency requirements. A typical example is music player or playing background music in the game.

From Reggae point of view, the task of playing audio from disk can be divided in two major parts. The first one is to get raw audio samples out of encoded file. The second task is to feed audio data to the output.