annotate carfac/ear.h @ 610:01986636257a

Second check-in of Alex Brandmeyer's C++ implementation of CARFAC. Addressed style issues and completed implementation of remaining functions. Still needs proper testing of the output stages against the MATLAB version, and runtime functions need improvements in efficiency.
author alexbrandmeyer
date Thu, 16 May 2013 17:33:23 +0000
parents aefe2ca0674f
children 0fbaf443ec82
rev   line source
alexbrandmeyer@609 1 //
alexbrandmeyer@609 2 // ear.h
alexbrandmeyer@609 3 // CARFAC Open Source C++ Library
alexbrandmeyer@609 4 //
alexbrandmeyer@609 5 // Created by Alex Brandmeyer on 5/10/13.
alexbrandmeyer@609 6 //
alexbrandmeyer@609 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@609 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@609 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@609 10 //
alexbrandmeyer@609 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@609 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@609 13 // You may obtain a copy of the License at
alexbrandmeyer@609 14 //
alexbrandmeyer@609 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@609 16 //
alexbrandmeyer@609 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@609 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@609 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@609 20 // See the License for the specific language governing permissions and
alexbrandmeyer@609 21 // limitations under the License.
alexbrandmeyer@609 22
alexbrandmeyer@609 23 #ifndef CARFAC_Open_Source_C__Library_Ear_h
alexbrandmeyer@609 24 #define CARFAC_Open_Source_C__Library_Ear_h
alexbrandmeyer@609 25
alexbrandmeyer@609 26 #include "car_state.h"
alexbrandmeyer@609 27 #include "ihc_state.h"
alexbrandmeyer@609 28 #include "agc_state.h"
alexbrandmeyer@609 29
alexbrandmeyer@609 30 class Ear {
alexbrandmeyer@610 31 public:
alexbrandmeyer@610 32 // This is the primary initialization function that is called for each
alexbrandmeyer@610 33 // Ear object in the CARFAC 'Design' method.
alexbrandmeyer@610 34 void InitEar(int n_ch, long fs, FloatArray pole_freqs, CARParams car_p,
alexbrandmeyer@610 35 IHCParams ihc_p, AGCParams agc_p);
alexbrandmeyer@610 36 // These three methods apply the different stages of the model in sequence
alexbrandmeyer@610 37 // to individual audio samples.
alexbrandmeyer@610 38 FloatArray CARStep(FPType input);
alexbrandmeyer@610 39 FloatArray IHCStep(FloatArray car_out);
alexbrandmeyer@610 40 bool AGCStep(FloatArray ihc_out);
alexbrandmeyer@610 41 // These helper functions return portions of the CAR state for storage in the
alexbrandmeyer@610 42 // CAROutput structures.
alexbrandmeyer@610 43 FloatArray ReturnZAMemory();
alexbrandmeyer@610 44 FloatArray ReturnZBMemory();
alexbrandmeyer@610 45 FloatArray ReturnGMemory();
alexbrandmeyer@610 46 FloatArray ReturnZRCoeffs();
alexbrandmeyer@610 47 // These helper functions return portions of the AGC state during the cross
alexbrandmeyer@610 48 // coupling of the ears.
alexbrandmeyer@610 49 int ReturnAGCNStages();
alexbrandmeyer@610 50 int ReturnAGCStateDecimPhase(int stage);
alexbrandmeyer@610 51 FPType ReturnAGCMixCoeff(int stage);
alexbrandmeyer@610 52 int ReturnAGCDecimation(int stage);
alexbrandmeyer@610 53 FloatArray ReturnAGCStateMemory(int stage);
alexbrandmeyer@610 54 // This returns the stage G value during the closing of the AGC loop.
alexbrandmeyer@610 55 FloatArray StageGValue(FloatArray undamping);
alexbrandmeyer@610 56 // This function sets the AGC memory during the cross coupling stage.
alexbrandmeyer@610 57 void SetAGCStateMemory(int stage, FloatArray new_values);
alexbrandmeyer@610 58 // These are two functions to set the CARState dzB and dG memories when
alexbrandmeyer@610 59 // closing the AGC loop
alexbrandmeyer@610 60 void SetCARStateDZBMemory(FloatArray new_values);
alexbrandmeyer@610 61 void SetCARStateDGMemory(FloatArray new_values);
alexbrandmeyer@610 62 private:
alexbrandmeyer@610 63 // These methods carry out the design of the coefficient sets for each of the
alexbrandmeyer@610 64 // three model stages.
alexbrandmeyer@610 65 void DesignFilters(CARParams car_params, long fs, FloatArray pole_freqs);
alexbrandmeyer@610 66 void DesignIHC(IHCParams ihc_params, long fs);
alexbrandmeyer@610 67 void DesignAGC(AGCParams agc_params, long fs);
alexbrandmeyer@610 68 // These are the corresponding methods that initialize the model state
alexbrandmeyer@610 69 // variables before runtime using the model coefficients.
alexbrandmeyer@610 70 void InitIHCState();
alexbrandmeyer@610 71 void InitAGCState();
alexbrandmeyer@610 72 void InitCARState();
alexbrandmeyer@610 73 // These are the various helper functions called during the model runtime.
alexbrandmeyer@610 74 FloatArray OHC_NLF(FloatArray velocities);
alexbrandmeyer@610 75 bool AGCRecurse(int stage, FloatArray agc_in);
alexbrandmeyer@610 76 FloatArray AGCSpatialSmooth(int stage, FloatArray stage_state);
alexbrandmeyer@610 77 FloatArray AGCSmoothDoubleExponential(FloatArray stage_state, FPType pole_z1,
alexbrandmeyer@610 78 FPType pole_z2);
alexbrandmeyer@610 79 // These are the private data members that store the state and coefficient
alexbrandmeyer@610 80 // information.
alexbrandmeyer@609 81 CARCoeffs car_coeffs_;
alexbrandmeyer@609 82 IHCCoeffs ihc_coeffs_;
alexbrandmeyer@609 83 AGCCoeffs agc_coeffs_;
alexbrandmeyer@609 84 CARState car_state_;
alexbrandmeyer@609 85 IHCState ihc_state_;
alexbrandmeyer@609 86 AGCState agc_state_;
alexbrandmeyer@610 87 int n_ch_;
alexbrandmeyer@609 88 };
alexbrandmeyer@609 89
alexbrandmeyer@610 90 #endif