diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wdf/ear.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,180 @@
+/*
+    Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
+    ===========================================================================
+
+    Permission to use, copy, modify, and distribute this software without fee 
+    is hereby granted for research purposes, provided that this copyright 
+    notice appears in all copies and in all supporting documentation, and that 
+    the software is not redistributed for any fee (except for a nominal shipping 
+    charge). Anyone wanting to incorporate all or part of this software in a
+    commercial product must obtain a license from the Medical Research Council.
+
+    The MRC makes no representations about the suitability of this 
+    software for any purpose.  It is provided "as is" without express or implied 
+    warranty.
+ 
+    THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
+    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
+    A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
+    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
+    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+/*  
+    Acknowledgment:
+    ==============
+
+    The source code provided in this file was originally developed by 
+    Christian Giguere as part of a Ph.D degree at the Department of
+    Engineering of the University of Cambridge from April 1990 to
+    November 1993. The code was subsequently adapted under a grant
+    from the Hearing Research Trust for full compatibility with 
+    AIM Release 6.15.
+
+    Christian Giguere 25/03/94
+
+*/
+
+/*
+    ===========================================================
+    ear.c 
+    ===========================================================
+
+    Design of outer and middle ear (EAR) filter.
+    (uncoupled version)
+            
+    Author        : Christian Giguere
+    First written : 01st June, 1991
+    Last edited   : 07th March, 1994
+    ===========================================================
+*/
+
+
+/***** includes *****/
+
+#include <math.h>
+#include <stdio.h>
+#include "stitch.h"
+#include "source.h"
+#include "calc.h"
+#include "calc_tl.h"
+#include "wdf_ear.h"
+#include "ear.h"
+
+
+/***** defines *****/
+
+#if 0
+#define   _DEBUG_
+#endif
+
+/***** functions *****/
+
+
+/**************************************************************************
+* name:                    function:
+*
+* ear_callback()           Callable procedure returning pointer to filtered
+*                          data (stapes velocity).
+*
+* Ear()                    Set-up and initialization function for the design 
+*                          of the outer and middle ear filter (this filter is 
+*                          not coupled to the cochlea).  Returns pointer to
+*                          a new source.
+***************************************************************************/
+
+struct _ear_state {
+  struct _fillable_source parent ;
+  Source  source ; 
+  Pointer input ; 
+  int     inout_size ;
+  void    (*proc)(), (*close)() ;
+  int     Ntube ;
+  WaveWDFstate      *wave_states ;
+  EartubeWDFstate   **eartube_states ;
+  EarmiddleWDFstate *earmiddle_states ;
+  } ;
+
+
+/******************************** ear_callback() *************************************/
+
+static Pointer ear_callback( state, bytes, buffer )
+  struct _ear_state  *state ;
+  ByteCount *bytes ;
+  Pointer   buffer ;
+{
+  register int last = *bytes == 0 ;
+  register int points ;
+
+ /***** process *****/
+  if( !last ) {
+
+     /*** get input data ***/
+      Fill(state->source, *bytes, buffer ) ;
+
+     /*** process data ***/
+      points = *bytes / state->inout_size ;
+      state->proc( state->wave_states, state->eartube_states, state->earmiddle_states, 
+                   state->Ntube, buffer, points ) ; 
+           
+      return ( buffer ) ;
+  }
+
+ /***** close *****/
+  else {
+
+      Fill( state->source, 0, buffer ) ;
+      state->close( state->wave_states, state->eartube_states, state->earmiddle_states, state->Ntube ) ;
+
+      return ( DeleteFillableSource( state ) ) ;
+  }
+
+}
+
+
+/************************************ Ear() *******************************************/
+
+Source Ear( source, samplerate, output_gain, concha, canal )
+  Source    source ;
+  double    samplerate, output_gain ;
+  TubeInfo  *concha, *canal ;
+{
+  DeclareNew( struct _ear_state *, state ) ;
+  double    length, diam, attn ;
+  int       segment ;
+
+ /***** initialise input-related parameters *****/
+  state->inout_size = sizeof ( DataType ) ;
+  state->input  = ( Pointer ) 0 ;
+  state->source = source ;
+
+ /***** Specify WDF filter design parameters *****/
+  state->wave_states = FreefieldWDF( samplerate, RHO_air, C, As, concha->diameter/2. ) ;
+
+  state->Ntube = canal->Nsegments + concha->Nsegments ;
+  state->eartube_states = NewArray( EartubeWDFstate *, state->Ntube, "ear.c for eartube states" ) ;
+
+  length = concha->length / concha->Nsegments ;
+  diam   = concha->diameter ;
+  attn   = concha->att_factor ;
+  for( segment = 0 ; segment < concha->Nsegments ; segment++ ) 
+       state->eartube_states[ segment ] = EartubeWDF( samplerate, RHO_air, C, diam, length, attn ) ;
+
+  length = canal->length / canal->Nsegments ;
+  diam   = canal->diameter ;
+  attn   = canal->att_factor ;
+  for( ; segment < state->Ntube ; segment++ ) 
+       state->eartube_states[ segment ] = EartubeWDF( samplerate, RHO_air, C, diam, length, attn ) ;
+
+  state->earmiddle_states = EarmiddleWDF( samplerate, 0.0, output_gain, 1.0 ) ;
+
+  state->proc = DoEarWDF ;
+  state->close = CloseEarWDF ;
+
+ /***** return *****/
+  source = SetFillableSource( state, ear_callback, "ear filter stage" ) ;
+  return ( source ) ;
+
+}
+