1
\$\begingroup\$

We have managed to play audio files using SDL's Mix_PlayMusic function. The problem now we need to do some upsampling for one audio to match the other so that both have same duration. Any idea how to resolve this issue.

\$\endgroup\$
7
  • \$\begingroup\$ Well resampling is easy enough but I'm not fully clear on your question, if you use this technique to "Match duration" you will change the pitch of the whole sound. If you want the pitch to stay the same but the time to change, you are in for some heavy math! \$\endgroup\$
    – MickLH
    Commented Oct 2, 2013 at 17:28
  • \$\begingroup\$ @MickLH how can I do more sampling so that the duration of the short file is same as the longer file and just mix them is that possible? I saw some codes snippet where it first compare the length e.g. using this playing[i].sound->length. Then it decide on the sampling. \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 17:34
  • \$\begingroup\$ @MickLH so how to go about the Match Duration then. \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 17:50
  • \$\begingroup\$ If your question is about matching the duration, you should ask about that. Since your assumption that you need to upsample to achieve this might be incorrect. \$\endgroup\$
    – House
    Commented Oct 2, 2013 at 18:07
  • \$\begingroup\$ @Byte56 so if its matching duration what is best way to do about. First I guess to compare the length. Next I should expand the short duration sound right? \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 18:09

1 Answer 1

1
\$\begingroup\$

Do you want the pitch to warp with the speed?


Yes: Then you want time stretching.

This is simply interpolating / combining samples to generate the same overall waveform in a different number of samples. The obvious nearest neighbor approach will cause severe aliasing but technically works. To make it sound better one can use a higher order function like sinc interpolation.


No: Then you want time scaling.

This is usually boiling down the sound to a procedural / time domain representation, it is an active area of research and doesn't sound perfect. The common techniques are:

  1. Phase Vocoder
  2. Time Domain Harmonic Scaling

EDIT: Your question is WAY out of scope for SDL. If you just want a library (instead of understanding what you are doing) then try SoundTouch or Rubber Band.

\$\endgroup\$
4
  • \$\begingroup\$ any SDL syntax example on this for me to follow up? \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 18:36
  • \$\begingroup\$ is it possible for me to use SDL mixer to achieve all this. \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 18:43
  • \$\begingroup\$ Does it count if you pay me to write the code that outputs the buffers in a format that SDL mixer can use? \$\endgroup\$
    – MickLH
    Commented Oct 2, 2013 at 18:44
  • \$\begingroup\$ we wish to pay if possible but we are just doing some experiments on it. \$\endgroup\$
    – biz14
    Commented Oct 2, 2013 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .