GAME BOY / 02

Change volume over time after a note starts

A sound that fades quickly, or slowly grows louder. The envelope lets the APU itself change volume in steps after a note starts.

Change values and compare by listening

Start with initial volume 12, down, and period 2. Increasing the period to 7 makes each step take longer. Then compare rising volume with initial volume 3, up, and period 2.

Maximum minus minimum of the generated left-channel PCM, measured in 10 ms windows. Fixed axes: 0–2 seconds horizontally and 0–0.25 vertically. This does not read the APU's internal volume value.

No sound plays until you press Play.

The existing WASM core generates the DMG digital audio. It does not reproduce the hardware amplifier, speakers, or analog filters. Only the preview uses a fixed gain and 10 ms fades at both ends; the plot shows unprocessed PCM. Changing settings stops the preview, so press Play again.

Take the same settings into code

Changing values updates the code and link. Try it with Run in Playground; Stop ends playback.

What happens in the chip?

Pulse 1 (CH1) stays at A4 and 50% duty. Only NR12 initial volume, direction, and period change. Volume has 16 steps, from 0 to 15. With periods 1–7, it changes one step approximately every period / 64 seconds. At either endpoint, 0 or 15, it stops changing. Period 0 disables automatic changes.

Initial volume 0 with up lets you try a rise from silence. At 0 with down, the DAC is off and produces no sound. Reaching volume zero through the envelope is different from stopping the DAC with keyOff().

setVoice() is configured before calling keyOn() so playback starts from the initial volume each time. Writing NR12 during playback has hardware/core-dependent side effects, so this page stops and retriggers the sound when settings change.

sleep(2) is JavaScript control that stops the preview after two seconds. The APU itself advances the volume changes shown in the plot; JavaScript does not repeatedly rewrite the volume. No automatic volume adjustment is used apart from the fixed gain.

NR12:Volume & Envelope specification