Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
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;
		unit->m_transformbuf = 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));

	unit->m_transformbuf = (float*)RTAlloc(unit->mWorld, scfft_trbufsize(unit->m_fullbufsize));
	unit->m_scfft        = (scfft*)RTAlloc(unit->mWorld, sizeof(scfft));
	scfft_create(unit->m_scfft, unit->m_fullbufsize, unit->m_audiosize, unit->m_wintype, unit->m_fftsndbuf->data, unit->m_fftsndbuf->data, unit->m_transformbuf, false);

	// "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);

}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
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);
}
//buffer preparation
void PreparePartConv(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)
{
	// 'channels' not used- should just be mono, num frames= num samples
	float *data1 = buf->data;
	uint32 frombufnum = msg->geti();
	int fftsize = msg->geti();

	//output size must be frombuf->frames*2
	if (frombufnum >= world->mNumSndBufs) frombufnum = 0;
	SndBuf* frombuf = world->mSndBufs + frombufnum;
	int frames2 = frombuf->frames;
	float *data2 = frombuf->data;

	//scfft
	int nover2= fftsize>>1;

	int numpartitions;
	if(frames2 % nover2 == 0){
		numpartitions= frames2/nover2;
	}else{
		numpartitions= (frames2/nover2)+1;
	}

	//printf("reality check numpartitions %d fftsize %d product %d numinputframes %d \n", numpartitions, fftsize, numpartitions*fftsize, frames2);

	float * inputbuf= (float*)RTAlloc(world, fftsize * sizeof(float));
	float * spectrum= (float*)RTAlloc(world, fftsize * sizeof(float));

	SCWorld_Allocator alloc(ft, world);
	scfft* m_scfft = scfft_create(fftsize, fftsize, kRectWindow, inputbuf, spectrum, kForward, alloc);

	memset(inputbuf, 0, sizeof(float)*fftsize); // for zero padding

	//run through input data buffer, taking nover2 chunks, zero padding each
	for (int i=0; i<numpartitions; ++i) {
		int indexnow= nover2*i;
		int indexout= fftsize*i;

		if(i<(numpartitions-1)){
			memcpy(inputbuf, data2+indexnow, nover2 * sizeof(float));
		}else{
			int takenow = frames2 % nover2;
			if(takenow == 0){
				takenow = nover2;
			}

			memcpy(inputbuf, data2+indexnow, takenow * sizeof(float));
			if(takenow<nover2){
				memset(inputbuf+takenow, 0, (nover2-takenow)*sizeof(float));
			}
		}
		scfft_dofft(m_scfft);
		memcpy(data1+indexout, spectrum, fftsize * sizeof(float));
	}
	//clean up
	RTFree(world, inputbuf);
	RTFree(world, spectrum);

	if(m_scfft) scfft_destroy(m_scfft, alloc);
}
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;
	}
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
g_fixeddelay *make_fixeddelay(GVerb *unit, int size, int maxsize){
    g_fixeddelay *p;
    p = (g_fixeddelay*)RTAlloc(unit->mWorld, sizeof(g_fixeddelay));
    p->size = size;
    p->idx = 0;
    p->buf = (float*)RTAlloc(unit->mWorld, maxsize * sizeof(float));
	Clear(maxsize, p->buf);
	return(p);
    }
Ejemplo n.º 10
0
void MedianSeparation_Ctor( MedianSeparation* unit ) {
	
    //fft, fftharmonic, fftpercussive, fftsize, mediansize=17, hardorsoft=0, p=1
    
    //IFFT needs to know what it is operating on
	OUT0(0) = ZIN0(1); //-1;
    OUT0(1) = ZIN0(2);
    
    unit->fftsize_ = ZIN0(3); //so can set things up in constructor, rather than later on
    unit->mediansize_ = ZIN0(4); //default 17, may cause trouble otherwise? 
    
    //printf("MedianSeparation starting %d %d \n",unit->fftsize_,unit->mediansize_); 
    
    if(unit->mediansize_<3)
        unit->mediansize_ = 17; 
    
    unit->midpoint_ = unit->mediansize_/2; 
    
    
    
    unit->fftbins_ = (unit->fftsize_/2) +1; //actually /2 + 1 but polar form has separate packed dc and nyquist 
    
    unit->magnitudeposition_= 0; 
    unit->phaseposition_= 0; 
    
    //separate storage
    unit->magnitudes_ = (float *) RTAlloc(unit->mWorld, sizeof(float)* unit->mediansize_ * unit->fftbins_);
    
    
    unit->phases_ = (float *) RTAlloc(unit->mWorld, sizeof(float)* (unit->midpoint_+1) * unit->fftbins_); //only store half data since only need phases for midpoint about to output; this necessitates holding midpoint+1 values (to include just arrived)
    
    //float * data_; //2D grid
    
    //zero out all magnitudes and phases 
    
    int i; 
    
    for (i=0; i<unit->mediansize_ * unit->fftbins_; ++i)
        unit->magnitudes_[i] = 0.0f; 
    
    for (i=0; i<(unit->midpoint_+1) * unit->fftbins_; ++i)
        unit->phases_[i] = 0.0f;
    
    
    unit->collection_ = (float *) RTAlloc(unit->mWorld, sizeof(float)* unit->mediansize_); //reusable array for sorting and finding median
    unit->horizontalmedians_ = (float *) RTAlloc(unit->mWorld, sizeof(float)* unit->fftbins_); 
    unit->verticalmedians_ = (float *) RTAlloc(unit->mWorld, sizeof(float)* unit->fftbins_);
    
    //need to go a step at a time over the vertical, horizontal sort and the eventual output (so takes four blocks to calculate, FFT must be at least 256)
    unit->amortisationstep_=0; 
    
	SETCALC(MedianSeparation_next);
	
    
    
}
Ejemplo n.º 11
0
g_diffuser *make_diffuser(GVerb *unit, int size, float coef){
    g_diffuser* p;
    p = (g_diffuser*)RTAlloc(unit->mWorld, sizeof(g_diffuser));
    p->size = size;
    p->coef = coef;
    p->idx = 0;
    p->buf = (float*)RTAlloc(unit->mWorld, size * sizeof(float));
    Clear(size, p->buf);
    return(p);
    }
Ejemplo n.º 12
0
	LTIv(Unit* unit,int sizeB,int sizeA):cbuf(unit,sizeB),cbufout(unit,sizeA){
		//Print("LTIv construct\n");
		// for(int i=0;i<sizeB-1;i++){
			// Print("KernelB %d %g\n",i,KernelB[i]);
		// }
		this->unit = unit;
		kernel_sizeB = sizeB;
		kernel_sizeA = sizeA;
		KernelB = (float *)RTAlloc(unit->mWorld,sizeof(float)*sizeB);
		KernelA = (float *)RTAlloc(unit->mWorld,sizeof(float)*sizeA);
	};
Ejemplo n.º 13
0
void AnnBasic_Ctor(AnnBasic* unit)
{
    unit->ann_i = -1;
    unit->inputs = 0;

    int ann_i = IN0( IN_ANN_NUM );
    unsigned int inc = sigInCount(unit);
    unsigned int outc = sigOutCount(unit);

    // init ANN input buffer

    fann_type* ann_ins = (fann_type*) RTAlloc( unit->mWorld, sizeof(fann_type) * inc);
    for(int i=0; i < inc; ++i) ann_ins[i] = 0.f;

    // set up the unit

    unit->ann_i = ann_i;
    unit->inputs = ann_ins;
    SETCALC( AnnBasic_next);

    // Calculate one sample of output

    AnnBasic_next( unit, 1 );
    //AnnBasic_idle( unit, 1 );
}
Ejemplo n.º 14
0
void differentiator(Filter *c) 
{
  c->x = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];//(float *)RTAlloc(gWorld,sizeof(float[2]));//
  c->y = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  memset(c->x,0,2*sizeof(float));
  memset(c->y,0,2*sizeof(float));
  
  c->a[0] = 1;
  c->a[1] = 0;
  c->b[0] = 1;
  c->b[1] = -1;
  
  c->n = 1;
}
Ejemplo n.º 15
0
g_damper *make_damper(GVerb *unit, float damping){
    g_damper* p;
    p = (g_damper*)RTAlloc(unit->mWorld, sizeof(g_damper));
    p->damping = damping;
    p->delay = 0.f;
    return(p);
    }
Ejemplo n.º 16
0
void init_delay(Delay *c, int di)
{
  // turn size into a mask for quick modding
  //c->size = 2*di;
  /*
  int p = 0;
  while(c->size) {
    c->size /= 2;
    p++;
  }
  c->size = 1;
  while(p) {
    c->size *= 2;
    p--;
  }
  c->mask = c->size - 1;
	*/
	c->size = NEXTPOWEROFTWO(2*di);
	c->mask = c->size - 1;
  c->x = (float *)RTAlloc(gWorld,sizeof(float) * c->size);//new float[c->size];
  //c->y = new float[c->size];
  memset(c->x,0,c->size*sizeof(float));
 // memset(c->y,0,c->size*sizeof(float));

  c->cursor = 0;
  c->di = di;
  c->d1 = (c->size-di)%c->size;
}
Ejemplo n.º 17
0
    void* operator new(size_t sz, Unit* unit) {
        //Print("TUBE new\n");
		void * ptr = NULL;
        ptr = RTAlloc(unit->mWorld,sz);

        return ptr;
	}
