Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related waveshaper.cpp00001 // 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 00008 #include "waveshaper.h" 00009 00010 /* ---- Waveshaper -------------*/ 00011 00012 00013 namespace SynthCore { 00014 00015 WaveShaper::WaveShaper(SynthVoice * S1) { 00016 hostVoice = S1; 00017 00018 Output1 = new Output(this); 00019 Input1 = new Input(this); 00020 00021 MyStep = 0; 00022 setAmount(0.5f); 00023 } 00024 00025 Module * WaveShaper::newInstance(SynthVoice * S1) { 00026 return new WaveShaper(S1); 00027 } 00028 00029 Module * WaveShaper::sharedClone() { 00030 return new WaveShaper(hostVoice); 00031 } 00032 00033 00034 void WaveShaper::update() { 00035 // Example WaveShaper 00036 temp = Input1->read(); 00037 00038 if (temp < 0.0f) {temp2 = -temp;} else {temp2 =temp;}; 00039 00040 Output1->write( temp*(temp2 + k)/(temp*temp + (k-1.0f)*temp2 + 1.0f) ); 00041 } 00042 00043 void WaveShaper::setAmount(float amount) 00044 { 00045 k = amount*15.0f; 00046 } 00047 00048 00049 std::string WaveShaper::getXML(int indent ) { 00050 00051 std::string S = Utils::space(indent) + "<Module ID=\""+Utils::intToString((int)this)+"\" >"+ Utils::newline(); 00052 S += Utils::space(indent+2) + "<TypeID>" + typeid(*this).name() + "</TypeID>" + Utils::newline(); 00053 00054 S += saveParameter("amount",k, indent+2); 00055 00056 S += Output1->getXML("Output1", indent+2); 00057 S += Input1->getXML("Input1", indent+2); 00058 00059 S += saveID(indent+2); 00060 00061 S += Utils::space(indent) + "</Module>" + Utils::newline(); 00062 return S; 00063 } 00064 00065 00066 00067 void WaveShaper::loadXML(XMLNode * n, bool firstPass) { 00068 cout << "Parsing Waveshaper XML" << endl; 00069 00070 string TypeID = n->getTagText("TypeID") ; 00071 if (typeid(*this).name() != TypeID) { 00072 throw parseError("Trying to put "+TypeID+" into "+typeid(*this).name()); 00073 } 00074 00075 00076 if (firstPass) { 00077 loadParameter("amount",k, n); 00078 Output1->loadXML("Output1", n); 00079 } else { 00080 Input1->loadXML("Input1", n); 00081 } 00082 00083 }; 00084 00085 00086 }; // end of namespace: SynthCore Docs made by Doxygen. Email: Mikael Christensen |