1 /* SpiralSynth 2 * Copyleft (C) 2000 David Griffiths <dave@pawfal.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #include "Mixer.h" 20 21 Mixer::Mixer() : 22 m_Type(ADD), 23 m_Amount(0.001) 24 { 25 } 26 27 void Mixer::GetOutput(short *data1, short *data2) 28 { 29 long temp=0; 30 31 for (int n=0; n<SpiralInfo::BUFSIZE; n++) 32 { 33 switch (m_Type) 34 { 35 case ADD: temp=data1[n]+data2[n]; break; 36 case XMOD: temp=data1[n]; break; 37 case RING: temp=(long)(data1[n]*data2[n]*m_Amount); break; 38 case NONE: break; 39 } 40 41 if (temp>SpiralInfo::MAXSAMPLE) temp=SpiralInfo::MAXSAMPLE; 42 if (temp<-SpiralInfo::MAXSAMPLE) temp=-SpiralInfo::MAXSAMPLE; 43 44 data2[n]=(short)temp; 45 } 46 } 47 48 void Mixer::Randomise() 49 { 50 float t=RandFloat(); 51 if (t<0.3) m_Type=ADD; 52 else if (t<0.6) m_Type=XMOD; 53 else m_Type=RING; 54 55 m_Amount=RandFloat(0.0f,0.002f); 56 } 57 58 istream &operator>>(istream &s, Mixer &o) 59 { 60 s>>(int&)o.m_Type>>o.m_Amount; 61 return s; 62 } 63 64 ostream &operator<<(ostream &s, Mixer &o) 65 { 66 s<<(int)o.m_Type<<" "<<o.m_Amount<<" "; 67 return s; 68 } 69 70