Skip to content

Sound and Music workflow

Jay Garcia edited this page Jan 8, 2020 · 4 revisions

Requires

https://github.com/ModusCreateOrg/modite-adventure/wiki/Development-Workflow

Tools

Workflow music

Most of the below is for new, but the "edit" workflow is similar, minus the additions.

  • Add a song to <project_root>/modite-adventure-resources/resources/music.
  • Add the to <project_root>/modite-adventure/src/Resources.r like the following:
########### SOUND :: MUSIC ###########
PATH resources/music/
RAW EmptySong.xm <--- Do not touch this one
RAW Main_Menu.xm
RAW Your_New_Song.xm
  • Compile resources :
# within modite-adventure/ 
make resources

If the above fails, you may have not named file appropriately in Resources.r.

  • Add your song to the game by editing GSoundPlayer.cpp (in modite-adventure/src/)
static const TUint16 allSongs[] = {
  EMPTYSONG_XM,
  MAIN_MENU_XM,
  YOUR_NEW_SONG_XM
};
  • Add your song to the area within the game you'd like to play. Eg. Main Menu:
GMainMenuState::GMainMenuState() : BGameEngine(gViewPort) {
  gSavedGameList.LoadSavedGameList();
  mFont16 = new BFont(gResourceManager.GetBitmap(FONT_16x16_SLOT), FONT_16x16);
  mPlayfield = new GMainMenuPlayfield();
  AddProcess(new GMainMenuProcess());

  gWidgetTheme.Configure(
      WIDGET_TEXT_BG, COLOR_TEXT_BG,
      WIDGET_TITLE_FONT, mFont16,
      WIDGET_TITLE_FG, COLOR_TEXT,
      WIDGET_TITLE_BG, -1,
      WIDGET_WINDOW_BG, gDisplay.renderBitmap->TransparentColor(),
      WIDGET_WINDOW_FG, gDisplay.renderBitmap->TransparentColor(),
      WIDGET_END_TAG);

  gDisplay.SetColor(COLOR_TEXT, 255, 255, 255);
  gDisplay.SetColor(COLOR_TEXT_BG, 255, 92, 93);

#ifdef ENABLE_AUDIO
  gSoundPlayer.PlayMusic(YOUR_NEW_SONG_XM);
#endif
}

We wrap all gSoundPlayer.PlayMusic(); calls with #ifdef ENABLE_AUDIO and #endif preprocessor directives for debugging purposes.

  • Run the game, go to whatever area of the game to listen to the music :)
  • If the above fails, check Resources.h for your song and make sure your pre-processor reference (Eg. YOUR_NEW_SONG_XM) is correct.

SFX Workflow

  • Create your sound effect & save within <project_root>/modite-adventure-resources/resources/sound_effects.
  • Add file to modite-adventure/src/Resources.r
########### SOUND :: SFX ###########
PATH resources/sound_effects/
RAW SFX_empty.wav
RAW SFX_menu_nav_down.wav
...
RAW SFX_your_effects_file.wav
  • Create public utility function in GSoundPlayer.h
class GSoundPlayer : public BSoundPlayer {
public:
  void Init(TUint8 aNumberFxChannels);
//...
  // SFX Methods //

  void SfxSaveGame();
  void SfxStartGame();
  void SfxYourEffectsFile(); 
};
``
- Add file to `GSoundPlayer.cpp` `effectlist[]` array. 
```CPP
static const TUint16 effectsList[] = {
  SFX_EMPTY_WAV,
  SFX_MENU_NAV_UP_WAV,
  ...
  SFX_ITEM_HEART_WAV, // <-- Be sure add Comma
  SFX_YOUR_EFFECTS_FILE_WAV // Comes from Resources.h
};
  • Implement your Sound effect in a function
void GSoundPlayer::SfxYourEffectsFile() {
  PlaySfx(FindSfxNumber(SFX_YOUR_EFFECTS_FILE_WAV));
  // The JavaScript version would be:
  // this.PlaySfx(this.FindSfxNumber(SFX_YOUR_EFFECTS_FILE_WAV)
}
  • Make use your SFX in the game.
void GEnemyProcess::NewState(TUint16 aState, DIRECTION aDirection) {
  mState = aState;
  mSprite->mDirection = aDirection;
  mSprite->mDx = 0;
  mSprite->mDy = 0;

  switch (aState) {

//...
    case HIT_STATE:
      mSprite->vx = 0;
      mSprite->vy = 0;
      mStep = 0;
      mSprite->cMask &= ~STYPE_EBULLET;
      gSoundPlayer.SfxEnemyTakeDamage(); // <--- Here
      Hit(aDirection);
      break;
//.. 
    default:
      break;
  }
}

General Notes

  • All Songs should use no more than 10 channels and saved in the Impluse Tracker (XM) format.
  • Songs use 8-bit samples from NES, and Gameboy
  • Use the SONG_TEMPLATE.xm for new song creations
  • SFX files should be saved in 16Bit 44.1Khz Mono Windows Wave (.wav).

All resources are stored within the Modite Adventure Resources repository within:

resources/
├── music
└── sound_effects
Naming Conventions:
  • Important: Only special characters allowed in song names are_ and .;
  • Music: Song_Title.xm
  • SFX: SFX_some_action.wav.
Examples:
├── SFX_empty.wav ## Please do not edit
├── SFX_enemy_death.wav
├── SFX_enemy_take_damage.wav
├── SFX_item_heart.wav
├── SFX_player_earn_key.wav
├── SFX_player_quaff_fire_spell.wav
├── SFX_player_slash.wav
└── SFX_player_take_damage.wav