Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created August 11, 2014 23:08
Show Gist options
  • Save domgetter/8db787793da339a3de2b to your computer and use it in GitHub Desktop.
Save domgetter/8db787793da339a3de2b to your computer and use it in GitHub Desktop.
require 'sound'
Sound::Device.new {|d| d.play Sound::Data.new.sine_wave(440, 500, 1)}
# This is the short way that opens and closes the device automatically
# Here is the more verbose way:
device = Sound::Device.new("w")
format = Sound::Format.new(Sound::Format::PCM)
data = Sound::Data.new(format)
data.generate_sine_wave(440, 500, 1)
device.write(data)
device.flush
device.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment