ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
It¡¯s so quiet. 
Let¡¯s make music. 
Loren Segal 
RubyConf 2014
@lsegal
WARNING: 
MUSIC 
AHEAD 
? ?
What is 
music 
even?
S + R = M 
ound 
hythm 
usic
S + R = M 
ound 
hythm 
usic
S + R = M 
ound 
uby 
usic
S + R = 
ound 
uby
S + R = 
ound 
uby 
This talk.
Sounddd beep. 
boop.
Analog 
Audio
Good Vibrations
Continuous Signal
DIGITAL 
AUDIO
? ? ?
Discrete Signal (not continuous) 
187 
198 
-84 -84
not continuous, 
Just Samples
Discrete Signal (not continuous)
Discrete Signal (not continuous)
Discrete Signal (sampling)
Discrete Signal (sampling)
Discrete Signal (sampling)
Audio Vocabulary 
[Sample Rate]? 
¡°Number of data values for 
each second of audio¡± 
Measured in Hertz (Hz)
20 Samples 
20.times.map {|i| (Math.sin(i) * 255).floor } 
[0, 214, 231, 35, -193, 
-245, -72, 167, 252, 105, 
-139, -255, -137, 107, 252, 
165, -74, -246, -192, 38]
Common Sample Rates 
44,100 Hz 
44,800 Hz 
96,000 Hz 
used by VHS, CDs
? ?
fundamental 
WAVES
SINE 
sin(x)
#math
It's so quiet. Let's make music.
f(t) = A sin(2¦Ð¦¸t) 
s
f(t) = A sin(2¦Ð¦¸t) 
Amplitude 
Frequency 
s
Amplitude 
Frequency* 
¡­ish
Audio Vocabulary 
[Amplitude]? 
¡°Loudness¡± 
Measured in Decibels (dB)
Audio Vocabulary 
[Frequency]? 
¡°Pitch¡± 
Measured in Hertz (Hz)
¦¸s 
s = Sample Rate 
= e.g., 44100
Frequency?
¦¸ = 440 Hz [A3]
f(t) = sin(0.0627t)
It's so quiet. Let's make music.
SQUARE
f(t) = A ((¦¸t) < 0.5 ? -1 : 1) s
Triangle
f(t) = A(1 - 4(¦¸st - ¦¸st ))
SAW(tooth)
f(t) = 2A (¦¸t - ¦¸t ) s s
NOISE
f(t) = A rand() 
rand() = some evenly distributed random fn
Show, 
Don¡¯t Tell
Processing 
Audio
From 
synthesis
To 
analysis
Fourier 
Transform
It¡¯s Complex
Literally.
SIDE VIEW OF f(t)!
thefouriertransform.com
¡°All waveforms, no matter what you 
scribble or observe in the universe, 
are actually just the sum of simple 
sinusoids of different frequencies.¡±
It's so quiet. Let's make music.
It's so quiet. Let's make music.
It's so quiet. Let's make music.
It's so quiet. Let's make music.
It's so quiet. Let's make music.
Analysis 
Applications
1. 
Pitch Detection: 
Instrument Tuner, 
Visualization
2. 
Wave Shaping: 
Equalizer, 
Autotune
Let¡¯s see it.
RUBY 
TIME
ruby-audio $ gem install
libsndfile 
wrapper
Write a Sine Wave 
require 
'ruby-?©\audio' 
include 
RubyAudio 
sample_rate, 
len, 
freq, 
amp 
= 
48000, 
10, 
440, 
0.9 
buf 
= 
Buffer.float(sample_rate 
* 
len) 
buf.size.times 
do 
|i| 
sine_rad 
= 
((freq 
* 
Math::PI 
* 
2) 
/ 
sample_rate) 
* 
i 
buf[i] 
= 
amp 
* 
Math.sin(sine_rad) 
end 
format 
= 
FORMAT_WAV 
| 
FORMAT_PCM_16 
info 
= 
SoundInfo.new(channels: 
1, 
samplerate: 
sample_rate, 
format: 
format) 
snd 
= 
Sound.new('out.wav', 
'w', 
info) 
snd.write(buf) 
snd.close
easy_audio $ gem install
portaudio 
wrapper
Play a Sine Wave 
require 
'easy_audio' 
EasyAudio.easy_open(&EasyAudio::Waveforms::SINE) 
sleep 
2 
# 
play 
for 
2 
seconds
Increase Frequency / Time 
require 
'easy_audio' 
triangle 
= 
EasyAudio::Waveforms::TRIANGLE 
stream 
= 
EasyAudio.easy_open(freq: 
220, 
&triangle) 
Thread.new 
{ 
loop 
{ 
stream.frequency 
+= 
50; 
sleep 
0.2 
} 
} 
sleep 
3
Audio 
Plugins
VST
github.com/lsegal/ easy_vst
Embedding DRb - C++ 
AudioEffect* 
createEffectInstance(audioMasterCallback 
audioMaster) 
{ 
ruby_init(); 
ruby_init_loadpath(); 
rb_require("drb/drb"); 
rb_eval_string("DRb.start_service"); 
return 
new 
SampleVST(audioMaster); 
} 
// 
... 
server 
= 
rb_eval_string( 
"DRbObject.new_with_uri('druby://localhost:9090')");
Call Distributed Method 
rb_funcall( 
server, 
// 
the 
DRb 
object 
rb_intern(¡°process¡±), 
// 
the 
remote 
method 
1, 
// 
one 
argument 
INT2FIX(sampleFrames)); 
// 
number 
of 
samples
Fun 
Time!
Summary
1. Audio is samples!
2. Making waves! 
Sine, Square, 
Saw, Triangle, 
Noise
3. Fourier = analysis
4. Ruby libraries! 
ruby-audio 
easy_audio 
easy_vst
5. Music!
? 
gnuu.org
github.com/lsegal
@lsegal
Thanks! Questions?

