Skip to content

Compiling songs

Veikko Sariola edited this page Feb 20, 2024 · 3 revisions

Once you have composed your song.yml, you need to first compile it into an .asm file with sointu-compile, which can then be compiled with nasm into an object file. For example on Windows:

sointu-compile -o . -arch=386 song.yml
nasm -f win32 song.asm

Note most 4k intros are 32-bit code (-arch=386) instead of 64-bit code (-arch=amd64), but Sointu defaults to platform architecture if the architecture is not explicitly defined. Thus, usually you want use the -arch=386 and -win32 parameters. This gives you a object file (.o on linux or .obj on Windows) that you need to link with your program.

While compiling, sointu-compile also gives a song.h file, which is the header file you need to include in your code.

There is usually a single function, void su_render_song(SUsample *buffer); which you need to call to render the song into a buffer. SUsample is usually just float (the header has typedef float SUsample;), but sointu can also be configured to produce 16-bit integer samples.

The length of the buffer should be at least SU_BUFFER_LENGTH, which is defined as SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT i.e. the buffer should be something like SUsample sound_buffer[SU_BUFFER_LENGTH];.

Loading samples from gm.dls file

If you have used samples from gm.dls file, you need to call su_load_gmdls(); before su_render_song(); Sointu is kind enough to define SU_LOAD_GMDLS if you need to do so, so you can safely add the following lines to your code:

#ifdef SU_LOAD_GMDLS
su_load_gmdls();
#endif // SU_LOAD_GMDLS

Playback

The buffer can now be played back using various platform specific mechanisms e.g. by using mmsystem.h or dsound.h on Windows, or alsa/asoundlib.h on Linux. See examples/code/C for complete examples how to playback a song.

Clone this wiki locally