// Ctor is called to initialize the unit generator.
// It only executes once.
void PhaseInIrm_Ctor(PhaseInIrm* unit)
{

    if (INRATE(0) == calc_FullRate) {
        SETCALC(PhaseInIrm_next_k);
    } else {
        SETCALC(PhaseInIrm_next_k);
    }

    unit->curstate = 0;
    unit->timeCallRest = 0;
    unit->timeInhibited = 0;
    unit->callTrig = 0;
    unit->changeState = true;
    unit->timeInhibitedBeforeCall = 0;
    unit->avgScore = 0;


    unit->restTime = IN0(_restPeriod);
    unit->lastRestPeriod = unit->restTime;

    for (int i = 0; i < NUMSCORES; i++) {
        unit->scores[i] = 1;
    };
    unit->scoreIndex = 0;

    unit->score = 1;

    PhaseInIrm_next_k(unit, 1);
}
Beispiel #2
0
void BBlockerBuf_Ctor(BBlockerBuf *unit)
{
	new(unit) BBlockerBuf();
	unit->bblocker.init_thread(0);

	unit->m_fbufnum = -1e9f;
	unit->m_phase = 1.f;
	unit->m_freqMul = unit->mRate->mSampleDur;
	unit->m_lastFreq = ZIN0(1);
	
	// TODO: set initial start adress

	// SETCALC(BBlockerBuf_next_a);
	if(INRATE(1) == calc_ScalarRate) { // freq is not a scalar
// printf("freq is SCALAR     : %d\n", INRATE(1));
		SETCALC(BBlockerBuf_next_i);
		BBlockerBuf_next_i(unit, 1);
	} else if (INRATE(1) == calc_FullRate) {
// printf("freq is FULLRATE   : %d\n", INRATE(1));
		SETCALC(BBlockerBuf_next_a);
		BBlockerBuf_next_a(unit, 1);
	} else {
// printf("freq is CONTROLRATE: %d\n", INRATE(1));
		SETCALC(BBlockerBuf_next_k);
		BBlockerBuf_next_k(unit, 1);
	}

//	OUT0(0) = 0.f;
}
void PlaneTree_Ctor(PlaneTree* unit)
{
    // Infer the size of the "inputs" array which has been tagged on to the end of the arguments list.
    int ndims = unit->mNumInputs - 2;

    //Print("PlaneTree_Ctor: ndims is %i\n", ndims);

    // Allocate a comfy bit of memory where we'll put the input data while we process it
    unit->m_inputdata   = (float*)RTAlloc(unit->mWorld, ndims * sizeof(float));
    unit->m_workingdata = (float*)RTAlloc(unit->mWorld, ndims * sizeof(float));
    // Try and ensure that the first ever input won't get accidentally skipped:
    unit->m_inputdata[0] = -1e9f;

    // Get the buffer reference, and check that the size and num channels matches what we expect.
    unit->m_fbufnum = -1e9f;
    GET_BUF

    if((int)bufChannels != (ndims * 2 + 2)) {
        Print("PlaneTree_Ctor: number of channels in buffer (%i) != number of input dimensions (%i) * 2 + 2\n",
              bufChannels, ndims);
        SETCALC(*ClearUnitOutputs);
        return;
    }

    // initialize the unit generator state variables.
    unit->m_ndims    = ndims;
    unit->m_result   = -1e9f; // hopefully this will get filled in soon by a classification...

    SETCALC(PlaneTree_next);
    PlaneTree_next(unit, 1);
}
void Demand_Ctor(Demand *unit)
{
	//Print("Demand_Ctor\n");
	if (INRATE(0) == calc_FullRate) {
		if (INRATE(1) == calc_FullRate) {
			SETCALC(Demand_next_aa);
		} else {
			SETCALC(Demand_next_ak);
		}
	} else {
		if (INRATE(1) == calc_FullRate) {
			SETCALC(Demand_next_ka);
		} else {
			SETCALC(Demand_next_aa);
		}
	}

	unit->m_prevout = (float*) RTAlloc(unit->mWorld, unit->mNumOutputs * sizeof(float));
	unit->m_out = (float**) RTAlloc(unit->mWorld, unit->mNumOutputs * sizeof(float*));

	//Print("Demand_Ctor calc %08X\n", unit->mCalcFunc);
	unit->m_prevtrig = 0.f;
	unit->m_prevreset = 0.f;
	for (int i=0; i<unit->mNumOutputs; ++i) {
		unit->m_prevout[i] = 0.f;
		OUT0(i) = 0.f;
	}
}
Beispiel #5
0
void In_Ctor(IOUnit* unit)
{
//Print("->In_Ctor\n");
	World *world = unit->mWorld;
	unit->m_fbusChannel = -1.;

	if (unit->mCalcRate == calc_FullRate) {
#ifdef NOVA_SIMD
		if (BUFLENGTH == 64)
			SETCALC(In_next_a_nova_64);
		else if (!(BUFLENGTH & 15))
			SETCALC(In_next_a_nova);
		else
#endif
		SETCALC(In_next_a);
		unit->m_bus = world->mAudioBus;
		unit->m_busTouched = world->mAudioBusTouched;
//#ifdef IPHONE_VEC
//		vIn_next_a(unit, 1);
//#else
		In_next_a(unit, 1);
//#endif
	} else {
		SETCALC(In_next_k);
		unit->m_bus = world->mControlBus;
		//unit->m_busTouched = world->mControlBusTouched;
		In_next_k(unit, 1);
	}
//Print("<-In_Ctor\n");
}
Beispiel #6
0
void IFFT_Ctor(IFFT* unit){
	unit->m_wintype = (int)ZIN0(1); // wintype may be used by the base ctor
	if(!FFTBase_Ctor(unit, 2)){
		SETCALC(*ClearUnitOutputs);
		// These zeroes are to prevent the dtor freeing things that don't exist:
		unit->m_olabuf = 0;
		return;
	}

	// This will hold the transformed and progressively overlap-added data ready for outputting.
	unit->m_olabuf = (float*)RTAlloc(unit->mWorld, unit->m_audiosize * sizeof(float));
	memset(unit->m_olabuf, 0, unit->m_audiosize * sizeof(float));

	SCWorld_Allocator alloc(ft, unit->mWorld);
	unit->m_scfft = scfft_create(unit->m_fullbufsize, unit->m_audiosize, (SCFFT_WindowFunction)unit->m_wintype, unit->m_fftsndbuf->data,
								 unit->m_fftsndbuf->data, kBackward, alloc);

	// "pos" will be reset to zero when each frame comes in. Until then, the following ensures silent output at first:
	unit->m_pos = 0; //unit->m_audiosize;

	if (unit->mCalcRate == calc_FullRate) {
		unit->m_numSamples = unit->mWorld->mFullRate.mBufLength;
	} else {
		unit->m_numSamples = 1;
	}

	SETCALC(IFFT_next);
}
void MedianTriggered_Ctor(MedianTriggered* unit)
{	
	if (INRATE(1) == calc_FullRate) {
		SETCALC(MedianTriggered_next_xa);
	}else{
		SETCALC(MedianTriggered_next_xk);
	}
	
	int length = (int)ZIN0(2); // Fixed number of items to average over

	unit->m_circbuf = (float*)RTAlloc(unit->mWorld, length * sizeof(float));
	unit->m_sortbuf = (float*)RTAlloc(unit->mWorld, length * sizeof(float));
	for(int i=0; i<length; i++){
		unit->m_circbuf[i] = 0.f;
	}
	unit->m_circbufpos = 0;
	unit->m_length = length;
	unit->m_outval = 0.f;
	unit->m_length_is_odd = (length % 2) == 1;
	// If odd, this number is the index to take. If even, we take this number and the one above.
	unit->m_medianpos = unit->m_length_is_odd ? ((length-1)/2) : (length/2 - 1);

	// prime the pumps
	MedianTriggered_next_xk(unit, 1);
}
void MatchingP_Ctor(MatchingP* unit)
{
	SETCALC(MatchingP_next);

	//  [trigger, residual, activ0, activ1,...] = MatchingP.ar(dict, in, dictsize, ntofind, hop=1, method=0)

	CTOR_GET_BUF

	// initialize the unit generator state variables.
	unit->m_dictsize = IN0(2);
	if(unit->m_dictsize != buf->channels){
		printf("ERROR: (unit->m_dictsize != bufChannels)\n");
		SETCALC(ClearUnitOutputs);
		return;
	}
	unit->m_hopspls  = static_cast<int>(sc_max(0.f, sc_min(1.f, IN0(4))) * buf->frames);
	unit->m_shuntspls = buf->frames - unit->m_hopspls;
	const int ntofind = (const int)IN0(3);
	// UNUSED: unit->mMethod = IN0(5);

	unit->m_audiowritepos    = unit->m_hopspls;
	unit->m_audioplaybackpos = 0;
	// audiobuf size is bufFrames + hopspls -- playback happens in first bufFrames, input is written in last hopspls, analysis is in last bufFrames
	unit->m_audiobuf    = (float* )RTAlloc(unit->mWorld, sizeof(float)  * (buf->frames + unit->m_hopspls));
	Clear(buf->frames + unit->m_hopspls, unit->m_audiobuf);
	// "activations" will contain [index0, activ0, index1, activ1, ... ]
	unit->m_activations = (float* )RTAlloc(unit->mWorld, sizeof(float)  * 2 * ntofind);

	// calculate one sample of output.
	unit->m_fbufnum = -9.9e9; // set it to something that will force the buffer info to be updated when _next runs
	MatchingP_next(unit, 1);
}
Beispiel #9
0
void Control_Ctor(Unit* unit)
{
	if (unit->mNumOutputs == 1) {
		SETCALC(Control_next_1);
		Control_next_1(unit, 1);
	} else {
		SETCALC(Control_next_k);
		Control_next_k(unit, 1);
	}
}
Beispiel #10
0
void TrigControl_Ctor(Unit* unit)
{
	//Print("TrigControl_Ctor\n");
	if (unit->mNumOutputs == 1) {
		SETCALC(TrigControl_next_1);
	} else {
		SETCALC(TrigControl_next_k);
	}
	ClearUnitOutputs(unit, 1);
}
Beispiel #11
0
void RedLbyl_Ctor(RedLbyl *unit) {
	if(unit->mCalcRate==calc_FullRate) {
		SETCALC(RedLbyl_next_a);
	} else {
		SETCALC(RedLbyl_next_k);
	}
	unit->m_prevout= ZIN0(0);
	unit->m_counter= 0;
	RedLbyl_next_k(unit, 1);
}
Beispiel #12
0
void Onsets_Ctor(Onsets *unit)
{
	if(ZIN0(8)>0)
		SETCALC(Onsets_next_rawodf);
	else
		SETCALC(Onsets_next);

	unit->m_needsinit = true;
	unit->m_ods = (OnsetsDS*) RTAlloc(unit->mWorld, sizeof(OnsetsDS) );

	ZOUT0(0) = unit->outval = 0.f;
}
void LFDClipNoise_Ctor(LFDClipNoise* unit)
{
	if (INRATE(0) == calc_FullRate) {
		SETCALC(LFDClipNoise_next);
	} else {
		SETCALC(LFDClipNoise_next_k);
	}

	unit->mPhase = 0.f;
	unit->mLevel = 0.f;

	LFDClipNoise_next(unit, 1);
}
Beispiel #14
0
void
RMS_Ctor (RMS *unit)
{
  unit->m_y1 = 0.f;
  if (INRATE(1) == calc_FullRate) {
	  SETCALC(RMS_next_a);
  } else {
	  unit->last_freq = ZIN0(1);
	  unit->last_lpf = 0;
	  unit->p = (1.f-2.f*tanf((unit->last_freq/SAMPLERATE)));
	  SETCALC(RMS_next);
  }
}
Beispiel #15
0
void AudioControl_Ctor(AudioControl* unit)
{
    unit->prevVal = (float*)RTAlloc(unit->mWorld, unit->mNumOutputs * sizeof(float));
    for(int i = 0; i < unit->mNumOutputs; i++){
	unit->prevVal[i] = 0.0;
    }
    if (unit->mNumOutputs == 1) {
	SETCALC(AudioControl_next_1);
	AudioControl_next_1(unit, 1);
    } else {
	SETCALC(AudioControl_next_k);
	AudioControl_next_k(unit, 1);
    }
}
void LFDNoise1_Ctor(LFDNoise1* unit)
{
	if (INRATE(0) == calc_FullRate) {
		SETCALC(LFDNoise1_next);
	} else {
		SETCALC(LFDNoise1_next_k);
	}

	unit->mPhase = 0.f;
	unit->mPrevLevel = 0.f;
	unit->mNextLevel = unit->mParent->mRGen->frand2();

	LFDNoise1_next(unit, 1);
}
Beispiel #17
0
void FFT_Ctor(FFT *unit)
{
	int winType = sc_clip((int)ZIN0(3), -1, 1); // wintype may be used by the base ctor
	unit->m_wintype = winType;
	if(!FFTBase_Ctor(unit, 5)){
		SETCALC(FFT_ClearUnitOutputs);
		// These zeroes are to prevent the dtor freeing things that don't exist:
		unit->m_inbuf = 0;
		unit->m_scfft = 0;
		return;
	}
	int audiosize = unit->m_audiosize * sizeof(float);

	int hopsize = (int)(sc_max(sc_min(ZIN0(2), 1.f), 0.f) * unit->m_audiosize);
	if (hopsize < unit->mWorld->mFullRate.mBufLength) {
		Print("FFT_Ctor: hopsize smaller than SC's block size (%i) - automatically corrected.\n", hopsize, unit->mWorld->mFullRate.mBufLength);
		hopsize = unit->mWorld->mFullRate.mBufLength;
	} else if (((int)(hopsize / unit->mWorld->mFullRate.mBufLength)) * unit->mWorld->mFullRate.mBufLength
				!= hopsize) {
		Print("FFT_Ctor: hopsize (%i) not an exact multiple of SC's block size (%i) - automatically corrected.\n", hopsize, unit->mWorld->mFullRate.mBufLength);
		hopsize = ((int)(hopsize / unit->mWorld->mFullRate.mBufLength)) * unit->mWorld->mFullRate.mBufLength;
	}
	unit->m_hopsize = hopsize;
	unit->m_shuntsize = unit->m_audiosize - hopsize;

	unit->m_inbuf = (float*)RTAlloc(unit->mWorld, audiosize);

	SCWorld_Allocator alloc(ft, unit->mWorld);
	unit->m_scfft = scfft_create(unit->m_fullbufsize, unit->m_audiosize, (SCFFT_WindowFunction)unit->m_wintype, unit->m_inbuf,
								 unit->m_fftsndbuf->data, kForward, alloc);

	if (!unit->m_scfft) {
		SETCALC(*ClearUnitOutputs);
		return;
	}

	memset(unit->m_inbuf, 0, audiosize);

	//Print("FFT_Ctor: hopsize %i, shuntsize %i, bufsize %i, wintype %i, \n",
	//	unit->m_hopsize, unit->m_shuntsize, unit->m_bufsize, unit->m_wintype);

	if (INRATE(1) == calc_FullRate) {
		unit->m_numSamples = unit->mWorld->mFullRate.mBufLength;
	} else {
		unit->m_numSamples = 1;
	}

	SETCALC(FFT_next);
}
Beispiel #18
0
void InTrig_Ctor(IOUnit* unit)
{
	World *world = unit->mWorld;
	unit->m_fbusChannel = -1.;

	if (unit->mCalcRate == calc_FullRate) {
		SETCALC(ClearUnitOutputs);
		ClearUnitOutputs(unit, 1);
	} else {
		SETCALC(InTrig_next_k);
		unit->m_bus = world->mControlBus;
		unit->m_busTouched = world->mControlBusTouched;
		InTrig_next_k(unit, 1);
	}
}
void PV_DecorTransExtract_Ctor(PV_DecorTransExtract *unit)
{
	// get input variables
	unit->retTrans = IN0(1);
	unit->iVal = IN0(2);
	unit->jVal = IN0(3);
	unit->alphaVal = IN0(4);
	unit->betaVal = IN0(5);
	unit->dVal = IN0(6);
	unit->lowFreqCutVal = IN0(7);

	// set other variables
	unit->numFreqBins = 0;
	unit->prevBinsIdx = 0;
	unit->littleOmegaIdx = 0;
	unit->bigOmegaIdx = 0;
	unit->initDebugFlag = true;
	unit->initFirstCalc = true;

	// set output
	ZOUT0(0) = ZIN0(0);

	// set calculation function (next)
	SETCALC(PV_DecorTransExtract_next);
}
Beispiel #20
0
void CheckBadValues_Ctor(CheckBadValues* unit)
{
	unit->prevclass = FP_NORMAL;
	unit->sameCount = 0;
	SETCALC(CheckBadValues_next);
	CheckBadValues_next(unit, 1);
}
Beispiel #21
0
void KeyState_Ctor(KeyState *unit)
{
	SETCALC(KeyState_next);
	unit->m_b1 = 0.f;
	unit->m_lag = 0.f;
	KeyState_next(unit, 1);
}
Beispiel #22
0
void MouseButton_Ctor(MouseInputUGen *unit)
{
	SETCALC(MouseButton_next);
	unit->m_b1 = 0.f;
	unit->m_lag = 0.f;
	MouseButton_next(unit, 1);
}
Beispiel #23
0
void SOMTrain_Ctor(SOMTrain* unit)
{
	// set the calculation function. do this before the base ctor because it may want to change it!
	SETCALC(SOMTrain_next);

	SOM_Ctor_base(unit, 7); // 7 is the offset before we get input data

	int traindur = (int)ZIN0(3);
	int traincountdown = traindur; // Decrement by one on each occasion

	double nhood = ZIN0(4) * (unit->m_netsize) * 0.5; // Neighbourhood size (fraction of total, here converted to span of nodes) to be included in a training update. Will decrement slowly.
	// The reason we halve it is for convenience: we look nhood/2 in positive direction, nhood/2 in negative direction.
	double nhooddelta = nhood / traindur; // This is how much it decrements by, each occasion.

	float weightfactor = ZIN0(6); // Scaling factor for how much the node "bends" towards the datum
	float mfactor = traindur * 0.25f; // Empirical scaling - weight falls to half of its value after 0.25 of the training

	// initialize the unit generator state variables.
	unit->m_traindur   = traindur;
	unit->m_traincountdown = traincountdown;
	unit->m_traincountup   = 0;
	unit->m_nhood      = nhood;
	unit->m_nhooddelta = nhooddelta;
	unit->m_weightfactor   = weightfactor;
	unit->m_mfactor   = mfactor;
	unit->m_writeloc  = 0.f;

	// calculate one sample of output.
	ZOUT0(0) = 0.f;
	ZOUT0(1) = 0.f;
}
Beispiel #24
0
void LoopBuf_Ctor(LoopBuf *unit)
{
// input 1 => rate
// input 2 => gate
//	if (INRATE(1) == calc_FullRate) {
//		if (INRATE(2) == calc_FullRate) {
//			SETCALC(LoopBuf_next_aa);
//		} else {
//			SETCALC(LoopBuf_next_ak);
//		}
//	} else {
//		if (INRATE(2) == calc_FullRate) {
//			SETCALC(LoopBuf_next_ka);
//		} else {
			SETCALC(LoopBuf_next_kk);
//		}
//	}

	unit->m_fbufnum = -1e9f;
	unit->m_prevgate = 0.;
	unit->m_phase = ZIN0(3);
	unit->m_playThrough = false;

	ClearUnitOutputs(unit, 1);
}
Beispiel #25
0
void FFTSubbandPower_Ctor(FFTSubbandPower *unit)
{
	SETCALC(FFTSubbandPower_next);
	ZOUT0(0) = unit->outval = 0.;

	unit->m_square = ZIN0(2) > 0.f;
	unit->m_normfactor = 0.f;

	// ZIN0(1) tells us how many cutoffs we're looking for
	int numcutoffs = (int)ZIN0(1);
	int numbands = numcutoffs+1;

	unit->m_scalemode = (int)ZIN0(3);

	float * outvals = (float*)RTAlloc(unit->mWorld, numbands * sizeof(float));
	for(int i=0; i<numbands; i++) {
		outvals[i] = 0.f;
	}
	unit->m_outvals = outvals;

	unit->m_cutoffs = (int*)RTAlloc(unit->mWorld, numcutoffs * sizeof(int));
	unit->m_cutoff_inited = false;

	unit->m_numbands = numbands;
}
Beispiel #26
0
void MIDIUIUgen_Ctor(MIDIUIUgen* unit)
{
	if(!initiated)
	{
		unsigned int midi_device = 0;
		char name[64];
		device_count = Midi::deviceCount();
		Print("Number of MIDI Input devices: %d\n", Midi::deviceCount());
		if( Midi::deviceCount()==0)
			return;
		
		for (int i = 0; i < device_count; i++)
		{
			Midi::deviceName(i, name);
			Print("%d: Device Name: %s\n",i, name);
			midi[i] = new Midi(i);
			midi[i]->threadBegin();
		}
		initiated=true;
	}
    SETCALC(MIDIUIUgen_next);
	unit->m_b1 = 0.f;
	unit->m_lag = 0.f;
	MIDIUIUgen_next(unit, 1);
}
Beispiel #27
0
void NearestN_Ctor(NearestN* unit) {
    // Infer the size of the "inputs" array which has been tagged on to the end of the arguments list.
    int ndims = unit->mNumInputs - 3;

    int num   = ZIN0(2);

    // Allocate a comfy bit of memory where we'll put the input data while we process it
    unit->m_inputdata   = (float*)RTAlloc(unit->mWorld, ndims * sizeof(float));
    unit->m_bestlist = (float*)RTAlloc(unit->mWorld, num * 3 * sizeof(float));
    Clear(num * 3, unit->m_bestlist);
    // Try and ensure that the first ever input won't get accidentally skipped:
    unit->m_inputdata[0] = -1e9f;

    // Get the buffer reference, and check that the size and num channels matches what we expect.
    unit->m_fbufnum = -1e9f;
    {
        GET_BUF

        // initialize the unit generator state variables.
        unit->m_ndims     = ndims;
        unit->m_num       = num;

        SETCALC(NearestN_next);
    }
    NearestN_next(unit, 1);
}
void Convolution_Ctor(Convolution *unit)
{
	//require size N+M-1 to be a power of two
	unit->m_insize=(int)ZIN0(2);

	//         printf("hello %i /n", unit->m_insize);
	unit->m_fftsize=2*(unit->m_insize);
	//just use memory for the input buffers and fft buffers
	int insize = unit->m_insize * sizeof(float);
	int fftsize = unit->m_fftsize * sizeof(float);

	unit->m_inbuf1 = (float*)RTAlloc(unit->mWorld, insize);
	unit->m_inbuf2 = (float*)RTAlloc(unit->mWorld, insize);
	unit->m_fftbuf1 = (float*)RTAlloc(unit->mWorld, fftsize);
	unit->m_fftbuf2 = (float*)RTAlloc(unit->mWorld, fftsize);

	unit->m_outbuf = (float*)RTAlloc(unit->mWorld, fftsize);
	unit->m_overlapbuf = (float*)RTAlloc(unit->mWorld, insize);

	memset(unit->m_outbuf, 0, fftsize);
	memset(unit->m_overlapbuf, 0, insize);

	//unit->m_log2n = LOG2CEIL(unit->m_fftsize);

	unit->m_pos = 0;

	SCWorld_Allocator alloc(ft, unit->mWorld);
	unit->m_scfft1 = scfft_create(unit->m_fftsize, unit->m_fftsize, kRectWindow, unit->m_fftbuf1, unit->m_fftbuf1, kForward, alloc);
	unit->m_scfft2 = scfft_create(unit->m_fftsize, unit->m_fftsize, kRectWindow, unit->m_fftbuf2, unit->m_fftbuf2, kForward, alloc);
	unit->m_scfftR = scfft_create(unit->m_fftsize, unit->m_fftsize, kRectWindow, unit->m_fftbuf1, unit->m_outbuf, kBackward, alloc);

	SETCALC(Convolution_next);
}
//include local buffer test in one place
static SndBuf * ConvGetBuffer(Unit * unit, uint32 bufnum, const char * ugenName, int inNumSamples)
{
	SndBuf *buf;
	World *world = unit->mWorld;

	if (bufnum >= world->mNumSndBufs) {
		int localBufNum = bufnum - world->mNumSndBufs;
		Graph *parent = unit->mParent;
		if (localBufNum <= parent->localMaxBufNum) {
			buf = parent->mLocalSndBufs + localBufNum;
		} else {
			if (unit->mWorld->mVerbosity > -1)
				Print("%s: invalid buffer number (%d).\n", ugenName, bufnum);
			goto handle_failure;
		}
	} else {
		buf = world->mSndBufs + bufnum;
	}

	if (buf->data == NULL) {
		if (unit->mWorld->mVerbosity > -1)
			Print("%s: uninitialized buffer (%i).\n", ugenName, bufnum);
		goto handle_failure;
	}

	return buf;

handle_failure:
	SETCALC(*ClearUnitOutputs);
	ClearUnitOutputs(unit, inNumSamples);
	unit->mDone = true;
	return NULL;
}
Beispiel #30
0
void TextVU_Ctor(TextVU* unit)
{
	SETCALC(TextVU_next_kk);

	unit->m_trig = IN0(0);
	unit->m_id = IN0(4); // number of chars in the id string
	unit->m_id_string = (char*)RTAlloc(unit->mWorld, ((int)unit->m_id + 1) * sizeof(char));
	Print("TextVU: string length %g\n", unit->m_id);
	for(int i = 0; i < (int)unit->m_id; i++){
		unit->m_id_string[i] = (char)IN0(5+i);
	};
	unit->m_id_string[(int)unit->m_id] = '\0';

	size_t width = (size_t)std::max(IN0(2), 2.f);
	unit->m_width = width;
	// Now we want to initialise the set of cutoffs, where the first is -60dB and last is 0dB.
	unit->m_cutoffs = (float*)RTAlloc(unit->mWorld, width * sizeof(float));
	unit->m_vustring  = (char*)RTAlloc(unit->mWorld, (width+1) * sizeof(char));
	unit->m_vustring[width] = 0;
	float cutstep = 60.f / (float)(width-1);
	float db = -60.f;
	for(size_t i=0; i<width; ++i){
		// calc cutoffs in amplitude from the db vals
		unit->m_cutoffs[i] = sc_dbamp(db);
		//Print("cutoff %i: %g\n", i, unit->m_cutoffs[i]);
		db += cutstep;
	}
	unit->m_maxinepoch = 0.f;
	unit->m_maxever = 0;

	unit->m_mayprint = unit->mWorld->mVerbosity >= 0;

	TextVU_next_kk(unit, 1);
}