Created
August 21, 2012 13:35
-
-
Save erikkallen/3415462 to your computer and use it in GitHub Desktop.
Convert a wave file that has for some odd reason both stereo channels interlaced on the left channel and an empty right channel
This file contains 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
require 'rubygems' | |
require 'wav-file' | |
f = open("test_48khz_c2_s32_le_stereo_on_ch1.wav") | |
format = WavFile::readFormat(f) | |
dataChunk = WavFile::readDataChunk(f) | |
f.close | |
puts format | |
bit = 'l*' if format.bitPerSample == 32 # int16_t | |
bit = 's*' if format.bitPerSample == 16 # int16_t | |
bit = 'c*' if format.bitPerSample == 8 # signed char | |
wavs = dataChunk.data.unpack(bit) # read binary | |
wav2 = [] | |
wavs.each_slice(4) do |left, right, left2, right2| | |
#right = left2; | |
wav2 << [left, left2] | |
end | |
dataChunk.data = wav2.flatten.reverse.pack(bit) | |
open("output.wav", "w"){|out| | |
WavFile::write(out, format, [dataChunk]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment