OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Tracker music with transport controls, and sound effects over it, via SNESMOD. More...

#include <snes.h>
#include <snes/snesmod.h>
#include <snes/text.h>
#include "soundbank.h"

Macros

#define NUM_EFFECTS   4
 Number of effects loaded.

Functions

int main (void)
 Entry point — initialize audio, display controls, run transport loop.

Variables

static const char *const effect_name [4]
 Their names on screen, padded to the same width.
static const u16 effect_source [4]
 The effects' sources in the soundbank, in the order they are loaded.
static const char *const pitch_name [3] = { "LOW ", "NORMAL", "HIGH " }
static const u8 pitch_value [3]
 The three pitches of snesmodPlayEffect(), and their names.

Detailed Description

Tracker music with transport controls, and sound effects over it, via SNESMOD.

Plays an Impulse Tracker (.it) module through the SPC700 sound processor using the SNESMOD library, with transport controls (play, stop, pause/resume, volume, fade out), and fires sound effects over the music.

The soundbank holds two modules: the music (nocturne) and a module that is only a set of instruments (neo_lumen_sfx), whose samples become the sound effects. Effects are uploaded into the SPC700's RAM after the module, in the room the module and its echo buffer leave, and the driver does not check: an effect past the room is copied over the echo buffer, which the echo then overwrites. opensnes-music inspect gives the room (the README has the figures); the four effects fit.

The music and the instruments are composed and synthesized for OpenSNES (devtools/audio_assets); the effects are Kenney's (kenney.nl, CC0). The program began as PVSnesLib's "music" and "effects" examples by alekmaul.

SNES Concepts
  • SPC700 audio: separate coprocessor with 64 KB audio RAM
  • SNESMOD workflow: init → setSoundbank → loadModule → play
  • Per-frame snesmodProcess(): sends the queued commands (play, stop, volume, sound effects) to the SPC700, which plays the patterns itself
  • Module volume and fade control
  • Sound effects: snesmodLoadEffect() uploads a sample, snesmodPlayEffect() plays it on a free voice, with volume, pan and pitch
  • SPC RAM is shared: module, samples, echo buffer and effects
What to Observe
  • Music plays immediately on boot
  • A=play, B=stop, X=pause/resume, L/R=volume, START=fade out
  • LEFT/RIGHT choose an effect, UP/DOWN its pitch, Y plays it over the music
Modules Used
console, sprite, dma, input, background, text
See also
snesmod.h

Macro Definition Documentation

◆ NUM_EFFECTS

#define NUM_EFFECTS   4

Number of effects loaded.

Function Documentation

◆ main()

int main ( void )

Entry point — initialize audio, display controls, run transport loop.

Returns
Never returns

Variable Documentation

◆ effect_name

const char* const effect_name[4]
static
Initial value:
= {
"JUMP ", "POWERUP", "LASER ", "CONFIRM"
}

Their names on screen, padded to the same width.

◆ effect_source

const u16 effect_source[4]
static
Initial value:
= {
SFX_JUMP, SFX_POWERUP, SFX_LASER, SFX_CONFIRM
}

The effects' sources in the soundbank, in the order they are loaded.

◆ pitch_name

const char* const pitch_name[3] = { "LOW ", "NORMAL", "HIGH " }
static

◆ pitch_value

const u8 pitch_value[3]
static
Initial value:
= {
4 , 8 , 12
}

The three pitches of snesmodPlayEffect(), and their names.