Пример #1
0
void DspTableRead4::processDspWithIndex(int fromIndex, int toIndex) {
  if (table != NULL) { // ensure that there is a table to read from!
    int bufferLength;
    float *buffer = table->getBuffer(&bufferLength);
    if (ArrayArithmetic::hasAccelerate) {
      #if __APPLE__
      //float zero = 0.0f;
      //float bufferLengthFloat = (float) (bufferLength-2);
      //vDSP_vclip(inputBuffer+startSampleIndex, 1, &zero, &bufferLengthFloat,
      //    inputBuffer+startSampleIndex, 1, endSampleIndex-startSampleIndex);
      // NOTE(mhroth): is isn't clear what the clipping behaviour of vDSP_vlint is, but I
      // *think* that it is doing the right thing (i.e., clipping OOB indicies)
      vDSP_vsadd(dspBufferAtInlet0+fromIndex, 1, &offset, dspBufferAtOutlet0+fromIndex, 1,
          toIndex-fromIndex);
      vDSP_vlint(buffer, dspBufferAtInlet0+fromIndex, 1, dspBufferAtOutlet0+fromIndex, 1,
          toIndex-fromIndex, bufferLength);
      #endif
    } else {
      int maxIndex = bufferLength-1;
      for (int i = fromIndex; i < toIndex; i++) {
        int x = (int) (dspBufferAtInlet0[i] + offset);
        if (x <= 0) {
          dspBufferAtOutlet0[i] = buffer[0];
        } else if (x >= maxIndex) {
          dspBufferAtOutlet0[i] = buffer[maxIndex];
        } else {
          // 2-point linear interpolation (basic and fast)
          float dx = dspBufferAtInlet0[i] - ((float) x);
          float y0 = buffer[x];
          float y1 = buffer[x+1];
          float slope = (y1 - y0);
          dspBufferAtOutlet0[i] = (slope * dx) + y0;
        }
      }
    }
  }
}
inline void maxiCollider::createGabor(flArr &atom, const float freq, const float sampleRate, const uint length, 
						 float startPhase, const float kurtotis, const float amp) {
	atom.resize(length);
    flArr sine;
    sine.resize(length);
    
//	float gausDivisor = (-2.0 * kurtotis * kurtotis);
//    float phase =-1.0;
    
    double *env = maxiCollider::envCache.getWindow(length);
#ifdef __APPLE_CC__	    
    vDSP_vdpsp(env, 1, &atom[0], 1, length);
#else    
	for(uint i=0; i < length; i++) {
        atom[i] = env[i];
    }
#endif
    
//#ifdef __APPLE_CC__	    
//    vDSP_vramp(&phase, &inc, &atom[0], 1, length);
//    vDSP_vsq(&atom[0], 1,  &atom[0], 1, length);
//    vDSP_vsdiv(&atom[0], 1, &gausDivisor, &atom[0], 1, length);
//    for(uint i=0; i < length; i++) atom[i] = exp(atom[i]);
//#else
//	for(uint i=0; i < length; i++) {
//		//gaussian envelope
//		atom[i] = exp((phase* phase) / gausDivisor);
//        phase += inc;
//    }
//#endif
    
	float cycleLen = sampleRate / freq;
	float maxPhase = length / cycleLen;
	float inc = 1.0 / length;

	
#ifdef __APPLE_CC__	
    flArr interpConstants;
    interpConstants.resize(length);
    float phase = 0.0;
    vDSP_vramp(&phase, &inc, &interpConstants[0], 1, length);
    vDSP_vsmsa(&interpConstants[0], 1, &maxPhase, &startPhase, &interpConstants[0], 1, length);
    float waveTableLength = 512;
    vDSP_vsmul(&interpConstants[0], 1, &waveTableLength, &interpConstants[0], 1, length);
    for(uint i=0; i < length; i++) {
        interpConstants[i] = fmod(interpConstants[i], 512.0f); 
    }
    vDSP_vlint(sineBuffer2, &interpConstants[0], 1, &sine[0], 1, length, 514);
    vDSP_vmul(&atom[0], 1, &sine[0], 1, &atom[0], 1,  length);
	vDSP_vsmul(&atom[0], 1, &amp, &atom[0], 1, length);
#else
	maxPhase *= TWOPI;
    for(uint i=0; i < length; i++) {
		//multiply by sinewave
		float x = inc * i;
		sine[i] = sin((x * maxPhase) + startPhase);
	}
	for(uint i=0; i < length; i++) {
        atom[i] *= sine[i];
		atom[i] *= amp;
	}
#endif
}