コード例 #1
0
IOReturn IOAudioEngine::mixOutputSamples(const void *sourceBuf, void *mixBuf, UInt32 firstSampleFrame, UInt32 numSampleFrames, const IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream)
{
    IOReturn result = kIOReturnBadArgument;

    if (sourceBuf && mixBuf)
    {
        const float * floatSource1Buf;
        const float * floatSource2Buf;
        float * floatMixBuf;

        UInt32 numSamplesLeft = numSampleFrames * streamFormat->fNumChannels;

        __darwin_size_t numSamps = numSamplesLeft;

        floatMixBuf = &(((float *)mixBuf)[firstSampleFrame * streamFormat->fNumChannels]);
        floatSource2Buf = floatMixBuf;
        floatSource1Buf = (const float *)sourceBuf;

        __darwin_ptrdiff_t strideOne=1, strideTwo=1, resultStride=1;

        vDSP_vadd(floatSource1Buf, strideOne, floatSource2Buf, strideTwo, floatMixBuf, resultStride, numSamps);

        result = kIOReturnSuccess;
    }

    return result;
}
コード例 #2
0
ファイル: Dsp.c プロジェクト: eriser/FxDSP
/*******************************************************************************
 VectorVectorAdd */
Error_t
VectorVectorAdd(float         *dest,
                const float   *in1,
                const float   *in2,
                unsigned      length)
{
#ifdef __APPLE__
    // Use the Accelerate framework if we have it
    vDSP_vadd(in1, 1, in2, 1, dest, 1, length);
    
#else
    // Otherwise do it manually
    unsigned i;
    const unsigned end = 4 * (length / 4);
    for (i = 0; i < end; i+=4)
    {
        dest[i] = in1[i] + in2[i];
        dest[i + 1] = in1[i + 1] + in2[i + 1];
        dest[i + 2] = in1[i + 2] + in2[i + 2];
        dest[i + 3] = in1[i + 3] + in2[i + 3];
    }
    for (i = end; i < length; ++i)
    {
        dest[i] = in1[i] + in2[i];
    }
    
#endif
    return NOERR;
}
コード例 #3
0
ファイル: CMFFT.c プロジェクト: redpola/cocoamodem
void CMPerformFFT( CMFFT *fft, float *input, float *output )
{
	int i, n, nby2 ;
	
	n = fft->size ;
	nby2 = n/2 ;

	switch ( fft->style ) {
	case PowerSpectrum:
		vDSP_ctoz( ( COMPLEX* )input, 2, &fft->z, 1, nby2 ) ; 
		if ( fft->window ) {
			for ( i = 0; i < nby2; i++ ) {
				fft->z.realp[i] *= fft->window[i] ;
				fft->z.imagp[i] *= fft->window[i] ;
			}
		}
		vDSP_fft_zript( fft->vfft, &fft->z, 1, &fft->tempBuf, fft->log2n, FFT_FORWARD ) ;
		vDSP_vsq( fft->z.realp, 1, fft->z.realp, 1, nby2 ) ;
		vDSP_vsq( fft->z.imagp, 1, fft->z.imagp, 1, nby2 ) ;
		vDSP_vadd( fft->z.realp, 1, fft->z.imagp, 1,  &output[0], 1, nby2 ) ;
		break ;
	default:
		break ;
	}
}
コード例 #4
0
ファイル: DspUtilities.cpp プロジェクト: eriser/dm-dsp
void dm_vvadd(const float* input_, float* input2_, float* result_, unsigned long size_) {
#ifdef DSP_USE_ACCELERATE
  vDSP_vadd(input_, 1, input2_, 1, result_, 1, size_);
#else // generic
  std::transform(input_, input_ + size_, input2_, result_, std::plus<float>());
#endif

}
コード例 #5
0
ファイル: siglab_glue.cpp プロジェクト: Eskatrem/LispPlotter
void siglab_cbPwr(float *src, float *dst, int nfft)
{
  // requires dst to be nel/2+1 element or more
  // src is in separated Re and Im arrays, A(Im) = A(Re) + NFFT/2
  vDSP_vsq(src,1,dst,1,nfft);
  int nfft2 = nfft/2;
  vDSP_vadd(dst+1,1,dst+nfft2+1,1,dst+1,1,nfft2-1);
}
コード例 #6
0
ファイル: FFT_UGens.cpp プロジェクト: scztt/sc-debug
void IFFT_next(IFFT *unit, int wrongNumSamples){

	float *out = OUT(0); // NB not ZOUT0

	// Load state from struct into local scope
	int pos     = unit->m_pos;
	int fullbufsize  = unit->m_fullbufsize;
	int audiosize = unit->m_audiosize;
// 	int numSamples = unit->mWorld->mFullRate.mBufLength;
	int numSamples = unit->m_numSamples;
	float *olabuf = unit->m_olabuf;
	float fbufnum = ZIN0(0);

	// Only run the IFFT if we're receiving a new block of input data - otherwise just output data already received
	if (fbufnum >= 0.f){

		// Ensure it's in cartesian format, not polar
		ToComplexApx(unit->m_fftsndbuf);

		float* fftbuf = unit->m_fftsndbuf->data;

		scfft_doifft(unit->m_scfft);

		// Then shunt the "old" time-domain output down by one hop
		int hopsamps = pos;
		int shuntsamps = audiosize - hopsamps;
		if(hopsamps != audiosize){  // There's only copying to be done if the position isn't all the way to the end of the buffer
			memcpy(olabuf, olabuf+hopsamps, shuntsamps * sizeof(float));
		}

		// Then mix the "new" time-domain data in - adding at first, then just setting (copying) where the "old" is supposed to be zero.
		#if SC_DARWIN
			vDSP_vadd(olabuf, 1, fftbuf, 1, olabuf, 1, shuntsamps);
		#else
			// NB we re-use the "pos" variable temporarily here for write rather than read
			for(pos = 0; pos < shuntsamps; ++pos){
				olabuf[pos] += fftbuf[pos];
			}
		#endif
		memcpy(olabuf + shuntsamps, fftbuf + shuntsamps, (hopsamps) * sizeof(float));

		// Move the pointer back to zero, which is where playback will next begin
		pos = 0;

	} // End of has-the-chain-fired

	// Now we can output some stuff, as long as there is still data waiting to be output.
	// If there is NOT data waiting to be output, we output zero. (Either irregular/negative-overlap
	//     FFT firing, or FFT has given up, or at very start of execution.)
	if(pos >= audiosize){
		ClearUnitOutputs(unit, numSamples);
	}else{
		memcpy(out, olabuf + pos, numSamples * sizeof(float));
		pos += numSamples;
	}
	unit->m_pos = pos;

}
コード例 #7
0
BEGIN_UGEN_NAMESPACE

