annotate carfac/carfac.h @ 611:0fbaf443ec82

Carfac C++ revision 3, indluding more style improvements. The output structs are now classes again, and have separate storage methods for each output structure along with flags in the Run and RunSegment methods to allow for only storing NAPs if desired.
author alexbrandmeyer
date Fri, 17 May 2013 19:52:45 +0000
parents 01986636257a
children 586b0677aae8
rev   line source
alexbrandmeyer@609 1 //
alexbrandmeyer@609 2 // carfac.h
alexbrandmeyer@609 3 // CARFAC Open Source C++ Library
alexbrandmeyer@609 4 //
alexbrandmeyer@609 5 // Created by Alex Brandmeyer on 5/10/13.
alexbrandmeyer@609 6 //
alexbrandmeyer@609 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@609 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@609 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@609 10 //
alexbrandmeyer@609 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@609 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@609 13 // You may obtain a copy of the License at
alexbrandmeyer@609 14 //
alexbrandmeyer@609 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@609 16 //
alexbrandmeyer@609 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@609 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@609 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@609 20 // See the License for the specific language governing permissions and
alexbrandmeyer@609 21 // limitations under the License.
alexbrandmeyer@609 22 //
alexbrandmeyer@609 23 // *****************************************************************************
alexbrandmeyer@609 24 // Class: CARFAC
alexbrandmeyer@609 25 // *****************************************************************************
alexbrandmeyer@609 26 // The CARFAC class is the top-level class implementing the CAR-FAC C++ model.
alexbrandmeyer@609 27 // A CARFAC object knows how to design its details from a modest set of
alexbrandmeyer@609 28 // parameters, and knows how to process sound signals to produce "neural
alexbrandmeyer@609 29 // activity patterns" (NAPs) which are contained in a CARFACOutput object.
alexbrandmeyer@609 30 //
alexbrandmeyer@609 31 // The 'Design' method is used to intialize the CARFAC model, and is passed
alexbrandmeyer@609 32 // a set of CAR, IHC and AGC parameters along with sound file information
alexbrandmeyer@609 33 // (channels and sample rate).
alexbrandmeyer@609 34 //
alexbrandmeyer@609 35 // The two methods 'Run' and 'RunSegment' are responsible for
alexbrandmeyer@609 36 // processing sound signals. These both take two dimensional Eigen float arrays
alexbrandmeyer@609 37 // (samples x channels) as arguments and return CARFACOutput objects.
alexbrandmeyer@609 38
alexbrandmeyer@609 39 #ifndef CARFAC_Open_Source_C__Library_CARFAC_h
alexbrandmeyer@609 40 #define CARFAC_Open_Source_C__Library_CARFAC_h
alexbrandmeyer@609 41
alexbrandmeyer@609 42 #include "ear.h"
alexbrandmeyer@609 43 #include "carfac_output.h"
alexbrandmeyer@609 44
alexbrandmeyer@609 45 class CARFAC {
alexbrandmeyer@610 46 public:
alexbrandmeyer@609 47 // The 'Design' method takes a set of CAR, IHC and AGC parameters along with
alexbrandmeyer@609 48 // arguments specifying the number of 'ears' (audio file channels) and sample
alexbrandmeyer@609 49 // rate. This initializes a vector of 'Ear' objects -- one for mono, two for
alexbrandmeyer@609 50 // stereo, or more. Each 'Ear' includes various sub-objects representing the
alexbrandmeyer@609 51 // parameters, designs (coeffs) ,and states of different parts of the CAR-FAC
alexbrandmeyer@609 52 // model.
alexbrandmeyer@611 53 void Design(int n_ears, int32_t fs, CARParams car_params, IHCParams ihc_params,
alexbrandmeyer@609 54 AGCParams agc_params);
alexbrandmeyer@610 55 // The 'Run' method processes an entire file with the current model, using
alexbrandmeyer@610 56 // subsequent calls to the 'RunSegment' method
alexbrandmeyer@611 57 CARFACOutput Run(FloatArray2d sound_data, bool open_loop, bool store_bm,
alexbrandmeyer@611 58 bool store_ohc, bool store_agc);
alexbrandmeyer@610 59 // The 'RunSegment' method processes individual sound segments
alexbrandmeyer@610 60 void RunSegment(FloatArray2d sound_data, CARFACOutput *seg_output,
alexbrandmeyer@611 61 bool open_loop, bool store_bm, bool store_ohc,
alexbrandmeyer@611 62 bool store_agc);
alexbrandmeyer@609 63
alexbrandmeyer@610 64 private:
alexbrandmeyer@610 65 void CrossCouple();
alexbrandmeyer@610 66 void CloseAGCLoop();
alexbrandmeyer@609 67
alexbrandmeyer@610 68 int n_ears_; // This is the number of ears.
alexbrandmeyer@611 69 int32_t fs_; // This is our current sample rate.
alexbrandmeyer@610 70 int n_ch_; // This is the number of channels in the CARFAC model.
alexbrandmeyer@610 71 FPType max_channels_per_octave_;
alexbrandmeyer@610 72 // We store an array of Ear objects for mono/stereo/multichannel processing:
alexbrandmeyer@611 73 std::vector<Ear> ears_;
alexbrandmeyer@609 74 };
alexbrandmeyer@609 75
alexbrandmeyer@610 76 #endif