More Related Content

What's hot (10)

Introduction of ToySynth
Introduction of ToySynthIntroduction of ToySynth
Introduction of ToySynth
Ransui Iso
?
Audio DSP in ReasonML
Audio DSP in ReasonMLAudio DSP in ReasonML
Audio DSP in ReasonML
Ken Wheeler
?
USRP Implementation of Max-Min SNR Signal Energy based Spectrum Sensing Algor...
USRP Implementation of Max-Min SNR Signal Energy based Spectrum Sensing Algor...USRP Implementation of Max-Min SNR Signal Energy based Spectrum Sensing Algor...
USRP Implementation of Max-Min SNR Signal Energy based Spectrum Sensing Algor...
T. E. BOGALE
?
Lecture13
Lecture13Lecture13
Lecture13
INDHULEKSHMI M.C
?
Stream audio affects
Stream audio affectsStream audio affects
Stream audio affects
FreeWavesEntertainment
?
Lecture22
Lecture22Lecture22
Lecture22
nomio0703
?
Telecommunications: Motion Video
Telecommunications: Motion VideoTelecommunications: Motion Video
Telecommunications: Motion Video
Napier University
?
Forgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech GiantsForgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech Giants
Videoguy
?
Ultrasonic with buzzer
Ultrasonic with buzzerUltrasonic with buzzer
Ultrasonic with buzzer
Jawaher Abdulwahab Fadhil
?
Presentazione
PresentazionePresentazione
Presentazione
Giulia Cassar¨¤
?

Similar to It's so quiet. Let's make music. (20)

Sound Processing in MATLAB program speech
Sound Processing in MATLAB program speechSound Processing in MATLAB program speech
Sound Processing in MATLAB program speech
leknasunitha
?
noise removal in matlab
noise removal in matlabnoise removal in matlab
noise removal in matlab
umarjamil10000
?
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
Ö¾­v —î
?
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systems
anilkurhekar
?
Audio Signal Processing
Audio Signal Processing Audio Signal Processing
Audio Signal Processing
Ahmed A. Arefin
?
Polyanna manual
Polyanna manualPolyanna manual
Polyanna manual
Aleksi Eeben
?
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
Minh Anh Nguyen
?
example based audio editing
example based audio editingexample based audio editing
example based audio editing
Ramin Anushiravani
?
Digital Tuner
Digital TunerDigital Tuner
Digital Tuner
plun
?
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
Minh Anh Nguyen
?
Beamforming and microphone arrays
Beamforming and microphone arraysBeamforming and microphone arrays
Beamforming and microphone arrays
Ramin Anushiravani
?
Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)
Adam Sporka
?
Tomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.pptTomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.ppt
Rakesh Pogula
?
DJ Workshop v.0.2b
DJ Workshop v.0.2bDJ Workshop v.0.2b
DJ Workshop v.0.2b
Magmakern Industries
?
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
Roy van Rijn
?
Session3
Session3Session3
Session3
Krutarth Patel
?
Audio125 wk1-review-digital-audio-specs-and-acoustics
Audio125 wk1-review-digital-audio-specs-and-acousticsAudio125 wk1-review-digital-audio-specs-and-acoustics
Audio125 wk1-review-digital-audio-specs-and-acoustics
Raffiel203
?
Digital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonDigital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and Python
Mel Chua
?
Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)
Ron Reiter
?
Chapter 02 audio recording - part i
Chapter 02   audio recording - part iChapter 02   audio recording - part i
Chapter 02 audio recording - part i
Nazihah Ahwan
?
Sound Processing in MATLAB program speech
Sound Processing in MATLAB program speechSound Processing in MATLAB program speech
Sound Processing in MATLAB program speech
leknasunitha
?
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
Ö¾­v —î
?
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systems
anilkurhekar
?
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
Minh Anh Nguyen
?
Digital Tuner
Digital TunerDigital Tuner
Digital Tuner
plun
?
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
Minh Anh Nguyen
?
Beamforming and microphone arrays
Beamforming and microphone arraysBeamforming and microphone arrays
Beamforming and microphone arrays
Ramin Anushiravani
?
Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)
Adam Sporka
?
Tomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.pptTomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.ppt
Rakesh Pogula
?
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
Roy van Rijn
?
Audio125 wk1-review-digital-audio-specs-and-acoustics
Audio125 wk1-review-digital-audio-specs-and-acousticsAudio125 wk1-review-digital-audio-specs-and-acoustics
Audio125 wk1-review-digital-audio-specs-and-acoustics
Raffiel203
?
Digital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonDigital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and Python
Mel Chua
?
Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)
Ron Reiter
?
Chapter 02 audio recording - part i
Chapter 02   audio recording - part iChapter 02   audio recording - part i
Chapter 02 audio recording - part i
Nazihah Ahwan
?

Recently uploaded (20)

Revolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-StoryRevolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
ssuser52ad5e
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
Brave Browser Crack 1.45.133 Activated 2025
Brave Browser Crack 1.45.133 Activated 2025Brave Browser Crack 1.45.133 Activated 2025
Brave Browser Crack 1.45.133 Activated 2025
kherorpacca00126
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
Unlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & KeylockUnlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & Keylock
HusseinMalikMammadli
?
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptxUnderstanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
shyamraj55
?
UiPath Automation Developer Associate Training Series 2025 - Session 2
UiPath Automation Developer Associate Training Series 2025 - Session 2UiPath Automation Developer Associate Training Series 2025 - Session 2
UiPath Automation Developer Associate Training Series 2025 - Session 2
DianaGray10
?
Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)
nick896721
?
Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4
Margaret Maynard-Reid
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Backstage Software Templates for Java Developers
Backstage Software Templates for Java DevelopersBackstage Software Templates for Java Developers
Backstage Software Templates for Java Developers
Markus Eisele
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-StoryRevolutionizing-Government-Communication-The-OSWAN-Success-Story
Revolutionizing-Government-Communication-The-OSWAN-Success-Story
ssuser52ad5e
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
Brave Browser Crack 1.45.133 Activated 2025
Brave Browser Crack 1.45.133 Activated 2025Brave Browser Crack 1.45.133 Activated 2025
Brave Browser Crack 1.45.133 Activated 2025
kherorpacca00126
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
Unlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & KeylockUnlocking DevOps Secuirty :Vault & Keylock
Unlocking DevOps Secuirty :Vault & Keylock
HusseinMalikMammadli
?
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptxUnderstanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
shyamraj55
?
UiPath Automation Developer Associate Training Series 2025 - Session 2
UiPath Automation Developer Associate Training Series 2025 - Session 2UiPath Automation Developer Associate Training Series 2025 - Session 2
UiPath Automation Developer Associate Training Series 2025 - Session 2
DianaGray10
?
Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)Early Adopter's Guide to AI Moderation (Preview)
Early Adopter's Guide to AI Moderation (Preview)
nick896721
?
Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4
Margaret Maynard-Reid
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIATHE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
THE BIG TEN BIOPHARMACEUTICAL MNCs: GLOBAL CAPABILITY CENTERS IN INDIA
Srivaanchi Nathan
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
World Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a CrossroadsWorld Information Architecture Day 2025 - UX at a Crossroads
World Information Architecture Day 2025 - UX at a Crossroads
Joshua Randall
?
Future-Proof Your Career with AI Options
Future-Proof Your  Career with AI OptionsFuture-Proof Your  Career with AI Options
Future-Proof Your Career with AI Options
DianaGray10
?
Backstage Software Templates for Java Developers
Backstage Software Templates for Java DevelopersBackstage Software Templates for Java Developers
Backstage Software Templates for Java Developers
Markus Eisele
?
Technology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptxTechnology use over time and its impact on consumers and businesses.pptx
Technology use over time and its impact on consumers and businesses.pptx
kaylagaze
?

It's so quiet. Let's make music.