Chapter 13

Digital Audio Basics

Learning Objectives

  • Understand what digital audio is
  • Learn about sampling and bit depth
  • Work with audio files and formats
  • See how MixMind processes audio

What is Digital Audio?

Digital audio is a representation of sound using numbers. Real sound is a continuous wave of air pressure changes, but computers need to convert this into discrete numbers they can store and process.

This conversion happens in two steps:

  1. Sampling: Measuring the sound wave at regular intervals
  2. Quantization: Converting each measurement to a number

Sample Rate

Sample rate is how many times per second we measure the sound wave. Measured in Hz (Hertz) or kHz (kilohertz).

  • 44,100 Hz (44.1 kHz): CD quality, most common
  • 48,000 Hz (48 kHz): Professional audio, video
  • 96,000 Hz (96 kHz): High-resolution audio
💡 Nyquist Theorem:

To accurately capture a frequency, you must sample at least twice that frequency. Humans hear up to ~20kHz, so 44.1kHz is sufficient for all audible frequencies.

Bit Depth

Bit depth determines how many possible values each sample can have. More bits = more precision = better quality.

  • 16-bit: 65,536 possible values (CD quality)
  • 24-bit: 16,777,216 possible values (professional)
  • 32-bit float: Even more precision (used internally)
// In JavaScript/Web Audio API
// Audio is typically represented as Float32Array
// Values range from -1.0 to 1.0

const audioData = new Float32Array(44100); // 1 second at 44.1kHz
audioData[0] = 0.5; // Sample value
audioData[1] = -0.3;

Audio Channels

Channels represent different audio streams:

  • Mono: 1 channel (single speaker)
  • Stereo: 2 channels (left and right)
  • 5.1 Surround: 6 channels
  • 7.1 Surround: 8 channels

Most music is stereo. MixMind works with stereo audio.

Audio File Formats

FormatTypeQualityUse Case
WAVUncompressedLosslessProfessional audio, editing
AIFFUncompressedLosslessApple systems
FLACCompressedLosslessArchival, high-quality
MP3CompressedLossyDistribution, streaming
AACCompressedLossyStreaming, mobile
OGGCompressedLossyOpen-source alternative

🎵 MixMind Connection

How MixMind Uses Digital Audio

// When you upload audio to MixMind:
// 1. File is read as ArrayBuffer
const arrayBuffer = await file.arrayBuffer();

// 2. Web Audio API decodes it
const audioContext = new AudioContext();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);

// 3. Now we have:
console.log(audioBuffer.sampleRate); // 44100
console.log(audioBuffer.numberOfChannels); // 2 (stereo)
console.log(audioBuffer.duration); // in seconds
console.log(audioBuffer.length); // total samples

// 4. Access raw audio data
const leftChannel = audioBuffer.getChannelData(0);
const rightChannel = audioBuffer.getChannelData(1);

// Both are Float32Array with values from -1.0 to 1.0
console.log(leftChannel[0]); // First sample value

Exercise 13.1: Practice

Goal: Apply what you've learned in this chapter

Try the concepts from this chapter in your browser's console or a simple HTML file. Experiment with the code examples and modify them to see what happens.

📝 Quick Reference:

Review the key concepts from this chapter and make sure you understand each one before moving to the next chapter.