How do I resample an audio signal without altering its pitch? I'm working on concatenating videos again, this time with different playback speeds. The video stream part is easy enough, but the audio part is what's stumping me at the moment.

Currently, I've managed to do it by just multiplying the timestamp by a factor inversely derived from the desired playback speed, so that if the playback is to be half speed, the timestamps are multiplied by two.

Not only that, I've also altered the audio samples (in the form of a byte array) so that when the playback is half speed, every sample (of four bytes) is repeated, and when the playback is double speed, every second sample is discarded.

My problem is that this method also alters the pitch of the resulting audio track - the half-speed playback lowers the pitch, the double-speed playback raises it.

How can I resample these samples without altering their pitch?
Simple resampling would not work in your case. Resampling, while stretches/compresses the signal in the time domain, also does an inverse operation in the frequency domain.

Some basic time stretching algorithms you might want to look into (which do not result in pitch change) are:

1) OLA - overlap and add

2) PSOLA - pitch synchronous overlap and add

These work well for monophonic signals if that's what you have.

3) Phase vocoder

This works for polyphonic signals as well. But you may have to be careful about transients while using a phase vocoder approach.

There may be time stretcher plugins you could look at which use these. You could also find some open source code and time shift the signals in MATLAB/Python, etc.

Hope this helps. Let us know how it works out!