Mercurial > hg > aimc
diff trunk/C++/Ear.C @ 598:34dccba19c54
Fixed certain minor documentation bugs.
Added the CAR::designFilters and CAR::stageG methods. These methods design the CAR.coeff coefficients. They have been compared to be the same as the matlab coefficients.
An Ear is now contructed with a specific FS or, it uses the default.
Added the PsychoAcoustics class to do ERB and Hz conversions.
Added the EarTest.C main which allows the construction of an Ear class for testing.
author | flatmax |
---|---|
date | Wed, 20 Feb 2013 22:30:19 +0000 |
parents | 359bcd461dd1 |
children | b8a27b613867 |
line wrap: on
line diff
--- a/trunk/C++/Ear.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Ear.C Wed Feb 20 22:30:19 2013 +0000 @@ -1,5 +1,5 @@ // Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. -// Author Matt Flax <flatmax\@> +// Author Matt Flax <flatmax@> // // This C++ file is part of an implementation of Lyon's cochlear model: // "Cascade of Asymmetric Resonators with Fast-Acting Compression" @@ -23,10 +23,44 @@ #include "Ear.H" -Ear::Ear() { - //ctor +Ear::Ear(FP_TYPE fs_) { + fs=fs_; // set the specified sample rate + design(); } -Ear::~Ear() { - //dtor +Ear::Ear(void) { + fs=DEFAULT_SAMPLERATE; // Use the default sample rate + design(); } + +Ear::~Ear(void) { +} + +void Ear::design(void) { + + // first figure out how many filter stages (PZFC/car.AC channels): + FP_TYPE pole_Hz = car.param.first_pole_theta * fs / (2.*M_PI); + n_ch = 0; + while (pole_Hz > car.param.min_pole_Hz) { + n_ch = n_ch + 1; + pole_Hz = pole_Hz - car.param.ERB_per_step * + PsychoAcoustics::Hz2ERB(pole_Hz, car.param.ERB_break_freq, car.param.ERB_Q); + } + // Now we have n_ch, the number of channels, so can make the array + // and compute all the frequencies again to put into it: + car.pole_freqs.resize(n_ch, NoChange); + pole_Hz = car.param.first_pole_theta * fs / (2.*M_PI); + for (int ch = 0; ch<n_ch; ch++) { + car.pole_freqs[ch] = pole_Hz; + pole_Hz = pole_Hz - car.param.ERB_per_step * + PsychoAcoustics::Hz2ERB(pole_Hz, car.param.ERB_break_freq, car.param.ERB_Q); + } + // now we have n_ch, the number of channels, and pole_freqs array + + max_channels_per_octave = (FP_TYPE)(log(2.) / log(car.pole_freqs[0]/car.pole_freqs[1])); + + // convert to include an ear_array, each w coeffs and state... + car.designFilters(fs, n_ch); //(car.param. fs, car.pole_freqs); + //AGC.designAGC(CF_AGC_params, fs, n_ch); + //IHC.designIHC(CF_IHC_params, fs, n_ch); +}