phun with sound basic concepts for hardware (and other) hackers

24
Phun With Sound Basic Concepts For Hardware (and other) Hackers

Upload: taryn-herdman

Post on 19-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Phun With Sound

Basic ConceptsFor

Hardware (and other) Hackers

Page 2: Phun With Sound Basic Concepts For Hardware (and other) Hackers

You Don’t Know What This Is

But you want to!

Page 3: Phun With Sound Basic Concepts For Hardware (and other) Hackers

This Circuit Board

Made this famous riff

Page 4: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Phun With Sound

• Combo talk, covering:– Intro to sound– Some basics of synthesizers– Making sounds with microcontrollers

Page 5: Phun With Sound Basic Concepts For Hardware (and other) Hackers

What is Sound?

• Modulated air pressure• Frequency of modulation is pitch• Amplitude is volume• Waveforms can be defined (and created) with

math

Page 6: Phun With Sound Basic Concepts For Hardware (and other) Hackers

More Sound Basics

• Unit of frequency is Hertz (Hz)• Unit of sound energy is decibel• Human hearing is around 20 Hz to 20 kHz

• Phreak bonus: who is the unit of sound level named for?

Page 7: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Basic Waveforms

• Sine

• Triangle

• Square

Page 8: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Some Math

• Sine is the “purest” waveform both in math and acoustical presentation: f(x) = sin(x)

• Square waves are an infinite summation of sine waves:

• All those terms beyond the fundamental frequency are “harmonics”

Page 9: Phun With Sound Basic Concepts For Hardware (and other) Hackers

More Square Wave

Page 10: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Some Examples

• Using the SH101 analog synthesizer– Sine– Square– Triangle– PWM

• Microcontrollers driving motors often use PWM…

Page 11: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Pulse Width Modulation

• PWM: fixed period, changing duty cycle• Used as motor drive, DAC, and in sound

synthesis (and others)• Back to the square wave function…

• …does changing duty cycle change harmonics? YES!

• Bonus: what’s a 100% duty cycle PWM called?

Page 12: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Phun With Harmonics

• Subtractive Synthesis– Start with a signal with lots of harmonics– Filter it!

• Low pass filter

Page 13: Phun With Sound Basic Concepts For Hardware (and other) Hackers

More Filtering

• Traditional analog synths use voltage controlled filters VCF• Modern synths use digital filters running on DSPs

Page 14: Phun With Sound Basic Concepts For Hardware (and other) Hackers

The Filter Sweep

• Classic electronica music effect

Page 15: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Triangle Man (Delta)

• Non-changing waveforms sound dull, even irritating

• ∆ Sounds more interesting • How to implement change?– LFO, repeatable change– “Random” change

Page 16: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Art of Noise

• Noise is random• Pseudo-random isn’t random, nor noise• What does it sound like?– Noise on the SH101– Pseudo-random on the SH101– How the pros use pseudo-random influences

• InfoSec tie-in: see how limited pseudo-random is a bad choice for seeding crypto?

Page 17: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Making Sound With Microcontrollers

• Two basic approaches:– Synthesis– Sample playback

• Two areas of concern:– Hardware– Firmware

Page 18: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Making Sound With Microcontrollers: Firmware

• Synthesis options– Hardware based (waveform into VCF)– Math based (calculations in firmware)

• Sample option– Look up table– Can be waveform data (sine, triangle, DTMF)– Can also be “sample” in the sense of digital

recording

Page 19: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Microcontrollers: Hardware

• Synthesis options– Output waveform and control of external

elements (VCF, VCA)– Heavily filtered square wave– DAC…

Page 20: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Microcontrollers: Hardware

• Sampled sound needs DAC– Filtered PWM, single output pin, HW controlled– DAC Ladder, multiple output pins, simple interface– DAC hardware, multiple i/o pins, complex

interface

Page 21: Phun With Sound Basic Concepts For Hardware (and other) Hackers

Example: DEFCON 18Badge Hack

• What happens when you combine:– DC18 Badge– Beer– Pr0n– Top engineers from famous comm corp– And me?

• The Optimized Tomfoolery DC18 badge hack entry! (Kingpin approved!)

• The Hacker Jeopardy answer is: “Hey, what’s the input impedance of an LM386?”

Page 22: Phun With Sound Basic Concepts For Hardware (and other) Hackers

DEFCON Badge Hack

• Limited microcontroller code space…• …and limited hardware options (no PWM)• Sampled desired sound to get .wav• Edit .wav to get C #include• Crude R-2R ladder DAC (considered other

methods)• Play samples back from codespace• 4-bit low sample rate, was recognizable!

Page 23: Phun With Sound Basic Concepts For Hardware (and other) Hackers

DC18 Badge Hack

• Tools used:– Audacitiy: sound recording manipulation tool– Lame: mpg recorder option for Audacity– HxD: hex editor– Code Warrior: microcontroller IDE

• Search youtube for “DC18 Theater” for Kingpin’s video of our entry (NSFW!)

Page 24: Phun With Sound Basic Concepts For Hardware (and other) Hackers

¿Questions?