logo
Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related

tube.cpp

00001 //
00002 //  SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation.        
00003 //
00004 //      Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net)
00005 //
00006 
00007 #include "tube.h"
00008 
00009 namespace SynthCore {
00010 
00011 
00012 Module * Tube::sharedClone() {
00013         return new Tube(hostVoice);
00014 }
00015 
00016 Tube::Tube(SynthVoice * S1) {
00017         hostVoice = S1;
00018         Output1 = new Output(this);
00019         Output2 = new Output(this);
00020         
00021         Input1 = new Input(this);
00022         feedback = 0.4f;
00023         pos = 5000;
00024         pos2 = 13000;
00025         forwardLine  = new DelayLine(20000);
00026         backwardLine  = new DelayLine(20000);
00027         myFilter = new BiFilter();
00028         myFilter->lowpassFreqAndQ(2400.0f, 0.2f);
00029         myFilter2 = new BiFilter();
00030         myFilter2->lowpassFreqAndQ(2400.0f, 0.2f);
00031 
00032 }
00033 
00034 
00035 std::string Tube::getXML(int indent ) { 
00036 
00037         std::string S = Utils::space(indent) + "<Module ID=\""+Utils::intToString((int)this)+"\" >"+ Utils::newline();
00038         S += Utils::space(indent+2) + "<TypeID>" + typeid(*this).name() + "</TypeID>" + Utils::newline();
00039         
00040         S += saveParameter("feedback",feedback, indent+2);
00041         
00042         S += Output1->getXML("Output1", indent+2);
00043         S += Output2->getXML("Output2", indent+2);
00044         S += Input1->getXML("Input1", indent+2);
00045         
00046 
00047         S += saveID(indent+2);
00048         S += Utils::space(indent) + "</Module>" + Utils::newline();
00049         return S;               
00050 }
00051 
00052 void Tube::loadXML(XMLNode * n, bool firstPass) {
00053           cout << "Parsing tube XML" << endl;
00054         
00055           string TypeID = n->getTagText("TypeID") ;
00056       if (typeid(*this).name() != TypeID) {
00057                   throw parseError("Trying to put "+TypeID+" into "+typeid(*this).name());
00058           }
00059 
00060           
00061           
00062 
00063           if (firstPass) {  
00064                         loadParameter("feedback",feedback, n);
00065                     Output1->loadXML("Output1", n);       
00066                         Output2->loadXML("Output2", n);
00067           } else {
00068                         Input1->loadXML("Input1", n);   
00069           }
00070 };
00071 
00072 void Tube::update() {
00073         // read output from forwardLine into backwardLine
00074         temp = backwardLine->read(0.0f-myFilter->read(forwardLine->readNBack(0)));
00075 
00076         // Filter output;
00077         temp = myFilter2->read(temp);
00078         
00079         // read output from backwardLine into forwardLine
00080         // determine feedback
00081         // (We dont care about return value)
00082         // Also add some input
00083         forwardLine->read(feedback*temp + Input1->ConFrom->value );
00084 
00085         // Output is constructed by reading from both backward and forwardline.
00086         
00087         Output1->write(  (forwardLine->readNBack(pos)+2.0f*Input1->ConFrom->value+backwardLine->readNForward(pos))*0.25  );     
00088         Output2->write(  (forwardLine->readNBack(pos2)+2.0f*Input1->ConFrom->value+backwardLine->readNForward(pos2))*0.25  );           
00089 }
00090 
00091 Tube::~Tube() {
00092  delete Output1;
00093  delete Output2;
00094  delete Input1;
00095  delete forwardLine;
00096  delete backwardLine;
00097  delete myFilter;
00098  delete myFilter2;
00099 }
00100 
00101 Module * Tube::newInstance(SynthVoice * S1) { 
00102         return new Tube(S1); 
00103 }
00104 
00105 
00106 }; // end of namespace: SynthCore

Syntopia Project. Visit the web page, or the SourceForge page.
Docs made by Doxygen. Email: Mikael Christensen