Skip to content

Instantly share code, notes, and snippets.

@wgmyers
Created September 6, 2023 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgmyers/97acad1a136dba61f7b69b5578745b29 to your computer and use it in GitHub Desktop.
Save wgmyers/97acad1a136dba61f7b69b5578745b29 to your computer and use it in GitHub Desktop.
Play a drone on the given note for five minutes
#!/usr/bin/env ruby
# drone.rb
# Take a note on the command line
# Play a drone on that note for LENGTH seconds or until stopped
# See https://muted.io/note-frequencies/
NOTES = {
'G' => 196.0,
'G#' => 207.65,
'Ab' => 207.65,
'A' => 220.0,
'A#' => 233.08,
'Bb' => 233.08,
'B' => 246.94,
'C' => 261.63,
'C#' => 277.18,
'Db' => 277.18,
'D' => 293.66 / 2,
'D#' => 311.13 / 2,
'Eb' => 311.13 / 2,
'E' => 329.63 / 2,
'F' => 349.23 / 2,
'F#' => 369.99 / 2,
'Gb' => 369.99 / 2
}
# Play drone for this many seconds
LENGTH = 300
usage = "Usage: drone.rb NOTE"
note = ARGV[0]
if !note
puts usage
exit 1
end
# Allow note to be entered in lower case
note = note.capitalize
if !NOTES.has_key?(note)
puts usage
exit 1
end
puts "Note #{note} is #{NOTES[note]}Hz"
puts "Ctrl-C to stop"
# Use Sox
#`play -n synth #{LENGTH} sin #{NOTES[note]}`
# Use ffplay
`ffplay -f lavfi -i "sine=frequency=#{NOTES[note]}:duration=#{LENGTH}" -autoexit -nodisp 2>/dev/null`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment