Mercurial > hg > aimc
comparison trunk/C++/CARFACCommon.H @ 597:359bcd461dd1
First commit. Refer to the api [1] 'Philosophy of the implementation' for information on the approach used to implement CARFAC in C++.
[1] aimc/C++/api/html/index.html
author | flatmax |
---|---|
date | Sat, 09 Feb 2013 23:53:48 +0000 |
parents | |
children | 34dccba19c54 |
comparison
equal
deleted
inserted
replaced
596:b58758854b88 | 597:359bcd461dd1 |
---|---|
1 // Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. | |
2 // Author Matt Flax <flatmax\@> | |
3 // | |
4 // This C++ file is part of an implementation of Lyon's cochlear model: | |
5 // "Cascade of Asymmetric Resonators with Fast-Acting Compression" | |
6 // to supplement Lyon's upcoming book "Human and Machine Hearing" | |
7 // | |
8 // Licensed under the Apache License, Version 2.0 (the "License"); | |
9 // you may not use this file except in compliance with the License. | |
10 // You may obtain a copy of the License at | |
11 // | |
12 // http://www.apache.org/licenses/LICENSE-2.0 | |
13 // | |
14 // Unless required by applicable law or agreed to in writing, software | |
15 // distributed under the License is distributed on an "AS IS" BASIS, | |
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 // See the License for the specific language governing permissions and | |
18 // limitations under the License. | |
19 #ifndef CARFACCOMMON_H_INCLUDED | |
20 #define CARFACCOMMON_H_INCLUDED | |
21 | |
22 typedef float FP_TYPE; ///< The floating point type | |
23 #define AGC_STAGE_COUNT 4 ///< The number of cascades in the AGC | |
24 | |
25 #include <iostream> | |
26 using namespace std; | |
27 #include <Eigen/Dense> | |
28 using namespace Eigen; | |
29 | |
30 /** | |
31 \mainpage CARFAC C++ | |
32 | |
33 \author {Matt Flax <flatmax\@>} | |
34 \date 2013.02.08 | |
35 | |
36 \section intro_sec Introduction | |
37 | |
38 This C++ code implements Dick Lyon's CARFAC model for the peripheral hearing circuit. | |
39 | |
40 \section code_philo Philosophy of the implementation | |
41 | |
42 \subsection dd Matching the design document | |
43 | |
44 As requested by the CARFAC design description, this codebase uses Eigen to compute | |
45 matrix/vector operations. | |
46 | |
47 \subsection oo Object oriented acritecture | |
48 | |
49 Where possible common paradigms inherit from common Objects. This aims to minimise | |
50 the amount of coding required to implement and modify CARFAC. For example, the EarComponent | |
51 encapsulates the CAR, AGC and IHC where all of the have the common features of Coefficients, | |
52 Parameters and State. | |
53 | |
54 \subsection cc Common code | |
55 | |
56 Where possible typedefs, definitions, includes and namespace inclusions which are common | |
57 to the code, or usefull outside of class definitions are put in the CARFACCommon.H file. | |
58 | |
59 \subsection fileNames File naming convention and header guards | |
60 | |
61 C++ files in this codebase are named using the .C and .H suffixes (C code uses .c and .h). | |
62 | |
63 Header guards are labeled using the files name with '_' characters, for example.H would become | |
64 EXAMPLE_H_. | |
65 | |
66 \subsection globalVars Global variables | |
67 | |
68 In general the use of global variables is discouraged. Where possible the code must be instantiated | |
69 many times on the same computer system and the use of global variables complicates having multiple | |
70 instances of shared library classes. | |
71 | |
72 \subsection cvns Class and variable naming convention | |
73 | |
74 In general, classes begin with capitol letters and a variable name begis with a lower case character. | |
75 The consider a class for example : | |
76 | |
77 \code | |
78 class ForExample { class def here }; | |
79 | |
80 ForExample forExample; | |
81 | |
82 class OMG { class def here }; | |
83 | |
84 OMG omg; // here it is clear what is the type and what is the variable. | |
85 | |
86 \endcode | |
87 | |
88 The class 'ForExample' is defined, and the variable name 'forExample' may be used in the code, | |
89 which clearly indicates the type of the variable. | |
90 | |
91 The concept of labeling variables using 'p' for pointer, and type name references is not necessary, | |
92 and in some cases discouraged. Consider for example, \code float *fs \endcode defining the pointer to the sample rate. | |
93 If we were to use \code float * pFFs // don't do this - difficult to see that pFFs references fs - the sample rate \endcode , it becomes rather difficult to understand that pFFs actualy | |
94 points to the sample rate. | |
95 | |
96 A deeper argument for using simple variable names (in C++) is as follows. Good engineers program | |
97 classes and methods which are short and concise. As monitors (LCDs) get larger, most of your methods | |
98 and in some cases classes are visible in one or two pages of your monitor. Consequently if the exact | |
99 type of a variable named 'fs' needs to be found, it is as simple as looking at the top of your monitor | |
100 or scrolling up a little to find a method's input variable name/type. In the case of class member | |
101 variables, a class 'SoundCard' is expected to define a sound card. Consequently certain member variables | |
102 are expected to exist, for example, fs, inputChannels, outputChannels and so on. If the actual types | |
103 of these variables have been forgotten, then the header file is referenced, and this is normally as | |
104 simple as a few key strokes to change from the SoundCard.C file to the SoundCard.H file to inspect | |
105 the names and types of available member variables. | |
106 | |
107 \copyright {\code Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. | |
108 | |
109 Author Matt Flax <flatmax@> | |
110 | |
111 | |
112 This C++ file is part of an implementation of Lyon's cochlear model: | |
113 | |
114 "Cascade of Asymmetric Resonators with Fast-Acting Compression" | |
115 | |
116 to supplement Lyon's upcoming book "Human and Machine Hearing" | |
117 | |
118 | |
119 Licensed under the Apache License, Version 2.0 (the "License"); | |
120 | |
121 you may not use this file except in compliance with the License. | |
122 | |
123 You may obtain a copy of the License at | |
124 | |
125 | |
126 http://www.apache.org/licenses/LICENSE-2.0 | |
127 | |
128 | |
129 Unless required by applicable law or agreed to in writing, software | |
130 | |
131 distributed under the License is distributed on an "AS IS" BASIS, | |
132 | |
133 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
134 | |
135 See the License for the specific language governing permissions and | |
136 | |
137 limitations under the License. \endcode} | |
138 */ | |
139 | |
140 #endif // CARFACCOMMON_H_INCLUDED |