The tick in long music
Music in this game is streamed from the disc. The sound driver keeps a ring of two 256 KB pieces in the console’s audio memory and refills one while the other plays. The music is compressed with Nintendo’s DSP-ADPCM: blocks of 14 samples, each block with a header byte that sets its scale and its predictor, the rule by which a sample is predicted from the two before it.
- Where
- main.dol, sound driver stream refill and stream update (sd_stream_loader_step, sd_ax_callback)
- Cause
- The first block after a wrap gets the previous wrap’s scale and predictor (none at the first wrap)
- Interval
- About 20.8 s
- Size
- Errors of thousands of steps, for a few milliseconds
- In the Dolphin emulator
- Present at the title theme’s first wrap
- Audible
- As a faint tick (not checked by ear)Unconfirmed
- On a real console
- Expected to be the same; not testedUnconfirmed
When playback runs off the end of the ring and starts again at its beginning, the decoder skips the header byte of the first block there and takes the block’s scale and predictor from a restart setting that the driver gave it. The driver reads the right byte, the header of the block that will come next, but it only passes it on once it notices that the playback has wrapped, which is too late: each wrap uses the value saved for the wrap before. At the first wrap there is none yet, so the block decodes with a predictor and scale of 0. Either way 14 samples come out wrong, and since every later sample is predicted from the ones before, the error dies away over the next few hundred samples, a few milliseconds.
The driver also writes two raw bytes of the compressed data into the restart setting’s “previous samples”. That looks wrong too, but for a streaming voice the decoder keeps its own previous samples at a wrap and does not read those two.
Every music stream plays at 44,100 samples a second, so the ring wraps about every 20.8 seconds. Played through the game’s ring, three tracks (the title theme and two others) come out wrong by about 3,500 to 26,000 steps of the 16-bit range at a wrap, for about 3 to 9 milliseconds; the wraps where the old and the new header byte happen to agree come out clean.
Evidence
The stream refill function of the sound driver saves the restart setting from the buffer it has just filled, after the last piece of a ring’s turn is loaded, and the stream update hands it to the voice when it sees the play position jump back, that is after the wrap. The voice set-up gives every stream that plays through the ring an empty setting and marks the voice as a streaming voice. Both match the original machine code exactly. The sizes come from decoding the tracks once as one continuous stream and once the way the ring plays them.
In the Dolphin emulator (whose sound emulation leaves a streaming voice’s previous samples alone at a wrap), the game’s output at the first wrap of the title theme matches this decoding to within the emulator’s ordinary difference from the file, while a clean decode is off by about 3,000 steps there at the game’s output level.