float FourthOrderFilter::process(float sample){ float Aout, Bout; vDSP_vmul(A, 1, za1, 1, temp, 1, 4); vDSP_sve(temp, 1, &Aout, 4); vDSP_vmul(B, 1, zb1, 1, temp, 1, 4); vDSP_sve(temp, 1, &Bout, 4); float output = b0*sample + Bout - Aout; za1--; zb1--; if (za1 < Za) { // if we have reached the beginning of the buffer // copy za2, za3, za4, zb2, zb3, zb4 back to the end of the array *ZaEnd = *(Za + 2); *(ZaEnd - 1) = *(Za + 1); *(ZaEnd - 2) = *Za; *ZbEnd = *(Za + 2); *(ZbEnd - 1) = *(Zb + 1); *(ZbEnd - 2) = *Zb; // reset pointers za1 = ZaEnd - 3; zb1 = ZbEnd - 3; } *za1 = output; *zb1 = sample; return output; }
// windowSize and windowInterval are constrained to be multiples of the block size void DspEnvelope::processDspWithIndex(int fromIndex, int toIndex) { // copy the input into the signal buffer memcpy(signalBuffer + numSamplesReceived, dspBufferAtInlet0, numBytesInBlock); numSamplesReceived += blockSizeInt; numSamplesReceivedSinceLastInterval += blockSizeInt; if (numSamplesReceived >= windowSize) { numSamplesReceived = 0; } if (numSamplesReceivedSinceLastInterval == windowInterval) { numSamplesReceivedSinceLastInterval -= windowInterval; // apply hanning window to signal and calculate Root Mean Square float rms = 0.0f; if (ArrayArithmetic::hasAccelerate) { #if __APPLE__ vDSP_vsq(signalBuffer, 1, rmsBuffer, 1, windowSize); // signalBuffer^2 vDSP_vmul(rmsBuffer, 1, hanningCoefficients, 1, rmsBuffer, 1, windowSize); // * hanning window vDSP_sve(rmsBuffer, 1, &rms, windowSize); // sum the result #endif } else { for (int i = 0; i < windowSize; i++) { rms += signalBuffer[i] * signalBuffer[i] * hanningCoefficients[i]; } } // finish RMS calculation. sqrt is removed as it can be combined with the log operation. // result is normalised such that 1 RMS == 100 dB rms = 10.0f * log10f(rms) + 100.0f; PdMessage *outgoingMessage = getNextOutgoingMessage(0); // graph will schedule this at the beginning of the next block because the timestamp will be // behind the block start timestamp outgoingMessage->setTimestamp(0.0); outgoingMessage->setFloat(0, (rms < 0.0f) ? 0.0f : rms); graph->scheduleMessage(this, 0, outgoingMessage); } }
t_int *errfilt_perf_coeff(t_int *w) { t_float *in = (t_float *)(w[1]); t_float *coeffIn = (t_float *)(w[2]); t_float *coeffIdxIn = (t_float *)(w[3]); t_errfilt *x = (t_errfilt *)(w[4]); t_float *out = (t_float *)(w[5]); int n = (int)(w[6]); int order = x->a_order; int i, in_idx = 0, out_idx = 0; t_float val = 0.0; float sum = 0.0; while(n--) { //get rid of NANs if(IS_NAN_FLOAT(coeffIn[in_idx])) coeffIn[in_idx] = 0.0; in_idx++; } in_idx = 0; n = (int)(w[6]); //look at coefficient index, if not zeros, buffer in coefficients while (n--) { if ((int)(coeffIdxIn[in_idx]) > 0) { x->a_bBuff[(int)(coeffIdxIn[in_idx])-1] = coeffIn[in_idx]; if ((int)(coeffIdxIn[in_idx]) == order) { for(i = 0; i < order; i++) { x->a_b[i] = x->a_bBuff[i]; } } } in_idx++; } n = (int)(w[6]); while (n--) { val = in[out_idx]; vDSP_vmul(x->a_b,1,x->a_x,1,x->a_tempVec,1,order); vDSP_sve(x->a_tempVec,1,&sum,order); val -= sum; //for (i=0; i < order; i++) val -= x->a_b[i] * x->a_x[i]; for (i=order-1; i>0; i--) x->a_x[i] = x->a_x[i-1]; x->a_x[0] = in[out_idx]; out[out_idx] = (float)val; out_idx++; } return (w+7); }
/******************************************************************************* VectorSum */ float VectorSum(const float* src, unsigned length) { float res = 0.0; #ifdef __APPLE__ // Use the Accelerate framework if we have it vDSP_sve(src, 1, &res, length); #else for (unsigned i = 0; i < length; ++i) { res += src[i]; } #endif return res; }
float movingAverage::value() { if (cacheInvalid) { float total = 0; #ifdef __APPLE_CC__ vDSP_sve(&(values[0]), 1, &total, sampleSize); #else for(int i = 0; i < sampleSize; i++) { total += values[i]; } #endif cachedValue = total / (float) sampleSize; cacheInvalid = false; } return cachedValue; }