alexbrandmeyer@609: // alexbrandmeyer@609: // carfac.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: // Class: CARFAC alexbrandmeyer@609: // ***************************************************************************** alexbrandmeyer@609: // The CARFAC class is the top-level class implementing the CAR-FAC C++ model. alexbrandmeyer@609: // A CARFAC object knows how to design its details from a modest set of alexbrandmeyer@609: // parameters, and knows how to process sound signals to produce "neural alexbrandmeyer@609: // activity patterns" (NAPs) which are contained in a CARFACOutput object. alexbrandmeyer@609: // alexbrandmeyer@609: // The 'Design' method is used to intialize the CARFAC model, and is passed alexbrandmeyer@609: // a set of CAR, IHC and AGC parameters along with sound file information alexbrandmeyer@609: // (channels and sample rate). alexbrandmeyer@609: // alexbrandmeyer@609: // The two methods 'Run' and 'RunSegment' are responsible for alexbrandmeyer@609: // processing sound signals. These both take two dimensional Eigen float arrays alexbrandmeyer@609: // (samples x channels) as arguments and return CARFACOutput objects. alexbrandmeyer@609: alexbrandmeyer@609: #ifndef CARFAC_Open_Source_C__Library_CARFAC_h alexbrandmeyer@609: #define CARFAC_Open_Source_C__Library_CARFAC_h alexbrandmeyer@609: alexbrandmeyer@609: #include "ear.h" alexbrandmeyer@609: #include "carfac_output.h" alexbrandmeyer@609: alexbrandmeyer@609: class CARFAC { alexbrandmeyer@610: public: alexbrandmeyer@609: // The 'Design' method takes a set of CAR, IHC and AGC parameters along with alexbrandmeyer@609: // arguments specifying the number of 'ears' (audio file channels) and sample alexbrandmeyer@609: // rate. This initializes a vector of 'Ear' objects -- one for mono, two for alexbrandmeyer@609: // stereo, or more. Each 'Ear' includes various sub-objects representing the alexbrandmeyer@609: // parameters, designs (coeffs) ,and states of different parts of the CAR-FAC alexbrandmeyer@609: // model. alexbrandmeyer@609: void Design(int n_ears, long fs, CARParams car_params, IHCParams ihc_params, alexbrandmeyer@609: AGCParams agc_params); alexbrandmeyer@610: // The 'Run' method processes an entire file with the current model, using alexbrandmeyer@610: // subsequent calls to the 'RunSegment' method alexbrandmeyer@610: CARFACOutput Run(FloatArray2d sound_data, bool open_loop); alexbrandmeyer@610: // The 'RunSegment' method processes individual sound segments alexbrandmeyer@610: void RunSegment(FloatArray2d sound_data, CARFACOutput *seg_output, alexbrandmeyer@610: bool open_loop); alexbrandmeyer@609: alexbrandmeyer@610: private: alexbrandmeyer@610: void CrossCouple(); alexbrandmeyer@610: void CloseAGCLoop(); alexbrandmeyer@609: alexbrandmeyer@610: int n_ears_; // This is the number of ears. alexbrandmeyer@610: long fs_; // This is our current sample rate. alexbrandmeyer@610: int n_ch_; // This is the number of channels in the CARFAC model. alexbrandmeyer@610: FPType max_channels_per_octave_; alexbrandmeyer@610: // We store an array of Ear objects for mono/stereo/multichannel processing: alexbrandmeyer@610: Ear *ears_; alexbrandmeyer@609: }; alexbrandmeyer@609: alexbrandmeyer@610: #endif