1
$\begingroup$

I am attempting to develop a similar function as Audacity's Effects>Change Tempo effect.

Or more specifically: I am in need of a way to create a funciton in my own project that can modify the length of a .wav file without changing it's pitch or introducing pops/leakage.

I am writing a standalone application (in C#) that already has some functions to create and save .wav files. But I just realized that I must add some processing to allow me to adjust the duration/length of a .wav so I can sync it to be exactly as long as an associated animation (which can not be altered).

I am very interested in knowing if there are any examples that exist which demonstrate concepts on how to change a .wav file's tempo (without noticeable distortion)?

I should specify that I would not need to adjust the length by much more than ±5%.

What I have tried already is to remove slices of data at regular intervals for a given "slice width", which kind of worked but introduced many pops as the sine waves were no longer smooth/continuous.

I have also tried simply adjusting the playback speed at the player by a multiplier to adjust to a desired duration, but this obviously cause the pitch to change (and somewhat noticeably too).

This is something that I am very anxious to understand as my project now seems to be in trouble unless I can somehow synchronize the audio. Could someone please help me figure out if I can write my own function to process this?

$\endgroup$
  • 1
    $\begingroup$ here you will find lots of information on how to do this link1 link2 or link3 $\endgroup$ – ederwander Apr 10 at 21:44
  • $\begingroup$ I see one is called a: "phase vocoder" algorithm. But I read that it may not be best fit for voice data. Should I pursue using a phase vocoders if my .wavs are purely voice recordings? $\endgroup$ – Logic1 Apr 10 at 21:56
  • 2
    $\begingroup$ Maybe not a best choice for voices but yeah Phase Vocoder works, for monophonic sounds like voices I still love PSOLA, TDHS or WSOLA. $\endgroup$ – ederwander Apr 10 at 21:59
  • $\begingroup$ Thank you for posting those links too! Just curious, since I am beginner to DSP, which of PSOLA, TDHS or WSOLA would you recommend as being simplest to implement/understand? BTW, my application does have a decently powerful FFT library and some math functions, but that's it... $\endgroup$ – Logic1 Apr 10 at 22:02
  • 1
    $\begingroup$ @user2169557 are your voice recordings a single voice or are there multiple voices going simultaneously? if the former, you can time-stretch or time-compress a monophonic voice in the time-domain using splicing and something like auto-correlation to know what good splice points are (that's what prevents the pops). if you have multiple voices or "notes" (is in many different musical notes), that is polyphonic and you might need a phase vocoder to stretch or compress it without glitches. $\endgroup$ – robert bristow-johnson Apr 10 at 22:54
0
$\begingroup$

I would suggest the following steps:

  • identify voices and unvoiced sounds: for this you can use zero-crossing rate and intensity as a basic approach or use more complex methods: cepstrum, harmonicity, others.
  • the unvoiced sounds can be simply cut, usually without concerns
  • for the voiced sounds apply PSOLA or WSOLA. For PSOLA there are many implementation and it might be easier. So first you must identify the glotal pulses to be able to identify glotal periods. Then you can "cut" full periods (in a overlap and add sense). Always cut periods in the middle of the phonemes and never near the transition zones (borders)
$\endgroup$
  • $\begingroup$ Thanks, I just attempted writing a PSOLA function in Python, but I think I am lost on the how to "cut in full periods" part. $\endgroup$ – Logic1 Apr 11 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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