Audio and video¶
The ARM in the iPod decodes neither music nor films. Two other blocks on the chip do the work, and the firmware only configures them, feeds them and collects what comes out.
Video goes to a fixed-function H.264 decoder. Audio goes to sm1, a programmable DSP that runs a codec program the CPU copies into its internal SRAM before each track. The image does carry a decoder, then, but it is written for the DSP and stored as data. Chikuma reproduces everything around it and loads its own clean-room decoders on the DSP. How sm1 plays music walks through the whole audio path, register by register.
Audio¶
Load the program, feed, wait, collect¶
The audio engine is a bus-mastering DSP. For each track the firmware, and Chikuma after it, runs the same four steps:
- Load the codec's program and tables into the engine's SRAM, and configure it for the track.
- Hand it a linked list of descriptors in main memory, each pointing at one compressed packet.
- Wait on the completion interrupt.
- Collect the decoded 16-bit PCM from the slot the engine fills, and hand the slot back.
One engine for every codec¶
The engine has no idea which codec it runs. The codec lives in the program the CPU loaded and in how the stream is framed. An MP3 frame goes in whole. An AAC payload loses its container framing first.
A comparison of the engine's whole configuration between an AAC track and an MP3 podcast shows this. Only a handful of numeric parameters differ, and nothing in them names a format.
This shapes both targets. The emulator has to be the decoder, so it decodes on the host. The real
iPod needs a program loaded and the block driven. The interface is reproduced in
chikuma/drivers/audio/, and on the device it plays AAC, MP3 and ALAC in real time with Chikuma's
own decoders, sosumi, written in the DSP assembly of
x17.
WAV and AIFF skip the engine¶
Uncompressed files never reach sm1. Measured on the original, WAV and AIFF go from the CPU straight to the output at their own rate, and AIFF is byte-swapped on the way. The PCM at the DAC is the file's, bit for bit. Chikuma plays them the same way, with the same header checks.
The feeder sleeps between packets¶
The feeder hands over a packet and waits on a semaphore that the completion interrupt signals. A decoded result with data in it keeps the track going. An empty one ends it.
Because the feeder blocks instead of spinning, the window manager keeps painting while a track plays. Now Playing updates its title, position, progress bar and cover with playback running underneath.
Values the hardware publishes¶
If the firmware reads a value it never wrote, that value belongs to the hardware, and the emulator's model owes it as an input. This rule governs the whole device-model effort, and two audio crashes come from breaking it.
| Field | What the firmware expects | With a wrong model |
|---|---|---|
| Output ring size | the hardware publishes how many buffers the ring holds, and the firmware wraps its index against it | with zero there the index never wrapped, the buffer address walked off the end of memory, and the firmware faulted after 200 buffers |
| Output position pair | a window over the current output | treated as a running total, a derived pointer drifted out of memory and the firmware took a data abort right at the end of the track, minutes in |
Both crashes go away once the model publishes the field as what it is.
Video¶
A separate block, fed slices¶
Video and audio share nothing. Decoding a film and then a song leaves the audio engine's traffic byte-for-byte identical between the two. Video has its own on-chip H.264 decoder, and like sm1 it is hardware, so the work is the handshake, the buffer layout and the output contract.
The decoder does not take raw H.264 network units. It takes a table with one descriptor per slice. Each entry holds the slice body, already stripped, plus the header fields the driver parsed, and the decoder rebuilds the picture from those.
What the reproduction does¶
The driver lives in chikuma/drivers/video/.
| Stage | State |
|---|---|
| Decoding | clean, including a two-layer temporal GOP. One reference-flag field is derived from the frame's position in the group, and with it every frame decodes with zero errors. The rebuilt units self-check against the descriptor |
| Start of a frame | the run control is a bit that stays set across frames. The hardware acts on its rising edge and clears it on completion, so the model has to clear it too, or the next frame never sees a rising edge and the stream falls out of step. Only the instant-interrupt QEMU machine shows this |
| Output | the frame goes on the one display-pipe window that scales instead of cropping, through a hardware polyphase scaler. Fit-to-screen or full-screen comes from the Video setting |
| Speed on the device | a feature-length film plays at its 24 frames a second, with sound |
On the device the speed depends on the reader. The firmware steps a cursor through the file's tables instead of locating every frame from their start. Chikuma steps the same cursor, and pushes the panel once a frame, as the original does.
The 3D is software¶
Cover Flow and the tilted album art are drawn by the CPU, not by a GPU. The image's OpenGL ES is Vincent, a software rasteriser, which the device runs with a just-in-time backend that generates code at run time.
Chikuma uses Vincent from upstream and recovers only the one vendor extension Apple added to it. The tilted, reflected covers are the processor's work on both firmwares, and they are compared frame to frame against the original on the same flick.
Volume, from the wheel to the codec¶
The volume path is recovered end to end, from a wheel notch to a register in the codec chip.
| Step | What happens |
|---|---|
| Wheel | a notch moves the level by two, clamped by a ceiling |
| Scale | the level lives on a 256-step internal scale, though far fewer codes are audible at the top |
| Region ceiling | a board sold into a market with a volume cap tops out lower. The user's own limit clamps against it and can never pass it |
| Codec choice | read from the SysCfg Codc record. The driver table has a Wolfson-style part at I2C 0x1A and a Cirrus CS42L55 at 0x4A, which the test unit carries. Driving the wrong one gives silence and no error |
| Wolfson-style gain | LOUT1 / ROUT1 with the update-latch bit, so both channels change together |
| CS42L55 gain | one auto-incrementing two-byte write starting at register 0x1A |
Each part maps the level through its own fixed curve. For the Wolfson-style part the reproduction matches a measured bus capture exactly, including how 256 input levels collapse onto far fewer distinct codes.
One calibration byte in the curve has no source in the image. The code names it as a stand-in and sets it to zero.
Pause is one byte¶
The device pauses by clearing a single flag. The transmitter stays configured and the cursor stays in place, so playback resumes without reprogramming and there is no DMA teardown at all. Stop is different: it tears the transmitter down and rewinds. Chikuma's pause reproduces this subset and says so.
The headphone jack¶
Jack detection and the in-line remote are reproduced in chikuma/drivers/hw/mikey.zig and work on a
real iPod. The remote's play/pause and transport buttons are confirmed on the device.
The remote is a small controller on the I2C bus. Presence comes from a GPIO line, but only after a one-shot task publishes the plug object, so a bare emulated device reads "unplugged" until that task runs. The interrupt stays held until the firmware's own read clears it. The emulator model does the same, and a gate asserts it.
The analog wire protocol below the decoded button-and-channel level is outside the recovery. The remote itself has its own section on Accessories.
Modes and fields not covered¶
Every codec mode has a place now. Besides AAC, MP3 and ALAC, the image has one program for its
uncompressed modes and one that serves only Audible's .aa audiobooks. Nobody has seen the original
load the uncompressed program, since the WAV and AIFF it was given never touched the engine, and
Chikuma does not play .aa for the moment. The volume curve's calibration byte also stays open.
On the video side the block plays films. The open points are narrow: one quantisation field, and confirmation on streams that vary it. The live account is in Status.