diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filter/gamma_tone.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,178 @@
+/*
+    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.
+*/
+
+/*
+
+     ====================================================================
+      gamma_tone.c - backward compatable interface to new filter release
+     ====================================================================
+
+		   J. Holdsworth - 28th January 1989.
+
+
+    Copywright (c) Applied Psychology Unit, Medical Research Council. 1989.
+    =======================================================================
+
+
+    Release 2:  5th July 1988.
+    Release 3: 20th September 1988.
+    Release 4: 28th January 1989.
+
+*/
+
+#include  <math.h>
+
+#ifndef   _STITCH_H_
+#include  "stitch.h"
+#endif
+#ifndef   _GAMMA_TONE_H_
+#include  "gamma_tone.h"
+#endif
+#ifndef   _FORMULAE_H_
+#include  "formulae.h"
+#endif
+#ifndef   _RECURSE_H_
+#include  "recurse.h"
+#endif
+#ifndef   _SCALES_H_
+#include  "scales.h"
+#endif
+#ifndef   _PHASE_H_
+#include  "phase.h"
+#endif
+
+/* identify object file */
+
+#ifndef lint
+static char *gt_object_ident = GT_IDENT_STRING ;
+#endif
+
+
+/* base center frequency */
+
+#define   Pi                 ( 3.1415926535 )
+#define   TwoPi              ( 2*Pi )
+
+double bankBaseFrequency   = 1000. ;
+double filterDefaultGain   = 4.    ;
+int filterDefaultInputBits = bits_significant ;
+
+
+/* generate array of filter center frequencies between the frequencies specified */
+
+double *GenerateCenterFrequencies( min_cf, max_cf, erb_density )
+double min_cf, max_cf, erb_density ;
+{
+    return ( GenerateScale( ErbScale( min_cf ), ErbScale( max_cf ), erb_density, ErbScale( bankBaseFrequency ), FofErbScale ) ) ;
+}
+
+int NumberCenterFrequencies( min_cf, max_cf, erb_density )
+double min_cf, max_cf, erb_density ;
+{
+    return ( NumberOnScale( ErbScale( min_cf ), ErbScale( max_cf ), erb_density, ErbScale( bankBaseFrequency ) ) ) ;
+}
+
+double *NumberedCenterFrequencies( min_cf, max_cf, channels )
+double min_cf, max_cf ;
+int channels ;
+{
+    return ( NumberedScale( ErbScale( min_cf ), ErbScale( max_cf ), channels, FofErbScale ) ) ;
+}
+
+/* initialise gamma tone filter code */
+
+FilterBankInfo *InitGammaToneFilterBank( samplerate, order, b_scalar, phase_comp, min_filter_cf )
+double samplerate ;
+int order ;
+double b_scalar ;
+int phase_comp ;
+double min_filter_cf ;
+{
+    DeclareNew( FilterBankInfo *, filter_info ) ;
+    extern int n_using_sin_table ;
+
+    filter_info->samplerate = samplerate ;
+    filter_info->order      = order ;
+    filter_info->b_scalar   = b_scalar ;
+    filter_info->phase_comp = phase_comp ;
+
+    /* store maximum required time shift for whole filter bank */
+    /* originally time advance was implemented as delay of     */
+    /* maximum advance minus desired advance (still supported) */
+
+    if( filter_info->phase_comp >= 0 )
+	filter_info->max_desired_advance_time = 1. / min_filter_cf * filter_info->phase_comp ;
+    else
+	filter_info->max_desired_advance_time = ( filter_info->order - 1. ) / ( TwoPi * filter_info->b_scalar * Erb( min_filter_cf ) ) ;
+
+    return ( filter_info ) ;
+}
+
+FilterChannelInfo *InitGammaToneFilterChannel( filter_info, cf )
+FilterBankInfo *filter_info ;
+double cf ;
+{
+    RecursiveFilterState *filter_state ;
+    double sample_delay ;
+
+    if( filter_info->phase_comp > 0 || filter_info->phase_comp == ENVELOPE_ALIGNMENT || filter_info->phase_comp == FINE_ALIGNMENT )
+	sample_delay = filter_info->max_desired_advance_time * filter_info->samplerate ;
+    else
+	sample_delay = 0. ;
+
+    filter_state = NewRecursiveFilter(
+		       filter_info->samplerate,
+		       cf,
+		       Erb( cf ) * filter_info->b_scalar,
+		       filterDefaultGain,
+		       filter_info->order,
+		       filter_info->phase_comp,
+		       filterDefaultInputBits,
+		       & sample_delay ) ;
+
+    return( ( FilterChannelInfo * ) NewPhaseCompensator(
+				       ( FilterState ) filter_state,
+				       ( FilterModule ) 0,
+				       sample_delay ) ) ;
+}
+
+/* end processing of channel - free state varibales */
+
+void EndChannel( channel_info )
+FilterChannelInfo *channel_info ;
+{
+    FreeCompensatedFilter( ( PhaseCompensatorState * ) channel_info ) ;
+
+    return ;
+}
+
+/* free up filter state variables and sin table if finished with it */
+
+void EndFilter( filter_info )
+FilterBankInfo *filter_info ;
+{
+    Delete( filter_info ) ;
+
+    return ;
+}
+