SGDK. Adding music.

In SGDK, wav and vgm/xgmformats are supported:

  • wav – mainly used for sounds,because a lot of space, but it is possible for music.
  • vga, xgm – they store music (analogue midi),weighs little.

In this article, we will add jump sound and music to the platformer from SGDK. Creating a platformer for Sega Genesis

Import resources.

Download resources from MEGA,and put them in the res folder

In resources.res, add the following lines:

XGM xgm_music "Pump It.vgm"
WAV jump_sfx "jump.wav" XGM

XGM,the syntax is clear, it’s

XGM name path_to_file

WAV needs to specify a driver for the Z80processor that will play the sound.

WAV name path_to_file driver

Of these, the highest quality is XGM. Detailed information about the available drivers and, in general, about all resources is available in SGDK/bin/recomp.txt

Now, let’s add music.

Add music.

Open main.c, in the mainfunction, add the following (anywhere before while).


That’s it, done. Compile and runto hear the music.

Add the sound of the jump.

Add the following line, just before the while loop.

XGM_setPCM(64, jump_sfx, sizeof(jump_sfx));

XGM_setPCM – announces a new PCM sample for the following syntax.

XGM_setPCM(id_semple, sample, sample_size_in_bytes);
  • id_ samples – values from 1 to 63 are used for music,from 64 to 255 occupy sounds.
  • sample – the name of the desired resource that was uploaded to resources.res
  • size_in_bytes allocated space for the sample.

Next, in handleInput,at the moment of the jump,I added the following line:

XGM_startPlayPCM(64, 15, SOUND_PCM_CH2);

Let’s break it down.

XGM_startPlayPCM(id_samples, priority, channel);
  • priority – value from 0 to 15, where 0 is the lower priority and 15 is the higher priority. If the sound is already playing, the priority determines whether the new sound should replace the old sound? That is, the priority is solved by the conflict, two sounds that want to be played on the same channel.
  • channel – specifies a separate channel on which 1 sound can be played. Channels from SOUND_PCM_CH1 to SOUND_PCM_CH4are available. The channel is SOUND_PCM_CH1 used by music.

So here.

XGM_startPlayPCM(64, 15, SOUND_PCM_CH2);
  • We play the 64th sample, in which we recorded the sound of the jump.
  • Highest Priority (15)
  • On channel 2 (SOUND_PCM_CH2).

Done, now during the jump, you will hear the sound.

What to write music for the Sega Genesis?

Music is written on DelfeMask.

There are 2 versions, paid and free:

  • paid – costs $ 10,available on PC and android. The latest version of the program is used.
  • free – available on version 0.12.1. There is only on PC.

Example of music written in DelfeMask:

Final result.

Пожалуйста отключи блокировщик рекламы, или внеси сайт в белый список!

Please disable your adblocker or whitelist this site!