-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSound.java
66 lines (57 loc) · 1.32 KB
/
Sound.java
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
package aoop;
import java.util.ArrayList;
/**
* Abstract class sound
* Implements basic functions used by a filterable sound
* @author Daniel and Erik
*/
public abstract class Sound implements FilterableSound{
/**
* default constructor. Initializes filter list
*/
public Sound(){
filters = new ArrayList();
}
/**
* Plays the sound
*/
@Override
public void play(){
sample = generateSample();
applyFilters();
duration = sample.toArray().length/SAMPLING_RATE;
StdAudio.play(sample.toArray());
}
/**
* adds a filter to the list
* @param f filter
*/
public void addFilter(Filter f){
filters.add(f);
}
/**
* applies all filters
*/
private void applyFilters(){
for(Filter f : filters){
sample = f.apply(sample);
}
}
/**
* Return the duration of the sound
* @return
*/
public double getDuration(){
return duration;
}
public double[] getSample()
{
sample = generateSample();
applyFilters();
return sample.toArray();
}
private double duration;
public final int SAMPLING_RATE = StdAudio.SAMPLE_RATE;
private Sample sample;
private final ArrayList<Filter> filters;
}