
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # but WITHOUT ANY WARRANTY without even the implied warranty of # This program is distributed in the hope that it will be useful,
Wavosaur sample rate without resampling software#
# the Free Software Foundation either version 2 of the License, or
Wavosaur sample rate without resampling license#
# it under the terms of the GNU General Public License as published by # This program is free software you can redistribute it and/or modify Never got around to use the command line arguments. Edit the input/output names at the start of the code. If you have stereo, or use other formats, it shouldn't be that difficult to adapt.

Here's a small program which converts (unsigned) 8 and 16 bits mono from 44.1 to 16. It might (should) work for both, but I haven't tested it. There's another headache, because in the wave module in Python, there is no way to tell if the data is signed or not (only if it's 8 or 16 bits).

It's a bit of a headache to do, because there's some type conversion to be done between the bytestring native to python and the arrays needed in scipy. Notice you can also use the method decimate in the case you are only doing downsampling and want something faster than fourier. Number_of_samples = round(len(data) * float(new_rate) / sampling_rate)ĭata = sps.resample(data, number_of_samples) I was indeed in the case I was loading a 44100Hz wave file and required a 48000Hz sampled data, so I wrote the few following lines to load my data: # Imports The "resampling" function use fourier transform. See the following picture for two curves of upsampling using a different algorithm from scipy. Since fourier transform isn't something you want to re-write by hand, if you want a good subsampling/supsampling, You could use a linear interpolation (connect points with a line) or a binomial interpolation (connect three points with a piece of polynom) or (sometimes the best for sound) use a Fourier transform and interpolate in the space of frequency. The reason is that interpolating the right way isn't easy or either obvious. You could do it by hand if you understand the principle, but I strongly recommend you to use a library. See the picture below where you have a curve sampled at two different scales. In this case, you just have to take buckets of $k$ samples and keep only the first one.

The only case where subsampling would be easy is when you divide the sampling rate by an integer $k$. This is because you want to know the value of the sound wave at some time that wasn't sampled, so you have to guess this value by one way or an other. The idea is that you need to somehow draw a curve between your points, and then take values from this curve at the new sampling rate. To downsample (also called decimate) your signal (it means to reduce the sampling rate), or upsample (increase the sampling rate) you need to interpolate between your data.
