[PD-cvs] externals/postlude/flib/src cc~.c,1.2,1.3 flib.h,1.5,1.6

Jamie Bullock postlude at users.sourceforge.net
Fri Aug 25 17:49:32 CEST 2006


Update of /cvsroot/pure-data/externals/postlude/flib/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29337

Modified Files:
	cc~.c flib.h 
Log Message:
Corrected freq domain cc~ (provided by Charles Henry)


Index: flib.h
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/flib/src/flib.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** flib.h	30 May 2006 13:42:23 -0000	1.5
--- flib.h	25 Aug 2006 15:49:30 -0000	1.6
***************
*** 22,26 ****
  #include <string.h>
  
! #define VERSION "0.83"
  
  void sc_tilde_setup(void);
--- 22,26 ----
  #include <string.h>
  
! #define VERSION "0.84"
  
  void sc_tilde_setup(void);

Index: cc~.c
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/flib/src/cc~.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** cc~.c	30 May 2006 13:42:23 -0000	1.2
--- cc~.c	25 Aug 2006 15:49:29 -0000	1.3
***************
*** 31,35 ****
  
  
! #include "flib.h"
  #define SQ(a) (a * a)
  
--- 31,38 ----
  
  
! #include <math.h>
! #include <stdlib.h>
! #include <stdio.h>
! #include <m_pd.h>
  #define SQ(a) (a * a)
  
***************
*** 41,47 ****
      t_int delay;
      t_int is_freq_domain;
!     t_float *buffer2Nsig1, *buffer2Nsig2;
      t_float *output_prev_block;
!     t_int is_new;
      t_int n;
  } t_cc;
--- 44,50 ----
      t_int delay;
      t_int is_freq_domain;
!     t_float *bufferNsig1, *bufferNsig2;
      t_float *output_prev_block;
!     t_int is_new_or_rszd;
      t_int n;
  } t_cc;
***************
*** 113,158 ****
    t_sample *out  = (t_sample *)(w[4]);
    t_int size  = (int) w[5];
-   x->n = size;
    t_int size2 = size*2;
    t_int half = size/2;
    t_float *expsig1 = NULL;
    t_float *revsig2 = NULL;
    t_float temp, temp2;
    t_int i=0;
-   t_int thrhalf;
  
  // This stuff here sets up two buffers to hold the previous N samples
  // To get the usual overlapping block (2) design on each input
  
!   if (x->is_new)
    {
!     x->buffer2Nsig1=getbytes(size*sizeof(t_float));    
!     x->buffer2Nsig2=getbytes(size*sizeof(t_float));
!     x->output_prev_block=getbytes(size*sizeof(t_float));        
!     x->is_new=0;
!   }
! //  Here we set the buffers for the next round
!   for(i=half; i < size; i++)
!  {
!     x->buffer2Nsig1[i]=sig1[i];
!     x->buffer2Nsig2[i]=sig2[i];
    }
- // The two signals are created, nonzero on 0 to 1/4 and 3/4 to 1
- // Using a block size of 2N, --size2
  
!   expsig1=(float *) getbytes(size2*sizeof(float));
!   revsig2=(float *) getbytes(size2*sizeof(float));
  
- // Loops for assignment of old values in buffer + new block
-   thrhalf = 3*half;
    for (i=0; i < half ; i++)
    {
!     expsig1[i]=x->buffer2Nsig1[i];
!     revsig2[i]=0;
    }
    for (i=half; i < size ; i++)
    {
!     expsig1[i]=x->buffer2Nsig1[i];
!     revsig2[i]=sig2[size-i];            /// Needs revision here, not too clear
    }
    expsig1[size]=sig1[0];
--- 116,176 ----
    t_sample *out  = (t_sample *)(w[4]);
    t_int size  = (int) w[5];
    t_int size2 = size*2;
    t_int half = size/2;
+   t_int thrhalf = 3*half;
    t_float *expsig1 = NULL;
    t_float *revsig2 = NULL;
    t_float temp, temp2;
    t_int i=0;
  
+   if (x->n!=size)
+   {
+     x->n = size;
+     x->is_new_or_rszd=1;
+   }
+   
  // This stuff here sets up two buffers to hold the previous N samples
  // To get the usual overlapping block (2) design on each input
  
!   if (x->is_new_or_rszd)
    {
!     if (x->bufferNsig1!=NULL)
!     {
!       freebytes(x->bufferNsig1,size*sizeof(t_float));
!       freebytes(x->bufferNsig2,size*sizeof(t_float));
!       freebytes(x->output_prev_block,size*sizeof(t_float));
!     }
!     x->bufferNsig1=getbytes(size*sizeof(t_float));
!     x->bufferNsig2=getbytes(size*sizeof(t_float));
!     x->output_prev_block=getbytes(size*sizeof(t_float));
!     for(i=0; i<size; i++)
!     {
!       x->bufferNsig1[i]=0;
!       x->bufferNsig2[i]=0;
!       x->output_prev_block[i]=0;
!     }
!     x->is_new_or_rszd=0;
    }
  
! // The two signals are created, using a block size of 2N, --size2
! // expsig1 is the expanded signal1 x->bufferNsig1 + sig1
! // revsig2 is the reversed signal2 (reversed about i=0)
! // it is made 0.0 on 0 to half and thrhalf to size2
! 
! 
!   expsig1=(t_float *) getbytes(size2*sizeof(t_float));
!   revsig2=(t_float *) getbytes(size2*sizeof(t_float));
! 
! // Loops for assignment of old values in new block + buffer
  
    for (i=0; i < half ; i++)
    {
!     expsig1[i]=x->bufferNsig1[i];
!     revsig2[i]=0.0;
    }
    for (i=half; i < size ; i++)
    {
!     expsig1[i]=x->bufferNsig1[i];
!     revsig2[i]=sig2[size-i];
    }
    expsig1[size]=sig1[0];
