/* SpiralSound * Copyleft (C) 2001 David Griffiths * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "WaveTablePlugin.h" #include "WaveTablePluginGUI.h" #include #include "SpiralIcon.xpm" static const int IN_FREQ = 0; static const int IN_PW = 1; static const int IN_SHLEN = 2; static const int OUT_MAIN = 0; extern "C" { SpiralPlugin* CreateInstance() { return new WaveTablePlugin; } char** GetIcon() { return SpiralIcon_xpm; } int GetID() { return 0x0017; } } /////////////////////////////////////////////////////// WaveTablePlugin::WaveTablePlugin() : m_Type(SINE), m_Octave(0), m_FineFreq(1.0f), m_ModAmount(1.0f), m_TableLength(DEFAULT_TABLE_LEN) { m_CyclePos=0; m_Note=0; m_PluginInfo.Name="WaveTable"; m_PluginInfo.Width=245; m_PluginInfo.Height=110; m_PluginInfo.NumInputs=1; m_PluginInfo.NumOutputs=1; m_PluginInfo.PortTips.push_back("Frequency CV"); m_PluginInfo.PortTips.push_back("Output"); m_AudioCH->Register("Octave",&m_Octave,ChannelHandler::INPUT); m_AudioCH->Register("FineFreq",&m_FineFreq,ChannelHandler::INPUT); m_AudioCH->Register("Type",(char*)&m_Type,ChannelHandler::INPUT); m_AudioCH->Register("ModAmount",&m_ModAmount,ChannelHandler::INPUT); } WaveTablePlugin::~WaveTablePlugin() { } PluginInfo &WaveTablePlugin::Initialise(const HostInfo *Host) { PluginInfo& Info= SpiralPlugin::Initialise(Host); for (int n=0; nBUFSIZE; n++) { SetOutput(OUT_MAIN,n,0); if (InputExists(0)) { Freq=GetInputPitch(0,n); Freq*=m_ModAmount; } else { Freq=110; } Freq*=m_FineFreq; if (m_Octave>0) Freq*=1<<(m_Octave); if (m_Octave<0) Freq/=1<<(-m_Octave); Incr = Freq*(m_TableLength/(float)m_HostInfo->SAMPLERATE); m_CyclePos+=Incr; while (m_CyclePos>=m_TableLength) { m_CyclePos-=m_TableLength; } if (m_CyclePos<0 || m_CyclePos>=m_TableLength) m_CyclePos=0; SetOutput(OUT_MAIN,n,m_Table[m_Type][m_CyclePos]); } } void WaveTablePlugin::StreamOut(ostream &s) { s<>version>>*this; } istream &operator>>(istream &s, WaveTablePlugin &o) { s>>(int&)o.m_Type>>o.m_Octave>>o.m_FineFreq>>o.m_ModAmount; return s; } ostream &operator<<(ostream &s, WaveTablePlugin &o) { s<<(int)o.m_Type<<" "<