Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created July 20, 2011 02:51
Show Gist options
  • Select an option

  • Save nbqx/1094232 to your computer and use it in GitHub Desktop.

Select an option

Save nbqx/1094232 to your computer and use it in GitHub Desktop.
class Waver
def initialize(filename)
@filename = File.expand_path(filename)
@byte_order = []
@size = File.size @filename
open(@filename).each_byte{|ch|
@byte_order << ch
}
end
def create(output)
@output = File.expand_path(output)
open(@output,"w") do |f|
f.print put_header
@byte_order.reverse.each do |ch|
f.print ch.chr
end
end
end
private
def put_header
return ["RIFF",36+@size,"WAVE","fmt ",16,1,2,44100,44100*2*16/8,2*16/8,16,"data",@size].pack("a4Va4a4Vv2V2v2a4V")
end
end
if $0 == __FILE__
wave = Waver.new(ARGV[0])
wave.create("out.wav")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment