The sound package offers functionality to play sounds and manipulate the playback within certain boundaries. All manipulations are done via the {@link org.freelords.sound.AudioManager AudioManager} class; other classes deal mostly with the internal workings.

An elementary concept in this package is the concept sound events and common sounds, because they are treated differently throughout the code. Normal sounds are miscellaneous sound snipplets that are typically played in a fire and forget manner; you start them and never care about them again. Examples are unit sounds, or terrain background sounds. For each started normal sound, a new input line to the sound system is claimed, and you get a {@link org.freelords.sound.PlayerReference PlayerReference} instance, which can be used to kill a specific sound later on.

Set apart from them are sound events. Typically, there are a number of events for which specific sounds are played. Examples are winning/loosing a game or background music. They are treated differently from normal sounds in a number of ways.

  1. Only one event is played at a time. If, for example, you celebrate winning a game, the background music is supressed.
  2. They are looped by default.
  3. An event can refer to different sounds; and when looping, a random sound should be picked every time. Also, the mapping from events to sounds should be customizable, so that for example different scenarios can have different background music.

To implement the last item, we introduce the {@link org.freelords.sound.ScenarioEventSounds ScenarioEventSounds} class, which provides such a mapping from an event to one or more sounds. For the rest of the functionality, we implement different interfaces in the AudioManager for normal sounds and sound events. The two classes of sounds can be separately started, stopped, muted, and have their volume set. This is also convenient because the distinction between sounds and sound events roughly follows the line between music and sounds.