Actions

SCHG

Music Hacking/Voice and Note Editing

From Sonic Retro

Music Hacking: Pointer and Header Format | Voice and Note Editing | DAC Samples, Coordination Flags, Game Specifics, and Real-Time Music Editing | Other Games and Data Locations | Tricks of the Trade



Voice editing

Voices are the instruments that you hear playing in the music throught the FM channels. To edit them correctly, you need to know FM synthesis. Swapping and copying voices is a simple copy-paste job. A voice is $19 hex bytes, and has no header. It is raw data that gives information to the YM2612 FM chip in the Megadrive to give the desired sound output. The format of a voice is as follows.

Offset Description Register
Ch.1/3 Ch.2/4 Ch.3/6
$0 Feedback (next 3 bits) / Algorithm (lower 3 bits) B0 B1 B2
$1 Detune of operator 1 (nybble 1) / Coarse-frequency multiplier [MULT] of operator 1 (nybble 2) 30 31 32
$2 Detune of operator 3 (nybble 1) / Coarse-frequency multiplier [MULT] of operator 3 (nybble 2) 38 39 3A
$3 Detune of operator 2 (nybble 1) / Coarse-frequency multiplier [MULT] of operator 2 (nybble 2) 34 35 36
$4 Detune of operator 4 (nybble 1) / Coarse-frequency multiplier [MULT] of operator 4 (nybble 2) 3C 3D 3E
$5 Rate scaling [RS] of operator 1 (upper 2 bits) / Attack rate [AR] of operator 1 (lower 5 bits) 50 51 52
$6 Rate scaling [RS] of operator 3 (upper 2 bits) / Attack rate [AR] of operator 3 (lower 5 bits) 58 59 5A
$7 Rate scaling [RS] of operator 2 (upper 2 bits) / Attack rate [AR] of operator 2 (lower 5 bits) 54 55 56
$8 Rate scaling [RS] of operator 4 (upper 2 bits) / Attack rate [AR] of operator 4 (lower 5 bits) 5C 5D 5E
$9 LFO enabled [AM] for operator 1 / First decay rate [D1R/DR] of operator 1 (lower 5 bits) 60 61 62
$A LFO enabled [AM] for operator 3 / First decay rate [D1R/DR] of operator 3 (lower 5 bits) 68 69 6A
$B LFO enabled [AM] for operator 2 / First decay rate [D1R/DR] of operator 2 (lower 5 bits) 64 65 66
$C LFO enabled [AM] for operator 4 / First decay rate [D1R/DR] of operator 4 (lower 5 bits) 6C 6D 6E
$D Second decay rate/sustain rate [D2R/SR] of operator 1 70 71 72
$E Second decay rate/sustain rate [D2R/SR] of operator 3 78 79 7A
$F Second decay rate/sustain rate [D2R/SR] of operator 2 74 75 76
$10 Second decay rate/sustain rate [D2R/SR] of operator 4 7C 7D 7E
$11 First decay level/sustain level [D1L/SL] of operator 1 (nybble 1) / Release rate [RR] of operator 1 (nybble 2) 80 81 82
$12 First decay level/sustain level [D1L/SL] of operator 3 (nybble 1) / Release rate [RR] of operator 3 (nybble 2) 88 89 8A
$13 First decay level/sustain level [D1L/SL] of operator 2 (nybble 1) / Release rate [RR] of operator 2 (nybble 2) 84 85 86
$14 First decay level/sustain level [D1L/SL] of operator 4 (nybble 1) / Release rate [RR] of operator 4 (nybble 2) 8C 8D 8E
$15 Total level [TL] of operator 1 40 41 42
$16 Total level [TL] of operator 3 48 49 4A
$17 Total level [TL] of operator 2 44 45 46
$18 Total level [TL] of operator 4 4C 4D 4E
It should be noted that Sonic 2 uses a different format (which actually correctly follows the internal order of operators used by the YM2612) than the other main Sonic games; to correcty convert songs from and to that game, it is necessary to swap the second and the third byte in each group of operators, as shown in the following chart:
VoiceOperators.png

Note Editing

The way the music is set up in the Sonic games is similar to how music is structured in a module file. Here are some values that will help you directly edit notation data in the music.

Notation is SMPS usually follows the same general formula:

Note | Duration

What's worth noting, however, is that the format of notation is not strictly limited by a note definition followed by a duration. Once either a note or a duration value is defined, you can omit repetition of those values; however, you must always define a note before you can define a duration for the first time.

An example of valid note combinations:


81 01 04 03 02

This particular combination of values will play note $81 at multiple durations — first 01, then 04, then 03, and then 02. As long as a note is defined, its value will stay in memory and be repeated on any subsequent duration parsed in the channel.

Another example:

82 02 81 82 83 84 86 8F

This combination of values will play all of the defined notes with a duration of 02 — first 82, then 81, then 82, then 83... so on and so forth. As previously stated, the first definition in a string of values must always be a note. When repeating notes instead of definitions to omit duplicate data, the string will be ended by placing a new duration value.

