void FFT32_configureWindow(FFT32 *self, FFTWindowType windowType)
{
    Float32 one = 1;
    
    switch (windowType) {
            
        case kFFTWindowType_None:
            
            vDSP_vfill(&one, self->window, 1, self->FFTFrameSize);
            break;
            
        case kFFTWindowType_Hanning:
            
            vDSP_hann_window(self->window, self->FFTFrameSize, vDSP_HANN_DENORM);
            break;
            
        case kFFTWindowType_Hamming:
            
            vDSP_hamm_window(self->window, self->FFTFrameSize, 0);
            break;
            
        default:
            printf("Valid window not specified, default to none\n");
            vDSP_vfill(&one, self->window, 1, self->FFTFrameSize);
            break;
    }
}
Example #2
0
void DspLine::processDspWithIndex(int fromIndex, int toIndex) {
  if (numSamplesToTarget <= 0.0f) { // if we have already reached the target
    if (ArrayArithmetic::hasAccelerate) {
      #if __APPLE__
      vDSP_vfill(&target, dspBufferAtOutlet0+fromIndex, 1, toIndex-fromIndex);
      #endif
    } else {
      memset_pattern4(dspBufferAtOutlet0+fromIndex, &target, (toIndex-fromIndex)*sizeof(float));
    }
    lastOutputSample = target;
  } else {
    // the number of samples to be processed this iteration
    float processLength = toIndex - fromIndex;
    if (processLength > 0.0f) {
      // if there is anything to process at all (several messages may be received at once)
      if (numSamplesToTarget < processLength) {
        int targetIndexInt = fromIndex + numSamplesToTarget;
        if (ArrayArithmetic::hasAccelerate) {
          #if __APPLE__
          vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet0+fromIndex, 1, targetIndexInt-fromIndex);
          vDSP_vfill(&target, dspBufferAtOutlet0+targetIndexInt, 1, toIndex-targetIndexInt);
          #endif
        } else {
          // if we will process more samples than we have remaining to the target
          // i.e., if we will arrive at the target while processing
          dspBufferAtOutlet0[fromIndex] = lastOutputSample + slope;
          for (int i = fromIndex+1; i < targetIndexInt; i++) {
            dspBufferAtOutlet0[i] = dspBufferAtOutlet0[i-1] + slope;
          }
          for (int i = targetIndexInt; i < toIndex; i++) {
            dspBufferAtOutlet0[i] = target;
          }
        }
        lastOutputSample = target;
        numSamplesToTarget = 0;
      } else {
        // if the target is far off
        if (ArrayArithmetic::hasAccelerate) {
          #if __APPLE__
          vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet0+fromIndex, 1, toIndex-fromIndex);
          #endif
        } else {
          dspBufferAtOutlet0[fromIndex] = lastOutputSample + slope;
          for (int i = fromIndex+1; i < toIndex; i++) {
            dspBufferAtOutlet0[i] = dspBufferAtOutlet0[i-1] + slope;
          }
        }
        lastOutputSample = dspBufferAtOutlet0[toIndex-1];  
        numSamplesToTarget -= processLength;
      }
    }
  }
}
Example #3
0
File: Dsp.c Project: eriser/FxDSP
/*******************************************************************************
 FillBuffer */
