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.
Asked
Active
Viewed 547 times
1
-
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! – MickLH Oct 02 '13 at 17:28
-
@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. – biz14 Oct 02 '13 at 17:34
-
@MickLH so how to go about the Match Duration then. – biz14 Oct 02 '13 at 17:50
-
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. – House Oct 02 '13 at 18:07
-
@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? – biz14 Oct 02 '13 at 18:09
-
Short of just cutting the sound off at the end, I'm not sure how you'd do that without changing the pitch. You might want to ask that type of question over at http://sound.stackexchange.com/. You can remove this question for now. Get an answer over there, and if you have trouble implementing it then ask about that here. – House Oct 02 '13 at 18:13
-
@Byte56 ok will try there then. Thank you. – biz14 Oct 02 '13 at 18:17
1 Answers
1
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:
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.

MickLH
- 2,757
- 18
- 26
-
-
-
Does it count if you pay me to write the code that outputs the buffers in a format that SDL mixer can use? – MickLH Oct 02 '13 at 18:44
-
we wish to pay if possible but we are just doing some experiments on it. – biz14 Oct 02 '13 at 18:46