00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "MeddisHairCell.h"
00020
00021
00022 using std::ostringstream;
00023 using std::max;
00024 using std::min;
00025
00026 using namespace Marsyas;
00027
00028 MeddisHairCell::MeddisHairCell(mrs_string name):MarSystem("MeddisHairCell",name)
00029 {
00030
00031
00032
00033 numChannels = 0;
00034
00035 addControls();
00036 }
00037
00038 MeddisHairCell::~MeddisHairCell()
00039 {
00040 }
00041
00042 MarSystem*
00043 MeddisHairCell::clone() const
00044 {
00045 return new MeddisHairCell(*this);
00046 }
00047
00048 void MeddisHairCell::addControls()
00049 {
00050 addctrl("mrs_bool/subtractSpont", false);
00051 }
00052
00053 void
00054 MeddisHairCell::myUpdate(MarControlPtr sender)
00055 {
00056 MRSDIAG("MeddisHairCell.cpp - MeddisHairCell:myUpdate");
00057
00058
00059
00060
00061 MarSystem::myUpdate(sender);
00062
00063
00064 M = 1;
00065 A = 5;
00066 B = 300;
00067 g = 2000;
00068 y = 5.05f;
00069 l = 2500;
00070 r = 6580;
00071 x = 66.31f;
00072 h = 50000;
00073
00074
00075 dt = 1/getctrl("mrs_real/israte")->to<mrs_real>();
00076 gdt = g*dt;
00077 ydt = y*dt;
00078 ldt = l*dt;
00079 rdt = r*dt;
00080 xdt = x*dt;
00081
00082
00083 kt = g*A/(A + B);
00084 spont = M*y*kt/(l*kt+y*(l + r));
00085
00086 if (numChannels != getctrl("mrs_natural/inSamples")->to<mrs_natural>()){
00087 numChannels = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00088 c.create(numChannels);
00089 q.create(numChannels);
00090 w.create(numChannels);
00091 for (mrs_natural i = 0; i < numChannels; ++i){
00092 c(i) = spont;
00093 q(i) = c(i)*(l + r)/kt;
00094 w(i) = c(i)*r/x;
00095 }
00096 }
00097 }
00098
00099 void
00100 MeddisHairCell::myProcess(realvec& in, realvec& out)
00101 {
00102 checkFlow(in, out);
00103
00104 if(getctrl("mrs_bool/mute")->to<mrs_bool>()) return;
00105
00106 mrs_real limitedSt;
00107 mrs_real replenish;
00108 mrs_real eject;
00109 mrs_real loss;
00110 mrs_real reuptake;
00111 mrs_real reprocess;
00112 bool subtractSpont = getctrl("mrs_bool/subtractSpont")->to<mrs_bool>();
00113 for (mrs_natural j = 0; j < getctrl("mrs_natural/inSamples")->to<mrs_natural>(); j++){
00114 for (mrs_natural i = 0; i < getctrl("mrs_natural/inObservations")->to<mrs_natural>(); ++i){
00115 limitedSt = max(in(i,j) + A, (mrs_real)0.0);
00116 kt = gdt*limitedSt/(limitedSt + B);
00117 replenish = max(ydt*(M - q(i)), (mrs_real)0.0);
00118 eject = kt*q(i);
00119 loss = ldt*c(i);
00120 reuptake = rdt*c(i);
00121 reprocess = xdt*w(i);
00122 q(i) += replenish - eject + reprocess;
00123 c(i) += eject - loss - reuptake;
00124 w(i) += reuptake - reprocess;
00125 out(i,j) = (subtractSpont) ? max((mrs_real)0.0, h*c(i) - spont) : h*c(i);
00126 }
00127 }
00128 }