Created
June 16, 2013 02:31
-
-
Save aberant/5790524 to your computer and use it in GitHub Desktop.
In case you ever wondered how to create an 808 kick in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# consult the signal flow graph for a ringing digital filter at | |
# http://i.stack.imgur.com/49pxl.jpg | |
require 'wavefile' | |
Frequency = 50 | |
SampleRate = 44_100 | |
DecayFactor = 0.15 | |
fc = 2 * Math.sin((Math::PI * Frequency)/SampleRate) | |
tc = Math.exp(-1/(SampleRate * DecayFactor)) | |
d1 = 1 | |
d2 = 0 | |
include WaveFile | |
samples = [] | |
50000.times do | |
output = d2 + (d1 * fc) | |
d1 = (d1 * tc) - ( output * fc) | |
d2 = output | |
samples << output | |
end | |
Writer.new("kick.wav", Format.new(:mono, :pcm_16, 44100)) do |writer| | |
buffer_format = Format.new(:mono, :float, 44100) | |
buffer = Buffer.new(samples, buffer_format) | |
writer.write(buffer) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment