comparison filter/gamma_tone.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal shipping
9 charge). Anyone wanting to incorporate all or part of this software in a
10 commercial product must obtain a license from the Medical Research Council.
11
12 The MRC makes no representations about the suitability of this
13 software for any purpose. It is provided "as is" without express or implied
14 warranty.
15
16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24 /*
25
26 ====================================================================
27 gamma_tone.c - backward compatable interface to new filter release
28 ====================================================================
29
30 J. Holdsworth - 28th January 1989.
31
32
33 Copywright (c) Applied Psychology Unit, Medical Research Council. 1989.
34 =======================================================================
35
36
37 Release 2: 5th July 1988.
38 Release 3: 20th September 1988.
39 Release 4: 28th January 1989.
40
41 */
42
43 #include <math.h>
44
45 #ifndef _STITCH_H_
46 #include "stitch.h"
47 #endif
48 #ifndef _GAMMA_TONE_H_
49 #include "gamma_tone.h"
50 #endif
51 #ifndef _FORMULAE_H_
52 #include "formulae.h"
53 #endif
54 #ifndef _RECURSE_H_
55 #include "recurse.h"
56 #endif
57 #ifndef _SCALES_H_
58 #include "scales.h"
59 #endif
60 #ifndef _PHASE_H_
61 #include "phase.h"
62 #endif
63
64 /* identify object file */
65
66 #ifndef lint
67 static char *gt_object_ident = GT_IDENT_STRING ;
68 #endif
69
70
71 /* base center frequency */
72
73 #define Pi ( 3.1415926535 )
74 #define TwoPi ( 2*Pi )
75
76 double bankBaseFrequency = 1000. ;
77 double filterDefaultGain = 4. ;
78 int filterDefaultInputBits = bits_significant ;
79
80
81 /* generate array of filter center frequencies between the frequencies specified */
82
83 double *GenerateCenterFrequencies( min_cf, max_cf, erb_density )
84 double min_cf, max_cf, erb_density ;
85 {
86 return ( GenerateScale( ErbScale( min_cf ), ErbScale( max_cf ), erb_density, ErbScale( bankBaseFrequency ), FofErbScale ) ) ;
87 }
88
89 int NumberCenterFrequencies( min_cf, max_cf, erb_density )
90 double min_cf, max_cf, erb_density ;
91 {
92 return ( NumberOnScale( ErbScale( min_cf ), ErbScale( max_cf ), erb_density, ErbScale( bankBaseFrequency ) ) ) ;
93 }
94
95 double *NumberedCenterFrequencies( min_cf, max_cf, channels )
96 double min_cf, max_cf ;
97 int channels ;
98 {
99 return ( NumberedScale( ErbScale( min_cf ), ErbScale( max_cf ), channels, FofErbScale ) ) ;
100 }
101
102 /* initialise gamma tone filter code */
103
104 FilterBankInfo *InitGammaToneFilterBank( samplerate, order, b_scalar, phase_comp, min_filter_cf )
105 double samplerate ;
106 int order ;
107 double b_scalar ;
108 int phase_comp ;
109 double min_filter_cf ;
110 {
111 DeclareNew( FilterBankInfo *, filter_info ) ;
112 extern int n_using_sin_table ;
113
114 filter_info->samplerate = samplerate ;
115 filter_info->order = order ;
116 filter_info->b_scalar = b_scalar ;
117 filter_info->phase_comp = phase_comp ;
118
119 /* store maximum required time shift for whole filter bank */
120 /* originally time advance was implemented as delay of */
121 /* maximum advance minus desired advance (still supported) */
122
123 if( filter_info->phase_comp >= 0 )
124 filter_info->max_desired_advance_time = 1. / min_filter_cf * filter_info->phase_comp ;
125 else
126 filter_info->max_desired_advance_time = ( filter_info->order - 1. ) / ( TwoPi * filter_info->b_scalar * Erb( min_filter_cf ) ) ;
127
128 return ( filter_info ) ;
129 }
130
131 FilterChannelInfo *InitGammaToneFilterChannel( filter_info, cf )
132 FilterBankInfo *filter_info ;
133 double cf ;
134 {
135 RecursiveFilterState *filter_state ;
136 double sample_delay ;
137
138 if( filter_info->phase_comp > 0 || filter_info->phase_comp == ENVELOPE_ALIGNMENT || filter_info->phase_comp == FINE_ALIGNMENT )
139 sample_delay = filter_info->max_desired_advance_time * filter_info->samplerate ;
140 else
141 sample_delay = 0. ;
142
143 filter_state = NewRecursiveFilter(
144 filter_info->samplerate,
145 cf,
146 Erb( cf ) * filter_info->b_scalar,
147 filterDefaultGain,
148 filter_info->order,
149 filter_info->phase_comp,
150 filterDefaultInputBits,
151 & sample_delay ) ;
152
153 return( ( FilterChannelInfo * ) NewPhaseCompensator(
154 ( FilterState ) filter_state,
155 ( FilterModule ) 0,
156 sample_delay ) ) ;
157 }
158
159 /* end processing of channel - free state varibales */
160
161 void EndChannel( channel_info )
162 FilterChannelInfo *channel_info ;
163 {
164 FreeCompensatedFilter( ( PhaseCompensatorState * ) channel_info ) ;
165
166 return ;
167 }
168
169 /* free up filter state variables and sin table if finished with it */
170
171 void EndFilter( filter_info )
172 FilterBankInfo *filter_info ;
173 {
174 Delete( filter_info ) ;
175
176 return ;
177 }
178