Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "MeddisHairCell.h" 00020 #include "../common_source.h" 00021 #include <algorithm> 00022 00023 using std::ostringstream; 00024 using std::max; 00025 using std::min; 00026 00027 using namespace Marsyas; 00028 00029 MeddisHairCell::MeddisHairCell(mrs_string name):MarSystem("MeddisHairCell",name) 00030 { 00031 //type_ = "MeddisHairCell"; 00032 //name_ = name; 00033 00034 numChannels = 0; 00035 00036 addControls(); 00037 } 00038 00039 MeddisHairCell::~MeddisHairCell() 00040 { 00041 } 00042 00043 MarSystem* 00044 MeddisHairCell::clone() const 00045 { 00046 return new MeddisHairCell(*this); 00047 } 00048 00049 void MeddisHairCell::addControls() 00050 { 00051 addctrl("mrs_bool/subtractSpont", false); 00052 } 00053 00054 void 00055 MeddisHairCell::myUpdate(MarControlPtr sender) 00056 { 00057 MRSDIAG("MeddisHairCell.cpp - MeddisHairCell:myUpdate"); 00058 00059 // setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")); 00060 // setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")); 00061 // setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00062 MarSystem::myUpdate(sender); //lmartins: what about the feature names?!? [?] 00063 00064 //parameters 00065 M = 1; 00066 A = 5; 00067 B = 300; 00068 g = 2000; 00069 y = 5.05f; 00070 l = 2500; 00071 r = 6580; 00072 x = 66.31f; 00073 h = 50000; 00074 00075 //internal constants 00076 dt = 1/getctrl("mrs_real/israte")->to<mrs_real>(); 00077 gdt = g*dt; 00078 ydt = y*dt; 00079 ldt = l*dt; 00080 rdt = r*dt; 00081 xdt = x*dt; 00082 00083 //initial values 00084 kt = g*A/(A + B); 00085 spont = M*y*kt/(l*kt+y*(l + r)); 00086 00087 if (numChannels != getctrl("mrs_natural/inSamples")->to<mrs_natural>()) { 00088 numChannels = getctrl("mrs_natural/inSamples")->to<mrs_natural>(); 00089 c.create(numChannels); 00090 q.create(numChannels); 00091 w.create(numChannels); 00092 for (mrs_natural i = 0; i < numChannels; ++i) { 00093 c(i) = spont; 00094 q(i) = c(i)*(l + r)/kt; 00095 w(i) = c(i)*r/x; 00096 } 00097 } 00098 } 00099 00100 void 00101 MeddisHairCell::myProcess(realvec& in, realvec& out) 00102 { 00103 checkFlow(in, out); 00104 //lmartins: if (mute_) return; 00105 if(getctrl("mrs_bool/mute")->to<mrs_bool>()) return; 00106 00107 mrs_real limitedSt; 00108 mrs_real replenish; 00109 mrs_real eject; 00110 mrs_real loss; 00111 mrs_real reuptake; 00112 mrs_real reprocess; 00113 bool subtractSpont = getctrl("mrs_bool/subtractSpont")->to<mrs_bool>(); 00114 for (mrs_natural j = 0; j < getctrl("mrs_natural/inSamples")->to<mrs_natural>(); j++) { 00115 for (mrs_natural i = 0; i < getctrl("mrs_natural/inObservations")->to<mrs_natural>(); ++i) { 00116 limitedSt = max(in(i,j) + A, (mrs_real)0.0); 00117 kt = gdt*limitedSt/(limitedSt + B); 00118 replenish = max(ydt*(M - q(i)), (mrs_real)0.0); 00119 eject = kt*q(i); 00120 loss = ldt*c(i); 00121 reuptake = rdt*c(i); 00122 reprocess = xdt*w(i); 00123 q(i) += replenish - eject + reprocess; 00124 c(i) += eject - loss - reuptake; 00125 w(i) += reuptake - reprocess; 00126 out(i,j) = (subtractSpont) ? max((mrs_real)0.0, h*c(i) - spont) : h*c(i); 00127 } 00128 } 00129 }