2
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ Resampling results in either sample decimation (removing samples) or interpolation (adding samples). To keep the pitch unchanged, you'd have to adjust the playback speed accordingly. Which software are you using ? $\endgroup$
    – dsp_user
    Commented Mar 2, 2018 at 10:01
  • 1
    $\begingroup$ Just resampling won't work. You will need to do a time-pitch re-synthesis/correction to stretch the track before resampling. See: en.wikipedia.org/wiki/Audio_time_stretching_and_pitch_scaling $\endgroup$
    – hotpaw2
    Commented Mar 2, 2018 at 17:58

1 Answer 1

3
$\begingroup$

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!

$\endgroup$
7
  • $\begingroup$ PSOLA - Pitch Synchronous Overlap and Add $\endgroup$
    – ederwander
    Commented Mar 2, 2018 at 19:02
  • $\begingroup$ also the overlap and add method referred in the answer as "OLA" is not really the same. the wikipedia reference is about the OLA we do for fast convolution. and the window implied is only the rectangular window. that is not exactly the same as the windowed overlap add we do for audio analysis/synthesis usually with a Hann window. $\endgroup$ Commented Mar 2, 2018 at 19:34
  • $\begingroup$ Yes, a window like Hann would definitely help. Although the choice of window maybe the choice of the user. $\endgroup$ Commented Mar 2, 2018 at 19:35
  • $\begingroup$ but, Somesh, the reference to wikipedia for OLA is not what you want for this appl. $\endgroup$ Commented Mar 2, 2018 at 19:37
  • $\begingroup$ Oh, sorry about that. You're right. Maybe I should remove that link. Thanks! $\endgroup$ Commented Mar 2, 2018 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.