flatmax@592: // Copyright 2013 Matt R. Flax All Rights Reserved. flatmax@593: // Author Matt Flax flatmax@592: // flatmax@592: // This C++ file is part of an implementation of Lyon's cochlear model: flatmax@592: // "Cascade of Asymmetric Resonators with Fast-Acting Compression" flatmax@592: // to supplement Lyon's upcoming book "Human and Machine Hearing" flatmax@592: // flatmax@592: // Licensed under the Apache License, Version 2.0 (the "License"); flatmax@592: // you may not use this file except in compliance with the License. flatmax@592: // You may obtain a copy of the License at flatmax@592: // flatmax@592: // http://www.apache.org/licenses/LICENSE-2.0 flatmax@592: // flatmax@592: // Unless required by applicable law or agreed to in writing, software flatmax@592: // distributed under the License is distributed on an "AS IS" BASIS, flatmax@592: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. flatmax@592: // See the License for the specific language governing permissions and flatmax@592: // limitations under the License. flatmax@592: #ifndef CARFACCOMMON_H_INCLUDED flatmax@592: #define CARFACCOMMON_H_INCLUDED flatmax@592: flatmax@592: typedef float FP_TYPE; ///< The floating point type flatmax@592: #define AGC_STAGE_COUNT 4 ///< The number of cascades in the AGC flatmax@593: #define DEFAULT_SAMPLERATE 22050. ///< The default sample rate in Hz flatmax@592: flatmax@592: #include flatmax@592: using namespace std; flatmax@592: #include flatmax@592: using namespace Eigen; flatmax@592: flatmax@593: #include "PsychoAcoustics.H" flatmax@593: flatmax@601: #define AGC_DESIGN_ITERATION_ERROR -100 ///< Error when designing the AGC filter taps flatmax@601: #define AGC_DESIGN_TAPS_OOB_ERROR -101 ///< The number of taps requested have not been accounted for in the code yet. flatmax@601: #define AGC_FIR_TAP_COUNT_ERROR -102 ///< The number of taps passed to the AGC::Design_FIR_coeffs method are not handled flatmax@601: flatmax@592: /** flatmax@592: \mainpage CARFAC C++ flatmax@592: flatmax@592: \author {Matt Flax } flatmax@592: \date 2013.02.08 flatmax@592: flatmax@592: \section intro_sec Introduction flatmax@592: flatmax@592: This C++ code implements Dick Lyon's CARFAC model for the peripheral hearing circuit. flatmax@592: flatmax@592: \section code_philo Philosophy of the implementation flatmax@592: flatmax@592: \subsection dd Matching the design document flatmax@592: flatmax@592: As requested by the CARFAC design description, this codebase uses Eigen to compute flatmax@592: matrix/vector operations. flatmax@592: flatmax@592: \subsection oo Object oriented acritecture flatmax@592: flatmax@592: Where possible common paradigms inherit from common Objects. This aims to minimise flatmax@592: the amount of coding required to implement and modify CARFAC. For example, the EarComponent flatmax@592: encapsulates the CAR, AGC and IHC where all of the have the common features of Coefficients, flatmax@592: Parameters and State. flatmax@592: flatmax@592: \subsection cc Common code flatmax@592: flatmax@592: Where possible typedefs, definitions, includes and namespace inclusions which are common flatmax@592: to the code, or usefull outside of class definitions are put in the CARFACCommon.H file. flatmax@592: flatmax@592: \subsection fileNames File naming convention and header guards flatmax@592: flatmax@592: C++ files in this codebase are named using the .C and .H suffixes (C code uses .c and .h). flatmax@592: flatmax@592: Header guards are labeled using the files name with '_' characters, for example.H would become flatmax@592: EXAMPLE_H_. flatmax@592: flatmax@592: \subsection globalVars Global variables flatmax@592: flatmax@592: In general the use of global variables is discouraged. Where possible the code must be instantiated flatmax@592: many times on the same computer system and the use of global variables complicates having multiple flatmax@592: instances of shared library classes. flatmax@592: flatmax@592: \subsection cvns Class and variable naming convention flatmax@592: flatmax@592: In general, classes begin with capitol letters and a variable name begis with a lower case character. flatmax@592: The consider a class for example : flatmax@592: flatmax@592: \code flatmax@592: class ForExample { class def here }; flatmax@592: flatmax@592: ForExample forExample; flatmax@592: flatmax@592: class OMG { class def here }; flatmax@592: flatmax@592: OMG omg; // here it is clear what is the type and what is the variable. flatmax@592: flatmax@592: \endcode flatmax@592: flatmax@592: The class 'ForExample' is defined, and the variable name 'forExample' may be used in the code, flatmax@592: which clearly indicates the type of the variable. flatmax@592: flatmax@592: The concept of labeling variables using 'p' for pointer, and type name references is not necessary, flatmax@592: and in some cases discouraged. Consider for example, \code float *fs \endcode defining the pointer to the sample rate. flatmax@592: 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: points to the sample rate. flatmax@592: flatmax@592: A deeper argument for using simple variable names (in C++) is as follows. Good engineers program flatmax@592: classes and methods which are short and concise. As monitors (LCDs) get larger, most of your methods flatmax@592: and in some cases classes are visible in one or two pages of your monitor. Consequently if the exact flatmax@592: type of a variable named 'fs' needs to be found, it is as simple as looking at the top of your monitor flatmax@592: or scrolling up a little to find a method's input variable name/type. In the case of class member flatmax@592: variables, a class 'SoundCard' is expected to define a sound card. Consequently certain member variables flatmax@592: are expected to exist, for example, fs, inputChannels, outputChannels and so on. If the actual types flatmax@592: of these variables have been forgotten, then the header file is referenced, and this is normally as flatmax@592: simple as a few key strokes to change from the SoundCard.C file to the SoundCard.H file to inspect flatmax@592: the names and types of available member variables. flatmax@592: flatmax@592: \copyright {\code Copyright 2013 Matt R. Flax All Rights Reserved. flatmax@592: flatmax@592: Author Matt Flax flatmax@592: flatmax@592: flatmax@592: This C++ file is part of an implementation of Lyon's cochlear model: flatmax@592: flatmax@592: "Cascade of Asymmetric Resonators with Fast-Acting Compression" flatmax@592: flatmax@592: to supplement Lyon's upcoming book "Human and Machine Hearing" flatmax@592: flatmax@592: flatmax@592: Licensed under the Apache License, Version 2.0 (the "License"); flatmax@592: flatmax@592: you may not use this file except in compliance with the License. flatmax@592: flatmax@592: You may obtain a copy of the License at flatmax@592: flatmax@592: flatmax@592: http://www.apache.org/licenses/LICENSE-2.0 flatmax@592: flatmax@592: flatmax@592: Unless required by applicable law or agreed to in writing, software flatmax@592: flatmax@592: distributed under the License is distributed on an "AS IS" BASIS, flatmax@592: flatmax@592: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. flatmax@592: flatmax@592: See the License for the specific language governing permissions and flatmax@592: flatmax@592: limitations under the License. \endcode} flatmax@592: */ flatmax@592: flatmax@592: #endif // CARFACCOMMON_H_INCLUDED