Exemplo n.º 1
0
int main(void){
    printf("program starts\n");
	// this is just a random sudoku i inputed. to test the code
	// uncomment out the user input if you want to solve your own sudoku	
    int sudoku[9][9] ={
      {2,8,5,0,0,0,0,0,0}, //1
      {0,7,0,0,2,5,0,0,9}, //2
      {0,0,0,0,0,0,0,0,4}, //3
      {1,9,0,0,0,0,0,0,0}, //4
      {6,0,0,0,9,0,0,1,0}, //5
      {0,0,0,7,0,4,0,8,0}, //6
      {0,0,0,8,0,3,0,0,0}, //7
      {0,0,3,6,0,0,0,4,0}, //8
      {0,0,0,0,0,0,5,0,0}  //9  
    };
    int (*pointer)[9][9] = &sudoku;
	// just creates a place to store value
	// default value is that all the location is 1
	// convert will change the values from 1 to 0 if the location is unknown    
    int values[9][9] = {	
      {1,1,1,1,1,1,1,1,1}, //1
      {1,1,1,1,1,1,1,1,1}, //2
      {1,1,1,1,1,1,1,1,1}, //3
      {1,1,1,1,1,1,1,1,1}, //4
      {1,1,1,1,1,1,1,1,1}, //5
      {1,1,1,1,1,1,1,1,1}, //6
      {1,1,1,1,1,1,1,1,1}, //7
      {1,1,1,1,1,1,1,1,1}, //8
      {1,1,1,1,1,1,1,1,1}  //9
    };
    int (*valuepointer)[9][9] = &values;
	
	// uncomment the next line you want to input your own sudoku    
    //input(pointer); 
	
	// converts the sudoku values to prime so it is easier to deal with    
    convert(pointer, valuepointer);
	// use logic to solve sudoku
    totallogic(pointer, valuepointer, 1);
	// if the logic can not solve the sudoku
	// then guess and checking with recurbrute will begin    
    if (issudokucomplete(valuepointer)==0){
      recurbrute(pointer, valuepointer, 1);  
    }
	// unconvert the values from primes to normal numbers
	// so the user can understand    
    unconvert(pointer);
	// prints the finished sudoku for the user to see    
    printraw(pointer);
	// i don't have a system pause because i am not a pleb
	// i run my programs from cmd prompt      
    return 0;
}
Exemplo n.º 2
0
void do_thresher(t_thresher *x)
{
	int i;
	
	t_fftease *fft = x->fft;
	t_float *channel = fft->channel;
	t_float damping_factor = x->damping_factor;
	int max_hold_frames = x->max_hold_frames;
	int *frames_left = x->frames_left;
	t_float *composite_frame = x->composite_frame;
	int N = fft->N;
	t_float move_threshold = x->move_threshold;

	fold(fft);
	rdft(fft,FFT_FORWARD);
	convert(fft);
	
	if( x->first_frame ){
		for ( i = 0; i < N+2; i++ ){
			composite_frame[i] = channel[i];
			frames_left[i] = max_hold_frames;
		}
		x->first_frame = 0;
	} else {
		for( i = 0; i < N+2; i += 2 ){
			if(fabs( composite_frame[i] - channel[i] ) > move_threshold || frames_left[i] <= 0 ){
				composite_frame[i] = channel[i];
				composite_frame[i+1] = channel[i+1];
				frames_left[i] = max_hold_frames;
			} else {
				--(frames_left[i]);
				composite_frame[i] *= damping_factor;
			}
		}
	}
	// try memcpy here
	for ( i = 0; i < N+2; i++ ){
		channel[i] = composite_frame[i];
	}
	if(fft->obank_flag){
		oscbank(fft);
	} else {
		unconvert(fft);
		rdft(fft,FFT_INVERSE);
		overlapadd(fft);
	}	
}
Exemplo n.º 3
0
void makeWaves(
	       struct FFTSound *fftsound,
	       struct RSynthData *rsd,
	       void(*waveconsumer)(struct FFTSound *fftsound,void *pointer,double **samples,int num_samples),
	       bool (*progressupdate)(int pr,void *pointer),
	       void *pointer,
	       int start,int end,
	       bool obank,
               bool keep_formants
	       )
{
  double a0=0.0;
  long point=0, point2=0;
  int ch;
  int on=(-fftsound->Nw*fftsound->I)/fftsound->Dn, in=-fftsound->Nw;
  int j,i;
  double coef[fftsound->numcoef2+2];
  int keepform=0;

  if(obank){
    fprintf(stderr,"\n\nWarning! The result of the additiv resynthesis might be buggy. Please listen to the result to check that its okey or use the IFFT type.\n\n");
  }

  //  init_again();
  //  rsd=getRSynthData(fftsound);
  
  memset(coef,0.0,sizeof(double)*(fftsound->numcoef2+2));

  if (keep_formants  && fftsound->numcoef2!=0)
    keepform=1;
  
  for (j=start; j<end; j++) {
    on+=fftsound->I; in+=fftsound->Dn;

    for (ch=0; ch<fftsound->samps_per_frame; ch++) {
      point = 
	ch*fftsound->horiz_num*fftsound->numchannels 
	+ j*fftsound->numchannels;
      point2=ch*lpc_horiz_num*(fftsound->numcoef2+2)+j*(fftsound->numcoef2+2);

      if(fftsound->usemem==false) pthread_mutex_lock(&fftsound->mutex);
      for (i=0; i<fftsound->numchannels; i++) {
	rsd->channel[i+i]=MEGAMP_GET(point+i); //ch*fftsound->horiz_num + i,j
	rsd->channel[i+i+1]=MEGFREQ_GET(point+i);
      }
      if(fftsound->usemem==false) pthread_mutex_unlock(&fftsound->mutex);
      
      //	printf("j2: %d\n",j);
      if (obank==true) {

        if (j==start){
	  for (i=0; i<fftsound->N2+1; i++) {
	    rsd->lastfreq[ch][i]=rsd->channel[i+i+1];
	    rsd->lastamp[ch][i]=rsd->channel[i+i];
	    rsd->indx[ch][i]=0.;
	  }
	}

        if (j>=lpc_horiz_num) keepform=0;

        if (keepform) {
          for (i=0; i<fftsound->numcoef2+2; i++) {
            coef[i]=lpc_coef[point2]; point2++;
          }
          a0=coef[fftsound->numcoef2+1];
        }

        oscbank(
		fftsound,
		rsd,rsd->channel,
		fftsound->N2, fftsound->R, fftsound->I,
		rsd->output[ch], ch, 
		fftsound->Nw,coef, 
		fftsound->numcoef2*keepform,a0
		);

      } else {
        unconvert(rsd, rsd->channel,  rsd->buffer,  fftsound->N2,  fftsound->I,  fftsound->R, ch);
        rfft(rsd->buffer,  fftsound->N2,  INVERSE);
        overlapadd(rsd->buffer,  fftsound->N,  fftsound->Wsyn,  rsd->output[ch],  fftsound->Nw,  on);
      }

    } // end for(ch=0; ch<fftsound->samps_per_frame; ch++)


    if (obank==true){
      shiftout(
	       fftsound,
	       waveconsumer,
	       pointer,
	       rsd->output, 
	       fftsound->Nw,  
	       fftsound->I,
	       in+fftsound->Nw2+fftsound->Dn
	       );
    }else{
      shiftout(
	       fftsound,
	       waveconsumer,
	       pointer,
	       rsd->output,
	       fftsound->Nw,
	       fftsound->I,
	       on
	       );
    }

    if(progressupdate!=NULL){
      if((*progressupdate)(j,pointer)==false)break;
    }

  } // end for(j=start; j<end; j++)

  //  returnRSynthData(rsd);
}
Exemplo n.º 4
0
t_int *thresher_perform(t_int *w)
{
	float sample, outsamp ;
	int		    i,j;
	
	t_thresher *x = (t_thresher *) (w[1]);
	
	float *in = (t_float *)(w[2]);
	float *inthresh = (t_float *)(w[3]);
	float *damping = (t_float *)(w[4]);
	float *out = (t_float *)(w[5]);
	int n = (int)(w[6]);
	
	float	*input = x->input;
	float *output = x->output;
	float *buffer = x->buffer;
	float *Wanal = x->Wanal;
	float *Wsyn = x->Wsyn;
	float *channel = x->channel;
	float damping_factor = x->damping_factor;
	int max_hold_frames = x->max_hold_frames;
	int *frames_left = x->frames_left;
	float *composite_frame = x->composite_frame;
	float *c_lastphase_in = x->c_lastphase_in;
	float *c_lastphase_out = x->c_lastphase_out;
	float c_fundamental = x->c_fundamental;
	float c_factor_in = x->c_factor_in;
	float c_factor_out = x->c_factor_out;
	int *bitshuffle = x->bitshuffle;
	float *trigland = x->trigland;
	float mult = x->mult;	
	int in_count = x->in_count;
	int R = x->R;
	int N = x->N;
	int N2 = x->N2;
	int D = x->D;
	int Nw = x->Nw;
	float move_threshold = x->move_threshold;
	
	
	if( x->mute ) {
		for( j = 0; j < D; j++) {
			*out++ = 0.0 ;
		}
		return (w+7);
	} 
	
	if ( x->bypass ) {
		for( j = 0; j < D; j++) {
			*out++ = *in++ ;
		}
		return (w+7);
	} 
	
	
	
	
    if( x->thresh_connected ) {
		move_threshold = *inthresh ;
    }
    if( x->damping_connected ) {
		damping_factor = *damping ;
    }
	
	in_count += 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, in_count );
	
	rdft( N, 1, buffer, bitshuffle, trigland );
	
	convert( buffer, channel, N2, c_lastphase_in, c_fundamental, c_factor_in  );
	
	if( x->first_frame ){
		for ( i = 0; i < N+2; i++ ){
			composite_frame[i] = channel[i];
			frames_left[i] = max_hold_frames;
		}
		x->first_frame = 0;
	} else {
		for( i = 0; i < N+2; i += 2 ){
			if(fabs( composite_frame[i] - channel[i] ) > move_threshold ||
			   frames_left[i] <= 0 ){
				composite_frame[i] = channel[i];
				composite_frame[i+1] = channel[i+1];
				frames_left[i] = max_hold_frames;
			} else {
				--(frames_left[i]);
				composite_frame[i] *= damping_factor;
			}
		}
	}
	
	
    unconvert( composite_frame, buffer, N2, c_lastphase_out, c_fundamental, c_factor_out  );
    rdft( N, -1, buffer, bitshuffle, trigland );
	
    overlapadd( buffer, N, Wsyn, output, Nw, in_count );
	
    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.;
	
    x->in_count = in_count;
    x->damping_factor = damping_factor;
	
    return (w+7);
}
Exemplo n.º 5
0
/***********************************************************************
Vocoder:
tratto da Ceres di ([email protected])


***********************************************************************/
ULONG
WavVocoder (PCSZ name, LONG argc, const RXSTRING * argv,
	    PCSZ queuename, PRXSTRING retstr)
{
  PSHORT pCh, pCh2, ptemp;
  APIRET rc;
  int i, frame, FDec, nCamp;
  int campioni, puntifft, Kn2, Koverlap;
  double soglia;

  if (argc != 4)
    {
      SendMsg (FUNC_VOCODER, ERR_NUMERO_PARAMETRI);
      return INVALID_ROUTINE;
    }

  if (!sscanf (argv[0].strptr, "%d", &pCh))
    {
      SendMsg (FUNC_VOCODER, ERR_PUNTATORE_ERRATO);
      return INVALID_ROUTINE;
    }

  if (!sscanf (argv[1].strptr, "%d", &pCh2))
    {
      SendMsg (FUNC_VOCODER, ERR_PUNTATORE_ERRATO);
      return INVALID_ROUTINE;
    }

  nCamp = atol (argv[2].strptr);
  if (nCamp < 1)
    {
      SendMsg (FUNC_VOCODER, ERR_VALORE_INVALIDO);
      return INVALID_ROUTINE;
    }

  pCh = (PSHORT) AllineaCh (pCh, (ULONG) nCamp, FUNC_VOCODER);
  if (!pCh)
    return INVALID_ROUTINE;

  pCh2 = (PSHORT) AllineaCh (pCh2, (ULONG) nCamp, FUNC_VOCODER);
  if (!pCh2)
    return INVALID_ROUTINE;

  soglia = atof (argv[3].strptr) / 1000000;
  if ((soglia < 0) | (soglia > 1))
    {
      SendMsg (FUNC_VOCODER, ERR_VALORE_INVALIDO);
      return INVALID_ROUTINE;
    }


  fvec (inout, K_PUNTI);
  fvec (buffer, K_PUNTI);
  fvec (dativoc, K_PUNTI);
  fvec (WAnalisi, K_PUNTI);
  fvec (WSintesi, K_PUNTI);

  campioni = K_PUNTI;
  puntifft = K_PUNTI / 2;
  Kn2 = K_PUNTI / 2;
  Koverlap = 2;
  FDec = campioni / Koverlap;

  makewindows (WAnalisi, WSintesi, campioni, campioni, FDec);

  for (frame = 0; frame < (10 * nCamp / K_PUNTI); frame++)
    {
      for (i = 0; i < campioni; i++)
	inout[i] = (double) *pCh++ / (double) MAX_CAMPIONE;

      fold (inout, WAnalisi, campioni, buffer, campioni, frame * campioni);
      for (i = 0; i < campioni; i++)
	inout[i] = (double) 0;
/*
 */
      rfft (buffer, puntifft, FORWARD);
      convert (buffer, dativoc, Kn2, FDec, FreqCamp, 1);
      /*
         if(frame==100) for (i=0; i<Kn2; i++) {
         printf("freq %f, amp %f\n", dativoc[i+i+1], dativoc[i+i] * 1000);
         }

       */
      for (i = 0; i < Kn2; i++)
	{
	  if (dativoc[i + i] < soglia)
	    dativoc[i + i] = 0;
	}

      unconvert (dativoc, buffer, Kn2, FDec, FreqCamp, 1);
      rfft (buffer, puntifft, INVERSE);
      overlapadd (buffer, campioni, WSintesi, inout, campioni, frame * campioni);

      for (i = 0; i < campioni; i++)
	*pCh2++ = *pCh2 + (SHORT) (inout[i] * MAX_CAMPIONE);
      pCh = pCh - (SHORT) (K_PUNTI * 0.9);
      pCh2 = pCh2 - (SHORT) (K_PUNTI * 0.9);
    }

  free (inout);
  free (buffer);
  free (dativoc);
  free (WAnalisi);
  free (WSintesi);
  sprintf (retstr->strptr, "%f", ERR_OK);
  retstr->strlength = strlen (retstr->strptr);
  return VALID_ROUTINE;
}
Exemplo n.º 6
0
int PVOC::run()
{
#ifdef debug
    printf("PVOC::run\n\n");
#endif

    // This runs the engine forward until the first buffer of output data is ready (see PVOC::shiftout()).
    // This compensates for the group delay of the windowed output.

    int outFramesNeeded = framesToRun();

    if (_cachedOutFrames)
    {
        int toCopy = min(_cachedOutFrames, outFramesNeeded);
        if (toCopy >= 0)
        {
#ifdef debug
            printf("\twriting %d of %d leftover frames from _outbuf at offset %d to rtbaddout\n",
                   toCopy, _cachedOutFrames, _outReadOffset);
#endif
            rtbaddout(&_outbuf[_outReadOffset], toCopy);
            increment(toCopy);
            _outReadOffset += toCopy;
            assert(_outReadOffset <= _outWriteOffset);
            if (_outReadOffset == _outWriteOffset)
                _outReadOffset = _outWriteOffset = 0;
#ifdef debug
            printf("\t_outbuf read offset %d, write offset %d\n",
                   _outReadOffset, _outWriteOffset);
#endif
            outFramesNeeded -= toCopy;
            _cachedOutFrames -= toCopy;
        }
    }

    while (outFramesNeeded > 0)
    {
#ifdef debug
        printf("\ttop of loop: needed=%d _in=%d _on=%d Nw=%d\n",
               outFramesNeeded, _in, _on, Nw);
#endif
        /*
        * analysis: input D samples; window, fold and rotate input
        * samples into FFT buffer; take FFT; and convert to
        * amplitude-frequency (phase vocoder) form
        */
        shiftin( _pvInput, Nw, D);
        /*
         * increment times
         */
        _in += D;
        _on += I;

        if ( Np ) {
            ::vvmult( winput, Hwin, _pvInput, Nw );
            lpcoef[0] = ::lpa( winput, Nw, lpcoef, Np );
            /*			printf("%.3g/", lpcoef[0] ); */
        }
        ::fold( _pvInput, Wanal, Nw, _fftBuf, N, _in );
        ::rfft( _fftBuf, N2, FORWARD );
        convert( _fftBuf, channel, N2, D, R );

        // 	if ( I == 0 ) {
        // 		if ( Np )
        // 			fwrite( lpcoef, sizeof(float), Np+1, stdout );
        // 		fwrite( channel, sizeof(float), N+2, stdout );
        // 		fflush( stdout );
        // /*		printf("\n" );
        // 		continue;
        // 	}
        /*
         * at this point channel[2*i] contains amplitude data and
         * channel[2*i+1] contains frequency data (in Hz) for phase
         * vocoder channels i = 0, 1, ... N/2; the center frequency
         * associated with each channel is i*f, where f is the
         * fundamental frequency of analysis R/N; any desired spectral
         * modifications can be made at this point: pitch modifications
         * are generally well suited to oscillator bank resynthesis,
         * while time modifications are generally well (and more
         * efficiently) suited to overlap-add resynthesis
         */

        if (_pvFilter) {
            _pvFilter->run(channel, N2);
        }

        if ( obank ) {
            /*
             * oscillator bank resynthesis
             */
            oscbank( channel, N2, lpcoef, Np, R, Nw, I, P, _pvOutput );
#if defined(debug) && 0
            printf("osc output (first 16):\n");
            for (int x=0; x<16; ++x) printf("%g ",_pvOutput[x]);
            printf("\n");
#endif
            shiftout( _pvOutput, Nw, I, _on+Nw-I);
        }
        else {
            /*
             * overlap-add resynthesis
             */
            unconvert( channel, _fftBuf, N2, I, R );
            ::rfft( _fftBuf, N2, INVERSE );
            ::overlapadd( _fftBuf, N, Wsyn, _pvOutput, Nw, _on );
            // I samples written into _outbuf
            shiftout( _pvOutput, Nw, I, _on);
        }
        // Handle case where last synthesized block extended beyond outFramesNeeded

        int framesToOutput = ::min(outFramesNeeded, I);
#ifdef debug
        printf("\tbottom of loop. framesToOutput: %d\n", framesToOutput);
#endif
        int framesAvailable = _outWriteOffset - _outReadOffset;
        framesToOutput = ::min(framesToOutput, framesAvailable);
        if (framesToOutput > 0) {
#ifdef debug
            printf("\twriting %d frames from offset %d to rtbaddout\n",
                   framesToOutput, _outReadOffset);
#endif
            rtbaddout(&_outbuf[_outReadOffset], framesToOutput);
            increment(framesToOutput);
            _outReadOffset += framesToOutput;
            if (_outReadOffset == _outWriteOffset)
                _outReadOffset = _outWriteOffset = 0;
        }

        _cachedOutFrames = _outWriteOffset - _outReadOffset;
#ifdef debug
        if (_cachedOutFrames > 0) {
            printf("\tsaving %d samples left over\n", _cachedOutFrames);
        }
        printf("\toutbuf read offset %d, write offset %d\n\n",
               _outReadOffset, _outWriteOffset);
#endif
        outFramesNeeded -= framesToOutput;
    }	/* while (outFramesNeeded > 0) */

    return framesToRun();
}
Exemplo n.º 7
0
t_int *bthresher_perform(t_int *w)
{
	
  float sample, outsamp ;
  int	i, j, on;
  t_bthresher *x = (t_bthresher *) (w[1]);
  float *in = (t_float *)(w[2]);
  float *inthresh = (t_float *)(w[3]);
  float *damping = (t_float *)(w[4]);
  float *out = (t_float *)(w[5]);
  t_int n = w[6];
	

  int *bitshuffle = x->bitshuffle;
  float *trigland = x->trigland;
  float mult = x->mult;	

  int in_count = x->in_count;
  int R = x->R;
  int N = x->N;
  int N2 = x->N2;
  int D = x->D;
  int Nw = x->Nw;
  float *Wanal = x->Wanal;
  float *Wsyn = x->Wsyn;
  float *damping_factor = x->damping_factor;
  float *move_threshold = x->move_threshold;
  float *input = x->input;
  float *output = x->output;
  float *buffer = x->buffer;
  float *channel = x->channel;
  float *composite_frame = x->composite_frame;
  int max_hold_frames = x->max_hold_frames;
  int *frames_left = x->frames_left;
  float thresh_scalar = x->thresh_scalar;
  float damp_scalar = x->damp_scalar;
  short inf_hold = x->inf_hold;
  
  if( x->mute ) {
    for( j = 0; j < D; j++) {
      *out++ = 0.0 ;
    }
  } else if ( x->bypass ) {
    for( j = 0; j < D; j++) {
      *out++ = *in++ * 0.5;
    }
  } else {
#if MSP
    if( x->thresh_connected ) {
      thresh_scalar = *inthresh++;
    }
    if( x->damping_connected ) {
      damp_scalar = *damping++;
    }
#endif

#if PD
      thresh_scalar = *inthresh++;
      damp_scalar = *damping++;
#endif	

    in_count += 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, in_count );
    rdft( N, 1, buffer, bitshuffle, trigland );
    convert( buffer, channel, N2, x->c_lastphase_in, x->c_fundamental, x->c_factor_in  );
	
    if( x->first_frame ){
      for ( i = 0; i < N+2; i++ ){
        composite_frame[i] = channel[i];
        x->frames_left[i] = max_hold_frames;
      }
      x->first_frame = 0;
    } else {
      if( thresh_scalar < .999 || thresh_scalar > 1.001 || damp_scalar < .999 || damp_scalar > 1.001 ) {
				for(i = 0, j = 0; i < N+2; i += 2, j++ ){
				  if( fabs( composite_frame[i] - channel[i] ) > move_threshold[j] * thresh_scalar|| frames_left[j] <= 0 ){
				    composite_frame[i] = channel[i];
				    composite_frame[i+1] = channel[i+1];
				    frames_left[j] = max_hold_frames;
				  } else {
				    if(!inf_hold){
				      --(frames_left[j]);
				    }
				    composite_frame[i] *= damping_factor[j] * damp_scalar;
				  }
				}

      } else {
				for( i = 0, j = 0; i < N+2; i += 2, j++ ){
				  if( fabs( composite_frame[i] - channel[i] ) > move_threshold[j] || frames_left[j] <= 0 ){
				    composite_frame[i] = channel[i];
				    composite_frame[i+1] = channel[i+1];
				    frames_left[j] = max_hold_frames;
				  } else {
				    if(!inf_hold){
				      --(frames_left[j]);
				    }
				    composite_frame[i] *= damping_factor[j];
				  }
				}
      }
    }

    unconvert(x->composite_frame, buffer, N2, x->c_lastphase_out, x->c_fundamental, x->c_factor_out);
    rdft(N, -1, buffer, bitshuffle, trigland);

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

    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.;
  }
  x->in_count = in_count % Nw;
  x->thresh_scalar = thresh_scalar;
  x->damp_scalar = damp_scalar;
	
  return (w+7);
}		
Exemplo n.º 8
0
t_int *cavoc_perform(t_int *w)
{
  int	i,j;
  float oldfrac,newfrac;
  t_cavoc *x = (t_cavoc *)(w[1]);
  float *trigger_vec = (t_float *)(w[2]);
  float *out = (t_float *)(w[3]);
  t_int n = w[4];

  int frames_left = x->frames_left;
  float *input = x->input;
  float *buffer = x->buffer;
  int in_count = x->in_count;
  int R = x->R;
  int N = x->N;
  int N2 = x->N2;
  int D = x->D;
  int Nw = x->Nw;
  float *Wanal = x->Wanal;
  float *Wsyn = x->Wsyn;
  float *output = x->output;
  float *channel = x->channel;
  float mult = x->mult ;
  int *bitshuffle = x->bitshuffle;
  float *trigland = x->trigland ;
  int hold_frames = x->hold_frames;
  short *rule = x->rule;
  short left = x->left;
  short right = x->right;
  short center = x->center;
  float *last_frame = x->last_frame;
  float *c_lastphase_out = x->c_lastphase_out;
  float c_fundamental = x->c_fundamental;
  float c_factor_out = x->c_factor_out;
  short external_trigger = x->external_trigger;
  short new_event = 0;
  
  in_count += D;

  if( x->mute ){
    while( n-- ){
      *out++ = 0.0;
    }
    return (w+5);
  }
  if(external_trigger){// only accurate to within a vector because of FFT
  	for(i=0;i<n;i++){
  		if(trigger_vec[i]){
  			new_event = 1;
  			break;
  		}
  	}
  } else if(!--frames_left){
    frames_left = hold_frames;
  	new_event = 1;
  }
  
  if(new_event){
    for( i = 2; i < N; i+=2 ){
      left = last_frame[ i - 2];
      center = last_frame[i] ;
      right = last_frame[i+2];
      channel[i] = cavoc_apply_rule(left, right, center, rule );
    }
    /* boundary cases */
    center = last_frame[0];
    right = last_frame[2];
    left = last_frame[N];
    channel[0] = cavoc_apply_rule(left, right, center, rule );

    center = last_frame[N];
    right = last_frame[0];
    left = last_frame[N - 2];
    channel[N] = cavoc_apply_rule(left, right, center, rule );


    /* save composite frame for next time */
    for( i = 0; i < N+1; i++ ){
      last_frame[i] = channel[i];
    }
  }
  unconvert( channel, buffer, N2, c_lastphase_out, c_fundamental, c_factor_out  );
  rdft( N, -1, buffer, bitshuffle, trigland );
  overlapadd( buffer, N, Wsyn, output, Nw, in_count);

  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->in_count = in_count % Nw;
  x->frames_left = frames_left;
  return (w+5);
}		
Exemplo n.º 9
0
t_int *resent_perform(t_int *w)
{

  int iphase, amp, freq, i, j;
  float fincr;	
  float fpos;
  ////////////////////////////////////////////// 
  t_resent *x = (t_resent *) (w[1]);
  float *frame_incr = x->frame_incr ;
  float *frame_phase = x->frame_phase ;
  float *composite_frame = x->composite_frame ;
  float in_sample;
  t_float *in = (t_float *)(w[2]);
  t_float *out = (t_float *)(w[3]);
  t_float *sync_vec = (t_float *)(w[4]);
  t_int n = w[5];
	
  /* dereference structure */	

  int inCount = x->inCount;
  int R = x->R;
  int N = x->N;
  int N2 = x->N2;
  int D = x->D;
  int Nw = x->Nw;
  float *Wanal = x->Wanal;
  float *Wsyn = x->Wsyn;		
  float *input = x->input;
  float *output = x->output;
  float *buffer = x->buffer;
  float *channel = x->channel;
  float fframe = x->current_frame ;
  float last_fpos = x->last_fpos ;
  int framecount = x->framecount;
  float mult = x->mult ;
  int *bitshuffle = x->bitshuffle;
  float *trigland = x->trigland ;
  float *c_lastphase_in = x->c_lastphase_in;
  float *c_lastphase_out = x->c_lastphase_out;
  float c_fundamental = x->c_fundamental;
  float c_factor_in = x->c_factor_in;
  float c_factor_out = x->c_factor_out;
  float sync = x->sync;
  
  sync = (float)x->frames_read / (float)x->framecount;
  
  if(x->mute || x->lock){
	while(n--){
	  *out++ = 0.0;
	  *sync_vec++ = sync;
	}
	return (w+6);
  }
  
  inCount += D;


  
  if(x->read_me){
    for ( j = 0 ; j < Nw - D ; j++ ){
      input[j] = input[j+D];
    }
    if(x->playthrough){
      for (j = Nw - D; j < Nw; j++) {
				in_sample = input[j] = *in++;
				*out++ = in_sample * 0.5; // scale down
				*sync_vec++ = sync;
		  }
    } else{
      for (j = Nw - D; j < Nw; j++) {
				input[j] = *in++;
				*out++ = 0.0;
				*sync_vec++ = sync;
      }
    }

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

    convert( buffer, x->loveboat[(x->frames_read)++], N2, c_lastphase_in, c_fundamental, c_factor_in );
    if(x->frames_read >= x->framecount){
      x->read_me = 0;
    } 	
  } 
  else {
    for( i = 0 ; i < N2; i++ ){
      amp = i<<1;
      freq = amp + 1 ;
      iphase = frame_phase[i]  ;
      if( iphase < 0 )
		iphase = 0;
      if( iphase > framecount - 1 )
		iphase = framecount - 1;
      composite_frame[amp] = x->loveboat[iphase][amp];
      composite_frame[freq] = x->loveboat[iphase][freq];
      frame_phase[i] += frame_incr[i] ;
      while( frame_phase[i] > framecount - 1)
		frame_phase[i] -= framecount ;
      while( frame_phase[i] < 0. )
		frame_phase[i] += framecount ;
    }

    unconvert(composite_frame, buffer, N2, c_lastphase_out, c_fundamental, c_factor_out);

    rdft( N, -1, buffer, bitshuffle, trigland );
    overlapadd( buffer, N, Wsyn, output, Nw, inCount );

    for (j = 0; j < D; j++){
      *out++ = output[j] * mult;
      *sync_vec++ = sync;
    }
    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;
  x->current_frame = fframe;
  x->last_fpos = last_fpos;
  x->sync = sync;


  return (w+6);
}