Logo Search packages:      
Sourcecode: ecasound2.2 version File versions

audiofx_filter.h

#ifndef INCLUDED_AUDIOFX_FILTER_H
#define INCLUDED_AUDIOFX_FILTER_H

#include <deque>
#include <string>
#include <vector>

#include "audiofx.h"
#include "samplebuffer_iterators.h"

/**
 * Virtual base for filter effects.
 * @author Kai Vehmanen
 */
00015 class EFFECT_FILTER : public EFFECT_BASE {

 public:
  virtual ~EFFECT_FILTER(void);
};

/**
 * Base class for butterworth filter effects.
 * 
 * Based on SPKit Butterworth algorithms. 
 * (for more info, see http://www.music.helsinki.fi/research/spkit)
 */
00027 class EFFECT_BW_FILTER : public EFFECT_FILTER {

private:
  
  SAMPLE_SPECS::sample_t outputSample;
  SAMPLE_ITERATOR_CHANNELS i;

  std::vector<std::vector<SAMPLE_SPECS::sample_t> > sin;
  std::vector<std::vector<SAMPLE_SPECS::sample_t> > sout;

  void init_values(void);

 protected:

  std::vector<SAMPLE_SPECS::sample_t> a;
  std::vector<SAMPLE_SPECS::sample_t> b;
   
public:

  void process_notused(SAMPLE_BUFFER* sbuf);
  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

  virtual EFFECT_BW_FILTER* clone(void) const = 0;

  //  EFFECT_BW_FILTER(void) : sin(2), sout(2), a(3), b(2) {

  EFFECT_BW_FILTER(void) : a(3), b(2) {
    init_values();
  }
};

/**
 * Bandpass filter
 *  
 * Based on SPKit Butterworth algorithms
 * (for more info, see http://www.music.helsinki.fi/research/spkit)
 */
