// // Programmer: Craig Stuart Sapp // Creation Date: Sun May 11 21:59:38 GMT-0800 1997 // Last Modified: Fri May 30 00:34:01 PDT 1997 // Filename: ...sig/maint/code/Filter/Osc/Osc.cpp // Web Address: http://sig.sapp.org/src/sigSignal/Osc.cpp // Documentation: http://sig.sapp.org/doc/classes/Osc // Syntax: C++ // #include "Osc.h" #include #include #ifndef TWOPI #define TWOPI 6.2831853 #endif int Osc::initSineTable = 1; PeriodTable Osc::sineTable; ////////////////////////////// // // Osc::Osc -- // default value: anAmplitude = 1.0 // Osc::Osc(sampleType anAmplitude) { setName("Osc"); brandname = FILTER; setAmplitude(anAmplitude); outputValue = 0; phaseSum = 0; tableIncrement = 0.0; quality = OSC_MEDIUM_QUALITY; // linear interpolation if (initSineTable) { initSineTable = 0; sineTable.setSize(1024); sineTable.sine(); } } ////////////////////////////// // // Osc::~Osc -- // Osc::~Osc() { } ////////////////////////////// // // Osc::action -- // void Osc::action(void) { switch (quality) { case OSC_HIGH_QUALITY: outputValue = getAmplitude() * sin(phaseSum); phaseSum += TWOPI * getFrequency() / getSrate(); break; case OSC_MEDIUM_QUALITY: case OSC_LOW_QUALITY: outputValue = getAmplitude() * sineTable[tableIncrement]; tableIncrement += sineTable.getSize() * getFrequency() / getSrate(); if (tableIncrement > sineTable.getSize()) { tableIncrement -= sineTable.getSize(); } break; default: cerr << "Error: unkonwn Osc quality" << endl; exit(1); } } ////////////////////////////// // // Osc::doHighQuality -- // void Osc::doHighQuality(void) { quality = OSC_HIGH_QUALITY; } ////////////////////////////// // // Osc::doMediumQuality -- // void Osc::doMediumQuality(void) { quality = OSC_MEDIUM_QUALITY; sineTable.doLinearInterpolation(); } ////////////////////////////// // // Osc::doLowQuality -- // void Osc::doLowQuality(void) { quality = OSC_LOW_QUALITY; sineTable.doConstantInterpolation(); } ////////////////////////////// // // Osc::getAmplitude -- // sampleType Osc::getAmplitude(void) { return inputs[1]; } ////////////////////////////// // // Osc::getFrequency -- // sampleType Osc::getFrequency(void) { return inputs[0]; } ////////////////////////////// // // Osc::output -- // sampleType Osc::output(int channel) { return outputValue; } ////////////////////////////// // // Osc::setAmplitude -- // void Osc::setAmplitude(sampleType anAmplitude) { connect(anAmplitude, 1); } ////////////////////////////// // // Osc::setPhase -- // void Osc::setPhase(sampleType aNormalizedPhase) { tableIncrement = sineTable.getSize() * aNormalizedPhase; phaseSum = aNormalizedPhase * TWOPI; } // md5sum: 17d4bec0d0cd909d465ac2d9f2e9a186 Osc.cpp [20010708]