title: Implementing simple high and low pass filters in C
body: <p>Trying to use portaudio to record some data, then use an algorithmic filter to change the recorded voice and then play it back. I've verified a lot of it (coming from example) but I'm quite new to C and I think in my filter implementation I've done something silly. </p>
  
  <pre><code>#if LOW_PASS 
  {
      float RC = 1.0/(CUTOFF*2*3.14);
      float dt = 1.0/SAMPLE_RATE;
      float alpha = dt/(RC+dt);
      float filteredArray[numSamples];
      filteredArray[0] = data.recordedSamples[0];
      for(i=1; i&lt;numSamples; i++){
          filteredArray[i] = filteredArray[i-1] + (alpha*(data.recordedSamples[i] - filteredArray[i-1]));
      }
      data.recordedSamples = filteredArray;
  }
  #endif
  #if HIGH_PASS
  {
      float RC = 1.0/(CUTOFF*2*3.14);
      float dt = 1.0/SAMPLE_RATE;
      float alpha = RC/(RC + dt);
      float filteredArray[numSamples];
      filteredArray[0] = data.recordedSamples[0];
      for (i = 1; i&lt;numSamples; i++){
          filteredArray[i] = alpha * (filteredArray[i-1] + data.recordedSamples[i] - data.recordedSamples[i-1]);
      }
      data.recordedSamples = filteredArray;
  }
  #endif
  </code></pre>
  
  <p>When the recorded signal tries to go through these filters I get something the following error: </p>
  
  <pre><code>*** glibc detected *** ./paex_record: free(): invalid pointer: 0xbfd68600 ***
  ======= Backtrace: =========
  /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb75e2ee2]
  ./paex_record[0x8048fe5]
  /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb75864d3]
  ./paex_record[0x80487f1]
  ======= Memory map: ========
  08048000-0804a000 r-xp 00000000 08:05 2363767    /home/svictoroff/Documents/CompArch/portaudio/examples/paex_record
  ...
  bfd68000-bff1a000 rw-p 00000000 00:00 0          [stack]
  Aborted (core dumped)
  </code></pre>
  
  <p>I'm just really not sure what's going on here. Any thoughts?
  Free is called from the end of the script at terminate here: </p>
  
  <pre><code>Pa_Terminate();
      if( data.recordedSamples )       /* Sure it is NULL or valid. */
          free( data.recordedSamples );
      if( err != paNoError )
      {
          fprintf( stderr, "An error occured while using the portaudio stream\n" );
          fprintf( stderr, "Error number: %d\n", err );
          fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
          err = 1;          /* Always return 0 or 1, but no other return codes. */
      }
      return err;
  </code></pre>