Music code

The music code for Death Dawn is geared very heavily around the concept of the 'radio' that is present in all GTA games. A user-defined playlist contains the music to play for each radio station (including non-stations such as the ambient sounds and the pause menu). The music code (in radio.c) then processes this playlist, attempting to play the correct tracks at the correct time. The code is based around a simple plugin system, to allow new playback devices (CDFS, AMPlayer, QTM, etc.) to be written with ease. For each music track, the radio playlist contains the name of the correct player to use.

Perhaps the most important function in the radio code is radio_continue(). This performs the per-frame processing for the radio; in particular it starts the playback of the next music track. To avoid constant polling of playback devices, the radio code estimates when the current track will finish (with the help of a request to the playback code to get the track length and position); when it gets within 5 seconds of the end of playback, it will poll every frame to see when playback finishes.

There are two core types of radio station supported: Timed and timeless. Timed stations have playback synchronised to the current gametime, whereas timeless stations are synchronised to realtime. Timeless stations are used for the pause menu and credits screen (to be implemented!). An important point about timeless stations is that when playback is started (via radio_play()), they always start playback at the start of the playlist.

Playback plugin interface

Each plugin needs to have 6 entry points defined:

  1. Initialisation function. Will only get called when uninitialised, and should set the initialised flag to 1 if successful.
  2. Shutdown function. Will only get called when initialised, and should set the initialised flag to 0 if successful. Will not get called during playback.
  3. Play function. Will only get called when the plugin is initialised; may get called while the plugin is currently playing. Should identify the current track to play (based around the radio state variables), load/open it, and begin playback from time index i (measured in cs).
  4. Stop function. Will only get called when the plugin is initialised. May get called if nothing is currently playing.
  5. Finished function. Is called to check whether the current track has finished playing yet; should return false if it's still playing.
  6. Tryload function. This should try and load the file with the given name, returning its playback length (in cs) if successful, or 0 for failure. Plugins which are unable to reliably determine track length can technically return any non-zero value, but this may impede radio operation as the radio code will be unable to correctly calculate which track should be playing when the player changes radio station. This function is only called during radio initialisation, when the playlist is scanned and the track lengths collected.

Big list 'o music

Current music candidates for use in game:

TODO:
MUST-DOCS: UNKNOWN: Music sources - stuff under Creative Commons (2.5) license? - http://www.throwingmusic.com/freemusic/ Or if the music is a completely seperate download, would it be possible to use stuff under the 2.0 license?
MUST-CODE: MED: Test and improve timplayer support - use SongSectionInfo to get more accurate song position when resuming playback, don't unload song until we know the next one is different, etc.
CODE: MED: Configurable radio file location? maybe just as optional override to the default location (as per mission script)? Will allow for easier management of custom user radios etc.
CODE: UNKNOWN: Fix QTM - transparent sound system only works if installed before sharedsound?
CODE: UNKNOWN: Make radio update player volume automatically as radio_vol changes. Just insert checks in radio_continue that compare new volume against old etc. Would therefore need extra func adding to player interface to udpate volume. May also need to handle stopping when volume <= 0?
CODE: UNKNOWN: Allow for tracks where plugin can't return the length - radio file itself will specify the length. (But perhaps only do this for certain plugins which can never return the length, as opposed to doing some generic code for all plugins? Seeing as the length-get function is also a file verirification method, etc.)
CODE: QUICK: DiskSample/AudioMPEG/Vorbis support
???
Profit!