Mercurial > hg > aim92
comparison wdf/ear.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 Acknowledgment: | |
26 ============== | |
27 | |
28 The source code provided in this file was originally developed by | |
29 Christian Giguere as part of a Ph.D degree at the Department of | |
30 Engineering of the University of Cambridge from April 1990 to | |
31 November 1993. The code was subsequently adapted under a grant | |
32 from the Hearing Research Trust for full compatibility with | |
33 AIM Release 6.15. | |
34 | |
35 Christian Giguere 25/03/94 | |
36 | |
37 */ | |
38 | |
39 /* | |
40 =========================================================== | |
41 ear.c | |
42 =========================================================== | |
43 | |
44 Design of outer and middle ear (EAR) filter. | |
45 (uncoupled version) | |
46 | |
47 Author : Christian Giguere | |
48 First written : 01st June, 1991 | |
49 Last edited : 07th March, 1994 | |
50 =========================================================== | |
51 */ | |
52 | |
53 | |
54 /***** includes *****/ | |
55 | |
56 #include <math.h> | |
57 #include <stdio.h> | |
58 #include "stitch.h" | |
59 #include "source.h" | |
60 #include "calc.h" | |
61 #include "calc_tl.h" | |
62 #include "wdf_ear.h" | |
63 #include "ear.h" | |
64 | |
65 | |
66 /***** defines *****/ | |
67 | |
68 #if 0 | |
69 #define _DEBUG_ | |
70 #endif | |
71 | |
72 /***** functions *****/ | |
73 | |
74 | |
75 /************************************************************************** | |
76 * name: function: | |
77 * | |
78 * ear_callback() Callable procedure returning pointer to filtered | |
79 * data (stapes velocity). | |
80 * | |
81 * Ear() Set-up and initialization function for the design | |
82 * of the outer and middle ear filter (this filter is | |
83 * not coupled to the cochlea). Returns pointer to | |
84 * a new source. | |
85 ***************************************************************************/ | |
86 | |
87 struct _ear_state { | |
88 struct _fillable_source parent ; | |
89 Source source ; | |
90 Pointer input ; | |
91 int inout_size ; | |
92 void (*proc)(), (*close)() ; | |
93 int Ntube ; | |
94 WaveWDFstate *wave_states ; | |
95 EartubeWDFstate **eartube_states ; | |
96 EarmiddleWDFstate *earmiddle_states ; | |
97 } ; | |
98 | |
99 | |
100 /******************************** ear_callback() *************************************/ | |
101 | |
102 static Pointer ear_callback( state, bytes, buffer ) | |
103 struct _ear_state *state ; | |
104 ByteCount *bytes ; | |
105 Pointer buffer ; | |
106 { | |
107 register int last = *bytes == 0 ; | |
108 register int points ; | |
109 | |
110 /***** process *****/ | |
111 if( !last ) { | |
112 | |
113 /*** get input data ***/ | |
114 Fill(state->source, *bytes, buffer ) ; | |
115 | |
116 /*** process data ***/ | |
117 points = *bytes / state->inout_size ; | |
118 state->proc( state->wave_states, state->eartube_states, state->earmiddle_states, | |
119 state->Ntube, buffer, points ) ; | |
120 | |
121 return ( buffer ) ; | |
122 } | |
123 | |
124 /***** close *****/ | |
125 else { | |
126 | |
127 Fill( state->source, 0, buffer ) ; | |
128 state->close( state->wave_states, state->eartube_states, state->earmiddle_states, state->Ntube ) ; | |
129 | |
130 return ( DeleteFillableSource( state ) ) ; | |
131 } | |
132 | |
133 } | |
134 | |
135 | |
136 /************************************ Ear() *******************************************/ | |
137 | |
138 Source Ear( source, samplerate, output_gain, concha, canal ) | |
139 Source source ; | |
140 double samplerate, output_gain ; | |
141 TubeInfo *concha, *canal ; | |
142 { | |
143 DeclareNew( struct _ear_state *, state ) ; | |
144 double length, diam, attn ; | |
145 int segment ; | |
146 | |
147 /***** initialise input-related parameters *****/ | |
148 state->inout_size = sizeof ( DataType ) ; | |
149 state->input = ( Pointer ) 0 ; | |
150 state->source = source ; | |
151 | |
152 /***** Specify WDF filter design parameters *****/ | |
153 state->wave_states = FreefieldWDF( samplerate, RHO_air, C, As, concha->diameter/2. ) ; | |
154 | |
155 state->Ntube = canal->Nsegments + concha->Nsegments ; | |
156 state->eartube_states = NewArray( EartubeWDFstate *, state->Ntube, "ear.c for eartube states" ) ; | |
157 | |
158 length = concha->length / concha->Nsegments ; | |
159 diam = concha->diameter ; | |
160 attn = concha->att_factor ; | |
161 for( segment = 0 ; segment < concha->Nsegments ; segment++ ) | |
162 state->eartube_states[ segment ] = EartubeWDF( samplerate, RHO_air, C, diam, length, attn ) ; | |
163 | |
164 length = canal->length / canal->Nsegments ; | |
165 diam = canal->diameter ; | |
166 attn = canal->att_factor ; | |
167 for( ; segment < state->Ntube ; segment++ ) | |
168 state->eartube_states[ segment ] = EartubeWDF( samplerate, RHO_air, C, diam, length, attn ) ; | |
169 | |
170 state->earmiddle_states = EarmiddleWDF( samplerate, 0.0, output_gain, 1.0 ) ; | |
171 | |
172 state->proc = DoEarWDF ; | |
173 state->close = CloseEarWDF ; | |
174 | |
175 /***** return *****/ | |
176 source = SetFillableSource( state, ear_callback, "ear filter stage" ) ; | |
177 return ( source ) ; | |
178 | |
179 } | |
180 |