annotate trunk/C++/CARFACCommon.H @ 598:34dccba19c54

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