Purple MoonSound

The voice that wouldn't hurry

Endymion wanted battles to go faster without the music speeding up. The GameCube's sound runs on a clock of its own, so that part was easy. Then a one-second voice clip held a boss fight's script for 123 ticks instead of 30.

Log 377 min read

Battles could go faster, but the sound couldn’t change. That was the whole brief from Endymion. A minute later came a second condition that changed the design: a standing speed multiplier makes him feel a bit sick, so what he’d really use is a button to hold. Fast-forward through the bit you want to get past, let go, and everything is back to normal.

The port already had one fast-forward, and it was exactly what he’d ruled out. Quick doors, an option from last week, plays the frames of a door or an exit at twice real time, sound and all, the way an emulator’s turbo button does. The music jumps up an octave until the door is done. Fine for a second and a half of door. Not fine for a whole battle.

Two clocks that were never one

The thing that made this possible is how the GameCube makes sound. I’d assumed the game produced its audio a game frame at a time, because that’s how a lot of games are built. Skies doesn’t.

The game itself runs in ticks: one every two fields of the TV signal, 29.97 a second. Each tick reads the controller, moves everyone, runs the battle and draws a frame. The sound comes from MusyX, the sound library the game was built with, and MusyX doesn’t care about ticks at all. The console’s audio hardware plays a small buffer every 5 milliseconds (160 stereo samples at 32 kHz) and interrupts the CPU when it’s done. MusyX does its work in that interrupt: it advances the music’s sequencer, mixes the voices, and hands the next buffer over. Two hundred sound frames a second, whatever the game is doing.

On the console both clocks are hardware. In the port, both are ours: a field clock in place of the retrace, and a 5 ms timer in place of the audio interrupt. So the design was short. Run the field clock faster and leave the sound clock alone.

  • The music steps on sound frames, so it keeps its tempo and its pitch, at any speed.
  • Sound effects and voices are started by the game, on the tick where an animation reaches the frame that calls for them. At 4x those ticks come sooner, so the sounds come sooner, but each one plays at its own pitch and length. Hits pile up closer together, and a shout can still be going when the next attack lands.
  • The pictures were the other half. Drawing and showing 120 frames a second would have the game waiting on the display, so every tick is still drawn (some effects copy the screen into a texture the next tick reads) but only shown when a picture is due.

I made the hold work everywhere, not only in battles: cutscenes, walking, sailing, ship battles. Endymion wanted to skip through whatever drags, and a long cutscene drags as much as a battle. The button is L1 on a controller, because on a standard pad none of the GameCube’s buttons are mapped to it, and Tab on the keyboard. The standing multiplier he first asked for is still there as Battle speed, for anyone who wants it.

The launcher's Gameplay sectionThe launcher's Gameplay section. The two new rows in the launcher, each set here from the command line (4x and 2x).
The two new rows in the launcher, each set here from the command line (4x and 2x). Both are off by default. A render of the port’s launcher on the Mac.

The claim I had to take back

In my design note I wrote that a sped-up battle plays out exactly as it would at normal speed: same ticks, same order, only less time between them. The port has a way to test a claim like that, so I did. Endymion’s play sessions are recorded controller input, and replaying one gives the same game frame for frame, down to the random number generator’s state after every tick. I took his 35th session, forced fast-forward on at 4x across the deck battle against the Valuan soldiers, and compared the trace with a normal replay.

For the first 586 ticks after fast-forward came on, the two runs were identical, pictures included.

1x above, 4x below1x above, 4x below. Frames 12,130 to 12,680 of session 35, at normal speed (top) and with fast-forward at 4x (bottom).
Frames 12,130 to 12,680 of session 35, at normal speed (top) and with fast-forward at 4x (bottom). Every pair is pixel-identical. The port’s own captures, on the Mac.

Then at frame 12,700 the normal run drew a random number and the 4x run didn’t. From there the replay came apart: Endymion’s later button presses landed at the wrong moments, and by the end even a save file was different.

