Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pulse Waves in WebAudio

Pulse Waves in WebAudio

Creating pulse waves and pulse width modulation in WebAudio.

Exercise boilerplate: http://codepen.io/stevegoldberg/pen/zGLKOP

Completed demonstration:

http://codepen.io/stevegoldberg/pen/BNVxmL

Steve Goldberg

July 30, 2015
Tweet

More Decks by Steve Goldberg

Other Decks in Technology

Transcript

  1. Waveforms cont'd • Sine – no harmonics, fundamental only •

    Sawtooth – all harmonics that fall off at −6 dB/oct • Square – odd harmonics that fall off at −6 dB/oct • Triangle – odd harmonics that fall off at −12 dB/oct Square Sawtooth Triangle
  2. Pulse wave • Like a square wave, but not symmetrical

    • Defined by its “duty cycle” or pulse width, i.e. the percentage of time it spends at 1 vs. 0
  3. WebAudio OscillatorNode • Easy to use • Frequency is in

    Hz, type can be 'sawtooth', 'triangle', 'square', 'sine', or 'custom' • Custom waves are defined by arrays
  4. Pulse Waves from Sawtooth Waves • Pulse waves can be

    generated from sawtooth waves • An inverted sawtooth wave is also known as a ramp wave or downward sawtooth • If you combine a sawtooth wave and a delayed ramp wave, you get a pulse wave whose width is defined by the delay • A gainNode with a gain of -1 will invert a waveform
  5. Try It Yourself, Part 1 • Goal: Create a pulse

    oscillator with user- defined width • Start and stop the oscillator on button clicks • Change the pulse width in response to a slider • Exercise boilerplate: bit.ly/1MbmCGp
  6. Modulation • In audio synthesis, some parameters are only heard

    indirectly, via their interaction with other audible parameters • This is called modulation • An oscillator that operates below the audio range and modulates another parameter is called a Low Frequency Oscillator (LFO) • LFOs can modulate many things, e.g. pitch, filter, or pulse width • A pulse wave whose width is modulated creates Pulse Wave Modulation (PWM)
  7. Try It Yourself, Part 2 • Goal: Building on part

    1, add an LFO to create PWM • Add sliders for PWM amount and LFO rate
  8. Good Job! • Completed example: bit.ly/1HXbWFe • Further reading: Sound

    On Sound Synth Secrets soundonsound.com/sos/allsynthsecrets.htm