// a first attempt at interpolation for the SampleMatrix. should be viewed as temporary. // needs to be fleshed out with different options... TTErr TTSampleMatrix::peeki(const TTFloat64 index, const TTColumnID channel, TTSampleValue& value) { // variables needed TTColumnID p_channel = channel; TTFloat64 indexIntegralPart = 0; TTFloat64 indexFractionalPart = modf(index, &indexIntegralPart); // before makeInBounds to get the right value! TTRowID indexThisInteger = TTRowID(indexIntegralPart); TTBoolean weAreNotInBounds = makeInBounds(indexThisInteger, p_channel); // out of range values are wrapped if (weAreNotInBounds) { // no reason to interpolate, just use the first or last value get2d(indexThisInteger, p_channel, value); return kTTErrOutOfBounds; // and report an error (is that what we want?) } else { TTRowID indexNextInteger = indexThisInteger + 1; makeRowIDInBounds(indexNextInteger); //does not allow interpolation between first and last sample // (is that what we want? if not, insert outOfBoundsWrap) TTSampleValue valueThisInteger, valueNextInteger; get2d(indexThisInteger, p_channel, valueThisInteger); get2d(indexNextInteger, p_channel, valueNextInteger); // simple linear interpolation adapted from TTDelay value = TTInterpolateLinear(valueThisInteger, valueNextInteger, indexFractionalPart); return kTTErrNone; } }
/** Perform one linear interpolation and compare the outcome to expected value. @param x0 Sample value at prior integer index @param x1 Sample value at next integer index @param delta The fractional value for which we want to perform the interpolation. delta=0 => x0 @n delta=1 => x1 @param expectedValue The expected outcome of the interpolation @return TRUE if the interpolat returnes the expected value, else FALSE */ TTFloat64 InterpolateAndTestLinear(const TTFloat64 x0, const TTFloat64 x1, const TTFloat64& aDelta, TTFloat64 anExpectedValue) { TTFloat64 interpolatedValue = TTInterpolateLinear(x0, x1, aDelta); TTBoolean result = TTTestFloatEquivalence(interpolatedValue , anExpectedValue); if (!result) TTTestLog("BAD INTERPOLATION @ delta=%.5f ( value=%.10f expected=%.10f )", aDelta, interpolatedValue, anExpectedValue); return result; }