Skip to content

PCM audio ​

PCM stores sound as a sequence of numeric sample values. Each sample is the waveform amplitude at one point in time. At 48 kHz, the device expects 48,000 samples per second per channel.

TermMeaning
sample ratesamples per second
channelmono/stereo layout
frameone sample per channel
buffermemory region sent to the device
amplitudenumeric signal level

The device consumes bytes, not musical intent. Translate frequency and duration into sample counts, frame counts, and byte counts. A small unit mistake makes audio too short, too long, distorted, or silent.

Square wave ​

A square wave alternates between positive and negative amplitude:

text
positive for half period
negative for half period
repeat

It is easy to generate and test. The sound is simple, but the expected buffer is easy to inspect. After the square wave works, a sine wave, envelope, melody, or tracker pattern is a higher-level transformation that still ends in PCM samples.

Course/docs licensed CC BY 4.0. Code licensed MIT.