Remember that when placing a new duration, it will apply to the last defined note value... so if there were a duration value of 07 after 8F, it would play with a duration of 07 instead of 02.

Value Definitions

The values you see in notation have varying ranges with different purposes. Their significance is as follows:

Range Purpose
$00-$7F Note duration (How long a note is held for)
$80-$DF Notes (80 is a rest)
$E0-$FF Coordination flags

Notes

When a note bye is read from a FM or PSG channel, it isn't sent directly to the sound chips. First, a special value called the channel key displacement — initially set in the header and modified with coordination flags $E9/$FB — is added to the byte value to get a new note value. This new note value is converted to a frequency the sound chips understand by looking at a frequency table. This frequency value then has another special value added to it called the channel frequency displacement — initially 0 and set with $E1 — before being sent to the chip.

Note Value Equivalents

Value Note
$81 C
$82 C♯/D♭
$83 D
$84 D♯/E♭
$85 E
$86 F
$87 F♯/G♭
$88 G
$89 G♯/A♭
$8A A
$8B A♯/B♭
$8C B
$8D 1C
$8E 1C♯/D♭
$8F 1D
$90 1D♯/E♭
$91 1E
$92 1F
$93 1F♯/G♭
$94 1G
$95 1G♯/A♭
$96 1A
$97 1A♯/B♭
$98 1B
$99 2C
$9A 2C♯/D♭
$9B 2D
$9C 2D♯/E♭
$9D 2E
$9E 2F
$9F 2F♯/G♭
$A0 2G
$A1 2G♯/A♭
$A2 2A
$A3 2A♯/B♭
$A4 2B
$A5 3C
$A6 3C♯/D♭
$A7 3D
$A8 3D♯/E♭
$A9 3E
$AA 3F
$AB 3F♯/G♭
$AC 3G
$AD 3G♯/A♭
$AE 3A
$AF 3A♯/B♭
$B0 3B
$B1 4C
$B2 4C♯/D♭
$B3 4D
$B4 4D♯/E♭
$B5 4E
$B6 4F
$B7 4F♯/G♭
$B8 4G
$B9 4G♯/A♭
$BA 4A
$BB 4A♯/B♭
$BC 4B
$BD 5C
$BE 5C♯/D♭
$BF 5D
$C0 5D♯/E♭
$C1 5E
$C2 5F
$C3 5F♯/G♭
$C4 5G
$C5 5G♯/A♭
$C6 5A
$C7 5A♯/B♭
$C8 5B
$C9 6C
$CA 6C♯/D♭
$CB 6D
$CC 6D♯/E♭
$CD 6E
$CE 6F
$CF 6F♯/G♭
$D0 6G
$D1 6G♯/A♭
$D2 6A
$D3 6A♯/B♭
$D4 6B
$D5 7C
$D6 7C♯/D♭
$D7 7D
$D8 7D♯/E♭
$D9 7E
$DA 7F
$DB 7F♯/G♭
$DC 7G
$DD 7G♯/A♭
$DE 7A
$DF 7A♯/B♭

Alternate SMPS Mode for S3+

In alternate SMPS mode, you have only two cases: you are either dealing with a coordination flag or with a note. Coordination flags are handled as usual; notes are very different, and follows the following format:

offset Description
$00-$01 Raw frequency of the note (BIG endian): it has 14 bits for FM channels or 10 bits for PSG channels. For a nonzero frequency, the track's key displacement is sign extended and added as a frequency modifier; this is *instead* of changing the note's key.
$02 Stored to track RAM, but ignored.
$03 Raw duration, even if $80-$FF, but still subjected to the same notes as normal durations on multiplication by dividing timing.

And that is it; all else works as for normal SMPS.

DAC Sample Definitions

Sonic 1

Value Sample
$81 Kick
$82 Snare
$83 Timpani (uses pitch of last played 88-8B Timpani)
$84 invalid/Noise
$85 invalid/Noise
$86 invalid/Noise
$87 Sega Sound
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Floor-Timpani

Sonic 2 Beta

Value Sample
$81 Kick
$82 Snare
$83 Clap
$84 Scratch
$85 Low-Timpani (slightly higher than $8A)
$86 Mid-Tom (Note: same pitch as Floor-Tom from Sonic 2 Final)
$87 Silent
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Floor-Timpani
$8C Mid-Tom (same as $86)
$8D Low-Tom
$8E Floor-Tom
$8F Clap

Sonic 2 Final

Value Sample
$81 Kick
$82 Snare
$83 Clap
$84 Scratch
$85 Low-Timpani (slightly higher than $8A)
$86 Floor-Tom
$87 Floor-Bongo
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Floor-Timpani
$8C Hi-Tom
$8D Mid-Tom
$8E Low-Tom
$8F Hi-Bongo
$90 Mid-Bongo
$91 Low-Bongo

Sonic 3 and Knuckles/Sonic 3D Blast

