-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwave.h
93 lines (79 loc) · 1.77 KB
/
wave.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "iostream"
#include <string>
#include <math.h>
using namespace std;
#include "SoundSamples.h"
const float PI = 3.14;
/**
* Superclass that provides method generateFunction that must be redefined in subclasses.
* Also has a unique name and a generateSamples method that outputs a SoundSamples array.
**/
class wave
{
protected:
string name;
public:
SoundSamples * generateSamples (float freqency, float sampleRate, float duration);
virtual float generateFunction (float time) = 0;
};
/**
*Subclass of wave that generates basic sin wave.
**/
class SineWave : public wave
{
public:
SineWave (string _name)
{
this->name = _name;
}
float generateFunction (float time)
{
return sin (2 * PI * time);
}
};
/**
*Subclass of wave that generates square sin wave.
**/
class SquareWave : public wave
{
public:
SquareWave (string _name)
{
this->name = _name;
}
float generateFunction (float time)
{
if (sin (2 * PI * time) >= 0) return 1.0;
else return -1.0;
}
};
/**
*Subclass of wave that generates triangular sin wave.
**/
class TriangleWave : public wave
{
public:
TriangleWave (string _name)
{
this->name = _name;
}
float generateFunction (float time)
{
return (2 / PI) * asin (sin (2 * PI * time));
}
};
/**
*Subclass of wave that generates sawtooth sin wave.
**/
class SawtoothWave : public wave
{
public:
SawtoothWave (string _name)
{
this->name = _name;
}
float generateFunction (float time)
{
return -(2 / PI) * atan (1 / (tan (PI * time)));
}
};