double CWTOscillator::doWaveTable(double& dReadIndex, double dWT_inc) { double dOut = 0; // apply phase modulation, if any double dModReadIndex = dReadIndex + m_dPhaseMod*WT_LENGTH; // check for multi-wrapping on new read index checkWrapIndex(dModReadIndex); // get INT part int nReadIndex = abs((int)dModReadIndex); // get FRAC part float fFrac = dModReadIndex - nReadIndex; // setup second index for interpolation; wrap the buffer if needed int nReadIndexNext = nReadIndex + 1 > WT_LENGTH-1 ? 0 : nReadIndex + 1; // interpolate the output dOut = dLinTerp(0, 1, m_pCurrentTable[nReadIndex], m_pCurrentTable[nReadIndexNext], fFrac); // add the increment for next time dReadIndex += dWT_inc; // check for wrap checkWrapIndex(dReadIndex); return dOut; }
void WaveTable_doOscillate(WaveTable *this, fixedp *pYn) { fixedp outSample = 0; // get int part int readIndex = qipart(this->readPointer); // get frac part fixedp frac = qfpart(this->readPointer); // check for next, might wrap around int readNextIndex = readIndex + 1 > N - 1 ? 0 : readIndex + 1; //printf("This: %ld, Next: %ld, Frac: %ld \n", this->table[readIndex], this->table[readNextIndex], frac); outSample = dLinTerp(0, short2q(1), this->table[readIndex], this->table[readNextIndex], frac); // add increment this->readPointer = qadd(this->readPointer, this->mInc); // check for wrap around if(this->readPointer >= qN) { this->readPointer = qsub(this->readPointer, qN); } // output *pYn = outSample; if(this->invert) { *pYn *= short2q(-1); }
float processSample(float sample) { float xn = sample; // head output float ynHeads[NBR_HEADS]; // delay output float yn=0.0; for (int i=0; i < NBR_HEADS; i++) { ynHeads[i] = buffer[readIndex[i]]; if (readIndex[i] == writeIndex && delayInSamples < 1.00) { ynHeads[i] = xn; } if (activeHeads[i]) { int readIndex_1 = readIndex[i] - 1; if (readIndex_1 < 0) { readIndex_1 = bufferSize - 1; } float yn_1 = buffer[readIndex_1]; float fracDelay = delayInSamples - (int) delayInSamples; ynHeads[i] = dLinTerp(0, 1, ynHeads[i], yn_1, fracDelay); } else { ynHeads[i] = 0; } readIndex[i]++; if (readIndex[i] >= bufferSize) { readIndex[i] = 0; } if (activeHeads[i]) { yn = yn + (ynHeads[i] * (1.0 / nbrActiveHead)); // hard limiting if (yn > 1.0) yn = 1.0; else if (yn < -1.0) yn = -1.0; } } // no delay! if (delayInSamples == 0) yn = xn; buffer[writeIndex] = xn + getParameterValue(PARAMETER_B) * yn; // increment for next sample writeIndex++; if (writeIndex >= bufferSize) { writeIndex = 0; } return getParameterValue(PARAMETER_C) * yn + (1.0 - getParameterValue(PARAMETER_C)) * xn; }