annotate carfac/carfac_common.h @ 611:0fbaf443ec82

Carfac C++ revision 3, indluding more style improvements. The output structs are now classes again, and have separate storage methods for each output structure along with flags in the Run and RunSegment methods to allow for only storing NAPs if desired.
author alexbrandmeyer
date Fri, 17 May 2013 19:52:45 +0000
parents 01986636257a
children 586b0677aae8
rev   line source
alexbrandmeyer@609 1 //
alexbrandmeyer@609 2 // carfac_common.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 // *****************************************************************************
alexbrandmeyer@609 24 // carfac_common.h
alexbrandmeyer@609 25 // *****************************************************************************
alexbrandmeyer@609 26 // This file contains the base level definitions and includes used within the
alexbrandmeyer@609 27 // CARFAC C++ library. It also defines some low level functions which are used
alexbrandmeyer@609 28 // during the calculation of the various coefficient sets required by the model.
alexbrandmeyer@609 29 //
alexbrandmeyer@609 30 // The current implementation of the library is dependent on the use of the
alexbrandmeyer@609 31 // Eigen C++ library for linear algebra. Specifically, Eigen Arrays are used
alexbrandmeyer@609 32 // extensively for coefficient wise operations during both the design and run
alexbrandmeyer@609 33 // stages of the model.
alexbrandmeyer@609 34 //
alexbrandmeyer@609 35 // The 'FPType' typedef is specified in this file in order to enable quick
alexbrandmeyer@609 36 // switching between precision levels (i.e. float vs. double) throughout the
alexbrandmeyer@609 37 // library. The remainder of the code uses this type for specifying floating
alexbrandmeyer@609 38 // point scalars.
alexbrandmeyer@609 39 //
alexbrandmeyer@609 40 // Two additional typedefs are defined for one and two dimensional arrays:
alexbrandmeyer@609 41 // FloatArray and FloatArray2d. These in turn make use of FPType so that the
alexbrandmeyer@609 42 // precision level across floating point data is consistent.
alexbrandmeyer@609 43 //
alexbrandmeyer@609 44 // The functions 'ERBHz' and 'CARFACDetect' are defined here, and are used
alexbrandmeyer@609 45 // during the design stage of a CARFAC model.
alexbrandmeyer@609 46
alexbrandmeyer@609 47 #ifndef CARFAC_Open_Source_C__Library_CARFACCommon_h
alexbrandmeyer@609 48 #define CARFAC_Open_Source_C__Library_CARFACCommon_h
alexbrandmeyer@609 49
alexbrandmeyer@610 50 // This section is where the base include operations for the CARFAC project
alexbrandmeyer@610 51 // occur.
alexbrandmeyer@610 52 // <math.h> is used during coefficient calculations and runtime operations.
alexbrandmeyer@610 53 #include <math.h>
alexbrandmeyer@610 54 // <vector> is used in place of 2d Eigen Arrays for the AGC memory
alexbrandmeyer@610 55 #include <vector>
alexbrandmeyer@610 56 // The Eigen library is used extensively for 1d and 2d floating point arrays.
alexbrandmeyer@610 57 // For more information, see: http://eigen.tuxfamily.org
alexbrandmeyer@610 58 #include <Eigen/Dense>
alexbrandmeyer@609 59 using namespace Eigen;
alexbrandmeyer@609 60
alexbrandmeyer@610 61 // One constant value is defined here, but see my TODO regarding style issues.
alexbrandmeyer@610 62 // A fixed value of PI is defined throughout the project.
alexbrandmeyer@610 63 // TODO alexbrandmeyer: verify that this is OK with Google Style.
alexbrandmeyer@610 64 #define PI 3.141592653589793238
alexbrandmeyer@609 65
alexbrandmeyer@610 66 // Three typedefs are used for enabling quick switching of precision and array
alexbrandmeyer@610 67 // usage.
alexbrandmeyer@610 68 // The 'FPType' typedef is used to enable easy switching in precision level.
alexbrandmeyer@610 69 typedef double FPType;
alexbrandmeyer@610 70 // These are the two typedefs for Eigen floating point arrays.
alexbrandmeyer@610 71 typedef Eigen::Array<FPType, Dynamic, 1> FloatArray; // This is a 1d array.
alexbrandmeyer@610 72 typedef Eigen::Array<FPType, Dynamic, Dynamic> FloatArray2d; // This is 2d.
alexbrandmeyer@610 73
alexbrandmeyer@611 74 // Two helper functions are defined here for use by the different model stages
alexbrandmeyer@611 75 // in calculating coeffecients and during model runtime.
alexbrandmeyer@609 76
alexbrandmeyer@609 77 // Function: ERBHz
alexbrandmeyer@609 78 // Auditory filter nominal Equivalent Rectangular Bandwidth
alexbrandmeyer@609 79 // Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138
alexbrandmeyer@609 80 FPType ERBHz(FPType cf_hz, FPType erb_break_freq, FPType erb_q);
alexbrandmeyer@609 81
alexbrandmeyer@609 82 // Function CARFACDetect
alexbrandmeyer@611 83 // This returns the IHC detection nonilnearity function of the filter output
alexbrandmeyer@611 84 // values. This is here because it is called both in design and run phases.
alexbrandmeyer@609 85 FloatArray CARFACDetect (FloatArray x);
alexbrandmeyer@610 86
alexbrandmeyer@610 87 #endif