Pin Eight Home: Home

GBA sample rate calculator

Developers on the Game Boy Advance platform have often complained of clicks in their programs' audio output. These clicks tend to arise when the programmer chooses a sample rate such that the number of samples played per frame is not a whole number. There exist only a few "nice" sample rates on the GBA that will result in clickless playback when switching sample buffers in vblank; this tool searches for them.

Skip explanation

Explanation of tool

In computer engineering, the term "divider" refers to a circuit that generates one output pulse for every n input pulses, where n denotes a positive integer called the divisor. A "fixed divider" has a fixed divisor; a "programmable divider" has a means for other devices to control the divisor within a given range.

First, I'll give a model of a typical audio playback system's variable rate DAC (digital to analog converter).

  • a master clock with a given rate,
  • a main memory containing PCM samples,
  • a PCM digital to analog converter,
  • a FIFO buffer for samples,
  • a programmable divider on the master clock that triggers loading a new sample from the FIFO into the DAC, called "period divider" because it controls the period of each sample,
  • a fixed divider on the programmable divider that triggers fetching more samples from main memory into the FIFO, whose divisor is equal to the number of samples fetched, called "fetch divider", and
  • a second fixed divider on the master clock that triggers pointing the FIFO at a block of audio samples in main memory, called "frame divider" because it is often set up to occur when loading a new video frame.

Nintendo designed the Game Boy Advance system's PCM channels with master clock rate 16777216 Hz and fetch width 16 samples. The GBA also has four programmable clock dividers, one of which the PCM hardware uses to determine the sample period. Some game engines use a second programmable divider for the frame divider, but I find this a bit too unpredictable in practice given that the video and the rest of the game engine run off the video hardware's vblank divider, which runs at 280896*n master clock cycles, where n denotes a positive integer representing the number of video frames corresponding to the length of one block of audio samples.

The script in this page generates periods (and corresponding buffer sizes and sample rates) such that an integral number of fetches occur within one frame. First make sure you're on a relatively recent web browser that supports the HTML DOM (such as IE 6 or Mozilla), and turn on scripting. Then fill in this form, click Update, and read good rates from the table.

The calculator

masterClock Constant frequency of the master clock Hz
fetchWidth Constant divisor of the fetch divider samples per fetch
frameLen Constant divisor of the frame divider frames of master clock cycles
period Variable divisor of the period divider to cycles
Good sample rates based on values in form
Buffer length
Sample rate

Return to GBA section


2000–2014 Damian Yerrick. Some rights reserved: except where otherwise indicated, this site is free content, licensed under your choice of Creative Commons Attribution-ShareAlike 2.5 or GNU Free Documentation License 1.2. Terms apply.