Ejemplo n.º 18
0
void cmdDemoFunc(World *inWorld, void* inUserData, struct sc_msg_iter *args, void *replyAddr)
{
	Print("->cmdDemoFunc %p\n", inUserData);

	// user data is the plug-in's user data.
	MyPluginData* thePlugInData = (MyPluginData*)inUserData;

	// allocate command data, free it in cmdCleanup.
	MyCmdData* myCmdData = (MyCmdData*)RTAlloc(inWorld, sizeof(MyCmdData));
	myCmdData->myPlugin = thePlugInData;

	// ..get data from args..
	myCmdData->x = 0.;
	myCmdData->y = 0.;
	myCmdData->name = 0;

	// float arguments
	myCmdData->x = args->getf();
	myCmdData->y = args->getf();

	// how to pass a string argument:
	const char *name = args->gets(); // get the string argument
	if (name) {
		myCmdData->name = (char*)RTAlloc(inWorld, strlen(name)+1); // allocate space, free it in cmdCleanup.
		strcpy(myCmdData->name, name); // copy the string
	}

	// how to pass a completion message
	int msgSize = args->getbsize();
	char* msgData = 0;
	if (msgSize) {
		// allocate space for completion message
		// scsynth will delete the completion message for you.
		msgData = (char*)RTAlloc(inWorld, msgSize);
		args->getb(msgData, msgSize); // copy completion message.
	}

	DoAsynchronousCommand(inWorld, replyAddr, "cmdDemoFunc", (void*)myCmdData,
						  (AsyncStageFn)cmdStage2,
						  (AsyncStageFn)cmdStage3,
						  (AsyncStageFn)cmdStage4,
						  cmdCleanup,
					   msgSize, msgData);

	Print("<-cmdDemoFunc\n");
}
Ejemplo n.º 19
0
void resonator(float f, float Fs, float tau, Filter *c) {
  c->x = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->y = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  memset(c->x,0,3*sizeof(float));
  memset(c->y,0,3*sizeof(float));

  float rp = exp(-1/(tau*Fs));
  float omega = 2*PI*f/Fs;
  c->a[0] = 1;
  c->a[1] = -2*rp*cos(omega);
  c->a[2] = rp*rp;
  c->b[0] = 0;
  c->b[1] = sin(omega);
  c->b[2] = 0;
  c->n = 2;
}
Ejemplo n.º 20
0
void loss(float f0, float fs, float c1, float c3, Filter *c)
{
  c->x = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->y = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  memset(c->x,0,2*sizeof(float));
  memset(c->y,0,2*sizeof(float));
  
  float g = 1.0 - c1/f0; 
  float b = 4.0*c3+f0;
  float a1 = (-b+sqrt(b*b-16.0*c3*c3))/(4.0*c3);
  c->b[0] = g*(1+a1);
  c->b[1] = 0;
  c->a[0] = 1;
  c->a[1] = a1;

  c->n = 1;
}
Ejemplo n.º 21
0
void FFT_Ctor(FFT *unit)
{
	unit->m_wintype = (int)ZIN0(3); // wintype may be used by the base ctor
	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_transformbuf = 0;
		unit->m_scfft = 0;
		return;
	}
	int fullbufsize = unit->m_fullbufsize * sizeof(float);
	int audiosize = unit->m_audiosize * sizeof(float);

	int hopsize = (int)(sc_max(sc_min(ZIN0(2), 1.f), 0.f) * unit->m_audiosize);
	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);

	unit->m_transformbuf = (float*)RTAlloc(unit->mWorld, scfft_trbufsize(unit->m_fullbufsize));
	unit->m_scfft        = (scfft*)RTAlloc(unit->mWorld, sizeof(scfft));
	scfft_create(unit->m_scfft, unit->m_fullbufsize, unit->m_audiosize, unit->m_wintype, unit->m_inbuf, unit->m_fftsndbuf->data, unit->m_transformbuf, true);

	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);
}
Ejemplo n.º 22
0
void Neuromodule_initInputs(Dneuromodule *unit, int size)
{
    int memsize = size * sizeof(double);
    int numWeights = size * size;


    unit->m_theta = (double*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_theta, 0, memsize);

    unit->m_x = (double*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_x, 0, memsize);

    unit->m_weights = (double*)RTAlloc(unit->mWorld, numWeights);
    memset(unit->m_weights, 0, numWeights);

    unit->m_x_temp = (double*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_x_temp, 0, memsize);


}
Ejemplo n.º 23
0
    void* operator new(size_t sz, Unit* unit) {
        //Print("KL_Junction new\n");
		void * ptr = NULL;
        ptr = RTAlloc(unit->mWorld,sz);
        /*
        if(ptr==NULL)
            Print("Null pointer\n");
        else
            Print("not Null pointer\n");*/
        return ptr;
	}
