How does MPT convert samples to Output audio?

Started by Smileynator, August 16, 2021, 10:44:20

Previous topic - Next topic

Smileynator

Hey Modplug Central,

I am trying to learn about audio generation and conversion from a code perspective. I know that all kinds of samples are put into MPT to later be played back at what i assume is something like 44100Hz sample rate on a modern device.
Which means it somewhere has to convert really tiny and low sample rate audio, to this output format.
It is something i have been trying to figure out, but can't seem to find in the source code, nor in any other context (Game Emulators on modern PC's for example).

If anyone knows where i can find the code responsible for this specific step, in order for me to learn how that works. Or any pointers in the right direction, that would be great. I know it is a tad selfish, but i really have not

Sincerely,
Smileynator

Saga Musix

The process is called Sample Rate Conversion (SRC) or resampling. There are many different ways to do that with different types of interpolation, which you can also choose and configure in OpenMPT, so there is not one single place in OpenMPT where this happens. OpenMPT contains several resamplers:
- No interpolation. This just repeats the sample in case of upsample, so if you play a sample at 11025Hz and need to output 44100Hz, and the original sample has the value 55, then you would just output 55 four times.
- Linear interpolation. The second-simplest type of resampling. As the name implies, you linearly interpolate between two neighbouring sample points based on the fractional playback position. So for example if the playback position of your sample is 130.4, you would interpolate between the sample values at 130 and 131 (sample[130] * 0.6 + sample[131] * 0.4).
- Various higher-order interpolation types which extend beyond the concept of linear interpolation by also taking more surrounding sampling points into account. This is to reduce the amount of aliasing produced, but the principle is not that different.

In OpenMPT, you can have at the different interpolation classes in IntMixer.h. Each type of interpolation has its own interpolation class there (LinearInterpolation, FastSincInterpolation, etc.). Let me know if you have any question about those.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.