annotate C++/CARFACCommon.H @ 592:76c6b3fd0a05

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