It is very likely the dtype
that is different. When you generate the zeros to pad at the beggining, you are not specifying a dtype, so they are probably np.int32
. Your original data is probably np.uint8
or np.uint16
, so the whole array gets promoted to np.int32
, which is not the right bit depth for your data. Simply do:
new_data = numpy.array([0,0], dtype=stereo_data)
I would actually rather do:
new_data = numpy.zeros((1, 2), dtype=stereo_data.dtype)
You could, by the way, streamline your code quite a bit, and get rid of a lot of for loops:
sr, stereo_data = sciwav.read('filename')
nparts = 100
part_length = len(stereo_data) // nparts
stereo_parts = numpy.split(stereo_data[:part_length*nparts], nparts)
new_data = numpy.vstack([numpy.zeros((1, 2), dtype=stereo_data.dtype)] +
stereo_parts)
sciwav.write('new_filename', sr, new_data)