annotate carfac/carfac.h @ 635:0bdd58ee6e92

ffmpeg no longer accepts a qscale value of 0. Changed qscale to 1, which also gives a very high quality output
author sness@sness.net
date Fri, 24 May 2013 22:38:09 +0000
parents 6a13139d4b71
children 27f2d9b76075
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@626 53 void Design(const int n_ears, const FPType fs, const CARParams& car_params,
alexbrandmeyer@626 54 const IHCParams& ihc_params, const 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@626 57 CARFACOutput Run(const std::vector<std::vector<float>>& sound_data);
alexbrandmeyer@610 58 // The 'RunSegment' method processes individual sound segments
alexbrandmeyer@626 59 void RunSegment(const std::vector<std::vector<float>>& sound_data,
alexbrandmeyer@626 60 const int32_t start, const int32_t length,
alexbrandmeyer@626 61 CARFACOutput* seg_output, const bool open_loop);
alexbrandmeyer@626 62
alexbrandmeyer@610 63 private:
alexbrandmeyer@610 64 void CrossCouple();
alexbrandmeyer@610 65 void CloseAGCLoop();
alexbrandmeyer@610 66 int n_ears_; // This is the number of ears.
alexbrandmeyer@626 67 FPType 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@611 71 std::vector<Ear> ears_;
alexbrandmeyer@626 72 FloatArray pole_freqs_;
alexbrandmeyer@609 73 };
alexbrandmeyer@609 74
ronw@630 75 #endif