RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gen_saw.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_saw.h"
19 
20 // default constructor
21 
23  : delay(1)
24  , width(1)
25  , amplitude(1)
26 {
27  dt = 1e-3;
28  numsamples = floor(width / 2 / dt) + 1;
29  double inc = amplitude / numsamples;
30  wave.clear();
31  for (int i = 0; i < floor(delay / dt); i++) {
32  wave.push_back(0); // initial delay
33  }
34  while (wave.back() < amplitude) {
35  wave.push_back(wave.back() + inc); // up
36  }
37  while (wave.back() > 0) {
38  wave.push_back(wave.back() - inc); // down
39  }
40  numsamples = wave.size();
41  index = 0;
42 }
43 
44 GeneratorSaw::GeneratorSaw(double delay, double width, double amplitude,
45  double dt)
46  : Generator()
47 {
48  numsamples = floor(width / 2 / dt) + 1;
49  double inc = amplitude / numsamples;
50  wave.clear();
51  for (int i = 0; i < floor(delay / dt); i++) {
52  wave.push_back(0); // initial delay
53  }
54  while (wave.back() < amplitude) {
55  wave.push_back(wave.back() + inc); // up
56  }
57  while (wave.back() > 0) {
58  wave.push_back(wave.back() - inc); // down
59  }
60  numsamples = wave.size();
61  index = 0;
62 }
63 
65 {
66 }
67 
68 void
69 GeneratorSaw::init(double delay, double width, double amplitude, double dt)
70 {
71  numsamples = floor(width / 2 / dt) + 1;
72  double inc = amplitude / numsamples;
73  wave.clear();
74 
75  for (int i = 0; i < floor(delay / dt); i++) {
76  wave.push_back(0); // initial delay
77  }
78  while (wave.back() < amplitude) {
79  wave.push_back(wave.back() + inc); // up
80  }
81  while (wave.back() > 0) {
82  wave.push_back(wave.back() - inc); // down
83  }
84  numsamples = wave.size();
85  index = 0;
86 }
double dt
Definition: generator.h:57
int numsamples
Definition: generator.h:56
double width
Definition: gen_saw.h:37
double delay
Definition: gen_saw.h:36
int index
Definition: generator.h:55
std::vector< double > wave
Definition: generator.h:54
double amplitude
Definition: gen_saw.h:38
void init()
Definition: generator.cpp:43