Skip to content

Technical design

LenweSaralonde edited this page Mar 23, 2020 · 23 revisions

Play music with the WoW API

The basic principle of Musician consists in playing audio recordings of instrument notes in time with a musical score or manually by the player using the computer keyboard.

The inspiration was taken from the Mellotron, an electro-mechanical keyboard instrument from the 1960’s on which each key plays a magnetic tape of the recorded note. This instrument and it’s very distinctive sound was made popular by artists such as The Beatles and David Bowie.

Musician relies on 2 core functions of the WoW API: PlaySoundFile and StopSound.

willPlay, soundHandle = PlaySoundFile(soundFile, channel)

PlaySoundFile accepts a path to an OGG file and a game sound channel. In our case, sounds are always played through the SFX channel so they are affected by the environmental audio effects (i.e. reverb when inside the Stormwind Cathedral etc.) which provides a more immersive experience.

The note keeps playing until StopSound is called or when the note exceeds the actual sound file duration.

StopSound(soundHandle, fadeoutTime)

StopSound accepts as parameter the sound handle provided by PlaySoundFile, but also a fadeoutTime. The fade out is essential in the case of playing musical notes to simulate the decay of the instrument and avoiding the note to end abruptly which would not sound natural at all.

Unfortunately, there is nothing more we can do with the WoW API. There is no way to change the volume, the panning, to set loop points or an envelope (except for the decay as explained above). Everything has to be pre-recorded in a sound file with a limited duration.

Creating a sample library

To be able to play music, we first need to create a sample library, with as much sound files as there are notes and instruments.

This can be achieved by recording each individual note of each instrument but since it requires the help of an actual musician, a full recording setup and a lot of time, the easy way is to generate the samples out of virtual instruments using a DAW such as FL Studio.

The maximum duration of each note is set to 6 seconds which covers 99% of the needs, without taking too much disk space. The note range start from the MIDI C0 (12 @ 16.3515 Hz) to C8 (108 @ 4186 Hz).

A MIDI file containing all the notes is rendered using the virtual instrument we want to use in WoW into a single WAV file, that is then splitted into individual OGG files using a Node.js script and FFmpeg.

The slicer script also performs some normalization for each individual note sample file to ensure each instrument has a constant volume level, is loud enough to be properly heard in game among the other instruments and avoid clipping when many simultaneous notes are playing.

The normalization settings usually applied are :

  • -10dB peak normalization for plucked instruments (harp, guitar etc.)
  • -20dB RMS normalization for continuous instruments (violin, flute, voice etc.)
  • -4dB peak normalization for drums (they need to be louder to preserve the dynamics)

File caching

Preloader

MIDI converter

Song import

Registry

Communication

Live play

Visual feedback

Clone this wiki locally