ElectronicZoologyfield notes from the garage
← Back
Audio

Sample Rate

How many audio samples per second — and why it controls both quality and file size

Sample rate is how many times per second the audio is measured and stored as a number. At 44100 Hz, the audio is captured 44,100 times every second. Each of those measurements is one 16-bit integer in your clip.h array.

More samples per second = higher quality = larger file. Fewer samples = smaller file = lower quality. The trick is finding the lowest rate that still sounds good for what you need.

The practical options

Sample rateSize per secondGood for
44100 Hz~88 KBMusic, anything that needs to sound great
22050 Hz~44 KBSpeech, sound effects - half the size, still clear
16000 Hz~32 KBVoice only - nearly triple capacity, fully intelligible

They must match

The sample rate in your sketch and the rate you converted the audio to with ffmpeg must be the same number. If they do not match, the audio will play back at the wrong speed and wrong pitch.

In the sketch:

#define SAMPLE_RATE 22050

In the ffmpeg conversion command:

ffmpeg -y -i /tmp/myclip.wav -ar 22050 -ac 1 -acodec pcm_s16le /tmp/clip_i2s.wav

Change both together and they will always stay in sync.

Key details

  • 44100 Hz = CD quality, ~88KB per second of audio
  • 22050 Hz = half the size, speech stays clear
  • 16000 Hz = nearly triple the capacity, voice only
  • SAMPLE_RATE in the sketch must match ffmpeg -ar