Ejemplo n.º 24
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 Dpoll_Ctor(Dpoll *unit)
{
	SETCALC(Dpoll_next);
	unit->m_id = IN0(3); // number of chars in the id string
	unit->m_id_string = (char*)RTAlloc(unit->mWorld, ((int)unit->m_id + 1) * sizeof(char));
	for(int i = 0; i < (int)unit->m_id; i++) {
		unit->m_id_string[i] = (char)IN0(4+i);
	}
	unit->m_id_string[(int)unit->m_id] = '\0';
	unit->m_mayprint = unit->mWorld->mVerbosity >= 0;
	OUT0(0) = 0.f;
}
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);
}
Ejemplo n.º 27
0
/*
void complex_divide(float Hn[2], float Hd[2], float H[2]) 
{
  float magn = sqrt(Hn[0]*Hn[0] + Hn[1]*Hn[1]);
  float argn = atan2(Hn[1],Hn[0]);
  float magd = sqrt(Hd[0]*Hd[0] + Hd[1]*Hd[1]);
  float argd = atan2(Hd[1],Hd[0]);
  float mag = magn/magd;
  float arg = argn - argd;
  H[0] = mag*cos(arg);
  H[1] = mag*sin(arg);
}
*/
float groupdelay(Filter *c, float f, float Fs) 
{
  float df = 5;
  float f2 = f + df;
  float f1 = f - df;
  float omega2 = 2*PI*f2/Fs;
  float omega1 = 2*PI*f1/Fs;
  return (omega2*phasedelay(c,f2,Fs) - omega1*phasedelay(c,f1,Fs))/(omega2-omega1);
}

float phasedelay(Filter *c, float f, float Fs) 
{
  float Hn[2];
  float Hd[2];
  float H[2];

  Hn[0] = 0.0; Hn[1] = 0.0;
  Hd[0] = 0.0; Hd[1] = 0.0;

  float omega = 2*PI*f/Fs;
  int N = c->n;
  for(int k=0;k<=N;k++) {
    Hn[0] += cos(k*omega)*c->b[k];
    Hn[1] += sin(k*omega)*c->b[k];
  }
  for(int k=0;k<=N;k++) {
    Hd[0] += cos(k*omega)*c->a[k];
    Hd[1] += sin(k*omega)*c->a[k];
  }
  complex_divide(Hn,Hd,H);
  float arg = atan2(H[1],H[0]);
  if(arg<0) arg = arg + 2*PI;
  
  return arg/omega;
}

void differentiator(Filter *c) 
{
  c->x = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];//(float *)RTAlloc(gWorld,sizeof(float[2]));//
  c->y = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  memset(c->x,0,2*sizeof(float));
  memset(c->y,0,2*sizeof(float));
  
  c->a[0] = 1;
  c->a[1] = 0;
  c->b[0] = 1;
  c->b[1] = -1;
  
  c->n = 1;
}


void resonator(float f, float Fs, float tau, Filter *c) {
  c->x = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->y = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  memset(c->x,0,3*sizeof(float));
  memset(c->y,0,3*sizeof(float));

  float rp = exp(-1/(tau*Fs));
  float omega = 2*PI*f/Fs;
  c->a[0] = 1;
  c->a[1] = -2*rp*cos(omega);
  c->a[2] = rp*rp;
  c->b[0] = 0;
  c->b[1] = sin(omega);
  c->b[2] = 0;
  c->n = 2;
}

