RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gen_sine.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Georgia Institute of Technology
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation, either version 3 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "gen_sine.h"
19 
20 #define TWOPI 6.28318531
21 
22 // default constructor
23 
25  : freq(1)
26  , amplitude(1)
27 {
28  index = 0;
29  dt = 1e-3;
30  numsamples = floor(1 / freq / dt);
31  wave.clear();
32  for (int i = 0; i < numsamples; i++) {
33  wave.push_back(amplitude * sin(TWOPI * freq * i * dt));
34  }
35  numsamples = wave.size();
36  index = 0;
37 }
38 
39 GeneratorSine::GeneratorSine(double freq, double amplitude, double dt)
40  : Generator()
41 {
42  numsamples = floor(1 / freq / dt);
43  wave.clear();
44  for (int i = 0; i < numsamples; i++) {
45  wave.push_back(amplitude * sin(TWOPI * freq * i * dt));
46  }
47  numsamples = wave.size();
48  index = 0;
49 }
50 
52 {
53 }
54 
55 void
56 GeneratorSine::init(double freq, double amplitude, double dt)
57 {
58  numsamples = floor(1 / freq / dt);
59  wave.clear();
60  for (int i = 0; i < numsamples; i++) {
61  wave.push_back(amplitude * sin(TWOPI * freq * i * dt));
62  }
63  numsamples = wave.size();
64  index = 0;
65 }
double freq
Definition: gen_sine.h:36
double dt
Definition: generator.h:57
int numsamples
Definition: generator.h:56
int index
Definition: generator.h:55
std::vector< double > wave
Definition: generator.h:54
double amplitude
Definition: gen_sine.h:37
#define TWOPI
Definition: gen_sine.cpp:20
void init()
Definition: generator.cpp:43