There are many algorithms of varying degrees of sophistication to perform audio resampling (what you're trying to do here). If you have access to a raw buffer of audio samples, here are some naïve ways to manipulate them as you described:
- To do 2X playback, iterate over the sample of buffers and average (arithmetic mean) each successive pair of samples, placing the results into a new buffer. The resampled buffer should be half as long as the original buffer.
- To do 0.5X playback, compute the averages of successive sample pairs but insert the average between the 2 samples. This resampled buffer should be twice as long as the original buffer.