Error_t
FillBuffer(float *dest, unsigned length, float value)
{
#ifdef __APPLE__
    // Use the Accelerate framework if we have it
    vDSP_vfill(&value, dest, 1, length);
    
#else
    // Otherwise do it manually
    unsigned i = 0;
    const unsigned end = 4 * (length / 4);
    for (i = 0; i < end; i+=4)
    {
        dest[i] = value;
        dest[i + 1] = value;
        dest[i + 2] = value;
        dest[i + 3] = value;
    }
    for (i = end; i < length; ++i)
    {
        dest[i] = value;
    }
#endif
    return NOERR;
}
Example #4
0
File: DTW.c Project: eddyc/DSPTools
DTW32 *DTW32_new(size_t rowCount, size_t maximumColumnCount)
{
    DTW32 *self = calloc(1, sizeof(DTW32));
    
    if (rowCount < maximumColumnCount) {
        
        rowCount = maximumColumnCount;
    }
    
    self->maximumRowCount = rowCount;
    self->maximumColumnCount = maximumColumnCount;
    self->maximumElementCount = rowCount * rowCount;
    
    self->ones = calloc(self->maximumElementCount, sizeof(Float32));
    Float32 one = 1;
    vDSP_vfill(&one, self->ones, 1, self->maximumElementCount);
    
    self->distanceMatrix = calloc(self->maximumElementCount, sizeof(Float32));
    
    size_t globalDistanceElementCount = (rowCount + 1) * (rowCount + 1);
    self->globalDistanceMatrix = calloc(globalDistanceElementCount, sizeof(Float32));
    self->multiplicationTemp = calloc(self->maximumElementCount, sizeof(Float32));
    self->inputTemp = calloc(self->maximumElementCount, sizeof(Float32));
    self->comparisonDataTemp = calloc(self->maximumElementCount, sizeof(Float32));
    
    self->normalisationMatrix = calloc(self->maximumElementCount, sizeof(Float32));
    self->phi = calloc(self->maximumElementCount, sizeof(Float32));;
    self->p = calloc(self->maximumElementCount, sizeof(Float32));
    self->q = calloc(self->maximumElementCount, sizeof(Float32));
    return self;
}
Example #5
0
void dm_vsfill(float value, float * vector_, unsigned long size_) {
#ifdef DSP_USE_ACCELERATE
  vDSP_vfill(&value, vector_, 1,size_);
#else // generic
  std::fill(vector_, vector_ + size_, value);
#endif
}
void JUCE_CALLTYPE FloatVectorOperations::fill (float* dest, float valueToFill, int num) noexcept
{
   #if JUCE_USE_VDSP_FRAMEWORK
    vDSP_vfill (&valueToFill, dest, 1, (size_t) num);
   #else
    JUCE_PERFORM_VEC_OP_DEST (dest[i] = valueToFill, val, JUCE_LOAD_NONE,
                              const Mode::ParallelType val = Mode::load1 (valueToFill);)
   #endif
}
Example #7
0
void TonicFrames :: resize( size_t nFrames, unsigned int nChannels, TonicFloat value )
{
    this->resize( nFrames, nChannels );

#ifdef USE_APPLE_ACCELERATE
    vDSP_vfill(&value, data_, 1, size_);
#else
    for ( size_t i=0; i<size_; i++ ) data_[i] = value;
#endif

}
Example #8
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;
}
Example #9
0
void DspLine::processDspWithIndex(int fromIndex, int toIndex) {
  if (numSamplesToTarget <= 0.0f) { // if we have already reached the target
    int n = toIndex - fromIndex;
    if (n > 0) { // n may be zero
      ArrayArithmetic::fill(dspBufferAtOutlet[0], target, fromIndex, toIndex);
      lastOutputSample = target;
    }
  } else {
    // the number of samples to be processed this iteration
    int n = toIndex - fromIndex;
    if (n > 0) { // n may be zero
      // if there is anything to process at all (several messages may be received at once)
      if (numSamplesToTarget < n) {
        int targetIndexInt = fromIndex + numSamplesToTarget;
        #if __APPLE__
        vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet[0]+fromIndex, 1, targetIndexInt-fromIndex);
        vDSP_vfill(&target, dspBufferAtOutlet[0]+targetIndexInt, 1, toIndex-targetIndexInt);
        #else
        // if we will process more samples than we have remaining to the target
        // i.e., if we will arrive at the target while processing
        dspBufferAtOutlet[0][fromIndex] = lastOutputSample;
        for (int i = fromIndex+1; i < targetIndexInt; i++) {
          dspBufferAtOutlet[0][i] = dspBufferAtOutlet[0][i-1] + slope;
        }
        for (int i = targetIndexInt; i < toIndex; i++) {
          dspBufferAtOutlet[0][i] = target;
        }
        #endif
        lastOutputSample = target;
        numSamplesToTarget = 0;
      } else {
        // if the target is far off
        #if __APPLE__
        vDSP_vramp(&lastOutputSample, &slope, dspBufferAtOutlet[0]+fromIndex, 1, n);
        #else
        dspBufferAtOutlet[0][fromIndex] = lastOutputSample;
        for (int i = fromIndex+1; i < toIndex; i++) {
          dspBufferAtOutlet[0][i] = dspBufferAtOutlet[0][i-1] + slope;
        }
        #endif
        lastOutputSample = dspBufferAtOutlet[0][toIndex-1] + slope;
        numSamplesToTarget -= n;
      }
    }
  }
}
Example #10
0
/* TB: vectorized version */
static t_int *line_tilde_perf8(t_int *w)
{
    t_line *x = (t_line *)(w[1]);
    t_sample *out = (t_sample *)(w[2]);
    int n = (int)(w[3]);
    t_sample f = x->x_value;

    if (PD_BIGORSMALL(f))
        x->x_value = f = 0;
    if (x->x_retarget)
    {
        int nticks = x->x_inletwas * x->x_dspticktomsec;
        if (!nticks) nticks = 1;
        x->x_ticksleft = nticks;
        x->x_biginc = (x->x_target - x->x_value)/(t_sample)nticks;
        x->x_inc = x->x_1overn * x->x_biginc;
        x->x_retarget = 0;
    }
    if (x->x_ticksleft)
    {
        t_sample f = x->x_value;
#if USE_ACCEL_OPTIM
        vDSP_vramp(&f, &x->x_inc, out, 1, n);
#else
        while (n--) *out++ = f, f += x->x_inc;
#endif
        x->x_value += x->x_biginc;
        x->x_ticksleft--;
    }
    else
    {
        t_sample f = x->x_value = x->x_target;
#if USE_ACCEL_OPTIM
        vDSP_vfill(&f, out, 1, n);
#else
        for (; n; n -= 8, out += 8)
        {
            out[0] = f; out[1] = f; out[2] = f; out[3] = f;
            out[4] = f; out[5] = f; out[6] = f; out[7] = f;
        }
#endif
    }
    return (w+4);
}
Example #11
0
File: Dsp.cpp Project: Ahbee/Cinder
void fill( float value, float *array, size_t length )
{
	vDSP_vfill( &value, array, 1, length );
}
Example #12
0
File: DTW.c Project: eddyc/DSPTools
Float32 DTW32_getSimilarityScore(DTW32 *self,
                                 Float32 *inputData,
                                 size_t inputRowCount,
                                 Float32 *comparisonData,
                                 size_t comparisonDataRowCount,
                                 size_t currentColumnCount)
{
    
//    Float32_printContiguous2DArray(inputData, inputRowCount, currentColumnCount, "input");
//    Float32_printContiguous2DArray(comparisonData, comparisonDataRowCount, currentColumnCount, "compare");

    Float32 similarity = INFINITY;
    self->currentInputRowCount = inputRowCount;
    self->currentComparisonDataRowCount = comparisonDataRowCount;
    vDSP_vsq(inputData, 1, self->inputTemp, 1, inputRowCount * currentColumnCount);
    vDSP_vsq(comparisonData, 1, self->comparisonDataTemp, 1, comparisonDataRowCount * currentColumnCount);
    

    
    vDSP_mtrans(self->inputTemp, 1, self->multiplicationTemp, 1, currentColumnCount, inputRowCount);
    vDSP_mmul(self->ones, 1, self->multiplicationTemp, 1, self->inputTemp, 1, 1, inputRowCount, currentColumnCount);
    
    vDSP_mtrans(self->comparisonDataTemp, 1, self->multiplicationTemp, 1, currentColumnCount, comparisonDataRowCount);
    vDSP_mmul(self->ones, 1, self->multiplicationTemp, 1, self->comparisonDataTemp, 1, 1, comparisonDataRowCount, currentColumnCount);
    
    const int elementCountInput = (int)inputRowCount;
    const int elementCountComparisonData = (int)comparisonDataRowCount;
    
    vvsqrtf(self->inputTemp, self->inputTemp, &elementCountInput);
    vvsqrtf(self->comparisonDataTemp, self->comparisonDataTemp, &elementCountComparisonData);
 
    cblas_sgemm(CblasRowMajor,
                CblasNoTrans,
                CblasTrans,
                (SInt32)inputRowCount,
                (SInt32)comparisonDataRowCount,
                1,
                1.0,
                self->inputTemp,
                1,
                self->comparisonDataTemp,
                1,
                0.,
                self->normalisationMatrix,
                (SInt32)comparisonDataRowCount);
    
    cblas_sgemm(CblasRowMajor,
                CblasNoTrans,
                CblasTrans,
                (SInt32)inputRowCount,
                (SInt32)comparisonDataRowCount,
                (SInt32)currentColumnCount,
                1.0,
                inputData,
                (SInt32)currentColumnCount,
                comparisonData,
                (SInt32)currentColumnCount,
                0.,
                self->distanceMatrix,
                (SInt32)comparisonDataRowCount);
    
    vDSP_vdiv(self->normalisationMatrix, 1, self->distanceMatrix, 1, self->distanceMatrix, 1, inputRowCount * comparisonDataRowCount);
    
//    Float32_printContiguous2DArray(self->distanceMatrix, inputRowCount, comparisonDataRowCount, "norm");

    
    Float32 minusOne =  -1.f;

    vDSP_vsma(self->distanceMatrix, 1, &minusOne, self->ones, 1, self->distanceMatrix, 1, inputRowCount * comparisonDataRowCount);

//    Float32_printContiguous2DArray(self->distanceMatrix, inputRowCount, comparisonDataRowCount, "norm");

    
    vDSP_mmov(self->distanceMatrix, &self->globalDistanceMatrix[comparisonDataRowCount + 2], comparisonDataRowCount, inputRowCount, comparisonDataRowCount, comparisonDataRowCount + 1);


    Float32 nan = NAN;
    
    vDSP_vfill(&nan, &self->globalDistanceMatrix[1], 1, comparisonDataRowCount);
    vDSP_vfill(&nan, &self->globalDistanceMatrix[comparisonDataRowCount + 1], comparisonDataRowCount + 1, inputRowCount);
    
    Float32 comparisonArray[3] = {0};
    

    
    for (size_t i = 0; i < inputRowCount; ++i) {
        
        for (size_t j = 0; j < comparisonDataRowCount; ++j) {
            
            comparisonArray[0] = self->globalDistanceMatrix[i * (comparisonDataRowCount + 1) + j];
            comparisonArray[1] = self->globalDistanceMatrix[i * (comparisonDataRowCount + 1) + (j + 1)];
            comparisonArray[2] = self->globalDistanceMatrix[(i + 1) * (comparisonDataRowCount + 1) + j];
            
            
            Float32 dmax;
            size_t index;
            vDSP_minvi(comparisonArray, 1, &dmax, &index, 3);
            self->phi[(i * comparisonDataRowCount) + j] = index + 1;
            
            
            self->globalDistanceMatrix[(i + 1) * (comparisonDataRowCount + 1) + (j + 1)] = self->globalDistanceMatrix[(i + 1) * (comparisonDataRowCount + 1) + (j + 1)] + dmax;
            
        }
    }
    

    
    similarity = self->globalDistanceMatrix[(comparisonDataRowCount + 1) * (inputRowCount + 1) - 1];
        
    return similarity;
}