コード例 #1
0
ファイル: synthe.c プロジェクト: Mag-Stellon/puredata
/* Initialize synthe on PureData 
   @param (autonorm value)? (bypass value)?
 */
void *synthe_new(int argc, t_atom *argv){

  t_synthe *m = (t_synthe *)pd_new(synthe_class);

  m->window = malloc(VECTOR_SIZE * (sizeof * m->window));
  m->bitshuffle = malloc(VECTOR_SIZE * 2 * (sizeof * m->bitshuffle));
  m->weighting = malloc(VECTOR_SIZE * 2 * (sizeof * m->weighting));
  init_with_blackman(m->window);
  init_rdft(VECTOR_SIZE, m->bitshuffle, m->weighting);

  switch (argc) {
  case 1 :
    m->autonorm = atom_getint(argv);
    m->bypass = 1;
    m->shapeWidth = 0.5;
  case 2 :
    m->bypass = atom_getint(argv + (1 * sizeof(t_atom)));
    m->autonorm = 1;
    m->shapeWidth = 0.5;
  default :
    m->autonorm = 1;
    m->bypass = 1;
    m->shapeWidth = 0.5;
  }
  m->modulatrice = inlet_new(&m->x_obj, &m->x_obj.ob_pd,&s_signal, &s_signal);
  floatinlet_new(&m->x_obj, &m->shapeWidth);
  m->messages = inlet_new(&m->x_obj,&m->x_obj.ob_pd,gensym("list"),gensym("messages"));
  m->x_out = outlet_new(&m->x_obj, &s_signal);

  	
  return (void*)m;
}
コード例 #2
0
ファイル: shapee~.c プロジェクト: pd-projects/fftease
void shapee_init(t_shapee *x, short initialized)
{
  int i;
  x->D = x->vs;
  x->N = x->vs * x->overlap;
  x->Nw = x->N * x->winfac;
  limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->inCount = -(x->Nw);
  x->mult = 1. / (float) x->N;
  
	if(!initialized){
	  x->mute = 0;

	  x->Wanal = (float *) getbytes( MAX_Nw * sizeof(float) );	
	  x->Wsyn = (float *) getbytes( MAX_Nw * sizeof(float) );	
	  x->Hwin = (float *) getbytes( MAX_Nw * sizeof(float) ); 
	  x->inputOne = (float *) getbytes( MAX_Nw * sizeof(float) );
	  x->inputTwo = (float *) getbytes( MAX_Nw * sizeof(float) );	
	  x->bufferOne = (float *) getbytes( MAX_N  * sizeof(float) );
	  x->bufferTwo = (float *) getbytes( MAX_N  * sizeof(float) ); 
	  x->channelOne = (float *) getbytes(  (MAX_N+2) * sizeof(float) );
	  x->channelTwo = (float *) getbytes(  (MAX_N+2) * sizeof(float) );
	  x->output = (float *) getbytes( MAX_Nw * sizeof(float) );
	  x->bitshuffle = (int *) getbytes( MAX_N * 2 * sizeof( int ) );
	  x->trigland = (float *) getbytes( MAX_N * 2 * sizeof( float ) );
	}
	memset((char *)x->inputOne,0,x->Nw * sizeof(float));
	memset((char *)x->inputTwo,0,x->Nw * sizeof(float));
	memset((char *)x->output,0,x->Nw * sizeof(float));

  init_rdft(x->N, x->bitshuffle, x->trigland);
  makehanning(x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 1);// wants an ODD window
}
コード例 #3
0
ファイル: leaker~.c プロジェクト: Angeldude/pd
void leaker_init(t_leaker *x, short initialized)
{
	int i;
	if(!power_of_two(x->overlap))
		x->overlap = 4;
	if(!power_of_two(x->winfac))
		x->winfac = 2;
	x->N = x->D * x->overlap;
	x->Nw = x->N * x->winfac;
	limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
	x->N2 = (x->N)>>1;
	x->Nw2 = (x->Nw)>>1;
	x->inCount = -(x->Nw);
	x->mult = 1. / (float) x->N;
	x->c_fundamental =  (float) x->R/( (x->N2)<<1 );
	x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
	x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
	
	if(!initialized) {
		x->mute = 0;
		x->bypass = 0;
		x->fade_connected = 0;
		x->fade_value = 0;
		
		x->input1 = (float *) getbytes(MAX_Nw * sizeof(float));	
		x->buffer1 = (float *) getbytes(MAX_N * sizeof(float));
		x->channel1 = (float *) getbytes((MAX_N+2) * sizeof(float));
		x->input2 = (float *) getbytes(MAX_Nw * sizeof(float));	
		x->buffer2 = (float *) getbytes(MAX_N * sizeof(float));
		x->channel2 = (float *) getbytes((MAX_N+2) * sizeof(float));
		x->Wanal = (float *) getbytes(MAX_Nw * sizeof(float));	
		x->Wsyn = (float *) getbytes(MAX_Nw * sizeof(float));	
		x->Hwin = (float *) getbytes(MAX_Nw * sizeof(float));
		x->output = (float *) getbytes(MAX_Nw * sizeof(float));
		x->bitshuffle = (int *) getbytes (MAX_N * 2 * sizeof( int ));
		x->trigland = (float *) getbytes(MAX_N * 2 * sizeof( float ));	  
		x->sieve = (int *) getbytes((MAX_N2 + 1) * sizeof(int));
		x->c_lastphase_in1 = (float *) getbytes((MAX_N2+1) * sizeof(float));
		x->c_lastphase_in2 = (float *) getbytes((MAX_N2+1) * sizeof(float));
		x->c_lastphase_out = (float *) getbytes((MAX_N2+1) * sizeof(float));
		
	}  

		memset((char *)x->input1,0,x->Nw);
		memset((char *)x->input2,0,x->Nw);
		memset((char *)x->output,0,x->Nw);
		memset((char *)x->c_lastphase_in1,0,(x->N2+1) * sizeof(float));
		memset((char *)x->c_lastphase_in2,0,(x->N2+1) * sizeof(float));
		memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));

	init_rdft(x->N, x->bitshuffle, x->trigland);
	makehanning(x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);
	if(initialized != 2){
		for(i = 0; i < x->N2; i++){
			x->sieve[i] = i;
		}
	}
}
コード例 #4
0
ファイル: crossx~.c プロジェクト: pd-projects/fftease
void crossx_init(t_crossx *x, short initialized)
{
  int i;
  
  x->D = x->vs;
  x->N = x->D * x->overlap;
  x->Nw = x->N * x->winfac;
  limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->inCount = -(x->Nw);
  x->mult = 1. / (float) x->N;

  x->c_fundamental =  (float) x->R/( (x->N2)<<1 );
  x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
  x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
	if(!initialized){
      x->threshie = .001 ;
      x->autonorm = 0;
        x->mute = 0;
	  x->Wanal = (float *) getbytes((MAX_Nw) * sizeof(float));	
	  x->Wsyn = (float *) getbytes((MAX_Nw) * sizeof(float));	
	  x->Hwin = (float *) getbytes((MAX_Nw) * sizeof(float));
	  x->output = (float *) getbytes((MAX_Nw) * sizeof(float));
	  x->bitshuffle = (int *) getbytes((MAX_N * 2)* sizeof(int));
	  x->trigland = (float *) getbytes((MAX_N * 2)* sizeof(float));

	  x->input1 = (float *) getbytes(MAX_Nw * sizeof(float));	
	  x->buffer1 = (float *) getbytes(MAX_N * sizeof(float));
	  x->channel1 = (float *) getbytes((MAX_N+2) * sizeof(float));
	  x->input2 = (float *) getbytes(MAX_Nw * sizeof(float));	
	  x->buffer2 = (float *) getbytes(MAX_N * sizeof(float));
	  x->channel2 = (float *) getbytes((MAX_N+2) * sizeof(float));
	  x->last_channel = (float *) getbytes((MAX_N+2) * sizeof(float));
	  x->c_lastphase_in1 = (float *) getbytes((MAX_N2+1) * sizeof(float));
	  x->c_lastphase_in2 = (float *) getbytes((MAX_N2+1) * sizeof(float));
	  x->c_lastphase_out = (float *) getbytes((MAX_N2+1) * sizeof(float));
	} 
		memset((char *)x->input1,0,x->Nw * sizeof(float));
		memset((char *)x->input2,0,x->Nw * sizeof(float));
		memset((char *)x->output,0,x->Nw * sizeof(float));
		memset((char *)x->buffer1,0,x->N * sizeof(float));
		memset((char *)x->buffer2,0,x->N * sizeof(float));
		memset((char *)x->channel1,0,(x->N+2) * sizeof(float));
		memset((char *)x->channel2,0,(x->N+2) * sizeof(float));
		memset((char *)x->c_lastphase_in1,0,(x->N2+1) * sizeof(float));
		memset((char *)x->c_lastphase_in2,0,(x->N2+1) * sizeof(float));
		memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));
	
  init_rdft( x->N, x->bitshuffle, x->trigland);
  makehanning( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);
}
コード例 #5
0
ファイル: pvcompand~.c プロジェクト: Angeldude/pd
void pvcompand_init(t_pvcompand *x,short initialized)
{
int i;

  if(!power_of_two(x->overlap))
  	x->overlap = 4;
  if(!power_of_two(x->winfac))
  	x->winfac = 1;
  	
  x->N = x->D * x->overlap;
  x->Nw = x->N * x->winfac;	
  limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->inCount = -(x->Nw);
  x->mult = 1. / (float) x->N;

	if(!initialized){
	  x->norml = 0;
	  x->mute = 0;
	  x->bypass = 0;
	  x->thresh_interval = 1.0;
	  x->last_max_atten =  x->max_atten; 
	  x->atten_interval = 2.0 ; 
	  x->tstep = 1.0 ;
	  x->gstep = 2.0 ;	
    x->Wanal = (float *) getbytes(MAX_Nw * sizeof(float));	
    x->Wsyn = (float *) getbytes(MAX_Nw * sizeof(float));	
    x->Hwin = (float *) getbytes(MAX_Nw * sizeof(float));	
    x->input = (float *) getbytes(MAX_Nw * sizeof(float) );	
    x->buffer = (float *) getbytes(MAX_N * sizeof(float) );
    x->channel = (float *) getbytes( (MAX_N+2) * sizeof(float) );
    x->output = (float *) getbytes(MAX_N * sizeof(float) );
    x->bitshuffle = (int *) getbytes(MAX_N * 2 * sizeof( int ) );
    x->trigland = (float *) getbytes(MAX_N * 2 * sizeof( float ) );
    x->thresh = (float *) getbytes(MAX_N * sizeof(float) );
	  x->atten = (float *) getbytes(MAX_N * sizeof(float) );
	  x->curthresh = (float *) getbytes(MAX_N * sizeof(float) );
	} 
		
		memset((char *)x->input,0,x->Nw * sizeof(float));
		memset((char *)x->output,0,x->Nw * sizeof(float));

	  init_rdft( x->N, x->bitshuffle, x->trigland);
	  makewindows( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D);
	  update_thresholds(x); 

}
コード例 #6
0
ファイル: scs~.c プロジェクト: davidsan/pd-ppc
/*
 * Q.2 - Création d'un nouvel objet scs
 */