#include "../basics/ugen_BinaryOpUGens.h"


void BinaryAddUGenInternal::processBlock(bool& shouldDelete, const unsigned int blockID, const int channel) throw() 
{ 
	const int numSamplesToProcess = uGenOutput.getBlockSize(); 
	float* const outputSamples = uGenOutput.getSampleData(); 
	const float* const leftOperandSamples = inputs[LeftOperand].processBlock(shouldDelete, blockID, channel); 
	const float* const rightOperandSamples = inputs[RightOperand].processBlock(shouldDelete, blockID, channel); 
	vDSP_vadd(leftOperandSamples, 1, rightOperandSamples, 1, outputSamples, 1, numSamplesToProcess);
}
コード例 #8
0
ファイル: Dsp.cpp プロジェクト: Ahbee/Cinder
void add( const float *arrayA, const float *arrayB, float *result, size_t length )
{
	vDSP_vadd( arrayA, 1, arrayB, 1, result, 1, length );
}
コード例 #9
0
ファイル: TriangleFilterBank.c プロジェクト: eddyc/DSPTools
TriangleFilterBank32 *TriangleFilterBank32_new(size_t filterCount, size_t magnitudeFrameSize, size_t samplerate)
{
    TriangleFilterBank32 *self = calloc(1, sizeof(TriangleFilterBank32));
    self->filterCount = filterCount;
    self->filterFrequencyCount = filterCount + 2;
    self->magnitudeFrameSize = magnitudeFrameSize;
    self->samplerate = samplerate;
    self->filterFrequencies = calloc(self->filterFrequencyCount, sizeof(Float32));
    self->filterBank = calloc(self->magnitudeFrameSize * self->filterCount, sizeof(Float32));
    Float32 *filterTemp = calloc(self->magnitudeFrameSize * self->filterCount, sizeof(Float32));

    Float32 one = 2;
    Float32 zero = 0;
    
    vDSP_vgen(&zero, &one, self->filterFrequencies, 1, self->filterFrequencyCount);

    for (size_t i = 0; i < self->filterFrequencyCount; ++i) {
        
        self->filterFrequencies[i] = powf(10, self->filterFrequencies[i]);

    }
    
    Float32 minusFirstElement = -self->filterFrequencies[0];
    vDSP_vsadd(self->filterFrequencies, 1, &minusFirstElement, self->filterFrequencies, 1, self->filterFrequencyCount);
    Float32 maximum = self->filterFrequencies[self->filterFrequencyCount - 1];

    vDSP_vsdiv(self->filterFrequencies, 1, &maximum, self->filterFrequencies, 1, self->filterFrequencyCount);
    
    Float32 nyquist = self->samplerate / 2;
    
    vDSP_vsmul(self->filterFrequencies, 1, &nyquist, self->filterFrequencies, 1, self->filterFrequencyCount);
    
    Float32 *magnitudeFrequencies = calloc(self->magnitudeFrameSize, sizeof(Float32));

    vDSP_vgen(&zero, &nyquist, magnitudeFrequencies, 1, self->magnitudeFrameSize);
    
    Float32 *lower = calloc(self->filterCount, sizeof(Float32));
    Float32 *center = calloc(self->filterCount, sizeof(Float32));
    Float32 *upper = calloc(self->filterCount, sizeof(Float32));
    
    Float32 *temp1 = (Float32 *)calloc(self->magnitudeFrameSize, sizeof(Float32));
    Float32 *temp2 = (Float32 *)calloc(self->magnitudeFrameSize, sizeof(Float32));
    

    cblas_scopy((SInt32)self->filterCount, &self->filterFrequencies[0], 1, lower, 1);
    cblas_scopy((SInt32)self->filterCount, &self->filterFrequencies[1], 1, center, 1);
    cblas_scopy((SInt32)self->filterCount, &self->filterFrequencies[2], 1, upper, 1);

   
    for (size_t i = 0; i < self->filterCount; ++i) {
        
        Float32 negateLowerValue = -lower[i];
        vDSP_vsadd(magnitudeFrequencies, 1, &negateLowerValue, temp1, 1, self->magnitudeFrameSize);
        Float32 divider = center[i] - lower[i];
        vDSP_vsdiv(temp1, 1, &divider, temp1, 1, self->magnitudeFrameSize);
        
        for (size_t j = 0; j < self->magnitudeFrameSize; ++j) {
            
            if (!(magnitudeFrequencies[j] > lower[i] && magnitudeFrequencies[j] <= center[i])) {
                
                temp1[j] = 0;
            }
        }
        
        Float32 minusOne = -1;
        vDSP_vsmul(magnitudeFrequencies, 1, &minusOne, temp2, 1, self->magnitudeFrameSize);
        vDSP_vsadd(temp2, 1, &upper[i], temp2, 1, self->magnitudeFrameSize);
        divider = upper[i] - center[i];
        vDSP_vsdiv(temp2, 1, &divider, temp2, 1, self->magnitudeFrameSize);
        
        for (size_t j = 0; j < self->magnitudeFrameSize; ++j) {
            
            if (!(magnitudeFrequencies[j] > center[i] && magnitudeFrequencies[j] <= upper[i])) {
                
                temp2[j] = 0;
            }
        }
        
        vDSP_vadd(temp1, 1, temp2, 1, &filterTemp[i * self->magnitudeFrameSize], 1, self->magnitudeFrameSize);
    }
    
    vDSP_mtrans(filterTemp, 1, self->filterBank, 1, self->magnitudeFrameSize, self->filterCount);
    
    free(lower);
    free(center);
    free(upper);
    free(temp1);
    free(temp2);
    free(magnitudeFrequencies);
    free(filterTemp);
    
    return self;
}
コード例 #10
0
 // apple bug
static void Workaround_vsub(const float *a, int aStride, const float *b, int bStride, float *c, int cStride, int size )
{
    const float minusOne = -1.0f;
    vDSP_vsmul(a, aStride, &minusOne, c, cStride, size);
    vDSP_vadd( c, cStride, b, bStride, c, cStride, size );	
}