Value Sample
$81 Snare
$82 High-Tom
$83 Mid-Tom
$84 Low-Tom
$85 Floor Tom
$86 Kick
$87 Kick + Snare
$88 Crash Cymbal
$89 Ride Cymbal(?)
$8A Low Metal Hit
$8B Metal Hit
$8C High Metal Hit
$8D Higher Metal Hit
$8E Low Metal Hit
$8F Clap
$90 Electric High-Tom
$91 Electric Mid-Tom
$92 Electric Low-Tom
$93 Electric Floor Tom
$94 Tight Snare
$95 Mid-pitch Snare
$96 Loose Snare
$97 Looser Snare
$98 Hi-Timpani
$99 Low-Timpani
$9A Mid-Timpani
$9B Quick Loose Snare
$9C Click
$9D Power Kick
$9E Quick Glass Crash
$9F Glass Crash with Snare
$A0 Glass Crash
$A1 Glass Crash with Kick
$A2 Quiet Glass Crash
$A3 Odd Snare with Kick
$A4 Kick with extra bass
$A5 "Come on!"
$A6 Dance Snare
$A7 Loose Kick
$A8 Moderately Loose Kick
$A9 "Woo!"
$AA "Go!"
$AB Snare with voice going "Go!"
$AC Power Tom
$AD Hi-Wood Block
$AE Low-Wood Block
$AF Hi-Hit Drum
$B0 Low-Hit Drum
$B1 Metal Crash Hit
$B2 Echoed Clap Hit
$B3 Lower Echoed Clap Hit
$B4 Hip-Hop style hit with a kick
$B5 Hip-Hop style hit with a Power Kick
$B6 Some Bass with a voice going "Hey!"
$B7 Dance Style Kick
$B8 Hip-Hop hit with a kick
$B9 pointer to $B8
$BA Reverse Fading Wind Sound
$BB Scratch
$BC Loose Snare with noise
$BD Power Kick
$BE Crashing noise with voice going "Woo!"
$BF Quick Hit
$C0 Kick with a voice going "Hey!"
$C1 Power Kick with hit
$C2 Low Power Kick with hit
$C3 Lower Power Kick with hit
$C4 Lowest Power Kick with hit

Note: Sonic 3D has all samples $81 to $9E from Sonic 3 & Knuckles plus two unique ones $9F and $A0.

Knuckles' Chaotix

Value Sample
$81 Electric Kick
$82 Electric Snare
$83 Splash Cymbal
$84 Ride Bell
$85 High Tom
$86 Mid Tom
$87 Low Tom
$88 Electric Hi-Hat
$89 Crash Cymbal
$8A Clap
$8B Acoustic Kick
$8C Acoustic Snare
$8D Bell
$8E Fingers Snapping
$8F Cowbell
$90 High Click
$91 Low Click
$92 High Bongo
$93 Low Bongo
$94 High Timpani
$95 Low Timpani
$96 Silence

Sonic Crackers

Value Sample
$81 Kick
$82 Snare
$83 Hi-Tom
$84 Mid-Tom
$85 Low-Tom
$86 Voice sample "Let's go!"
$87 Voice sample "Hey!"
Sonic Community Hacking Guide
General
Sonic Music Hacking Guide | SonED2 Manual
Game-Specific
Sonic the Hedgehog (16-bit) | Sonic the Hedgehog (8-bit) | Sonic Eraser | Sonic CD (prototype 510) | Sonic CD | Sonic CD (PC) | Sonic 2 (Nick Arcade prototype) | Sonic 2 (Simon Wai prototype) | Sonic 2 (16-bit) | Sonic 2 (8-bit) | Sonic 2 & Knuckles | Dr. Robotnik's Mean Bean Machine | Sonic Triple Trouble | Sonic 3 | Sonic & Knuckles | Sonic 3 & Knuckles | Sonic & Knuckles Collection | Sonic Crackers | Sonic 3D: Flickies' Island | Chaotix | Sonic R PC | Sonic Jam 6 | Sonic Advance | Sonic Advance 2 | Sonic Advance 3 | Sonic Battle | Sonic Adventure | Sonic Adventure DX: Director's Cut | Sonic Adventure DX: PC | Sonic Adventure (2010) | Sonic Adventure 2 | Sonic Adventure 2: Battle | Sonic Adventure 2 (PC) | Sonic Heroes | Shadow the Hedgehog | Sonic Riders | Sonic the Hedgehog (2006) | Sonic & Sega All-Stars Racing | Sonic Unleashed (Xbox 360/PS3) | Sonic Generations
Legacy Guides
The Nemesis Hacking Guides The Esrael Hacking Guides
ROM: Sonic 1 | Sonic 2 | Sonic 2 Beta | Sonic 3

Savestate: Sonic 1 | Sonic 2 Beta/Final | Sonic 3

Sonic 1 (English / Portuguese) | Sonic 2 Beta (English / Portuguese) | Sonic 2 and Knuckles (English / Portuguese)
Move to Sega Retro
Number Systems (or scrap) | Assembly Hacking Guide | Subroutine Equivalency List | 68000 Instruction Set | 68000 ASM-to-Hex Code Reference | VDP Documentation | Official Sega 32X Documentation | Official Mega-CD Documentation | Official Sega Mega Drive Documentation