00065 class EFFECT_BANDPASS: public EFFECT_BW_FILTER {

private:
    
  parameter_t center;
  parameter_t width;

  parameter_t C;
  parameter_t D;

public:
  
00077   virtual std::string name(void) const { return("Bandpass filter"); }
00078   virtual std::string parameter_names(void) const { return("center-freq,width"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

00083   EFFECT_BANDPASS* clone(void) const  { return new EFFECT_BANDPASS(*this); }
00084   EFFECT_BANDPASS* new_expr(void) const { return new EFFECT_BANDPASS(); }
  EFFECT_BANDPASS (parameter_t centerf = 1000.0, parameter_t width = 1000.0);
};

/**
 * Bandreject filter
 *  
 * Based on SPKit Butterworth algorithms
 * (for more info, see http://www.music.helsinki.fi/research/spkit)
 */
00094 class EFFECT_BANDREJECT: public EFFECT_BW_FILTER {

private:
    
  parameter_t center;
  parameter_t width;

  parameter_t C;
  parameter_t D;

public:

00106   virtual std::string name(void) const { return("Bandreject filter"); }
00107   virtual std::string parameter_names(void) const { return("center-freq,width"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

00112   EFFECT_BANDREJECT* clone(void) const { return new EFFECT_BANDREJECT(*this); }
00113   EFFECT_BANDREJECT* new_expr(void) const { return new EFFECT_BANDREJECT(); }
  EFFECT_BANDREJECT (parameter_t centerf = 1000.0, parameter_t width = 1000.0);
};

/**
 * Highpass filter
 *
 * Based on SPKit Butterworth algorithms
 * (for more info, see http://www.music.helsinki.fi/research/spkit)
 */
00123 class EFFECT_HIGHPASS : public EFFECT_BW_FILTER {
  
 private:

  parameter_t cutOffFreq;
  parameter_t C;
    
public:
    
00132   virtual std::string name(void) const { return("Highpass filter"); }
00133   virtual std::string parameter_names(void) const { return("cutoff-freq"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

00138   EFFECT_HIGHPASS* clone(void) const { return new EFFECT_HIGHPASS(*this); }
00139   EFFECT_HIGHPASS* new_expr(void) const { return new EFFECT_HIGHPASS(); }
  EFFECT_HIGHPASS (parameter_t cutoff = 1000.0);
};

/**
 * Allpass filter
 */
00146 class EFFECT_ALLPASS_FILTER : public EFFECT_FILTER {

  std::vector<std::deque<SAMPLE_SPECS::sample_t> > inbuf, outbuf;
  SAMPLE_ITERATOR_CHANNELS i;

  parameter_t feedback_gain;
  parameter_t D;

public:

00156   virtual std::string name(void) const { return("Allpass filter"); }
00157   virtual std::string parameter_names(void) const { return("delay-samples,feedback-%"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00165   EFFECT_ALLPASS_FILTER* clone(void) const { return new EFFECT_ALLPASS_FILTER(*this); }  
00166   EFFECT_ALLPASS_FILTER* new_expr(void) const { return new EFFECT_ALLPASS_FILTER(); }
  EFFECT_ALLPASS_FILTER (void) { }
};


/**
 * Comb filter
 *
 * The basic theory behind this can be found from Ken Steiglitz's book 
 * "A digital signal processing primer", page 103.
 */
00177 class EFFECT_COMB_FILTER : public EFFECT_FILTER {

  std::vector<std::deque<SAMPLE_SPECS::sample_t> > buffer;
  std::vector<SAMPLE_SPECS::sample_t> temp;
  SAMPLE_ITERATOR_CHANNELS i;

  parameter_t C;
  parameter_t D;

public:

00188   virtual std::string name(void) const { return("Comb filter"); }
00189   virtual std::string parameter_names(void) const { return("delay-samples,radius"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00197   EFFECT_COMB_FILTER* clone(void) const { return new EFFECT_COMB_FILTER(*this); }  
00198   EFFECT_COMB_FILTER* new_expr(void) const { return new EFFECT_COMB_FILTER(); }
  EFFECT_COMB_FILTER (int delay_in_samples = 1, parameter_t constant = 1.0);
};

/**
 * Inverse comb filter
 *
 * The basic theory behind this can be found from Ken Steiglitz's book 
 * "A digital signal processing primer", page 77.
 */
00208 class EFFECT_INVERSE_COMB_FILTER : public EFFECT_FILTER {

  std::vector<parameter_t> laskuri;
  std::vector<std::deque<SAMPLE_SPECS::sample_t> > buffer;
  std::vector<SAMPLE_SPECS::sample_t> temp;
  SAMPLE_ITERATOR_CHANNELS i;

  parameter_t C;
  parameter_t D;

public:

00220   virtual std::string name(void) const { return("Inverse comb filter"); }
00221   virtual std::string parameter_names(void) const { return("delay-samples,radius"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00229   EFFECT_INVERSE_COMB_FILTER* clone(void) const { return new EFFECT_INVERSE_COMB_FILTER(*this); }  
00230   EFFECT_INVERSE_COMB_FILTER* new_expr(void) const { return new EFFECT_INVERSE_COMB_FILTER(); }
  EFFECT_INVERSE_COMB_FILTER (int delay_in_samples = 10, parameter_t constant = 1.0);
};

/**
 * Lowpass filter
 *  
 * Based on SPKit Butterworth algorithms
 * (for more info, see http://www.music.helsinki.fi/research/spkit)
 */
00240 class EFFECT_LOWPASS: public EFFECT_BW_FILTER {

private:

  parameter_t cutOffFreq;

  parameter_t C;

public:

00250   virtual std::string name(void) const { return("Lowpass filter"); }
00251   virtual std::string parameter_names(void) const { return("cutoff-freq"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  void set_cutoff(parameter_t value, long int srate);

00258   EFFECT_LOWPASS* clone(void) const { return new EFFECT_LOWPASS(*this); }  
00259   EFFECT_LOWPASS* new_expr(void) const { return new EFFECT_LOWPASS(); }
  EFFECT_LOWPASS (parameter_t cutoff = 1000.0);
};

/**
 * A simple lowpass filter
 *                                              
 *   Algorithm:  1nd order filter.             
 *   From Fugue source code:                   
 *                                             
 *    output[N] = input[N] * A + input[N-1] * B
 *                                             
 *    A = 2.0 * pi * center                    
 *    B = exp(-A / frequency)
 */                                            
00274 class EFFECT_LOWPASS_SIMPLE : public EFFECT_FILTER {

private:

  parameter_t cutOffFreq;
  parameter_t A, B;
  std::vector<SAMPLE_SPECS::sample_t> outhist, tempin, temphist;
  SAMPLE_ITERATOR_CHANNELS i;

public:

00285   virtual std::string name(void) const { return("Simple lowpass filter"); }
00286   virtual std::string parameter_names(void) const { return("cutoff-freq"); }

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

00294   EFFECT_LOWPASS_SIMPLE* clone(void) const { return new EFFECT_LOWPASS_SIMPLE(*this); }
00295   EFFECT_LOWPASS_SIMPLE* new_expr(void) const { return new EFFECT_LOWPASS_SIMPLE(); }
  EFFECT_LOWPASS_SIMPLE (parameter_t cutoff = 1000.0);
};

/**
 * Resonant bandpass filter
 */
00302 class EFFECT_RESONANT_BANDPASS : public EFFECT_FILTER {

private:

  std::vector<SAMPLE_SPECS::sample_t> outhist1, outhist2;
  
  parameter_t center;
  parameter_t width;
  
  parameter_t a, b, c, R;
  parameter_t pole_angle;

  SAMPLE_ITERATOR_CHANNELS i;

public:

00318   virtual std::string name(void) const { return("Resonant bandpass filter"); }
00319   virtual std::string parameter_names(void) const { return("center-freq,width"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00327   EFFECT_RESONANT_BANDPASS* clone(void) const { return new EFFECT_RESONANT_BANDPASS(*this); }  
00328   EFFECT_RESONANT_BANDPASS* new_expr(void) const { return new EFFECT_RESONANT_BANDPASS(); }  
  EFFECT_RESONANT_BANDPASS (parameter_t centerf = 1000.0, parameter_t width = 1000.0);
};

/**
 * Resonant lowpass filter
 *
 * Algorithm is based on a sample filter-routine (iir_filter) posted to comp.dsp.
 */
00337 class EFFECT_RESONANT_LOWPASS : public EFFECT_FILTER {

  SAMPLE_ITERATOR_CHANNELS i;
    
  std::vector<SAMPLE_SPECS::sample_t> outhist0, outhist1, outhist2, outhist3;
  std::vector<SAMPLE_SPECS::sample_t> newhist0, newhist1;
    
  class TRIPLE_COEFS {
  public:
    parameter_t a0, a1, a2;       // numerator coefficients
    parameter_t b0, b1, b2;       // denominator coefficients
  };

  class FILTER_COEFS {
  public:
    parameter_t A, B, C, D;       // filter coefficients
  };
    
  std::vector<TRIPLE_COEFS> ProtoCoef;         // Filter prototype coefficients,
                                          // for each filter section
  std::vector<FILTER_COEFS> Coef;
    
  parameter_t cutoff, Q, gain, gain_orig;
  parameter_t pi;
  parameter_t laskuri;

  parameter_t ad, bd, wp;      // for szxform()

  void szxform(int section);
  void refresh_values(void);

public:

00370   virtual std::string name(void) const { return("Resonant lowpass filter"); }
00371   virtual std::string parameter_names(void) const { return("cutoff-freq,resonance,gain"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00379   EFFECT_RESONANT_LOWPASS* clone(void) const { return new EFFECT_RESONANT_LOWPASS(*this); }  
00380   EFFECT_RESONANT_LOWPASS* new_expr(void) const { return new EFFECT_RESONANT_LOWPASS(); }  
  EFFECT_RESONANT_LOWPASS (parameter_t cutoff = 1000.0,
                     parameter_t resonance = 1.0,
                     parameter_t gain = 1.0);
};

/**
 * Resonating bandpass filter
 *
 * Based on a second order all-pole (IIR) band-pass filter from SPKit 
 * (for more info, see: http://www.music.helsinki.fi/research/spkit)
 */
00392 class EFFECT_RESONATOR : public EFFECT_FILTER {

private:

  SAMPLE_ITERATOR_CHANNELS i;
    
  parameter_t center;
  parameter_t width;

  std::vector<SAMPLE_SPECS::sample_t> cona;
  std::vector<SAMPLE_SPECS::sample_t> conb;

  std::vector<SAMPLE_SPECS::sample_t> saout0, saout1;

public:

00408   virtual std::string name(void) const { return("Resonator filter"); }
00409   virtual std::string parameter_names(void) const { return("center-freq,width"); }

  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  virtual void init(SAMPLE_BUFFER *insample);
  virtual void process(void);

00417   EFFECT_RESONATOR* clone(void) const { return new EFFECT_RESONATOR(*this); }
00418   EFFECT_RESONATOR* new_expr(void) const { return new EFFECT_RESONATOR(); }  
  EFFECT_RESONATOR (parameter_t center = 1000.0, parameter_t width = 1000.0);
};

#endif

Generated by  Doxygen 1.6.0   Back to index