## Overview
- Music theory
- Web Audio API
- Audio graph
- Audio nodes
- Audio params
## Preamble
The web is silent
We are only connecting with people through sight
Audio opens up possiblities for completely new experiences
## Web Audio API
[https://www.w3.org/TR/webaudio/](https://www.w3.org/TR/webaudio/)
The specification is fairly stable and most features are implemented in modern browsers
What is sound?
In physics, sound is a vibration that propagates as a typically audible mechanical wave of pressure and displacement, through a medium such as air or water. In physiology and psychology, sound is the reception of such waves and their perception by the brain. (Wikipedia)
Everything is a wave
Volume is proportional to amplitude squared and pitch is logarithmically proportional to frequency
## Enough theory!
### What does that sound like?
```javascript
const audioContext = new AudioContext()
const gain = audioContext.createGain()
const osc = audioContext.createOscillator()
gain.gain.value = 0.2
osc.connect(gain).connect(audioContext.destination)
osc.start()
```
## Gotcha!
```javascript
osc.stop()
osc.start() // uh oh!
```
There are quite a few gotchas with web audio...
## Timing
What time is it?
```javascript
const {currentTime} = new AudioContext()
```
Time in seconds (to be consistent with the other JS timing APIs!) since AudioContext instance was created
## Equal temperament
- Let pitch number 0 be 440Hz
- If the octave is incremented the frequency doubles
- If the octave is decremented the frequency halves
- Each octave is divided into 12 notes
```javascript
const frequency = pitch => 440 * Math.pow(2, pitch / 12)
```
## AudioParams
Some AudioNode properties are AudioParams
```javascript
gain.gain.value = 1
osc.frequency.value = 440
```
## AudioParams
AudioParams have a few of cool methods for controlling their values over time
```javascript
const osc = audioContext.createOscillator()
const {currentTime} = audioContext
osc.connect(gain)
osc.frequency.setValueAtTime(110, currentTime)
osc.frequency.linearRampToValueAtTime(1760, currentTime + 1)
osc.start(currentTime)
osc.stop(currentTime + 1)
```