chapter 1
sound
How can we create music with a computer? One way is to use a DAW (digital audio workstation), programs like Ableton or FL Studio. These apps are great when you want to create conventional music with ready-made tools. But when we want to push boundaries and tap the full potential of this meta-medium, we turn to code. Instead of simply using software someone else wrote, we can program our own. Pre-made software gives us only the buttons, knobs, and menus its designers imagined. That can save time, but it also limits what and how we can create. By relying on someone else's GUI (graphical user interface), we restrict our imagination to their design choices, rather than exploring the much larger creative possibilities of the sounds a computer can make and how we might play it.
Learning to make sound and music with code isn't just about getting programs to run, it's about understanding the principles that make them possible. The ideas you can imagine in code grow directly from your grasp of core concepts. If you skip that foundation and lean only on tools (whether pre-made software or even generative AI) you'll tend to produce work bounded by what you already know or what the tool suggests. It may feel productive, but without a sense of how and why this code works, and the history of ideas behind it, you lose the agency to shape it into something truly your own. Invest in the fundamentals, history, and theory, and your imagination will expand alongside your technical craft. The more time you spend experimenting and wrestling with the material, the more you'll tap the true potential of the computer as a creative medium, and the more interesting and original your work will become.
what is sound
Before we talk about music, we need to talk about sound, what it is and how we’ll be making it. Sound happens when something vibrates, like a vocal chord, a guitar string or a speaker. These vibrations cause the tiny particles in the air around it to move, creating patterns of squished-together areas (compressions) and spread-out areas (rarefactions). These patterns travel outward as waves. When these waves reach your ears, they make your eardrum vibrate in the same pattern. Your brain takes these vibrations and processes them into what you experience as sound—like speech, music or noise. In a way, sound only exists in your mind: it's your brain's way of interpreting the physical vibrations in the air into a meaningful hallucination. Without a listener, “sound” is nothing more than patterns of vibrations in the air.
The pitch of a sound depends on how fast the particles are vibrating, and the volume depends on how much they’re moving. A sound's pitch is also called its frequency, which is measured in hertz (Hz) or cycles per second. Faster vibrations create higher frequencies and higher-pitched sounds, while slower vibrations create lower frequencies and lower-pitched sounds. The volume (loudness) of a sound depends on the wave's amplitude—how strong or "tall" the wave is. Higher amplitude means louder sounds, and it's measured in decibels (dB). A decibel is a unit that measures how loud a sound is, using a scale where every 10 dB means the sound is 10 times more intense than the previous level. In short, amplitude controls loudness, and frequency controls pitch.
We'll be generating sound by vibrating speakers attached to our computer. These could be small headphone speakers or larger blue-tooth connected speakers.
digital sound
So we'll rephrase the initial question: How can we vibrate our speakers (ie. create sound) using code on a computer? Many languages and environments can create sound. Because our goal is to publish pieces on the open web, we'll use JavaScript, the Web's de facto programming language. Websites are built on HTML, a beginner-friendly language for structuring content. We won't spend much time on HTML in this class, but if you're comfortable with HTML (and CSS) you're welcome to use them in your projects. Our focus will be JavaScript. To run it in the browser, we'll put our code inside a <script> tag in an HTML file. Running JavaScript in a web browser gives us access to the Web Audio API, a set of audio building blocks for generating and shaping sound from scratch.