There are two options for speeding up a sound file:
- Increase sampling rate
- Reduce the number of samples per unit time.
In any of these methods, an increase in playback speed will have a corresponding change in pitch.
Sample rate increase
Increasing the sampling rate will increase the speed of sound reproduction. For example, switching from a sampling frequency of 22 kHz to 44 kHz will cause playback to play twice as fast as the original. In this method, the original sampling data is not changed - only the sound reproduction parameters need to be changed.
Reduce the number of samples per unit time
In this method, the sampling frequency of the reproduction is kept constant, but the number of samples decreases — some of the samples are discarded.
A naive approach to reproducing sound twice as fast as the original one is to delete all other samples and play back at the original playback sample rate.
However, with this approach, some of the information will be lost, and I expect that some artifacts will be introduced into the audio, so this is not the most desirable approach.
Although I have not tried it myself, the idea of averaging samples to create a new sample was a good approach to start with. This, apparently, means that instead of just discarding the audio information, it can be “saved” to some extent by the averaging process.
As a rough idea of the process, here a piece of pseudocode doubles the playback speed:
original_samples = [0, 0.1, 0.2, 0.3, 0.4, 0.5] def faster(samples): new_samples = [] for i = 0 to samples.length: if i is even: new_samples.add(0.5 * (samples[i] + samples[i+1])) return new_samples faster_samples = faster(original_samples)
I also posted an answer to the question “ Getting started with software audio, ” where I talked in detail about some of the basic audio manipulations that can be performed, which may be interesting.