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@609
|
53 void Design(int n_ears, long 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@610
|
57 CARFACOutput Run(FloatArray2d sound_data, bool open_loop);
|
alexbrandmeyer@610
|
58 // The 'RunSegment' method processes individual sound segments
|
alexbrandmeyer@610
|
59 void RunSegment(FloatArray2d sound_data, CARFACOutput *seg_output,
|
alexbrandmeyer@610
|
60 bool open_loop);
|
alexbrandmeyer@609
|
61
|
alexbrandmeyer@610
|
62 private:
|
alexbrandmeyer@610
|
63 void CrossCouple();
|
alexbrandmeyer@610
|
64 void CloseAGCLoop();
|
alexbrandmeyer@609
|
65
|
alexbrandmeyer@610
|
66 int n_ears_; // This is the number of ears.
|
alexbrandmeyer@610
|
67 long fs_; // This is our current sample rate.
|
alexbrandmeyer@610
|
68 int n_ch_; // This is the number of channels in the CARFAC model.
|
alexbrandmeyer@610
|
69 FPType max_channels_per_octave_;
|
alexbrandmeyer@610
|
70 // We store an array of Ear objects for mono/stereo/multichannel processing:
|
alexbrandmeyer@610
|
71 Ear *ears_;
|
alexbrandmeyer@609
|
72 };
|
alexbrandmeyer@609
|
73
|
alexbrandmeyer@610
|
74 #endif |