CLAM-Development  1.4.0
WaveGenerator.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "OSDefines.hxx"
23 #include "WaveGenerator.hxx"
24 #include "CLAM_Math.hxx"
25 
26 namespace CLAM {
27 
29  {
30  AddAll();
31  UpdateData();
32  SetFrequency(440.0);
33  SetAmplitude(1.0);
34  SetPhase(0.0);
35  SetSampleRate(44100);
36  SetFrameSize(512);
37  SetWaveType(EWaveType::eSine);
38  }
39 
40 
41  template<>
43  {
44  return amplitude * sin(x);
45  }
46 
47 
48 
49 
51  : Output("Output",this)
52  {
54  };
55 
57  : Output("Output",this)
58  {
59  Configure(c);
60  };
61 
62  bool WaveGenerator::ConcreteConfigure(const ProcessingConfig& c)
63  {
65 
66  mAmplitude = mConfig.GetAmplitude();
67 
68  TData samples_per_period = mConfig.GetSampleRate() / mConfig.GetFrequency();
69 
70  mXDelta = 2.0 * M_PI / samples_per_period;
71 
72  mXPos = fmod( TData(mConfig.GetPhase()), TData(2 * M_PI) );
73 
74  mType = mConfig.GetWaveType();
75 
76  Output.SetSize(mConfig.GetFrameSize());
77 
78  return true;
79  }
80 
82  {
83  }
84 
86  {
87  switch(mType)
88  {
89  case EWaveType::eSine:
90 
91  FillBuffer< EWaveType_eSine > ( out.GetBuffer(), *this );
92  break;
93  default:
94  return false;
95  }
96  return true;
97  }
98 
99 
100  bool WaveGenerator::Do(void)
101  {
102  bool res = Do(Output.GetData());
103  Output.Produce();
104  return res;
105  }
106 
107 
108 }
109