Main Archive Specials Wiki | FAQ Links Submit Forum


Type : linear interpolated aliased resampling of a wave file
References : Posted by mail[AT]mroc[DOT]de

Notes :
som resampling stuff. the code is heavily used in MSynth, but do not lough about ;-)

perhaps, prefiltering would reduce aliasing.

Code :
signed short* pSample = ...;
unsigned int sampleLength = ...;

// stretch sample to length of one bar...
float playPosDelta = sampleLength / ( ( 240.0f / bpm ) * samplingRate );

// requires for position calculation...
float playpos1 = 0.0f;
unsigned int iter = 0;

// required for interpolation...
unsigned int i1, i2;

float* pDest = ....;
float* pDestStop = pDest + len;
for( float *pt=pDest;pt {
// linear interpolation...
i1 = (unsigned int)playpos;
i2 = i1 + 1;
(*pt) = ((pSample[i2]-pSample[i1]) * (playpos - i1) + pSample[i1]);

// position calculation preventing float sumation error...
playpos1 = (++iter) * playposIncrement;


Added on : 15/02/04 by Gog
Comment :
Linear interpolation normally introduces a lot of artefacts. An easy way to improve upon this is to use the hermite interpolator instead. The improvement is _dramatic_!

Added on : 04/05/04 by pete[ AT ]bannister25[ DOT ]plus[ DOT ]com
Comment :
i1 = (unsigned int)playpos;
i2 = i1 + 1;

would this be better as:

i1 = (unsigned int) floor(playpos);
i2 = (unsigned int) ceil(i1 + playposIncrement);


if you are actually decimating rather than interpolating (which is what would give aliasing), then the second interpolation point in the input could potentially be more than i1 + 1.

Added on : 05/05/04 by pete[ AT ]bannister25[ DOT ]plus[ DOT ]com
Comment :
no, sorry it wouldn't :%|

Added on : 13/08/04 by mail[ AT ]mroc[ DOT ]de
Comment :
yes, a more sophisticated interpolation would
improve the sound and prefiltering would
terminate the aliasing. but everything with
hi runtime overhead.

Add your own comment
Comments are displayed in fixed width, no HTML code allowed!


Are you human?

Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion