-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTone.java
More file actions
37 lines (31 loc) · 771 Bytes
/
Tone.java
File metadata and controls
37 lines (31 loc) · 771 Bytes
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
package aoop;
/**
* A simple tone
* @author Erik and Daniel
*/
public class Tone extends Sound{
/**
* creates a tone with frequency freq and duration
* @param freq
* @param d
*/
public Tone(double freq, double d){
frequency = freq;
duration = d;
}
/**
* generates Sample
* @return Sample with sound
*/
@Override
public Sample generateSample() {
int l = (int)(SAMPLING_RATE*duration);
double[] tone = new double[l];
for (int i = 0; i < l; i++) {
tone[i] = (0.5 * Math.sin(2*Math.PI * frequency * i / SAMPLING_RATE));
}
return new Sample(tone);
}
private double frequency;
private double duration;
}