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@626
|
67 // usage. These names may be changed based on the discussions being had within
|
alexbrandmeyer@626
|
68 // the AIMC group.
|
alexbrandmeyer@610
|
69 // The 'FPType' typedef is used to enable easy switching in precision level.
|
alexbrandmeyer@626
|
70 // It's currently set to double for during the unit testing phase of the
|
alexbrandmeyer@626
|
71 // project.
|
alexbrandmeyer@610
|
72 typedef double FPType;
|
alexbrandmeyer@626
|
73 // A typedef is used to define a one-dimensional Eigen array with the same
|
alexbrandmeyer@626
|
74 // precision level as FPType.
|
alexbrandmeyer@626
|
75 typedef Eigen::Array<FPType, Dynamic, 1> FloatArray;
|
alexbrandmeyer@610
|
76
|
alexbrandmeyer@611
|
77 // Two helper functions are defined here for use by the different model stages
|
alexbrandmeyer@611
|
78 // in calculating coeffecients and during model runtime.
|
alexbrandmeyer@609
|
79
|
alexbrandmeyer@609
|
80 // Function: ERBHz
|
alexbrandmeyer@609
|
81 // Auditory filter nominal Equivalent Rectangular Bandwidth
|
alexbrandmeyer@609
|
82 // Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138
|
alexbrandmeyer@626
|
83 FPType ERBHz(const FPType cf_hz, const FPType erb_break_freq,
|
alexbrandmeyer@626
|
84 const FPType erb_q);
|
alexbrandmeyer@609
|
85
|
alexbrandmeyer@609
|
86 // Function CARFACDetect
|
alexbrandmeyer@611
|
87 // This returns the IHC detection nonilnearity function of the filter output
|
alexbrandmeyer@611
|
88 // values. This is here because it is called both in design and run phases.
|
alexbrandmeyer@626
|
89 FloatArray CARFACDetect (const FloatArray& x);
|
alexbrandmeyer@610
|
90
|
ronw@628
|
91 #endif
|