Sound and music tutorial

From SRB2 Wiki
Jump to: navigation, search

Custom sounds and music are common in SRB2 addons. This tutorial teaches you how to implement them into WAD files. If you want custom music to be played in your custom level, see the level header article.

Accepted sound formats

SRB2 2.1 can play many different music formats. The most widely used is Ogg Vorbis (.ogg), as it compresses well without much drop in quality.

FMOD formats

Source: [1]
  • AIFF
  • ASF
  • ASX
  • DLS
  • FLAC
  • FSB (FMOD's sample bank format)
  • IT
  • M3U
  • MIDI
  • MOD
  • MP2
  • MP3
  • Ogg Vorbis
  • PLS
  • S3M
  • VAG (PS2/PSP format)
  • WAV
  • WAX (Windows Media Audio Redirector)
  • WMA
  • XM
  • XMA (only on the Xbox 360)
  • raw audio data

SDL_mixer formats

Source: [2]
  • FLAC
  • MikMod MOD
  • MIDI (Timidity or native Windows support)
  • Ogg Vorbis
  • MP3 (SMPEG libraries)
  • WAV

MikMod formats

Source: [3]
  • 669 (Composer 669, Unis 669)
  • AMF (DSMI Advanced Module Format)
  • AMF (ASYLUM Music Format V1.0)
  • APUN (APlayer)
  • DSM (DSIK internal format)
  • FAR (Farandole Composer)
  • GDM (General DigiMusic)
  • IT (Impulse Tracker)
  • IMF (Imago Orpheus)
  • MOD (15 and 31 instruments)
  • MED (OctaMED)
  • MTM (MultiTracker Module editor)
  • OKT (Amiga Oktalyzer)
  • S3M (Scream Tracker 3)
  • STM (Scream Tracker)
  • STX (Scream Tracker Music Interface Kit)
  • ULT (UltraTracker)
  • UNI (MikMod)
  • XM (FastTracker 2)

Game_Music_Emu formats

Source: [4]
  • AY (ZX Spectrum/Amstrad CPC)
  • GBS (Nintendo Game Boy)
  • GYM (Sega Genesis/Mega Drive)
  • HES (NEC TurboGrafx-16/PC Engine)
  • KSS (MSX Home Computer/other Z80 systems (doesn't support FM sound))
  • NSF/NSFE (Nintendo NES/Famicom (with VRC 6, Namco 106, and FME-7 sound))
  • SAP (Atari systems using POKEY sound chip)
  • SPC (Super Nintendo/Super Famicom)
  • VGM/VGZ (Sega Master System/Mark III, Sega Genesis/Mega Drive,BBC Micro)

Required tools

  • Your sound file. If you're adding a sound effect, it must be a WAV file. If you're adding music, it can be an Ogg, MP3, MIDI or MOD file.
  • A sound editor. Windows XP comes with a tool called Sound Recorder that is sufficient for this task. In later Windows versions, you need to install additional software such as Audacity.
  • A lump editor, such as SLADE or XWE.
  • If you want to add a loop point to your music, you also need a media application capable of editing a file's information tags, such as Winamp.

Sounds

ToDoIcon.png To do
(Monster Iestyn): Inuyasha tells me the first and third sections here are entirely incorrect and actively harmful ...but I can't do anything much to fix this since I know nothing. Can anyone else help the wiki out here?

Formatting the WAV file

SRB2 only recognizes WAV files in the 8-bit Mono format as sounds. If your WAV file is already in this format, you can skip this step. Otherwise, you will need to change its format. This tutorial explains how to do this using Windows XP's Sound Recorder. Later Windows versions come with a different version of Sound Recorder that can't perform the necessary tasks, so you will need to use other software.

Open Sound Recorder and open your WAV file with it. Now select File → Properties in the menu bar. A new window will then pop up. Under the "Format Conversion" box, click "Convert Now...". A second window will pop up. Under "Attributes", select "48.000kHz, 8 Bit, Mono". Click "OK". On the first window, click "OK" again. After that, save the WAV file.

Choosing the lump name

Now you need to know how to name your sound lump. The names of sound lumps are prefixed by DS, e.g. DSSPIN. If you want to replace an existing sound, look up the name of the lump in question in the list of sounds and give your lump the same name. To find out which sounds you want to replace, you can preview SRB2's sound lumps, which are stored in the file srb2.srb. SLADE and XWE both have settings for filtering the lump list, by selecting "Audio" on the "Show" drop-down box, or with the "Sound" button, respectively. Now that only sound effect and music files are shown, select the sound effect from the list you want to check and click the play button, or if using XWE, select Wave → Play in the menu bar.

If you want to add a new sound without replacing an old one, you must declare a name for it via SOC or Lua. The game will then automatically reserve one of 800 free slots for the new sound. The internal sound names used by SRB2 are in lowercase and use a sfx_ prefix. For example, if the name of your sound lump is DSCUSTOM, you must declare the sound as sfx_custom. See Freeslot > Declaring freeslot names for a guide on how to declare custom sounds.

Importing the sound file

Now you need to import your WAV file into your WAD as a lump. Open the WAD file with your lump editor. Now insert your sound file. In SLADE, you can simply drag and drop the file into the lump list. In XWE, select Entry → Load on the menu bar, navigate to the folder that contains your file and insert it. Once the file is imported, make sure the lump name matches the name you decided to use. If not, right-click on the lump and select Rename or Rename Entry, respectively. Now you need to convert your WAD file into Doom's sound format. In SLADE, right-click on the lump and select Audio → Convert WAV to Doom Sound. In XWE, click on the lump and select Wave → Save (as Doom Wave) in the menu bar.

Now save the WAD file, close the lump editor (XWE saves automatically) and load your WAD in SRB2 to test the music. If the old sound isn't replaced, check if you gave your lump the correct name.

Music

File format

Unlike sounds, music files don't need to be converted to a specific format. However, you should make sure the size of your file isn't too large. This isn't a problem with sampled music in the MIDI and MOD formats, whose file size is already very small. Recorded music (formats like MP3 and Ogg), however, can become rather large when using a high bitrate. It is recommended that you use the Ogg format (which sounds better at low bitrates) with a bitrate of no more than 128 kb/s. This article will not cover how to convert to Ogg. Note that if you choose to use the Ogg format, your file must have a wavelength of 44,100 Hz to function properly.

Choosing the lump name

Now you need to know how to name your music lump. Most music lumps in SRB2 go by the naming convention O_MAPxxM, with xx being the two-digit form of the number of the map in which the music should be used; for slots above 99 extended map numbers must be used. Some music lumps that are used for special purposes in the game don't follow this convention, such as O_CHRSEL for the music on the character select screen. If you want to replace SRB2's own music, look up the name of the lump in question in the List of music article and give your lump the same name. For example, if you want to replace the music for Greenflower Zone Act 1, name your lump O_MAP01M. If you don't want to replace existing music, you can give the lump any name as long as it starts with O_.

Note that music lumps in the MIDI format start with the prefix D_. The prefix O_ is used for all other formats.

To find out which music you want to replace, you can preview SRB2's music lumps, which are stored in the file music.dta. SLADE can play back Ogg music itself, but if you're using XWE, you will need to export the file. To do this, select the music lump in question and select Entry → Save As... in the menu bar. If your music lump starts with O_, you must save it as an Ogg file. Under "Save as type", select "All Files (*.*)" and then save your file as filename.ogg. Don't forget the file ending .ogg or your music file cannot be opened. After saving the file, you can open it in a compatible player such as Winamp.

Looping (optional)

An image illustrating the first method of inserting a looppoint.
An image illustrating the third (old) method of inserting a looppoint.

For digital music formats that do not automatically loop, there is a way to supply an external looping point for the music. This will cause SRB2 to loop the music back to a predefined point once it finishes playing, rather than the beginning of the track.

There are three ways to set up a loop point. The first two involve using a dedicated metadata tag, while the last uses the stream's COMMENT metadata field.

The preferred way of setting a loop point is using the LOOPMS metadata tag. When using LOOPMS, the loop point should be supplied in terms of milliseconds. Winamp can insert this dedicated tag in the "View file info..." dialog. To do so, click the "Advanced" tab, click "Add New", and highlight the new empty row. Then, input LOOPMS as the Name for the tag and input the desired time in milliseconds as the value (for example, 30.25 seconds equals 30250).

The other methods require that you supply the loop point in terms of audio samples, directly related to the sampling rate of the file. A crude way to calculate the value of the loop point would be to multiply the position where you want to place the loop point, in seconds, with the sampling rate of the file - for example, to place the loop point for a file with a sampling rate of 44,100 Hz at 30.250 seconds, you would use 1334025 (= 30.25 * 44100) as the value. That said, it can be any sample, so using an audio editor like Audacity to get a finer, more seamless loop point is recommended for those with the capability to do so.

The second method of setting a loop point is through another dedicated metadata tag, the LOOPPOINT tag. You can add this tag in Winamp in the exact same way as the LOOPMS tag; just use LOOPPOINT as the name instead, and the number of samples as the value (1334025 with our example).

The third and last method of supplying a loop point is to insert the text LOOPPOINT=<value> in the COMMENT field of the music file, where <value> is the number of audio samples as mentioned above (again, 1334025 with our example). This method for providing a loop point is mostly for backwards compatibility with older versions.

Note that music modules and emulated music tracks have different mechanics built-in; if you need to edit that, you are better off seeking a tutorial for the format in question. Also, SRB2 does not support looping MIDIs at all.

Importing the music file

Now you need to import your music file into your WAD as a lump. Open the WAD file with your lump editor. Now insert your music file. In SLADE, you can simply drag and drop the file into the lump list. In XWE, select Entry → Load on the menu bar, navigate to the folder that contains your file and insert it. Once the file is imported, make sure the lump name matches the name you decided to use. If not, right-click on the lump and select Rename or Rename Entry, respectively.

Now save the WAD file, close the lump editor (XWE saves automatically) and load your WAD in SRB2 to test the music. If the old music isn't replaced, check if you gave your lump the correct name.

Listening to music with SLADE

SLADE includes the functionality of playing certain formats of sound. These formats include Ogg, MP3, WAV, and MIDI. Some other formats, such as VGM, cannot be played in SLADE and will appear as a lump of unknown type. This does not mean your VGM won't work, but be sure to add the wad you're working on to SRB2 and test to see if the music works properly.