Mercurial > hg > aimc
changeset 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.
line wrap: on
line diff
--- a/trunk/C++/AGC.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGC.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"
--- a/trunk/C++/AGC.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGC.H 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"
--- a/trunk/C++/AGCCoeff.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCCoeff.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"
--- a/trunk/C++/AGCCoeff.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCCoeff.H 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"
--- a/trunk/C++/AGCParam.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCParam.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"
--- a/trunk/C++/AGCParam.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCParam.H 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"
--- a/trunk/C++/AGCState.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCState.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"
--- a/trunk/C++/AGCState.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/AGCState.H 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"
--- a/trunk/C++/CAR.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CAR.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" @@ -30,3 +30,62 @@ CAR::~CAR() { //dtor } + +void CAR::designFilters(FP_TYPE fs, int n_ch) { + // don't really need these zero arrays, but it's a clue to what fields + // and types are need in ohter language implementations: + coeff.r1_coeffs.resize(n_ch, 1); coeff.r1_coeffs-=coeff.r1_coeffs; // resize and zero + coeff.a0_coeffs.resize(n_ch, 1); coeff.a0_coeffs-=coeff.a0_coeffs; + coeff.c0_coeffs.resize(n_ch, 1); coeff.c0_coeffs-=coeff.c0_coeffs; + coeff.h_coeffs.resize(n_ch, 1); coeff.h_coeffs-=coeff.h_coeffs; + coeff.g0_coeffs.resize(n_ch, 1); coeff.g0_coeffs-=coeff.g0_coeffs; + // zr_coeffs is not zeroed ... perhaps it should be ? + +// zero_ratio comes in via h. In book's circuit D, zero_ratio is 1/sqrt(a), +// and that a is here 1 / (1+f) where h = f*c. +// solve for f: 1/zero_ratio^2 = 1 / (1+f) +// zero_ratio^2 = 1+f => f = zero_ratio^2 - 1 + FP_TYPE f = pow(param.zero_ratio,2.) - 1.; // nominally 1 for half-octave + +// Make pole positions, s and c coeffs, h and g coeffs, etc., +// which mostly depend on the pole angle theta: + Array<FP_TYPE, Dynamic, 1> theta = pole_freqs * (2. * M_PI / fs); + + +// undamped coupled-form coefficients: + coeff.c0_coeffs = theta.sin(); + coeff.a0_coeffs = theta.cos(); + +// different possible interpretations for min-damping r: +// r = exp(-theta * CF_CAR_params.min_zeta). +// Compress theta to give somewhat higher Q at highest thetas: + FP_TYPE ff = param.high_f_damping_compression; // 0 to 1 typ. 0.5 + Array<FP_TYPE, Dynamic,1> x = theta/M_PI; + + coeff.zr_coeffs = M_PI * (x - ff * x.pow(3.)); // when ff is 0, this is just theta, +// and when ff is 1 it goes to zero at theta = pi. + coeff.r1_coeffs = (1. - coeff.zr_coeffs.array() * param.max_zeta); // "r1" for the max-damping condition + +// Increase the min damping where channels are spaced out more, by pulling +// 25% of the way toward ERB_Hz/pole_freqs (close to 0.1 at high f) + Array<FP_TYPE, Dynamic, 1> min_zetas = param.min_zeta + 0.25*(PsychoAcoustics::Hz2ERB(pole_freqs, param.ERB_break_freq, param.ERB_Q).array() / pole_freqs - param.min_zeta); + coeff.zr_coeffs = coeff.zr_coeffs.array() * (param.max_zeta - min_zetas); // how r relates to undamping + +// the zeros follow via the h_coeffs + coeff.h_coeffs = coeff.c0_coeffs * f; + +// for unity gain at min damping, radius r; only used in CARFAC_Init: + Array<FP_TYPE, Dynamic,1> relative_undamping(n_ch, 1); + relative_undamping=(relative_undamping-=relative_undamping).cos();// what is an efficient way to set a matrix to 1. ? As this is in a design phase, I will leave it for now + +// this function needs to take CAR_coeffs even if we haven't finished +// constucting it by putting in the g0_coeffs: + coeff.g0_coeffs = stageG(relative_undamping); + +} + +Array<FP_TYPE, Dynamic, 1> CAR::stageG(Array<FP_TYPE, Dynamic, 1> &relative_undamping) { + // at max damping + Array<FP_TYPE, Dynamic, 1> r = coeff.r1_coeffs.array() + coeff.zr_coeffs.array() * relative_undamping; + return (1. - 2.*r*coeff.a0_coeffs.array() + r.pow(2.)) / (1. - 2.*r*coeff.a0_coeffs.array() + coeff.h_coeffs.array()*r*coeff.c0_coeffs.array() + pow(r,2.)); +}
--- a/trunk/C++/CAR.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CAR.H 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" @@ -21,6 +21,8 @@ #include "EarComponent.H" // includes the various {CAR, IHC, AGC} {Coeff, Param, State} .H files +class Ear; + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08 @@ -28,9 +30,26 @@ Cascade of asymmetric resonators (CAR). */ class CAR : public EarComponent<CARCoeff, CARParam, CARState> { + Array<FP_TYPE, Dynamic,1> pole_freqs; ///< The vector of pole frequencies used in filter design and variable estimation + + protected: + + /** Method to design the auditory filter coefficients + \param fs The sample rate in Hz + */ + void designFilters(FP_TYPE fs, int n_ch); + + /** Return the stage gain g needed to get unity gain at DC + \param relative_undamping Dick whats this ? + \return The stage gain required to obtain 0 dB at DC. + */ + Array<FP_TYPE, Dynamic, 1> stageG(Array<FP_TYPE, Dynamic, 1> &relative_undamping); + public: CAR(); virtual ~CAR(); + + friend class Ear; }; #endif // CAR_H_
--- a/trunk/C++/CARCoeff.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARCoeff.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"
--- a/trunk/C++/CARCoeff.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARCoeff.H 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" @@ -21,6 +21,8 @@ #include "Coefficients.H" +class CAR; // required for decleration as a friend + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08 @@ -28,9 +30,18 @@ Coefficients for the Cascaded Auditory Resonators */ class CARCoeff : public Coefficients { + Matrix<FP_TYPE, Dynamic,1> r1_coeffs; ///< Dick, whats this ? + Matrix<FP_TYPE, Dynamic,1> a0_coeffs; ///< Dick, whats this ? + Matrix<FP_TYPE, Dynamic,1> c0_coeffs; ///< Dick, whats this ? + Matrix<FP_TYPE, Dynamic,1> h_coeffs; ///< Dick, whats this ? + Matrix<FP_TYPE, Dynamic,1> g0_coeffs; ///< Dick, whats this ? + Matrix<FP_TYPE, Dynamic,1> zr_coeffs; ///< Dick, whats this ? + public: - CARCoeff(); - virtual ~CARCoeff(); + CARCoeff(); ///< Constructor + virtual ~CARCoeff(); ///< Destructor + + friend class CAR; }; #endif // CARCOEFFS_H_
--- a/trunk/C++/CARFACCommon.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARFACCommon.H 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" @@ -21,12 +21,15 @@ typedef float FP_TYPE; ///< The floating point type #define AGC_STAGE_COUNT 4 ///< The number of cascades in the AGC +#define DEFAULT_SAMPLERATE 22050. ///< The default sample rate in Hz #include <iostream> using namespace std; #include <Eigen/Dense> using namespace Eigen; +#include "PsychoAcoustics.H" + /** \mainpage CARFAC C++
--- a/trunk/C++/CARParam.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARParam.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"
--- a/trunk/C++/CARParam.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARParam.H 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" @@ -21,6 +21,9 @@ #include "Parameters.H" +class CAR; // required for decleration as a friend +class Ear; + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08 @@ -48,6 +51,9 @@ FP_TYPE ERB_per_step_=0.5, FP_TYPE min_pole_Hz_=30., FP_TYPE ERB_break_freq_=165.3, FP_TYPE ERB_Q_=1000./(24.7*4.37)); virtual ~CARParam(); ///< Destructor + + friend class CAR; + friend class Ear; }; #endif // CARPARAMS_H_
--- a/trunk/C++/CARState.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARState.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"
--- a/trunk/C++/CARState.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/CARState.H 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"
--- a/trunk/C++/Coefficients.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Coefficients.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"
--- a/trunk/C++/Coefficients.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Coefficients.H 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" @@ -19,6 +19,8 @@ #ifndef COEFFICIENTS_H_ #define COEFFICIENTS_H_ +#include "CARFACCommon.H" + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08
--- 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); +}
--- a/trunk/C++/Ear.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Ear.H 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" @@ -30,14 +30,28 @@ Class which encapsulates an ear, using the CAR, IHC and AGC classes */ class Ear { + FP_TYPE fs; ///< The sample rate + FP_TYPE max_channels_per_octave; ///< How many channels in each octave + int n_ch; ///< The number of channels (in the ear) - CAR car; ///< The cascade of asymmetric resontaors for this ear - IHC ihc; ///< The inner hair cell for this ear - AGC agc; ///< The automatic gain control for this ear + CAR car; ///< The cascade of asymmetric resontaors for this ear + IHC ihc; ///< The inner hair cell for this ear + AGC agc; ///< The automatic gain control for this ear public: - Ear(); - virtual ~Ear(); + /** Constructor specifying the sample rate + \param fs_ The sample rate to use + */ + Ear(FP_TYPE fs_); + + /** Constructor using the DEFAULT_SAMPLERATE as the sample rate + */ + Ear(void); + virtual ~Ear(void); + + /** Estimates the number of filter stages and executes the dsign method for each of CAR, AGC and IHC + */ + void design(void); }; #endif // EAR_H_
--- a/trunk/C++/EarComponent.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/EarComponent.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"
--- a/trunk/C++/EarComponent.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/EarComponent.H 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" @@ -29,6 +29,8 @@ #include "IHCParam.H" #include "IHCState.H" +#include "CARFACCommon.H" + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08 @@ -43,7 +45,7 @@ PARAMTYPE param; STATETYPE state; public: - EarComponent(){} + EarComponent() {} virtual ~EarComponent(){} };
--- a/trunk/C++/Ears.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Ears.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"
--- a/trunk/C++/Ears.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Ears.H 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"
--- a/trunk/C++/IHC.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHC.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"
--- a/trunk/C++/IHC.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHC.H 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"
--- a/trunk/C++/IHCCoeff.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCCoeff.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"
--- a/trunk/C++/IHCCoeff.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCCoeff.H 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"
--- a/trunk/C++/IHCParam.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCParam.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"
--- a/trunk/C++/IHCParam.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCParam.H 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"
--- a/trunk/C++/IHCState.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCState.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"
--- a/trunk/C++/IHCState.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/IHCState.H 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"
--- a/trunk/C++/Makefile Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Makefile Wed Feb 20 22:30:19 2013 +0000 @@ -20,12 +20,12 @@ # Author : Matt Flax <flatmax\@> # Date : 2012.02.08 -SRC= AGC.C AGCCoeff.C AGCParam.C AGCState.C CAR.C CARCoeff.C CARParam.C CARState.C Coefficients.C Ear.C EarComponent.C Ears.C IHC.C IHCCoeff.C IHCParam.C IHCState.C Parameters.C State.C +SRC= AGC.C AGCCoeff.C AGCParam.C AGCState.C CAR.C CARCoeff.C CARParam.C CARState.C Coefficients.C Ear.C EarComponent.C Ears.C IHC.C IHCCoeff.C IHCParam.C IHCState.C Parameters.C State.C PsychoAcoustics.C OBJ= $(SRC:.C=.o) -CFLAGS = `pkg-config --cflags eigen3` #-std=c++0x +CFLAGS = `pkg-config --cflags eigen3` -all: lib +all: lib ex VERMAJ=1 VERMIN=0 @@ -40,6 +40,9 @@ ln -sf ${LIBNAME} ${LIBNAMEMAJ} ln -sf ${LIBNAMEMAJ} ${LIBNAMEBASE} +ex: + ${CXX} ${CFLAGS} -I`pwd` -o test/EarTest test/EarTest.C -L`pwd` -lCARFAC + doc: doxygen Doxyfile
--- a/trunk/C++/Parameters.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Parameters.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"
--- a/trunk/C++/Parameters.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/Parameters.H 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"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/C++/PsychoAcoustics.C Wed Feb 20 22:30:19 2013 +0000 @@ -0,0 +1,32 @@ +// Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. +// 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" +// to supplement Lyon's upcoming book "Human and Machine Hearing" +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "PsychoAcoustics.H" + +/** + \author {Matt Flax <flatmax\@>} + \date 2013.02.08 +*/ + +FP_TYPE PsychoAcoustics::Hz2ERB(FP_TYPE CFHz, FP_TYPE ERBBreakFreq, FP_TYPE ERBQ){ + return (ERBBreakFreq + CFHz) / ERBQ; +} + +Array<FP_TYPE, Dynamic, 1> PsychoAcoustics::Hz2ERB(Array<FP_TYPE, Dynamic, 1> &CFHz, FP_TYPE ERBBreakFreq, FP_TYPE ERBQ){ + return (ERBBreakFreq + CFHz) / ERBQ; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/C++/PsychoAcoustics.H Wed Feb 20 22:30:19 2013 +0000 @@ -0,0 +1,48 @@ +// Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. +// 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" +// to supplement Lyon's upcoming book "Human and Machine Hearing" +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef PSYCHOACOUSTICS_H_ +#define PSYCHOACOUSTICS_H_ + +#include "CARFACCommon.H" + +class PsychoAcoustics { +public: + PsychoAcoustics() {} + virtual ~PsychoAcoustics() {} + + /** Auditory filter nominal Equivalent Rectangular Bandwidth + Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 + ERB = 24.7 * (1 + 4.37 * CF_Hz / 1000); + \param CFHz The central frequency to find the ERB at. + \param ERBBreakFreq The linear scaling factor for frequency + \param ERBQ The tuning of the rectangular bandwidth + */ + static FP_TYPE Hz2ERB(FP_TYPE CFHz, FP_TYPE ERBBreakFreq=1000./4.37 /* 228.833 */, FP_TYPE ERBQ=1000./(24.7*4.37) /* 9.2645 */); + + /** Auditory filter nominal Equivalent Rectangular Bandwidth + Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138 + ERB = 24.7 * (1 + 4.37 * CF_Hz / 1000); + \param CFHz The central frequency to find the ERB at. + \param ERBBreakFreq The linear scaling factor for frequency + \param ERBQ The tuning of the rectangular bandwidth + */ + static Array<FP_TYPE, Dynamic, 1> Hz2ERB(Array<FP_TYPE, Dynamic, 1> &CFHz, FP_TYPE ERBBreakFreq=1000./4.37 /* 228.833 */, FP_TYPE ERBQ=1000./(24.7*4.37) /* 9.2645 */); +}; + +#endif // PSYCHOACOUSTICS_H_
--- a/trunk/C++/State.C Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/State.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"
--- a/trunk/C++/State.H Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/State.H 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" @@ -19,6 +19,8 @@ #ifndef STATE_H_ #define STATE_H_ +#include "CARFACCommon.H" + /** \author {Matt Flax <flatmax\@>} \date 2013.02.08
--- a/trunk/C++/codeblocks/CARFAC.cbp Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/codeblocks/CARFAC.cbp Wed Feb 20 22:30:19 2013 +0000 @@ -101,10 +101,17 @@ <Option compilerVar="CC" /> </Unit> <Unit filename="../Parameters.H" /> + <Unit filename="../PsychoAcoustics.C"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="../PsychoAcoustics.H" /> <Unit filename="../State.C"> <Option compilerVar="CC" /> </Unit> <Unit filename="../State.H" /> + <Unit filename="../test/EarTest.C"> + <Option compilerVar="CC" /> + </Unit> <Extensions> <code_completion /> <envvars />
--- a/trunk/C++/codeblocks/CARFAC.layout Sat Feb 09 23:53:48 2013 +0000 +++ b/trunk/C++/codeblocks/CARFAC.layout Wed Feb 20 22:30:19 2013 +0000 @@ -1,118 +1,127 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="../AGC.C" open="1" top="0" tabpos="2"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../AGC.H" open="1" top="0" tabpos="3"> - <Cursor position="1028" topLine="0" /> - </File> - <File name="../AGCCoeff.C" open="1" top="0" tabpos="4"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../AGCCoeff.H" open="1" top="0" tabpos="5"> - <Cursor position="969" topLine="0" /> - </File> - <File name="../AGCParam.C" open="1" top="0" tabpos="6"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../AGCParam.H" open="1" top="0" tabpos="7"> - <Cursor position="967" topLine="0" /> - </File> - <File name="../AGCState.C" open="1" top="0" tabpos="8"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../AGCState.H" open="1" top="0" tabpos="9"> - <Cursor position="960" topLine="0" /> - </File> - <File name="../CAR.C" open="1" top="0" tabpos="10"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../CAR.H" open="1" top="0" tabpos="11"> - <Cursor position="1028" topLine="0" /> - </File> - <File name="../CARCoeff.C" open="1" top="0" tabpos="12"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../CARCoeff.H" open="1" top="0" tabpos="13"> - <Cursor position="969" topLine="0" /> - </File> - <File name="../CARFACCommon.H" open="1" top="1" tabpos="1"> - <Cursor position="5661" topLine="113" /> - </File> - <File name="../CARParam.C" open="1" top="0" tabpos="14"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../CARParam.H" open="1" top="0" tabpos="15"> - <Cursor position="967" topLine="0" /> - </File> - <File name="../CARState.C" open="1" top="0" tabpos="16"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../CARState.H" open="1" top="0" tabpos="17"> - <Cursor position="960" topLine="0" /> - </File> - <File name="../Coefficients.C" open="1" top="0" tabpos="18"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../Coefficients.H" open="1" top="0" tabpos="19"> - <Cursor position="948" topLine="0" /> - </File> - <File name="../Ear.C" open="1" top="0" tabpos="20"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../Ear.H" open="1" top="0" tabpos="21"> - <Cursor position="982" topLine="2" /> - </File> - <File name="../EarComponent.C" open="1" top="0" tabpos="22"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../EarComponent.H" open="1" top="0" tabpos="23"> - <Cursor position="1290" topLine="8" /> - </File> - <File name="../Ears.C" open="1" top="0" tabpos="24"> - <Cursor position="899" topLine="0" /> - </File> - <File name="../Ears.H" open="1" top="0" tabpos="25"> + <File name="../AGC.C" open="0" top="0" tabpos="2"> <Cursor position="94" topLine="0" /> </File> - <File name="../IHC.C" open="1" top="0" tabpos="26"> - <Cursor position="899" topLine="0" /> + <File name="../AGC.H" open="0" top="0" tabpos="3"> + <Cursor position="94" topLine="0" /> </File> - <File name="../IHC.H" open="1" top="0" tabpos="27"> - <Cursor position="1028" topLine="0" /> + <File name="../AGCCoeff.C" open="0" top="0" tabpos="4"> + <Cursor position="94" topLine="0" /> </File> - <File name="../IHCCoeff.C" open="1" top="0" tabpos="28"> - <Cursor position="899" topLine="0" /> + <File name="../AGCCoeff.H" open="0" top="0" tabpos="5"> + <Cursor position="94" topLine="0" /> </File> - <File name="../IHCCoeff.H" open="1" top="0" tabpos="29"> - <Cursor position="969" topLine="0" /> + <File name="../AGCParam.C" open="0" top="0" tabpos="5"> + <Cursor position="94" topLine="1" /> </File> - <File name="../IHCParam.C" open="1" top="0" tabpos="30"> - <Cursor position="899" topLine="0" /> + <File name="../AGCParam.H" open="0" top="0" tabpos="5"> + <Cursor position="1149" topLine="13" /> </File> - <File name="../IHCParam.H" open="1" top="0" tabpos="31"> - <Cursor position="967" topLine="0" /> + <File name="../AGCState.C" open="0" top="0" tabpos="8"> + <Cursor position="94" topLine="0" /> </File> - <File name="../IHCState.C" open="1" top="0" tabpos="32"> - <Cursor position="899" topLine="0" /> + <File name="../AGCState.H" open="0" top="0" tabpos="9"> + <Cursor position="94" topLine="0" /> </File> - <File name="../IHCState.H" open="1" top="0" tabpos="33"> - <Cursor position="960" topLine="0" /> + <File name="../CAR.C" open="1" top="0" tabpos="1"> + <Cursor position="3569" topLine="65" /> </File> - <File name="../Makefile" open="1" top="0" tabpos="34"> - <Cursor position="876" topLine="0" /> + <File name="../CAR.H" open="1" top="0" tabpos="2"> + <Cursor position="1679" topLine="26" /> </File> - <File name="../Parameters.C" open="1" top="0" tabpos="35"> - <Cursor position="899" topLine="0" /> + <File name="../CARCoeff.C" open="0" top="0" tabpos="12"> + <Cursor position="94" topLine="0" /> </File> - <File name="../Parameters.H" open="1" top="0" tabpos="36"> - <Cursor position="971" topLine="0" /> + <File name="../CARCoeff.H" open="1" top="0" tabpos="8"> + <Cursor position="1536" topLine="20" /> </File> - <File name="../State.C" open="1" top="0" tabpos="37"> - <Cursor position="899" topLine="0" /> + <File name="../CARFACCommon.H" open="1" top="0" tabpos="7"> + <Cursor position="2156" topLine="46" /> </File> - <File name="../State.H" open="1" top="0" tabpos="38"> - <Cursor position="934" topLine="0" /> + <File name="../CARParam.C" open="0" top="0" tabpos="7"> + <Cursor position="94" topLine="16" /> + </File> + <File name="../CARParam.H" open="0" top="0" tabpos="3"> + <Cursor position="2340" topLine="31" /> + </File> + <File name="../CARState.C" open="0" top="0" tabpos="16"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../CARState.H" open="0" top="0" tabpos="17"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../Coefficients.C" open="0" top="0" tabpos="18"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../Coefficients.H" open="1" top="0" tabpos="10"> + <Cursor position="1139" topLine="12" /> + </File> + <File name="../Ear.C" open="1" top="1" tabpos="3"> + <Cursor position="2174" topLine="25" /> + </File> + <File name="../Ear.H" open="1" top="0" tabpos="4"> + <Cursor position="1086" topLine="18" /> + </File> + <File name="../EarComponent.C" open="0" top="0" tabpos="6"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../EarComponent.H" open="1" top="0" tabpos="9"> + <Cursor position="1541" topLine="26" /> + </File> + <File name="../Ears.C" open="0" top="0" tabpos="24"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../Ears.H" open="0" top="0" tabpos="25"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHC.C" open="0" top="0" tabpos="26"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHC.H" open="0" top="0" tabpos="27"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCCoeff.C" open="0" top="0" tabpos="28"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCCoeff.H" open="0" top="0" tabpos="29"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCParam.C" open="0" top="0" tabpos="30"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCParam.H" open="0" top="0" tabpos="31"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCState.C" open="0" top="0" tabpos="32"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../IHCState.H" open="0" top="0" tabpos="33"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../Makefile" open="1" top="0" tabpos="6"> + <Cursor position="1159" topLine="9" /> + </File> + <File name="../Parameters.C" open="0" top="0" tabpos="35"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../Parameters.H" open="1" top="0" tabpos="11"> + <Cursor position="1125" topLine="12" /> + </File> + <File name="../PsychoAcoustics.C" open="0" top="0" tabpos="8"> + <Cursor position="889" topLine="6" /> + </File> + <File name="../PsychoAcoustics.H" open="0" top="0" tabpos="7"> + <Cursor position="1955" topLine="19" /> + </File> + <File name="../State.C" open="0" top="0" tabpos="37"> + <Cursor position="94" topLine="0" /> + </File> + <File name="../State.H" open="1" top="0" tabpos="12"> + <Cursor position="1095" topLine="12" /> + </File> + <File name="../test/EarTest.C" open="1" top="0" tabpos="5"> + <Cursor position="989" topLine="4" /> </File> </CodeBlocks_layout_file>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/C++/test/EarTest.C Wed Feb 20 22:30:19 2013 +0000 @@ -0,0 +1,32 @@ +// Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved. +// 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" +// to supplement Lyon's upcoming book "Human and Machine Hearing" +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +/** + \author {Matt Flax <flatmax\@>} + \date 2013.02.08 +*/ + +#include "Ear.H" + +//int main(int argc, char *argv[]){ +int main(){ + + Ear ear; + + return 0; +}