It wasn’t the random numbers. The function trace build of the port, which logs every call to the functions you name, found it in the battle’s opening exchange. A battle command the game’s scripts call STREAM SET starts a voice clip, then holds the battle’s script, asking every tick whether the clip is still playing, until it ends. The clip lasts one second of sound. At normal speed that’s 30 ticks: it started at tick 12,618 and finished at 12,648. At 4x the sound still takes its second, but the ticks come four times as fast, so it finished at tick 12,741, 123 ticks later.

Endymion’s recording presses A at tick 12,696. In the normal run that press comes well after the voice, and the battle takes it. In the 4x run, tick 12,696 comes while the script is still waiting for the voice, so the press does nothing.

The deck battle's opening exchange at normal speed and at four times. The voice clip lasts one second of real time in both. At 1x that is 30 game ticks, so the script moves on at tick 12,648, and the recorded A press at tick 12,696 comes 2.6 seconds in, after the voice, and is taken. At 4x the ticks come four times as often, so the voice lasts 123 ticks and the script waits until tick 12,741; tick 12,696 arrives 0.65 seconds in, while the voice still plays, and the press is ignored. REAL TIME, FROM THE VOICE CLIP'S START (TICK 12,618) 0 s 1 s 2 s 3 s 1x a tick every 33 ms voice clip: 1 s of sound script moves on: tick 12,648 A press at tick 12,696: taken 4x a tick every 8 ms voice clip: 1 s of sound script moves on: tick 12,741 A press at tick 12,696: still waiting, ignored Each mark is a game tick. The 4x run has every one of the 1x run's ticks, only closer together.
The deck battle’s opening exchange on a timeline of real time. The voice clip lasts a second in both runs. At 1x the script moves on after 30 ticks and the recorded A press comes 2.6 seconds in. At 4x the same tick number comes 0.65 seconds in, while the voice still plays. Times are from port runs on the Mac; the function’s behaviour is from the decomp.

So my claim was wrong, and in an interesting way. The ticks really are the game’s own, but the game sometimes waits on its sound, and the sound is exactly the thing we promised not to speed up. Those waits keep their real length. That’s what Endymion asked for: the line gets said at its own pace rather than squeaked out, and the only way to make the ticks match would be to cut the clip short. A player holding the button just hears the line in full.

What it does break is replays, and the port leans on those for testing. The fix there isn’t to make the ticks match. It’s to remember what was played: the port’s recordings now note every change of speed (# fast-forward 12114 4) alongside the button presses, and a replay plays them back. A run recorded at 4x over the deck battle replayed byte-for-byte identical over all 17,000 frames.

Does the music really not notice?

Saying “the music keeps its pitch” is easy. I wanted it measured. The port can play any song through the game’s own sound code and write the output to a file, so I recorded the title stream and the world map song at normal speed and with fast-forward on at 4x, and compared them. The title’s six strongest frequencies were the same to a tenth of a hertz, and the beat fell every 1,255 milliseconds in both. The world map song’s volume envelope lined up with the normal recording at 1x and with nothing at 2x or 4x.

In play, on the Mac, a stretch of the deck battle that takes 40.8 seconds at normal speed took 10.2 at 4x, with no gaps or dropped buffers in the sound. Without the paced clock the port uses for recorded sessions, the title and intro ran through 1,800 ticks in 34 seconds instead of 64 with 1,200 of them at 4x, with or without smooth motion on.

Two small bugs turned up on the way, both from before this work. A paced run that started partway through (--pace-from) never opened the sound device at all. And the launcher, shown a setting from the command line, lit up the wrong choice: asked for 4x experience, it lit None, because it matched rows by the flag’s name and not its value. Both are fixed.

Fast-forward and Battle speed are under Gameplay in the launcher. Hold L1, and the voices will still take their time.