【注意】  dmpmDSP用にC言語を拡張した部分です。


#include "iolib.h"

#define TAPNUM 2

/* Store input samples into delay line */
float storedelay(float in, float dm delay[], int tap)
{
  int i;
  float out;

  out = delay[tap - 1];

  for (i = tap - 1; i > 0; i-- ) {
    delay[i] = delay[i - 1];
  }
  delay[0] = in;

  return out;
}

/* FIR filtering */
float firfilter(float pm coef[], float dm delay[], int tap)
{
  int i;
  float out;

  for(out = 0.0, i = 0; i < tap; i++) {
    out += coef[i] * delay[i];
  }

  return out;
}

main()
{
  float dm delay[TAPNUM + 1];
  float pm coef[TAPNUM] = {0.5, 0.5};
  float in;
  float out;

  init(SAMPLE8000, 0);
  initdelay(delay, TAPNUM);

  for(;;) {
    in = read_input();
    (void) storedelay(in, delay, TAPNUM);
    out = firfilter(coef, delay, TAPNUM);
    write_output(out);
  }
}