/Users/lyon/j4p/src/sound/Voices.java
|
1 /**
2 * Created by IntelliJ IDEA.
3 * User: dlyon
4 * Date: Dec 8, 2003
5 * Time: 9:19:12 PM
6 * To change this template use Options | File Templates.
7 */
8 package sound;
9
10 import java.util.Vector;
11
12 public class Voices {
13 private Vector vec = new Vector();
14
15 public void add(Voice v) {
16 vec.addElement(v);
17 }
18 public static void main(String args[]){
19 Voice v1 = new Voice(1000);
20 Voice v2 = new Voice(1300);
21 Voices vcs = new Voices();
22 vcs.add(v1);
23 vcs.add(v2);
24 vcs.play();
25 }
26
27 public void play() {
28 UlawCodec ulc = new UlawCodec(getVoicedWaveForm());
29 ulc.play();
30 }
31
32 public double[] getVoicedWaveForm() {
33 if (vec.size() == 0) return null;
34 Voice v = (Voice) vec.elementAt(0);
35 double d[] = v.getVoicedWave();
36 if (vec.size() == 1) return v.getVoicedWave();
37 for (int i = 1; i < vec.size(); i++) {
38 Voice vb = (Voice) vec.elementAt(i);
39 d = v.add(d, vb.getVoicedWave());
40 }
41 return d;
42 }
43
44 public Voice[] getVoices() {
45 Voice v[] = new Voice[vec.size()];
46 vec.copyInto(v);
47 return v;
48 }
49 }
50