alexbrandmeyer@609: // alexbrandmeyer@609: // carfac_common.h alexbrandmeyer@609: // CARFAC Open Source C++ Library alexbrandmeyer@609: // alexbrandmeyer@609: // Created by Alex Brandmeyer on 5/10/13. alexbrandmeyer@609: // alexbrandmeyer@609: // This C++ file is part of an implementation of Lyon's cochlear model: alexbrandmeyer@609: // "Cascade of Asymmetric Resonators with Fast-Acting Compression" alexbrandmeyer@609: // to supplement Lyon's upcoming book "Human and Machine Hearing" alexbrandmeyer@609: // alexbrandmeyer@609: // Licensed under the Apache License, Version 2.0 (the "License"); alexbrandmeyer@609: // you may not use this file except in compliance with the License. alexbrandmeyer@609: // You may obtain a copy of the License at alexbrandmeyer@609: // alexbrandmeyer@609: // http://www.apache.org/licenses/LICENSE-2.0 alexbrandmeyer@609: // alexbrandmeyer@609: // Unless required by applicable law or agreed to in writing, software alexbrandmeyer@609: // distributed under the License is distributed on an "AS IS" BASIS, alexbrandmeyer@609: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. alexbrandmeyer@609: // See the License for the specific language governing permissions and alexbrandmeyer@609: // limitations under the License. alexbrandmeyer@609: // alexbrandmeyer@609: // ***************************************************************************** alexbrandmeyer@609: // carfac_common.h alexbrandmeyer@609: // ***************************************************************************** alexbrandmeyer@609: // This file contains the base level definitions and includes used within the alexbrandmeyer@609: // CARFAC C++ library. It also defines some low level functions which are used alexbrandmeyer@609: // during the calculation of the various coefficient sets required by the model. alexbrandmeyer@609: // alexbrandmeyer@609: // The current implementation of the library is dependent on the use of the alexbrandmeyer@609: // Eigen C++ library for linear algebra. Specifically, Eigen Arrays are used alexbrandmeyer@609: // extensively for coefficient wise operations during both the design and run alexbrandmeyer@609: // stages of the model. alexbrandmeyer@609: // alexbrandmeyer@609: // The 'FPType' typedef is specified in this file in order to enable quick alexbrandmeyer@609: // switching between precision levels (i.e. float vs. double) throughout the alexbrandmeyer@609: // library. The remainder of the code uses this type for specifying floating alexbrandmeyer@609: // point scalars. alexbrandmeyer@609: // alexbrandmeyer@609: // Two additional typedefs are defined for one and two dimensional arrays: alexbrandmeyer@609: // FloatArray and FloatArray2d. These in turn make use of FPType so that the alexbrandmeyer@609: // precision level across floating point data is consistent. alexbrandmeyer@609: // alexbrandmeyer@609: // The functions 'ERBHz' and 'CARFACDetect' are defined here, and are used alexbrandmeyer@609: // during the design stage of a CARFAC model. alexbrandmeyer@609: alexbrandmeyer@609: #ifndef CARFAC_Open_Source_C__Library_CARFACCommon_h alexbrandmeyer@609: #define CARFAC_Open_Source_C__Library_CARFACCommon_h alexbrandmeyer@609: alexbrandmeyer@610: // This section is where the base include operations for the CARFAC project alexbrandmeyer@610: // occur. alexbrandmeyer@610: // is used for debugging output, but it could go in final version. alexbrandmeyer@610: #include alexbrandmeyer@610: // is used during coefficient calculations and runtime operations. alexbrandmeyer@610: #include alexbrandmeyer@610: // is used in place of 2d Eigen Arrays for the AGC memory alexbrandmeyer@610: #include alexbrandmeyer@610: // The Eigen library is used extensively for 1d and 2d floating point arrays. alexbrandmeyer@610: // For more information, see: http://eigen.tuxfamily.org alexbrandmeyer@610: #include alexbrandmeyer@609: using namespace Eigen; alexbrandmeyer@609: alexbrandmeyer@610: // One constant value is defined here, but see my TODO regarding style issues. alexbrandmeyer@610: // A fixed value of PI is defined throughout the project. alexbrandmeyer@610: // TODO alexbrandmeyer: verify that this is OK with Google Style. alexbrandmeyer@610: #define PI 3.141592653589793238 alexbrandmeyer@609: alexbrandmeyer@610: // Three typedefs are used for enabling quick switching of precision and array alexbrandmeyer@610: // usage. alexbrandmeyer@610: // The 'FPType' typedef is used to enable easy switching in precision level. alexbrandmeyer@610: typedef double FPType; alexbrandmeyer@610: // These are the two typedefs for Eigen floating point arrays. alexbrandmeyer@610: typedef Eigen::Array FloatArray; // This is a 1d array. alexbrandmeyer@610: typedef Eigen::Array FloatArray2d; // This is 2d. alexbrandmeyer@610: alexbrandmeyer@610: // Two psychoacoustics helper functions are defined here for use by the alexbrandmeyer@610: // different processing stages in calculating coeffecients. alexbrandmeyer@609: alexbrandmeyer@609: // Function: ERBHz alexbrandmeyer@609: // Auditory filter nominal Equivalent Rectangular Bandwidth alexbrandmeyer@609: // Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 alexbrandmeyer@609: FPType ERBHz(FPType cf_hz, FPType erb_break_freq, FPType erb_q); alexbrandmeyer@609: alexbrandmeyer@609: // Function CARFACDetect alexbrandmeyer@609: // TODO explain a bit more alexbrandmeyer@609: FloatArray CARFACDetect (FloatArray x); alexbrandmeyer@610: alexbrandmeyer@610: #endif