bessel.h 3.57 KB
Newer Older
Monty Montgomery's avatar
Monty Montgomery committed
1 2 3 4
/*
 *
 *  postfish
 *    
Monty Montgomery's avatar
Monty Montgomery committed
5
 *      Copyright (C) 2002-2005 Monty
Monty Montgomery's avatar
Monty Montgomery committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  Postfish is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  Postfish is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

24 25 26
#include "postfish.h"
extern int input_rate;

27
#define MAXORDER    2
28 29 30 31 32 33 34 35

typedef struct {
  double c[MAXORDER];
  double g;
  int   order;
  float alpha; 
  float Hz; 
  float ms; 
36
  int   samples;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
} iir_filter;

static inline long impulse_ahead2(float alpha){
  return rint(.13f/alpha);
}
static inline long impulse_ahead3(float alpha){
  return rint(.22f/alpha);
}
static inline long impulse_ahead4(float alpha){
  return rint(.32f/alpha);
}

static inline long step_ahead(float alpha){
  return rint(.6f/alpha);
}

static inline float step_freq(long ahead){
  return input_rate*.6f/ahead;
}

static inline float impulse_freq2(long ahead){
  return input_rate*.13f/ahead;
}
static inline float impulse_freq3(long ahead){
  return input_rate*.22f/ahead;
}
static inline float impulse_freq4(long ahead){
  return input_rate*.32f/ahead;
}

typedef struct {
  double x[MAXORDER];
69
  double y[MAXORDER];
70 71 72
} iir_state;

extern double mkbessel(double raw_alpha,int order,double *ycoeff);
73

74

75 76 77 78 79 80 81 82 83 84 85 86 87
extern void compute_iir_symmetric_limited(float *x, int n, iir_state *is, 
					  iir_filter *attack, iir_filter *limit);

extern void compute_iir_decay_limited(float *x, int n, iir_state *is, 
				      iir_filter *decay, iir_filter *limit);


extern void compute_iir_freefall_limited(float *x, int n, iir_state *is, 
					 iir_filter *attack, iir_filter *limit);

extern void compute_iir_freefallonly1(float *x, int n, iir_state *is, 
				       iir_filter *decay);

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

extern void compute_iir_over_soft(float *x, int n, iir_state *is, 
				   iir_filter *attack, iir_filter *limit,
				   float knee, float mult, float *adj);

extern void compute_iir_under_soft(float *x, int n, iir_state *is, 
				   iir_filter *attack, iir_filter *limit,
				   float knee, float mult, float *adj);

extern void compute_iir_over_hard(float *x, int n, iir_state *is, 
				  iir_filter *attack, iir_filter *limit,
				  float knee, float mult, float *adj);

extern void compute_iir_under_hard(float *x, int n, iir_state *is, 
				   iir_filter *attack, iir_filter *limit,
				   float knee, float mult, float *adj);

extern void compute_iir_over_soft_del(float *x, int n, iir_state *is, 
					  iir_filter *attack, iir_filter *limit,
					  float knee, float mult, float mult2, 
					  float *adj);

extern void compute_iir_under_soft_del(float *x, int n, iir_state *is, 
					   iir_filter *attack, iir_filter *limit,
					   float knee, float mult, float mult2,
					   float *adj);

extern void compute_iir_over_hard_del(float *x, int n, iir_state *is, 
					  iir_filter *attack, iir_filter *limit,
					  float knee, float mult, float mult2,
					  float *adj);

extern void compute_iir_under_hard_del(float *x, int n, iir_state *is, 
					   iir_filter *attack, iir_filter *limit,
					   float knee, float mult, float mult2,
					   float *adj);

extern void reset_iir(iir_state *is,float value);