#!/usr/bin/env python
# Convert a broken 24-bit WAVE file -- that is, a file where the samples are 24
# bits padded to 32, but the header says they're 24, like "arecord -f S24_LE"
# will create -- to non-broken 32-bit format. Writing this probably wasn't
# faster than just sampling the LP again, but it was more interesting...

import wave

i = wave.open("1.wav", "rb")
i._sampwidth = 4
i._framesize = i._nchannels * i._sampwidth
i._nframes = i._data_chunk.chunksize // i._framesize
o = wave.open("2.wav", "wb")
print i.getparams()
o.setparams(i.getparams())
n = 0
m = 0
while 1:
	s = i.readframes(1024)
	if s == "":
		break
	o.writeframes("\0" + s[:-1])
	n += len(s) / i._framesize
	m = (m + 1) % 100
	if m == 0:
		print "%.1f%%" % ((100.0 * n) / i.getnframes(),)
i.close()
o.close()

