Created
July 20, 2011 02:51
-
-
Save nbqx/1094232 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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