

(“Sampling” gets its name from the process of turning a recording of a real sound into a series of samples.) Calling context.sampleRate tells us how many samples per second our device can produce. We call each one of these numbers a “sample”. Each number describes the amplitude of the sound at a particular point in time. We can describe audio digitally as a series of numbers. This information is contained in the AudioContext.Ĭonsole.log()

To generate audio using the Web Audio API, your browser needs to know about the sound producing device available to your computer, and what capabilities it has. We’ll kick off with the basis of all good drum loops, the kick drum. We’ll synthesise the kick and snare, and create a hi-hat sound from a recording of the original machine. In this article we’ll try and create something that sounds a bit like the classic electronic drum machine, Roland’s TR-808. Sampling on the other hand means we can start with any sound we like, but we are limited to just that sound, perhaps with some simple transformations (playing the sound back faster or slower, or applying some effects, for example). Synthesising, recreating the sound of a drum using a model of its acoustics and attempting to recreate that model in code, gives us infinite control, but it can be very difficult to accurately synthesise a realistic sounding drum. Shall we synthesise the sounds of our drum kit from scratch in the computer, or shall we use a recording of real-life sounds - a technique also known as “sampling”? There are pros and cons to both approaches. Let’s get started! Sampling or synthesising?Įarly on, we have a decision to make. From these bare bones, you’ll be able to extend the machine yourself, or apply the techniques you’ve learnt to other applications.

#CAMPBELL PET CO SNAPPY SNARE HOW TO#
We’ll learn just enough about the API to play a simple loop constructed from sounds we synthesise ourselves, and we’ll see how to use recordings of real-life sounds too. In this article, we’re going to learn more about the API by building a simple drum machine. It provides a way to playback pre-recorded audio, synthesise arbitrary new sounds and control the precise moment of sound generation accurately and reliably, irrespective of what else is happening in your application. The Web Audio API is a new way of working with audio on the web.
