-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareOscillator.java
More file actions
42 lines (34 loc) · 1.12 KB
/
SquareOscillator.java
File metadata and controls
42 lines (34 loc) · 1.12 KB
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
/**
SquareOscillator extends on the Oscillator class,
It acts as a square wave oscillator
**/
public class SquareOscillator extends Oscillator{
// Constructors
/**
Constructor for SquareOscillator by default sets freq to middle c, and amplitude to 100
@param sampleRate sets the sample rate of the oscillator
**/
public SquareOscillator(int sampleRate) {
super(sampleRate);
}
/**
Constructor for SquareOscillator
@param sampleRate sets the sample rate of the oscillator
@param freq sets the frequency of the oscillator
@param amplitude sets the amplitude of the oscillator
**/
public SquareOscillator(int sampleRate, double freq, double amplitude) {
super(sampleRate, freq, amplitude);
}
/**
Creates the frequency as a byte where at time t
@param t is the time at which the wave is at (1 sec => t=sampleRate)
@return The byte created by the square wave oscillator at time t
**/
@Override
public byte createWave(double t) {
// If sine wave at t is negative, return 0, otherwave return the amplitude
return (byte) ((super.sineWave(t, DEFAULT_SINE_CONSTANT) <= 0)
? 0 : this.amplitude);
}
}