Skip to content

Instantly share code, notes, and snippets.

@Demonstrandum
Last active January 21, 2018 16:29
Show Gist options
  • Save Demonstrandum/1971daed30fa71a23b298d86475392ac to your computer and use it in GitHub Desktop.
Save Demonstrandum/1971daed30fa71a23b298d86475392ac to your computer and use it in GitHub Desktop.
Generating sweet saw tooth wave synths in Ruby, duuuude.
def note frequency, volume, chord, octave
octaves = [ 'Qj}6jQ6%' '_u}6u_6%' ] # Some good sounding random octaves
octave_index = 0
octave_index = (frequency % 4 >> 16) % octaves.size
volume += 1
return 0 if volume.zero?
choose = frequency * (octaves[octave_index][chord % 8].ord + 51)
choose = (choose >> octave) % 4
choose % volume << 4
end
amp = 0
instruments = 4
loop do
amp += 1 # Pick an amplitude increment that sounds good
notes = Array.new
chord = amp >> 10 # Increase me to sloooowww the music
volume = amp
notes << note(amp, 1, chord, 12)
volume = amp >> 15 # Adjust the volume each iteration, lateness
notes << note(amp, volume, chord ^ amp >> 13, 10)
notes << note(amp, volume / 3, chord + ((amp >> 11) % 3), 10)
notes << note(amp, volume / 5, 8 + chord - ((amp >> 10) % 3), 9) # oct higher
print notes.sum.to_i.chr
sleep ARGV[0].to_f
end
def note frequency, volume, chord, octave
octaves = [ 'Qj}6jQ6%' '_u}6u_6%' ] # Some good sounding random octaves
octave_index = 0
octave_index = (frequency % 4 >> 16) % octaves.size
volume += 1
return 0 if volume.zero?
choose = frequency * (octaves[octave_index][chord % 8].ord + 51)
choose = (choose >> octave) % 4
choose % volume << 4
end
amp = 0
instruments = 4
loop do
amp += 2 # Pick and amplitude that sounds good
notes = Array.new
chord = amp >> 14 # Increase me to sloooowww the music
volume = amp >> 16 # Adjust the volume each iteration, lateness
notes << note(amp % 255, 1, chord, 12)
notes << note(amp % 255, volume / 3, chord + ((amp >> 11) % 3), 10)
notes << note(amp % 255, volume / 5, 8 + chord - ((amp >> 10) % 3), 9)
print notes.sum.to_i.chr
sleep ARGV[0].to_f
end
This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment