SlideShare a Scribd company logo
1 of 91
Download to read offline
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
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)
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.”
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

Introduction of ToySynth
Introduction of ToySynthIntroduction of ToySynth
Introduction of ToySynthRansui Iso
 
Audio DSP in ReasonML
Audio DSP in ReasonMLAudio DSP in ReasonML
Audio DSP in ReasonMLKen 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
 
Telecommunications: Motion Video
Telecommunications: Motion VideoTelecommunications: Motion Video
Telecommunications: Motion VideoNapier University
 
Forgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech GiantsForgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech GiantsVideoguy
 

What's hot (10)

Introduction of ToySynth
Introduction of ToySynthIntroduction of ToySynth
Introduction of ToySynth
 
Audio DSP in ReasonML
Audio DSP in ReasonMLAudio DSP in ReasonML
Audio DSP in ReasonML
 
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...
 
Lecture13
Lecture13Lecture13
Lecture13
 
Stream audio affects
Stream audio affectsStream audio affects
Stream audio affects
 
Lecture22
Lecture22Lecture22
Lecture22
 
Telecommunications: Motion Video
Telecommunications: Motion VideoTelecommunications: Motion Video
Telecommunications: Motion Video
 
Forgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech GiantsForgent Inc. v. High-Tech Giants
Forgent Inc. v. High-Tech Giants
 
Ultrasonic with buzzer
Ultrasonic with buzzerUltrasonic with buzzer
Ultrasonic with buzzer
 
Presentazione
PresentazionePresentazione
Presentazione
 

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

noise removal in matlab
noise removal in matlabnoise removal in matlab
noise removal in matlabumarjamil10000
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation志璿 楊
 
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsanilkurhekar
 
Audio Signal Processing
Audio Signal Processing Audio Signal Processing
Audio Signal Processing Ahmed A. Arefin
 
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 filesMinh Anh Nguyen
 
Digital Tuner
Digital TunerDigital Tuner
Digital Tunerplun
 
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 filesMinh Anh Nguyen
 
Beamforming and microphone arrays
Beamforming and microphone arraysBeamforming and microphone arrays
Beamforming and microphone arraysRamin 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.pptRakesh 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 knowRoy 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-acousticsRaffiel203
 
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 PythonMel 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 iNazihah Ahwan
 
Analog Communication fast mode material.pdf
Analog Communication fast mode material.pdfAnalog Communication fast mode material.pdf
Analog Communication fast mode material.pdfEngineering Funda
 

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

noise removal in matlab
noise removal in matlabnoise removal in matlab
noise removal in matlab
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
 
Vidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systemsVidyalankar final-essentials of communication systems
Vidyalankar final-essentials of communication systems
 
Audio Signal Processing
Audio Signal Processing Audio Signal Processing
Audio Signal Processing
 
Polyanna manual
Polyanna manualPolyanna manual
Polyanna manual
 
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
 
example based audio editing
example based audio editingexample based audio editing
example based audio editing
 
Digital Tuner
Digital TunerDigital Tuner
Digital Tuner
 
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
 
Beamforming and microphone arrays
Beamforming and microphone arraysBeamforming and microphone arrays
Beamforming and microphone arrays
 
Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)Audio Data Representation (NCGD009)
Audio Data Representation (NCGD009)
 
Tomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.pptTomas_IWAENC_keynote10.ppt
Tomas_IWAENC_keynote10.ppt
 
DJ Workshop v.0.2b
DJ Workshop v.0.2bDJ Workshop v.0.2b
DJ Workshop v.0.2b
 
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
 
Session3
Session3Session3
Session3
 
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
 
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
 
Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)Digital Audio & Signal Processing (Elad Gariany)
Digital Audio & Signal Processing (Elad Gariany)
 
Chapter 02 audio recording - part i
Chapter 02   audio recording - part iChapter 02   audio recording - part i
Chapter 02 audio recording - part i
 
Analog Communication fast mode material.pdf
Analog Communication fast mode material.pdfAnalog Communication fast mode material.pdf
Analog Communication fast mode material.pdf
 

Recently uploaded

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

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