Music format

From ZeldaHacking Wiki
Jump to: navigation, search

This page documents the format for music and sound effects in the context of the disassembly.

Sound channels

The gameboy has 4 sound channels, but the oracles keep track of 8 channels internally (4 for music, 4 for sound effects). Only one of each can play at a time, since they share the same hardware channels.

Actual channel Music channel index Sound effect channel index
Square 1 0 2
Square 2 1 3
Wave 4 5
Noise 6 7

The music melody usually goes on Square 2, so sound effects usually prefer Square 1, so as not to drown it out. Square 1 has the "frequency sweep" feature which may be better used for sound effects?

audio/ages/soundChannelPointers.s

Data is formatted like so (Lynna city music used as an example):

sound0a:
	.db $00
	.dw sound0aChannel0
	.db $01
	.dw sound0aChannel1
	.db $04
	.dw sound0aChannel4
	.db $06
	.dw sound0aChannel6
	.db $ff
  • The .db lines determine which channel to use, and what its priority is.
    • Bits 4-7 (the first digit) determine the priority. Lower or equal values will override higher ones when multiple sound effects are played.
    • Bits 0-3 (the second digit) determine the channel number.
  • The .dw lines are pointers to the channel data (in audio/ages/soundChannelData.s).
  • It stops reading channels at .db $ff.

Command list

These are commands used in audio/ages/soundChannelData.s.

Command Description
note $XX $YY Plays a note with frequency X for length Y.
wait1 $XX Wait a certain number of time units.
wait2 $XX  ?
env $X $YY Sets the channel "envelope", which controls how the volume changes while each note is being played.
vol $X Sets the channel volume (0-15). Does not work on the wave channel. (Volume control is limited, so it's reserved for softening on the menu screen? Must use softer waveforms instead to control volume.)
cmdf0 $XX  ?
duty $XX Sets the "duty cycle" (for square channels, 0-3), or the waveform (for the wave channel).
cmdf8 $XX  ?
vibrato $XX Controls vibrato.
cmdfd $XX Transpose?
goto <label> Jump to an address (used for looping).
cmdff End of music / sound effect?