void            *scs_tilde_new(int argc, t_atom * argv)
{
	int i  = 0;
	t_scs_tilde *m = (t_scs_tilde *)pd_new(scs_tilde_class);
	m->bypass = 0;
	m->autonorm = 1;
	m->shapeWidth = 1;

	// Si argument present
	switch (argc) {
		// Bypass en argument
		case 2 :
			m->bypass = atom_getint(argv + (1 * sizeof(t_atom)));
		case 1 :
			m->autonorm = atom_getint(argv);
		default :
			break;
	}

	m->x_in2 = inlet_new(&m->x_obj, &m->x_obj.ob_pd,
              &s_signal, &s_signal);
	floatinlet_new(&m->x_obj, &m->shapeWidth);
	m->messages = inlet_new(&m->x_obj,
			  &m->x_obj.ob_pd,
			  gensym("list"),
			  gensym("messages"));


  m->x_out = outlet_new(&m->x_obj, &s_signal);
  m->window = malloc(SIZE * sizeof * m->window);
  m->bitshuffle = malloc(SIZE * 2 * sizeof * m->bitshuffle);
  m->weighting = malloc(SIZE * 2 * sizeof * m->weighting);

  for (i = 0; i<SIZE; i++) {
    m->window[i] = (float) (0.54-0.46*(cos (TWOPI * i/SIZE)));
  }

  init_rdft(SIZE, m->bitshuffle, m->weighting);
  return (void *)m;
}
コード例 #7
0
ファイル: drown~.c プロジェクト: Angeldude/pd
void drown_init(t_drown *x, short initialized)
{
	int i;
	int mem;
	
	x->D = x->vs;
	x->N = x->D * x->overlap;
	x->Nw = x->N * x->winfac;
	limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
	x->N2 = (x->N)>>1;
	x->Nw2 = (x->Nw)>>1;
	x->inCount = -(x->Nw);
	x->mult = 1. / (float) x->N;
	
	if(!initialized){
		x->mute = 0;
		x->peakflag = 0;
		mem = (MAX_Nw) * sizeof(float);
		x->input = (float *) getbytes(mem);	
		x->output = (float *) getbytes(mem);
		x->Wanal = (float *) getbytes(mem);	
		x->Wsyn = (float *) getbytes(mem);	
		x->Hwin = (float *) getbytes(mem);
		mem = (MAX_N) * sizeof(float);
		x->buffer = (float *) getbytes(mem); 
		mem = (MAX_N+2) * sizeof(float);
		x->channel = (float *) getbytes(mem);
		mem = (MAX_N) * sizeof(int);
		x->bitshuffle = (int *) getbytes(mem);
		mem = (MAX_N) * sizeof(float);
		x->trigland = (float *) getbytes(mem);
	} 
		memset((char *)x->input,0,x->Nw * sizeof(float));
		memset((char *)x->output,0,x->Nw * sizeof(float));

	makehanning( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);
	init_rdft( x->N, x->bitshuffle, x->trigland);
}
コード例 #8
0
ファイル: thresher~.c プロジェクト: pd-projects/fftease
void thresher_init(t_thresher *x, short initialized)
{
	int i;
	
	if(!x->D)
		x->D = 256;
	if(!x->R)
		x->R = 44100;
	if(!fftease_power_of_two(x->overlap) )
		x->overlap = 4;
	if(!fftease_power_of_two(x->winfac) )
		x->winfac = 1;
	x->N = x->D * x->overlap;
	x->Nw = x->N * x->winfac;
	limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
	x->N2 = (x->N)>>1;
	x->Nw2 = (x->Nw)>>1;
	x->in_count = -(x->Nw);
	x->mult = 1. / (float) x->N;
	x->tadv = (float) x->D / (float) x->R ;
	
	
	
	if(!initialized){
		x->mute = 0;
		x->bypass = 0;
		if(!x->damping_factor){
			x->damping_factor = .95;
		}
		if(!x->move_threshold){
			x->move_threshold = .00001 ;
		}
		x->first_frame = 1;
		
		x->max_hold_time = DEFAULT_HOLD ;
		x->max_hold_frames = x->max_hold_time / x->tadv;
		x->c_fundamental =  (float) x->R/( (x->N2)<<1 );
		x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
		x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
		
		x->Wanal = (float *) getbytes( (MAX_Nw) * sizeof(float));	
		x->Wsyn = (float *) getbytes( (MAX_Nw) * sizeof(float));	
		x->Hwin = (float *) getbytes( (MAX_Nw) * sizeof(float));	
		x->input = (float *) getbytes( MAX_Nw * sizeof(float) );	
		x->output = (float *) getbytes( MAX_Nw * sizeof(float) );
		x->buffer = (float *) getbytes( MAX_N * sizeof(float) );
		x->channel = (float *) getbytes( (MAX_N+2) * sizeof(float) );
		x->bitshuffle = (int *) getbytes( MAX_N * 2 * sizeof( int ) );
		x->trigland = (float *) getbytes( MAX_N * 2 * sizeof( float ) );
		x->c_lastphase_in = (float *) getbytes( (MAX_N2+1) * sizeof(float) );
		x->c_lastphase_out = (float *) getbytes( (MAX_N2+1) * sizeof(float) );
		x->composite_frame = (float *) getbytes( (MAX_N+2) * sizeof(float) );
		x->frames_left = (int *) getbytes( (MAX_N+2) * sizeof(int) );
		
	}
	memset((char *)x->input,0,x->Nw * sizeof(float));
	memset((char *)x->output,0,x->Nw * sizeof(float));
	memset((char *)x->c_lastphase_in,0,(x->N2+1) * sizeof(float));
	memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));  
	memset((char *)x->frames_left,0,(x->N+2) * sizeof(float));
	
	init_rdft(x->N, x->bitshuffle, x->trigland);
	makehanning(x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);
}
コード例 #9
0
ファイル: bthresher~.c プロジェクト: Angeldude/pd
void bthresher_init(t_bthresher *x, short initialized)
{
int i; 

  if(!x->D)
    x->D = 256;
  if(!x->R)
    x->R = 44100;
  if(!power_of_two(x->overlap))
    x->overlap = 4;
  if(!power_of_two(x->winfac))
    x->winfac = 1;

  x->N = x->D * x->overlap;
  x->Nw = x->N * x->winfac;
    
limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);

  x->mult = 1. / (float) x->N;
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->in_count = -(x->Nw);
  x->c_fundamental =  (float) x->R/((x->N2)<<1 );
  x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
  x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
	      
	if(!initialized){
	  x->first_frame = 1;
	  x->max_hold_time = 60.0 ;
	  x->thresh_connected = 0;
	  x->damping_connected = 0;
	  x->thresh_scalar = 1;
	  x->damp_scalar = 1;
	  x->mute = 0;
	  x->bypass = 0;
	  x->inf_hold = 0;
	  x->Wanal = (float *) getbytes((MAX_Nw) * sizeof(float));	
	  x->Wsyn = (float *) getbytes((MAX_Nw) * sizeof(float));	
	  x->Hwin = (float *) getbytes((MAX_Nw) * sizeof(float));
	  x->input = (float *) getbytes((MAX_Nw) * sizeof(float));	
	  x->buffer = (float *) getbytes((MAX_N) * sizeof(float));
	  x->channel = (float *) getbytes(((MAX_N+2)) * sizeof(float));
	  x->output = (float *) getbytes((MAX_Nw) * sizeof(float));
	  x->bitshuffle = (int *) getbytes((MAX_N * 2) * sizeof(int));
	  x->trigland = (float *) getbytes((MAX_N * 2) * sizeof(float));

	  x->c_lastphase_in = (float *) getbytes((MAX_N2+1)* sizeof(float));
	  x->c_lastphase_out = (float *) getbytes((MAX_N2+1)* sizeof(float));
	  	  	  
	  x->composite_frame = (float *) getbytes( (MAX_N+2)* sizeof(float));
	  x->frames_left = (int *) getbytes((MAX_N+2)* sizeof(int));

	  // TRIPLETS OF bin# damp_factor threshold
	  x->list_data = (t_atom *) getbytes((MAX_N2 + 1) * 3 * sizeof(t_atom));

	  x->move_threshold = (float *) getbytes((MAX_N2+1)* sizeof(float));
	  x->damping_factor = (float *) getbytes((MAX_N2+1)* sizeof(float));
	  

	} 
  if(initialized == 0 || initialized == 1){
	  for(i = 0; i < x->N2+1; i++) {
	    x->move_threshold[i] = x->init_thresh;
	    x->damping_factor[i] = x->init_damping;
	  }
  }

	memset((char *)x->input,0,x->Nw * sizeof(float));
	memset((char *)x->output,0,x->Nw * sizeof(float));
	memset((char *)x->buffer,0,x->N * sizeof(float));
	memset((char *)x->c_lastphase_in,0,(x->N2+1) * sizeof(float));
	memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));


  x->tadv = (float) x->D / (float) x->R;
  x->max_hold_frames = x->max_hold_time / x->tadv;
  init_rdft(x->N, x->bitshuffle, x->trigland);
  makehanning(x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);
}
コード例 #10
0
ファイル: pvtuner~.c プロジェクト: ma4u/pd-macambira
void pvtuner_init(t_pvtuner *x,short initialized)
{
    int i, j;
    int mem;
    float curfreq;

    if(!x->R)//temp init if MSP functions returned zero
        x->R = 44100;
    if(!x->D)
        x->D = 256;

    if(!power_of_two(x->overlap))
        x->overlap = 4;
    if(!power_of_two(x->winfac))
        x->winfac = 2;

    x->Iinv = 1./x->D;
    x->N = x->D * x->overlap;
    x->Nw = x->N * x->winfac;
    limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
    x->N2 = (x->N)>>1;
    x->Nw2 = (x->Nw)>>1;

    x->inCount = -(x->Nw);
    x->mult = 1. / (float) x->N;
    x->c_fundamental =  (float) x->R/(float)( (x->N2)<<1 );
    x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
    x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;

    if(!initialized) {
        x->P = 1.0 ; // default
        x->bypass_state = 0;
        x->mute = 0;
        x->L = 8192;
        x->synt = .000001;
        mem = (MAX_Nw)*sizeof(float);
        x->Wanal = (float *) getbytes(mem);
        x->Wsyn = (float *) getbytes(mem);
        x->Hwin = (float *) getbytes(mem);
        x->input = (float *) getbytes(mem);
        x->output = (float *) getbytes(mem);
        mem = (MAX_N)*sizeof(float);
        x->buffer = (float *) getbytes(mem);
        mem = (MAX_N+2)*sizeof(float);
        x->channel = (float *) getbytes(mem);
        mem = (MAX_N*2)*sizeof(int);
        x->bitshuffle = (int *) getbytes(mem);
        mem = (MAX_N*2)*sizeof(float);
        x->trigland = (float *) getbytes(mem);
        mem = (MAXTONES+1)*sizeof(float);
        x->pitchgrid = (float *) getbytes(mem);
        mem = (MAX_N+1)*sizeof(float);
        x->lastamp = (float *) getbytes(mem);
        x->lastfreq = (float *) getbytes(mem);
        x->bindex = (float *) getbytes(mem);
        mem = (x->L)*sizeof(float);
        x->table = (float *) getbytes(mem);
        mem = (MAX_N2+1)*sizeof(float);
        x->c_lastphase_in = (float *) getbytes(mem);
        x->c_lastphase_out = (float *)getbytes(mem);

        x->pbase = BASE_FREQ;
        pvtuner_diatonic(x);// default scale
    }
    memset((char *)x->input,0,x->Nw * sizeof(float));
    memset((char *)x->output,0,x->Nw * sizeof(float));
    memset((char *)x->lastamp,0,(x->N+1) * sizeof(float));
    memset((char *)x->lastfreq,0,(x->N+1) * sizeof(float));
    memset((char *)x->bindex,0,(x->N+1) * sizeof(float));
    memset((char *)x->c_lastphase_in,0,(x->N2+1) * sizeof(float));
    memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));

    for ( i = 0; i < x->L; i++ ) {
        x->table[i] = (float) x->N * cos((float)i * TWOPI / (float)x->L);
    }

    if( x->hifreq < x->c_fundamental ) {
        x->hifreq = 3000.0 ;
    }

    x->hi_bin = 1;
    x->curfreq = 0;

    while( x->curfreq < x->hifreq ) {
        ++(x->hi_bin);
        x->curfreq += x->c_fundamental ;
    }

    x->lo_bin = 0;
    x->curfreq = 0;
    while( x->curfreq < x->lofreq ) {
        ++(x->lo_bin);
        x->curfreq += x->c_fundamental ;
    }

    if( x->hi_bin >= x->N2 )
        x->hi_bin = x->N2 - 1;

    x->hi_tune_bin = x->hi_bin;
    x->myPInc = x->P*x->L/x->R;
    x->ffac = x->P * PI/x->N;

    init_rdft( x->N, x->bitshuffle, x->trigland);
    makehanning( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);

}
コード例 #11
0
ファイル: cavoc~.c プロジェクト: Angeldude/pd
void cavoc_init(t_cavoc *x,short initialized)
{
int i;

  if(!x->D)
    x->D = 256;
  if(!x->R)
    x->R = 44100;
  if(!power_of_two(x->overlap))
    x->overlap = 4;
  if(!power_of_two(x->winfac))
    x->winfac = 1;
  x->N = x->D * x->overlap;
  x->Nw = x->N * x->winfac;
limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
  x->mult = 1. / (float) x->N;
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->in_count = -(x->Nw);
  x->c_fundamental =  (float) x->R/(float)((x->N2)<<1);
  x->frame_duration = (float)x->D/(float) x->R;
  if(x->hold_time <= 100) /* in milliseconds */
  	x->hold_time = 100;


  cavoc_hold_time(x, x->hold_time);  	

	if(!initialized){
	  
	  srand(time(0));
	  x->mute = 0;
	  x->set_count = 0;
	  x->external_trigger = 0;
	  if( x->density < 0.0 ){
	    x->density = 0;
	  } else if( x->density > 1.0 ){
	    x->density = 1.0;
	  }
	  x->start_breakpoint = 1.0 - x->density;
	  
	  x->Wanal = (float *) calloc( MAX_Nw, sizeof(float) );	
	  x->Wsyn = (float *) calloc( MAX_Nw, sizeof(float) );	
	  x->input = (float *) calloc( MAX_Nw, sizeof(float) );	
	  x->Hwin = (float *) calloc( MAX_Nw, sizeof(float) );
	  x->buffer = (float *) calloc( MAX_N, sizeof(float) );
	  x->channel = (float *) calloc( MAX_N+2, sizeof(float) );
	  x->last_frame = (float *) calloc(MAX_N+2, sizeof(float));
	  x->output = (float *) calloc( MAX_Nw, sizeof(float) );
	  x->bitshuffle = (int *) calloc( MAX_N * 2, sizeof( int ) );
	  x->trigland = (float *) calloc( MAX_N * 2, sizeof( float ) );
	  x->c_lastphase_out = (float *) calloc( MAX_N2+1, sizeof(float) );
	  
	  x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
	  x->rule = (short *)  calloc(8, sizeof(short));

	  x->rule[2] = x->rule[3] = x->rule[5] = x->rule[6] = 1;
	  x->rule[0] = x->rule[1] = x->rule[4] = x->rule[7] = 0;

	} 
		memset((char *)x->input,0,x->Nw * sizeof(float));
		memset((char *)x->output,0,x->Nw * sizeof(float));
		memset((char *)x->buffer,0,x->N * sizeof(float));
		memset((char *)x->c_lastphase_out,0,(x->N2+1) * sizeof(float));
		memset((char *)x->last_frame,0,(x->N+2) * sizeof(float));

  init_rdft( x->N, x->bitshuffle, x->trigland);
  makehanning( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D, 0);

  for(i = 0; i < x->N2 + 1; i++){
    if(cavoc_randf(0.0, 1.0) > x->start_breakpoint){
      x->channel[ i * 2 ] = 1;
      ++(x->set_count);
    } else {
      x->channel[i * 2] = 0;
    }
    x->channel[i * 2 + 1] = x->c_fundamental * (float) (i / 2) * cavoc_randf(.9,1.1);
  }

//  post("turned on %d of a possible %d bins", x->set_count, x->N2+1 );
  
  for( i = 0; i < x->N+2; i++ ){
    x->last_frame[i] = x->channel[i];
  }
//  post("cavoc~ FFT size: %d",x->N);
}
コード例 #12
0
ファイル: resent~.c プロジェクト: Angeldude/pd
void resent_init(t_resent *x,short initialized)
{
  int i;
  int last_framecount = x->framecount;

  x->lock = 1;
  
  if(!x->D)
    x->D = 256;
  if(!x->R)
    x->R = 44100;
  if(!power_of_two(x->winfac))
    x->winfac = 1;
  if(!power_of_two(x->overlap))
    x->overlap = 1;

  x->verbose = 0; // testing only
  
  x->N = x->D * x->overlap;
  x->Nw = x->N * x->winfac;
  limit_fftsize(&x->N,&x->Nw,OBJECT_NAME);
  x->N2 = (x->N)>>1;
  x->Nw2 = (x->Nw)>>1;
  x->inCount = -(x->Nw);
  x->current_frame = x->framecount = 0;
  x->fpos = x->last_fpos = 0;
  x->tadv = (float)x->D/(float)x->R;
  x->mult = 1. / (float) x->N;
  x->c_fundamental =  (float) x->R/( (x->N2)<<1 );
  x->c_factor_in =  (float) x->R/((float)x->D * TWOPI);
  x->c_factor_out = TWOPI * (float)  x->D / (float) x->R;
  if(x->duration < .005){
    x->duration = 1.0;
  }
  x->framecount =  x->duration/x->tadv ;
  x->read_me = 0;

  if(!initialized){
    x->frame_increment = 1.0 ;  
    x->mute = 0;
    x->playthrough = 0;
    x->sync = 0;
    x->frames_read = 0;

    x->Wanal = (float *) getbytes( (MAX_Nw) * sizeof(float));	
    x->Wsyn = (float *) getbytes( (MAX_Nw) * sizeof(float));	
    x->Hwin = (float *) getbytes( (MAX_Nw) * sizeof(float));	
    x->input = (float *) getbytes( MAX_Nw * sizeof(float) );	
    x->output = (float *) getbytes( MAX_Nw * sizeof(float) );
	x->buffer = (float *) getbytes( MAX_N * sizeof(float) );
    x->channel = (float *) getbytes( (MAX_N+2) * sizeof(float) );
    x->bitshuffle = (int *) getbytes( MAX_N * 2 * sizeof( int ) );
    x->trigland = (float *) getbytes( MAX_N * 2 * sizeof( float ) );
    x->c_lastphase_in = (float *) getbytes( (MAX_N2+1) * sizeof(float) );
    x->c_lastphase_out = (float *) getbytes( (MAX_N2+1) * sizeof(float) );
    x->composite_frame = (float *) getbytes( (MAX_N+2) * sizeof(float) );
    x->frame_incr = (float *) getbytes( MAX_N2 * sizeof(float) );
    x->store_incr = (float *) getbytes( MAX_N2 * sizeof(float) );
    x->frame_phase = (float *) getbytes( MAX_N2 * sizeof(float) );
    x->loveboat = (float **) getbytes(x->framecount * sizeof(float *));

    for(i=0;i<x->framecount;i++){
      x->loveboat[i] = (float *) getbytes((x->N+2) * sizeof(float));
      if(x->loveboat[i] == NULL){
				error("Insufficient Memory!");
				return;
      }
      memset((char *)x->loveboat[i],0,(x->N+2) * sizeof(float));
    }
  } else if(initialized == 1){
    for(i = 0; i < last_framecount; i++){
      freebytes(x->loveboat[i],0) ;
    }
    freebytes(x->loveboat,0);
    x->loveboat = (float **) getbytes(x->framecount * sizeof(float *));
    for(i=0;i<x->framecount;i++){
      x->loveboat[i] = (float *) getbytes((x->N+2) *sizeof(float));
      if(x->loveboat[i] == NULL){
				error("Insufficient Memory!");
				return;
      }
      memset((char *)x->loveboat[i],0,(x->N+2) * sizeof(float));
    }
  }
	memset((char *)x->input,0,x->Nw * sizeof(float));
	memset((char *)x->output,0,x->Nw * sizeof(float));
	memset((char *)x->c_lastphase_in,0,(x->N2+1) * sizeof(float));
	memset((char *)x->c_lastphase_out,0,(x->N2+1)* sizeof(float));
	memset((char *)x->frame_incr,0,(x->N2)* sizeof(float));
	memset((char *)x->store_incr,0,(x->N2) * sizeof(float));
	memset((char *)x->frame_phase,0,(x->N2) * sizeof(float));

	
  init_rdft( x->N, x->bitshuffle, x->trigland);
  x->hopsize = x->N / x->overlap;	
  makewindows( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D);

  
  x->lock = 0;
}
コード例 #13
0
ファイル: presidency~.c プロジェクト: Angeldude/pd
void presidency_init(t_presidency *x, short initialized)
{
	int i;
	long oldsize,newsize;
	int oldN = x->N;
	int oldN2 = x->N2;
	int oldNw = x->Nw;
	int last_framecount = x->framecount;
	x->lock = 1;
	x->virgin = 1;
	
	if(!power_of_two(x->winfac))
		x->winfac = 1;
	if(!power_of_two(x->overlap))
		x->overlap = 4;
	if(!x->R)
		x->R = 44100;
	if(!x->D){
		x->D = 256;
		x->vector_size = x->D;
	}
	x->N = x->D * x->overlap;
	x->Nw = x->N * x->winfac;
	limit_fftsize(&x->N, &x->Nw, OBJECT_NAME);
	
	x->N2 = (x->N)>>1;
	x->Nw2 = (x->Nw)>>1;
	x->inCount = -(x->Nw);
	x->mult = 1. / (float) x->N;
//	post("mult %f N %d",x->mult,x->N);
	x->current_frame = 0;
	x->fpos = x->last_fpos = 0;
	x->tadv = (float)x->D/(float)x->R;
	x->c_fundamental = (float)x->R/((x->N2)<<1);
	x->c_factor_in = (float) x->R/((float)x->D * TWOPI);
	x->c_factor_out = TWOPI * (float)x->D / (float)x->R;
	x->table_length = 8192;
	x->table_si = (float) x->table_length / (float) x->R;
	x->pitch_increment = 1.0 * x->table_si;
	
	if( x->duration <= 0 ){
		x->duration = 1.0;
	}
	
	x->framecount =  x->duration / x->tadv ;
	x->hopsize = (float)x->N / x->overlap;
	x->read_me = 0;
	
	if(!initialized){
		x->mute = 0;
		x->in2_connected = 0;
		x->in3_connected = 0;
		x->sync = 0;
		x->playthrough = 0;
		x->frame_increment = 1.0;
		x->verbose = 0;
		x->table = (float *) getbytes(x->table_length * sizeof(float));
		x->Wanal = (float *) getbytes(MAX_Nw*sizeof(float));	
		x->Wsyn = (float *) getbytes(MAX_Nw*sizeof(float));	
		x->input = (float *) getbytes(MAX_Nw*sizeof(float));	
		x->Hwin = (float *) getbytes(MAX_Nw*sizeof(float));
		x->bindex = (float *) getbytes( (MAX_N+1) * sizeof(float) );
		x->buffer = (float *) getbytes(MAX_N*sizeof(float));
		x->channel = (float *) getbytes((MAX_N+2)*sizeof(float));
		x->output = (float *) getbytes(MAX_Nw*sizeof(float));
		x->bitshuffle = (int *) getbytes((MAX_N*2)*sizeof(int));
		x->trigland = (float *) getbytes((MAX_N*2)*sizeof(float));
		x->c_lastphase_in = (float *) getbytes((MAX_N2+1)*sizeof(float));
		x->c_lastphase_out = (float *) getbytes((MAX_N2+1)*sizeof(float));
		x->lastamp = (float *) getbytes((MAX_N+1) * sizeof(float));
		x->lastfreq = (float *) getbytes((MAX_N+1) * sizeof(float));
		x->local_frame = (float *) getbytes((MAX_N+2)*sizeof(float));
		x->loveboat = (float **) getbytes(x->framecount*sizeof(float *));
		

		/* here we stay with old reallocation approach and pray */
		for(i=0;i<x->framecount;i++){
			x->loveboat[i] = (float *) getbytes(((x->N)+2)*sizeof(float));
			if(x->loveboat[i] == NULL){
				error("memory error");
				return;
			}
			memset((char *)x->loveboat[i],0,(x->N+2)*sizeof(float));
		}
	} else if(initialized == 1) {
		//free and allocate
		oldsize = (oldN+2)*sizeof(float);
		for(i = 0; i < last_framecount; i++){
			freebytes(x->loveboat[i],oldsize) ;
		}
		oldsize = last_framecount*sizeof(float *);
		freebytes(x->loveboat,oldsize);
		x->loveboat = (float **) getbytes(x->framecount*sizeof(float *));  
		for(i=0;i<x->framecount;i++){
			x->loveboat[i] = (float *) getbytes((x->N+2)*sizeof(float));
			if(x->loveboat[i] == NULL){
				error("memory error");
				return;
			}
			memset((char *)x->loveboat[i],0,(x->N+2)*sizeof(float));
		}
	}  
	memset((char *)x->input,0,x->Nw * sizeof(float));
	memset((char *)x->output,0,x->Nw * sizeof(float));
	memset((char *)x->c_lastphase_in,0,(x->N2+1) * sizeof(float));
	memset((char *)x->lastamp,0,(x->N+1)*sizeof(float));
	memset((char *)x->lastfreq,0,(x->N+1)*sizeof(float));
	memset((char *)x->bindex,0,(x->N+1)*sizeof(float));
	memset((char *)x->buffer,0,x->N * sizeof(float));
	if(!x->vector_size){
		post("zero vector size - something is really screwed up here!");
		return;
	}
	for ( i = 0; i < x->table_length; i++ ) {
		x->table[i] = (float) x->N * cos((float)i * TWOPI / (float)x->table_length);
	}	
	x->c_fundamental =  (float) x->R/(float)x->N ;
	x->c_factor_in =  (float) x->R/((float)x->vector_size * TWOPI);
	
	if( x->hi_freq < x->c_fundamental ) {
		x->hi_freq = x->topfreq ;
	}
	x->hi_bin = 1;  
	x->curfreq = 0;
	while( x->curfreq < x->hi_freq ) {
		++(x->hi_bin);
		x->curfreq += x->c_fundamental ;
	}
	
	x->lo_bin = 0;  
	x->curfreq = 0;
	while( x->curfreq < x->lo_freq ) {
		++(x->lo_bin);
		x->curfreq += x->c_fundamental ;
	}
	
	if( x->hi_bin > x->N2)
		x->hi_bin = x->N2 ;
	if(x->lo_bin > x->hi_bin)
		x->lo_bin = x->hi_bin;
	
	x->i_vector_size = 1.0/x->vector_size;
	x->pitch_increment = x->P*x->table_length/x->R;
	
	makewindows( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D);
	init_rdft( x->N, x->bitshuffle, x->trigland);

		  
	x->lock = 0;
}