***************
*** 161,212 ****
    {
      expsig1[i]=sig1[i-size];
!     revsig2[i]=x->buffer2Nsig2[size2-i];
    }
    for (i=thrhalf; i < size2 ; i++)
    {
      expsig1[i]=sig1[i-size];
!     revsig2[i]=0;
    }
- 
  //  fft the two blocks and multiply them
    mayer_realfft(size2, expsig1);
    mayer_realfft(size2, revsig2);
! 
    expsig1[0]*=revsig2[0];
    expsig1[size]*=revsig2[size];
!   for(i=1; i < size2; i++)  
    {
      temp=expsig1[i];
      temp2=expsig1[size2-i];
      expsig1[i]=temp*revsig2[i]-temp2*revsig2[size2-i];
!     expsig1[size2-i]=temp*revsig2[size2-i]+temp2*revsig2[i];
    }
-   
  //  ifft
    mayer_realifft(size2, expsig1);
- 
  //  format the output:  this section formats the ouptut either as
  //  a simple cc or as a running cc
! if (x->is_freq_domain == 1)
! {
!   for(i=0; i < half; i++)
    {
!     out[i]=expsig1[i]/size2;
!     out[half + i]=expsig1[half + i]/size2;
    }
! } else {
!   for(i=0; i < half; i++)
    {
!     out[i]=x->output_prev_block[i] + expsig1[i]/size2;
!     out[half + i]=x->output_prev_block[half + i] + expsig1[half + i]/size2;
!     x->output_prev_block[i] = out[i];
!     x->output_prev_block[half + i] = out[half + i];
    }
- }
  
! freebytes(expsig1, size2*sizeof(float));
! freebytes(revsig2, size2*sizeof(float));
    return(w+6);
- 
  }
  
--- 179,237 ----
    {
      expsig1[i]=sig1[i-size];
!     revsig2[i]=x->bufferNsig2[size2-i];
    }
    for (i=thrhalf; i < size2 ; i++)
    {
      expsig1[i]=sig1[i-size];
!     revsig2[i]=0.0;
!   }
! //  Here we set the buffers for the next round
!   for(i=0; i < size; i++)
!   {
!     x->bufferNsig1[i]=(t_float) sig1[i];
!     x->bufferNsig2[i]=(t_float) sig2[i];
    }
  //  fft the two blocks and multiply them
    mayer_realfft(size2, expsig1);
    mayer_realfft(size2, revsig2);
!   
    expsig1[0]*=revsig2[0];
    expsig1[size]*=revsig2[size];
!   
!   
!   for(i=1; i < size; i++)  
    {
      temp=expsig1[i];
      temp2=expsig1[size2-i];
      expsig1[i]=temp*revsig2[i]-temp2*revsig2[size2-i];
!     expsig1[size2-i]=-1.0*(temp*revsig2[size2-i]+temp2*revsig2[i]);
    }
  //  ifft
+   
    mayer_realifft(size2, expsig1);
  //  format the output:  this section formats the ouptut either as
  //  a simple cc or as a running cc
!   if (x->is_freq_domain == 1)
    {
!     for(i=0; i < half; i++)
!     {
!       out[i]=expsig1[thrhalf+i]/size2;
!       out[half + i]=expsig1[i]/size2;
!     }
    }
!   else
    {
!     for(i=0; i < half; i++)
!     {
!       out[i]=x->output_prev_block[i] + expsig1[thrhalf+i]/size2;
!       out[half + i]=x->output_prev_block[half + i] + expsig1[i]/size2;
!       x->output_prev_block[i] = out[i];
!       x->output_prev_block[half + i] = out[half + i];
!     }
    }
  
!   freebytes(expsig1, size2*sizeof(t_float));
!   freebytes(revsig2, size2*sizeof(t_float));
    return(w+6);
  }
  
***************
*** 250,256 ****
      inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
      outlet_new(&x->x_obj, &s_signal);
!     x->is_new=1;
!     x->buffer2Nsig1=NULL;
!     x->buffer2Nsig2=NULL;
      x->output_prev_block=NULL;
      return (void *)x;
--- 275,281 ----
      inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
      outlet_new(&x->x_obj, &s_signal);
!     x->is_new_or_rszd=1;
!     x->bufferNsig1=NULL;
!     x->bufferNsig2=NULL;
      x->output_prev_block=NULL;
      return (void *)x;
***************
*** 259,268 ****
  static void cc_free(t_cc *x)
  {
!   if     (x->buffer2Nsig1 != NULL)
!     freebytes(x->buffer2Nsig1, x->n*sizeof(float));
!   if     (x->buffer2Nsig2 != NULL)
!     freebytes(x->buffer2Nsig2, x->n*sizeof(float));
    if     (x->output_prev_block != NULL)
!     freebytes(x->output_prev_block, x->n*sizeof(float));
  }
  
--- 284,293 ----
  static void cc_free(t_cc *x)
  {
!   if     (x->bufferNsig1 != NULL)
!     freebytes(x->bufferNsig1, x->n*sizeof(t_float));
!   if     (x->bufferNsig2 != NULL)
!     freebytes(x->bufferNsig2, x->n*sizeof(t_float));
    if     (x->output_prev_block != NULL)
!     freebytes(x->output_prev_block, x->n*sizeof(t_float));
  }
  
***************
*** 281,282 ****
--- 306,308 ----
  }
  
+ 





More information about the Pd-cvs mailing list