Ejemplo n.º 1
0
void PauseUGenInternal::processBlock(bool& shouldDelete, const unsigned int blockID, const int channel) throw()
{
	int numSamplesToProcess = uGenOutput.getBlockSize();
	float* outputSamples = uGenOutput.getSampleData();
	
	float currentLevel = *(inputs[Level].processBlock(shouldDelete, blockID, channel));
	
	if(currentLevel == 0.f && prevLevel == 0.f)
	{
#ifdef UGEN_VDSP
		vDSP_vclr(outputSamples, 1, numSamplesToProcess);
#else
		memset(outputSamples, 0, numSamplesToProcess * sizeof(float));
#endif
	}
	else
	{
		float* inputSamples = inputs[Input].processBlock(shouldDelete, blockID, channel);
		
		if(currentLevel != prevLevel)
		{
			float inc = (currentLevel - prevLevel) / (float)numSamplesToProcess;
			float level = prevLevel;
			while(numSamplesToProcess--)
			{
				*outputSamples++ = *inputSamples++ * level;
				level += inc;
			}
		}
		else
		{
#ifdef UGEN_VDSP
			float zero = 0.f;
			vDSP_vsmsa(inputSamples, 1, &currentLevel, &zero, outputSamples, 1, numSamplesToProcess);
#else
			while(numSamplesToProcess--)
			{
				*outputSamples++ = *inputSamples++ * currentLevel;
			}
#endif
		}
	}
	
	prevLevel = currentLevel;
}
Ejemplo n.º 2
0
void WaveformForBuffer(Float32 * begin, size_t length, float w, float h, ofPolyline &outLine, unsigned rate) {
	const size_t size = length / rate;
	
	if(size == 0) {
		outLine.clear();
		return;
	}
	
	if(outLine.size() != size) {
		outLine.resize(size);
	}
	
	float * v = (float *)&outLine[0];
	float zero = 0;
	float half = h / 2.;
	vDSP_vsmsa(begin, rate, &half, &half, v + 1, 3, size); // multiply and add "y"s
	vDSP_vgen(&zero, &w, v, 3, size); // generate "x"s
}
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
}