Example #1
0
t_int *pvcompand_perform(t_int *w)
{
  float sample, outsamp ;	
  int i,j;	
  float maxamp ;	
  float fmult;
  float cutoff;
  float avr, new_avr, rescale;

  t_pvcompand *x = (t_pvcompand *) (w[1]);
  t_float *in = (t_float *)(w[2]);
  t_float *in2 = (t_float *)(w[3]);
  t_float *out = (t_float *)(w[4]);
  int n = (int)(w[5]);

  int  inCount = x->inCount;
  float *Wanal = x->Wanal;
  float *Wsyn = x->Wsyn;
  float *input = x->input;
  float *Hwin = x->Hwin;
  float *buffer = x->buffer;
  float *channel = x->channel;
  float *output = x->output;
  	
  int D = x->D;
  int I = D;
  int R = x->R;
  int Nw = x->Nw;
  int N = x->N ;
  int N2 = x-> N2;
  int Nw2 = x->Nw2;
  int *bitshuffle = x->bitshuffle;
  float *trigland = x->trigland;
  float mult = x->mult;
  int count = x->count;
  float *atten = x->atten;
  float *curthresh = x->curthresh;
  float *thresh = x->thresh;
  float max_atten = x->max_atten;		

if( x->mute ){
	while( n-- ){
		*out++ = 0.0;
	}
	return (w+6); 
}
if( x->bypass ){
	while( n-- ){
		*out++ = *in++ * 0.5; // gain compensation
	}
	return (w+6); 
}

#if MSP
  if( x->connected[1] ){
	  max_atten = *in2++ ;
	  if(max_atten != x->last_max_atten) {
	    x->last_max_atten = x->max_atten = max_atten;
	    update_thresholds(x);
	  }
  } 
#endif

#if PD
  max_atten = *in2++ ;
  if(max_atten != x->last_max_atten) {
    x->last_max_atten = x->max_atten = max_atten;
    update_thresholds(x);
  }
#endif

  inCount += D;

  for ( j = 0 ; j < Nw - D ; j++ ){
    input[j] = input[j+D];
  }
  for ( j = Nw - D; j < Nw; j++ ) {
    input[j] = *in++;
  }

  fold( input, Wanal, Nw, buffer, N, inCount );	
  rdft( N, 1, buffer, bitshuffle, trigland );

  leanconvert(buffer, channel, N2);

  maxamp = 0.;
  avr = 0;
  for( i = 0; i < N; i+= 2 ){
    avr += channel[i];
    if( maxamp < channel[i] ){
      maxamp = channel[i] ;
    }
  }
   if(count <= 1){
	//	post("count too low!"); 
		count = 1;
	}
  for( i = 0; i < count; i++ ){
    curthresh[i] = thresh[i]*maxamp ;
  }
  cutoff = curthresh[count-1];
  new_avr = 0;
  for( i = 0; i < N; i += 2){
    if( channel[i] > cutoff ){
      j = count-1;
      while( channel[i] > curthresh[j] ){
				j--;
				if( j < 0 ){
				  j = 0;
				  break;
				}
      }
      channel[i] *= atten[j];
    }
    new_avr += channel[i] ;
  }

  leanunconvert( channel,buffer, N2);

  rdft( N, -1, buffer, bitshuffle, trigland );

  overlapadd( buffer, N, Wsyn, output, Nw, inCount);
  if( x->norml ) {
    if( new_avr <= 0 ){
      new_avr = .0001;
    }
    rescale =  avr / new_avr ;
    mult *= rescale ;

  } else {
    mult *= pvcompand_ampdb( max_atten * -.5); ;
  }

  for ( j = 0; j < D; j++ ){
    *out++ = output[j] * mult;

  }
  for ( j = 0; j < Nw - D; j++ )
    output[j] = output[j+D];
			
  for ( j = Nw - D; j < Nw; j++ )
    output[j] = 0.;

	

  /* restore state variables */
  x->inCount = inCount % Nw;
  return (w+6);
}	
Example #2
0
t_int *drown_perform(t_int *w)
{
  int	i,j;
  float frame_peak = 0.0;
  float local_thresh;
	
  t_drown *x = (t_drown *) (w[1]);
  t_float *in = (t_float *)(w[2]);
  t_float *in2 = (t_float *)(w[3]);
  t_float *in3 = (t_float *)(w[4]);
  t_float *out = (t_float *)(w[5]);
  t_int n = w[6];

  float *Wanal = x->Wanal;
  float *Wsyn = x->Wsyn;
  float *input = x->input;
  float *Hwin = x->Hwin;
  float *buffer = x->buffer;
  float *channel = x->channel;
  float *output = x->output;

  int D = x->D;
  int I = D;
  int R = x->R;
  int Nw = x->Nw;
  int N = x->N ;
  int N2 = x-> N2;
  int Nw2 = x->Nw2;
  int *bitshuffle = x->bitshuffle;
  float *trigland = x->trigland;
  float mult = x->mult;
  int inCount = x->inCount ;  
  int on = inCount;
  float threshold = x->threshold;
  float drownmult = x->drownmult;
  short *connected = x->connected;
  // get multiplier from sig inlet

  /* dereference struncture  */	
	
	
  if( x->mute ){
    while( n-- ){
      *out++ = 0.0;
    }
    return (w+7);
  }
	
  if( connected[1] )
    threshold = *in2++ ;
		
  if( connected[2] )
    drownmult = *in3++ ;
	
  inCount += D;


  for ( j = 0 ; j < Nw - D ; j++ ){
    input[j] = input[j+D];
  }
  for ( j = Nw - D; j < Nw; j++ ) {
    input[j] = *in++;
  }

  fold( input, Wanal, Nw, buffer, N, inCount );	

  rdft(N, 1, buffer, bitshuffle, trigland);
  
  if( x->peakflag ){
  	leanconvert( buffer, channel, N2);
  	for(i = 0; i <N; i+= 2){	
  		if(frame_peak < channel[i])
  			frame_peak = channel[i];
  	}
  	local_thresh = frame_peak * threshold;
  	for(i = 0; i <N; i+= 2){	
  		if(channel[i] < local_thresh)
  			channel[i]  *= drownmult;
  	}  	
  	leanunconvert( channel, buffer, N2);
  } else {
 	 nudist( buffer, channel, threshold, drownmult, N2 );
  }
  rdft( N, -1, buffer, bitshuffle, trigland );

  overlapadd( buffer, N, Wsyn, output, Nw, inCount);

  for ( j = 0; j < D; j++ )
    *out++ = output[j] * mult;

  for ( j = 0; j < Nw - D; j++ )
    output[j] = output[j+D];
			
  for ( j = Nw - D; j < Nw; j++ )
    output[j] = 0.;

	

  /* restore state variables */
  x->inCount = inCount % Nw;
  return (w+7);
}		
/* ------------------------------------------------------------------- run -- */
int SPECTACLE_BASE :: run()
{
   if (first_time) {
      /* create segmented input buffer */
      int num_segments = (window_len / RTBUFSAMPS) + 2;
      int extrasamps = RTBUFSAMPS - framesToRun();
      if (extrasamps)
         num_segments++;
      int inbuf_samps = num_segments * RTBUFSAMPS * inputChannels();
      inbuf = new float [inbuf_samps];
      for (int i = 0; i < inbuf_samps; i++)
         inbuf[i] = 0.0;

      /* Read ptr chases write ptr by <window_len>.  Set read ptr to a position
         <window_len> frames from right end of input buffer.  Set write ptr to
         beginning of buffer, or, if framesToRun() is not the same as the RTcmix
         buffer size, set it so that the next run invocation after this one
         will find the write ptr at the start of the second buffer segment.
      */
      inbuf_readptr = inbuf + (inbuf_samps - (window_len * inputChannels()));
      inbuf_startptr = inbuf + (extrasamps * inputChannels());
      inbuf_writeptr = inbuf_startptr;
      inbuf_endptr = inbuf + inbuf_samps;

      int outbuf_samps = num_segments * RTBUFSAMPS * outputChannels();
      outbuf = new float [outbuf_samps];
      for (int i = 0; i < outbuf_samps; i++)
         outbuf[i] = 0.0;

      outbuf_readptr = outbuf + (outbuf_samps
                                       - (framesToRun() * outputChannels()));
      outbuf_writeptr = outbuf_readptr;
      outbuf_endptr = outbuf + outbuf_samps;
      first_time = 0;

      DPRINT3("framesToRun()=%d, extrasamps=%d, num_segments=%d\n",
                                 framesToRun(), extrasamps, num_segments);
      DPRINT3("inbuf_samps=%d, inbuf_readptr=%p, inbuf_writeptr=%p\n",
                                 inbuf_samps, inbuf_readptr, inbuf_writeptr);
      DPRINT3("outbuf_samps=%d, outbuf_readptr=%p, outbuf_writeptr=%p\n",
                                 outbuf_samps, outbuf_readptr, outbuf_writeptr);
   }

   const int insamps = framesToRun() * inputChannels();
   if (currentFrame() < total_insamps)
      rtgetin(inbuf_writeptr, this, insamps);

   int iterations = framesToRun() / decimation;
   if (framesToRun() < RTBUFSAMPS)
      iterations++;

   DPRINT1("iterations=%d\n", iterations);

   for (int i = 0; i < iterations; i++) {
      if (currentFrame() < input_end_frame) {
         DPRINT1("taking input...cursamp=%d\n", currentFrame());
         shiftin();
         fold(currentFrame());
         JGrfft(fft_buf, half_fft_len, FORWARD);
         leanconvert();
      }
      else
         flush_dry_delay();
      modify_analysis();
      leanunconvert();
      JGrfft(fft_buf, half_fft_len, INVERSE);
      overlapadd(currentFrame());
      shiftout();

      increment(decimation);
   }

   if (currentFrame() < input_end_frame) {
      inbuf_writeptr += insamps;
      if (inbuf_writeptr >= inbuf_endptr)
         inbuf_writeptr = inbuf;
   }

   rtbaddout(outbuf_readptr, framesToRun());
   outbuf_readptr += framesToRun() * outputChannels();
   if (outbuf_readptr >= outbuf_endptr)
      outbuf_readptr = outbuf;

   return framesToRun();
}
Example #4
0
t_int *xsyn_perform(t_int *w)
{
	t_float *in1,*out, *in2;
	
	float sample, outsamp ;
	
	float	*input1, *input2,
		*output,
		*buffer1, *buffer2,
		*Wanal,
		*Wsyn,
		*channel1, *channel2;
	
	int		n,
		i,j,
		inCount,
		R,
		N,
		N2,
		D,
		Nw;
	float maxamp ;	
	int	*bitshuffle;	
	float *trigland;	
	float mult;
	float a1, a2, b1, b2;
	int even, odd;
	
	
	
	t_xsyn *x = (t_xsyn *) (w[1]);
	in1 = (t_float *)(w[2]);
	in2 = (t_float *)(w[3]);
	out = (t_float *)(w[4]);
	n = (int)(w[5]);
	
	/* dereference struncture  */	
	input1 = x->input1;
	input2 = x->input2;
	buffer1 = x->buffer1;
	buffer2 = x->buffer2;
	inCount = x->inCount;
	R = x->R;
	N = x->N;
	N2 = x->N2;
	D = x->D;
	Nw = x->Nw;
	Wanal = x->Wanal;
	Wsyn = x->Wsyn;
	output = x->output;
	buffer1 = x->buffer1;
	buffer2 = x->buffer2;
	channel1 = x->channel1;
	channel2 = x->channel2;
	bitshuffle = x->bitshuffle;
	trigland = x->trigland;
	mult = x->mult;	
	
	if(x->mute){
		while(n--){
			*out++ = 0.0;
		}
		return (w+6);
	}
	x->inCount += D;
	
	for ( j = 0 ; j < Nw - D ; j++ ){
		input1[j] = input1[j+D];
		input2[j] = input2[j+D];
	}
	for ( j = Nw - D; j < Nw; j++ ) {
		input1[j] = *in1++;
		input2[j] = *in2++;
	}
	
	fold( input1, Wanal, Nw, buffer1, N, inCount );		
	fold( input2, Wanal, Nw, buffer2, N, inCount );	
	rdft( N, 1, buffer1, bitshuffle, trigland );
	rdft( N, 1, buffer2, bitshuffle, trigland );
	leanconvert( buffer1, channel1, N2 );
	leanconvert( buffer2, channel2, N2 );
	maxamp = 0 ;
	for( i = 0; i < N; i+= 2 ) {
		if( channel2[i] > maxamp ) {
			maxamp = channel2[i];
		}
	}
	if( maxamp == 0.0 )
		maxamp = 1.0 ;
	for( i = 0; i < N; i+= 2 ) {
		channel1[i] *= (channel2[i] / maxamp );
	}
	
	leanunconvert( channel1, buffer1,  N2 );
	
	rdft( N, -1, buffer1, bitshuffle, trigland );
	
	overlapadd( buffer1, N, Wsyn, output, Nw, inCount);
	
	for ( j = 0; j < D; j++ )
		*out++ = output[j] * mult;
	
	for ( j = 0; j < Nw - D; j++ )
		output[j] = output[j+D];
	
	for ( j = Nw - D; j < Nw; j++ )
		output[j] = 0.;
	
	
	
	/* restore state variables */
	x->inCount = inCount;
	return (w+6);
}