4.5.6.7–4.5.6.8 - Digital sound and MIDI

4.5.6.7–4.5.6.8 - Digital sound and MIDI

Learn how sound becomes a sequence of digital amplitude samples, how recording settings affect storage and fidelity, and why MIDI stores a musical performance differently.

Sample resolution, rate and Nyquist

A digital sound recording represents the changing amplitude of a sound signal as a time-ordered sequence of encoded samples.

A microphone converts changes in air pressure into an analogue electrical signal. An ADC measures that signal at sampling times, quantises each amplitude and encodes it. Sampling rate is the number of samples taken per second per channel, measured in hertz (Hz). At 48,000 Hz there are 48,000 sample times each second. Sample resolution, also called bit depth, is the number of bits used for each amplitude sample. At 16 bits there are 216=65,5362^{16}=65{,}536 possible amplitude codes. The exact signed mapping depends on the format.

Increasing rate takes measurements closer together in time. Increasing resolution allows finer amplitude distinctions over a fixed range and generally reduces quantisation noise. Neither restores information absent from the source, and the two changes address different limitations. A high bit depth with an inadequate rate still fails to capture rapid changes correctly; a high rate with very coarse amplitude steps still has quantisation error.

The Nyquist sampling theorem concerns frequency information. For ideal reconstruction of a band-limited signal, the sampling rate must exceed twice its highest frequency. Twice the highest frequency is the theoretical threshold; practical systems choose a rate above it and filter out frequencies above the usable band before sampling. The highest frequency that a sampling rate can represent without aliasing is below half that rate. Aliasing occurs when higher-frequency changes appear as a different, lower frequency in the sampled data; the missing information cannot be recovered just by increasing playback rate.

For an ideal band-limited signal, choose

fs>2fmax⁡,f_s>2f_{\max},

where fsf_s is samples per second and fmax⁡f_{\max} is the highest frequency to be retained.

For sound containing frequencies up to 18 kHz, twice the upper frequency is 36 kHz. A 48 kHz rate is above the threshold. A 32 kHz rate has a half-rate limit of 16 kHz, so it is insufficient to retain the 18 kHz component without aliasing. A filter can remove that component before sampling, but the recording then no longer retains that part of the original sound. Choosing exactly two samples per cycle can miss a sine wave entirely for an unfortunate sampling phase; using the threshold as a practical guarantee is unsafe.

Calculating sampled sound storage

Uncompressed sampled audio storage is found by counting all samples in every channel and multiplying by the bits per sample.

Ignoring metadata, padding and compression,

size in bytes=fs×b×t×c8,\text{size in bytes}=\frac{f_s\times b\times t\times c}{8},

where fsf_s is sampling rate in Hz, bb is bits per sample, tt is duration in seconds and cc is channel count.

Mono has one channel; stereo normally has two. A sample rate given per channel must therefore be multiplied by the channel count. For 30 seconds of stereo audio at 48,000 Hz and 16 bits per sample:

StepCalculationResult
Sample values across both channels48,000 × 30 × 22,880,000
Bits stored2,880,000 × 1646,080,000 bits
Bytes stored46,080,000 ÷ 85,760,000 bytes
Decimal MB5,760,000 ÷ 1,000,0005.76 MB

These are amplitude sample values, not bytes until the final conversion. If metadata or compression is present, account for it only with the additional information supplied. An actual audio file can have header fields identifying rate, resolution, channels and duration. The formula estimates the raw sample payload, not every compressed format's size.

At unchanged duration and other settings, doubling sample rate, bit depth or channel count doubles the payload. Doubling both rate and bit depth multiplies it by four. Choosing recording settings balances the required frequency/amplitude fidelity against storage and transfer demands.

MIDI stores performance events

MIDI represents instructions for a musical performance rather than storing the waveform of the resulting sound.

MIDI stands for Musical Instrument Digital Interface. It lets electronic instruments and computers communicate musical control events. A MIDI file stores timed event information. A synthesiser or other instrument interprets the events and generates the sound; the file itself is not a sequence of microphone amplitude samples.

Typical events include Note On with note number/pitch, velocity and channel, Note Off to end a note, Program Change to select an instrument sound, and controller changes such as sustain. Timing records when events occur, so their spacing determines rhythm and note duration. Velocity typically affects loudness or attack according to the instrument; it is a performance control, not a stored waveform amplitude at every instant.

This simplified performance list shows the principle, without requiring a particular binary MIDI-file syntax:

Time (s)EventMeaning
0.0Select piano sound on channel 1Choose the sound used by later notes
0.0Note On, note 60, velocity 80, channel 1Begin middle C with the stated performance velocity
0.5Note Off, note 60, channel 1End that note
0.5Note On, note 64, velocity 80, channel 1Begin E
1.0Note Off, note 64, channel 1End E

The same events can be played through different synthesisers with different results. This is both flexibility and a limitation: the file specifies performance controls, but does not preserve the exact sound of a particular instrument, room or singer. MIDI cannot directly reproduce an arbitrary microphone recording of speech or environmental noise.

For suitable music, MIDI files can be compact because they record events only when something changes, rather than thousands of samples per second. Notes can be transposed by changing note numbers, timing can be edited or the tempo changed, and instruments can be replaced without rerecording. This is especially useful for composing and arranging. A sampled recording is appropriate when preserving a particular real performance's timbre and ambience matters.