annotate carfac/carfac.h @ 662:7e18c84ca2b7

Small cleanup of eigen usage in SAI implementation.
author ronw@google.com
date Tue, 16 Jul 2013 19:56:11 +0000
parents 755c401da7a7
children
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@640 23 #ifndef CARFAC_CARFAC_H
alexbrandmeyer@640 24 #define CARFAC_CARFAC_H
alexbrandmeyer@609 25
alexbrandmeyer@640 26 #include <vector>
alexbrandmeyer@643 27
ronw@646 28 #include "agc.h"
ronw@646 29 #include "car.h"
alexbrandmeyer@643 30 #include "common.h"
alexbrandmeyer@643 31 #include "ihc.h"
alexbrandmeyer@609 32
ronw@647 33 class CARFACOutput;
ronw@647 34 class Ear;
ronw@647 35
ronw@646 36 // Top-level class implementing the CAR-FAC C++ model. See the chapter entitled
ronw@646 37 // 'The CAR-FAC Digital Cochlear Model' in Lyon's book "Human and Machine
ronw@646 38 // Hearing" for an overview.
alexbrandmeyer@643 39 //
alexbrandmeyer@643 40 // A CARFAC object knows how to design its details from a modest set of
alexbrandmeyer@643 41 // parameters, and knows how to process sound signals to produce "neural
ronw@646 42 // activity patterns" (NAPs) using CARFAC::RunSegment.
alexbrandmeyer@609 43 class CARFAC {
alexbrandmeyer@610 44 public:
ronw@646 45 // Constructs a vector of Ear objects, one for each input audio channel,
ronw@646 46 // using the given CAR, IHC and AGC parameters.
alexbrandmeyer@643 47 CARFAC(const int num_ears, const FPType sample_rate,
ronw@645 48 const CARParams& car_params, const IHCParams& ihc_params,
ronw@645 49 const AGCParams& agc_params);
ronw@648 50 ~CARFAC();
ronw@645 51
ronw@650 52 // Reinitialize using the specified parameters.
ronw@650 53 void Redesign(const int num_ears, const FPType sample_rate,
ronw@650 54 const CARParams& car_params, const IHCParams& ihc_params,
ronw@650 55 const AGCParams& agc_params);
ronw@650 56
ronw@650 57 // Reset the internal state so that subsequent calls to RunSegment are
ronw@650 58 // independent of previous calls. Does not modify the filterbank design.
ronw@650 59 void Reset();
ronw@645 60
ronw@646 61 // Processes an individual sound segment and copies the model output to
ronw@646 62 // seg_output.
ronw@646 63 //
ronw@646 64 // The input sound_data should contain a vector of audio samples for each
ronw@646 65 // ear.
alexbrandmeyer@626 66 void RunSegment(const std::vector<std::vector<float>>& sound_data,
alexbrandmeyer@626 67 const int32_t start, const int32_t length,
alexbrandmeyer@636 68 const bool open_loop, CARFACOutput* seg_output);
alexbrandmeyer@626 69
ronw@653 70 int num_channels() const { return num_channels_; }
ronw@653 71
alexbrandmeyer@610 72 private:
alexbrandmeyer@643 73 void DesignCARCoeffs(const CARParams& car_params, const FPType sample_rate,
alexbrandmeyer@643 74 const ArrayX& pole_freqs, CARCoeffs* car_coeffs);
alexbrandmeyer@643 75 void DesignIHCCoeffs(const IHCParams& ihc_params, const FPType sample_rate,
alexbrandmeyer@636 76 IHCCoeffs* ihc_coeffs);
alexbrandmeyer@643 77 void DesignAGCCoeffs(const AGCParams& agc_params, const FPType sample_rate,
alexbrandmeyer@636 78 std::vector<AGCCoeffs>* agc_coeffs);
alexbrandmeyer@610 79 void CrossCouple();
alexbrandmeyer@610 80 void CloseAGCLoop();
ronw@645 81
ronw@646 82 // Computes the nominal Equivalent Rectangular Bandwidth (ERB) of an auditory
ronw@646 83 // filter at the given center frequency.
alexbrandmeyer@643 84 // Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138
alexbrandmeyer@643 85 // See also the section 'Auditory Frequency Scales' of the chapter 'Acoustic
alexbrandmeyer@643 86 // Approaches and Auditory Influence' in "Human and Machine Hearing".
alexbrandmeyer@643 87 FPType ERBHz(const FPType center_frequency_hz, const FPType erb_break_freq,
ronw@646 88 const FPType erb_q) const;
ronw@641 89
alexbrandmeyer@643 90 CARParams car_params_;
alexbrandmeyer@643 91 IHCParams ihc_params_;
alexbrandmeyer@643 92 AGCParams agc_params_;
alexbrandmeyer@643 93 int num_ears_;
alexbrandmeyer@643 94 FPType sample_rate_;
alexbrandmeyer@643 95 int num_channels_;
alexbrandmeyer@610 96 FPType max_channels_per_octave_;
ronw@645 97
ronw@646 98 // One Ear per input audio channel.
ronw@645 99 std::vector<Ear*> ears_;
alexbrandmeyer@643 100 ArrayX pole_freqs_;
ronw@645 101
ronw@645 102 DISALLOW_COPY_AND_ASSIGN(CARFAC);
alexbrandmeyer@609 103 };
alexbrandmeyer@609 104
ronw@645 105 #endif // CARFAC_CARFAC_H