void loss(float f0, float fs, float c1, float c3, Filter *c)
{
  c->x = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->y = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[2]));//new float[2];
  memset(c->x,0,2*sizeof(float));
  memset(c->y,0,2*sizeof(float));
  
  float g = 1.0 - c1/f0; 
  float b = 4.0*c3+f0;
  float a1 = (-b+sqrt(b*b-16.0*c3*c3))/(4.0*c3);
  c->b[0] = g*(1+a1);
  c->b[1] = 0;
  c->a[0] = 1;
  c->a[1] = a1;

  c->n = 1;
}
/*/
void biquad(float f0, float fs, float Q, int type, Filter *c)
{
  c->x = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->y = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->a = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  c->b = (float *)RTAlloc(gWorld,sizeof(float[3]));//new float[3];
  memset(c->x,0,3*sizeof(float));
  memset(c->y,0,3*sizeof(float));

  float a = 1/(2*tan(PI*f0/fs));
  float a2 = a*a;
  float aoQ = a/Q;
  float d = (4*a2+2*aoQ+1);

  c->a[0] = 1;
  c->a[1] = -(8*a2-2) / d;
  c->a[2] = (4*a2 - 2*aoQ + 1) / d;
  
  switch(type) {
  case pass:
    c->b[0] = 2*aoQ/d;
    c->b[1] = 0;
    c->b[2] = -2*aoQ/d;
    break;
  case low:
    c->b[0] = 1/d;
    c->b[1] = 2/d;
    c->b[2] = 1/d;
    break;
  case high: 
    c->b[0] = 4*a2/d;
    c->b[1] = -8*a2/d;
    c->b[2] = 4*a2/d;
    break;
  case notch:
    c->b[0] = (1+4*a2)/d;
    c->b[1] = (2-8*a2)/d;
    c->b[2] = (1+4*a2)/d;
    break;
  }

  c->n = 2;
}
*/
void thirian(float D, int N, Filter *c) 
{
  c->x =(float *)RTAlloc(gWorld, sizeof(float) * (N + 1));// new float[N+1];
  c->y = (float *)RTAlloc(gWorld, sizeof(float) * (N + 1));//new float[N+1];
  c->a = (float *)RTAlloc(gWorld, sizeof(float) * (N + 1));//new float[N+1];
  c->b = (float *)RTAlloc(gWorld, sizeof(float) * (N + 1));//new float[N+1];
  memset(c->x,0,(N+1)*sizeof(float));
  memset(c->y,0,(N+1)*sizeof(float));

  for(int k=0;k<=N;k++) {
    double ak = (float)choose((long)N,(long)k);
    if(k%2==1)
      ak = -ak;
    for(int n=0;n<=N;n++) {
      ak *= ((double)D-(double)(N-n));
      ak /= ((double)D-(double)(N-k-n));
    }
    c->a[k] = (float)ak;
    c->b[N-k] = (float)ak;
  }
  c->n = N;
}
Ejemplo n.º 28
0
void Dtag_initInputs(Dtag *unit, int argOffset, int size)
{

    unit->m_tape_size = (int32) IN0(dtag_tape_param);

    // make sure axiom isn't longer than the tape.
    if(unit->m_axiom_size > (int) unit->m_tape_size) {
        unit->m_axiom_size = (int) unit->m_tape_size;
    }

    // allocate tape
    int32 memtapesize = (int32) unit->m_tape_size * sizeof(int);
    unit->m_tape = (float*)RTAlloc(unit->mWorld, memtapesize);
    memset(unit->m_tape, 0, memtapesize);


    // allocate offsets and lengths
    int memsize = size * sizeof(int);

    unit->m_rule_lengths = (int*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_rule_lengths, 0, memsize);

    unit->m_rule_offsets = (int*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_rule_offsets, 0, memsize);


    for(int i=0; i < size; i++) {
        unit->m_rule_lengths[i] = (int) IN0(i + argOffset); // drop first n args
    }

    // calculate positions
    int position = argOffset + size;
    for(int i=0; i < size; i++) {
        unit->m_rule_offsets[i] = position;
        position += unit->m_rule_lengths[i];
        // printf("m_rule_offsets[%ld]: %ld\n", i, unit->m_rule_offsets[i]);
    }
}
Ejemplo n.º 29
0
void DbufTag_initInputs(DbufTag *unit, int argOffset, int size)
{
    int memsize = size * sizeof(int);

    unit->m_rule_lengths = (int*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_rule_lengths, 0, memsize);

    unit->m_rule_offsets = (int*)RTAlloc(unit->mWorld, memsize);
    memset(unit->m_rule_offsets, 0, memsize);


    for(int i=0; i < size; i++) {
        unit->m_rule_lengths[i] = (int) IN0(i + argOffset); // drop first n args
    }

    // calculate positions
    int position = argOffset + size;
    for(int i=0; i < size; i++) {
        unit->m_rule_offsets[i] = position;
        position += unit->m_rule_lengths[i];
        // printf("m_rule_offsets[%d]: %d\n", i, unit->m_rule_offsets[i]);
    }
}
Ejemplo n.º 30
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);
    }
}