Esempio n. 1
0
void DspSignal::processDspToIndex(float blockIndex) {
  float *outputBuffer = localDspBufferAtOutlet[0];
  int startSampleIndex = getStartSampleIndex();
  int endSampleIndex = getEndSampleIndex(blockIndex);
  if (ArrayArithmetic::hasAccelerate) {
    #if __APPLE__
    vDSP_vfill(&constant, outputBuffer+startSampleIndex, 1, endSampleIndex-startSampleIndex);
    #endif
  } else {
    for (int i = getStartSampleIndex(); i < endSampleIndex; i++) {
      outputBuffer[i] = constant;
    }
  }
  blockIndexOfLastMessage = blockIndex;
}
Esempio n. 2
0
// http://en.wikipedia.org/wiki/High-pass_filter
void DspHighpassFilter::processDspToIndex(float blockIndex) {
  float *inputBuffer = localDspBufferAtInlet[0]; 
  float *outputBuffer = localDspBufferAtOutlet[0];
  int startSampleIndex = getStartSampleIndex();
  int endSampleIndex = getEndSampleIndex(blockIndex);
  if (ArrayArithmetic::hasAccelerate) {
    #if __APPLE__
    const int duration = endSampleIndex - startSampleIndex;
    const int durationBytes = duration * sizeof(float);
    memcpy(filterInputBuffer+2, inputBuffer+startSampleIndex, durationBytes);
    vDSP_deq22(filterInputBuffer, 1, coefficients, filterOutputBuffer, 1, duration);
    memcpy(outputBuffer+startSampleIndex, filterOutputBuffer+2, durationBytes);
    memcpy(filterInputBuffer, filterInputBuffer+duration, 2 * sizeof(float));
    memcpy(filterOutputBuffer, filterOutputBuffer+duration, 2 * sizeof(float));
    #endif
  } else {
    outputBuffer[startSampleIndex] = alpha * (tapOut + inputBuffer[startSampleIndex] - tapIn);
    for (int i = startSampleIndex+1; i < endSampleIndex; i++) {
      outputBuffer[i] = alpha * (outputBuffer[i-1] + inputBuffer[i] - inputBuffer[i-1]);
    }
    tapIn = inputBuffer[endSampleIndex-1];
    tapOut = outputBuffer[endSampleIndex-1];
  }
  blockIndexOfLastMessage = blockIndex;
}
Esempio n. 3
0
void DspSignal::processDspToIndex(float blockIndex) {
  float *outputBuffer = localDspBufferAtOutlet[0];
  int endSampleIndex = getEndSampleIndex(blockIndex);
  for (int i = getStartSampleIndex(); i < endSampleIndex; i++) {
    outputBuffer[i] = constant;
  }
  blockIndexOfLastMessage = blockIndex;
}
Esempio n. 4
0
void DspPhasor::processDspToIndex(float blockIndex) {
  switch (signalPrecedence) {
    case DSP_DSP: {
      // TODO(mhroth)
      break;
    }
    case DSP_MESSAGE: {
      int endSampleIndex = getEndSampleIndex(blockIndex);
      float *inputBuffer = localDspBufferAtInlet[0];
      float *outputBuffer = localDspBufferAtOutlet[0];
      for (int i = getStartSampleIndex(); i < endSampleIndex; index += inputBuffer[i++]) {
        if (index < 0.0f) {
          index += sampleRate; // account for negative frequencies
        } else if (index >= sampleRate) {
          index -= sampleRate;
        }
        outputBuffer[i] = phasor_table[(int) index];
      }
      break;
    }
    case MESSAGE_DSP: {
      // TODO(mhroth)
      break;
    }
    case MESSAGE_MESSAGE: {
      int endSampleIndex = getEndSampleIndex(blockIndex);
      float *outputBuffer = localDspBufferAtOutlet[0];
      for (int i = getStartSampleIndex(); i < endSampleIndex; i++, index += frequency) {
        if (index < 0.0f) {
          index += sampleRate; // account for negative frequencies
        } else if (index >= sampleRate) {
          index -= sampleRate;
        }
        outputBuffer[i] = phasor_table[(int) index];
      }
      break;
    }
  }
  blockIndexOfLastMessage = blockIndex; // update the block index of the last message
}