/Users/lyon/j4p/src/sound/Audio.java

1    package sound; 
2     
3     
4    public final class Audio { 
5        private double audioData[]; 
6        private int sampleRate = 8000; 
7        private final static double twopi = Math.PI * 2; 
8     
9        public Audio(double doubleArray[]) { 
10           audioData = doubleArray; 
11       } 
12    
13       public Audio(UlawCodec ulc) { 
14           audioData = ulc.getDoubleArray(); 
15       } 
16    
17       public double[] getAudioData() { 
18           return audioData; 
19       } 
20    
21       public int getSampleRate() { 
22           return sampleRate; 
23       } 
24    
25       public int getLength() { 
26           return audioData.length; 
27       } 
28    
29       public double getDuration() { 
30           return 
31                   ((double) audioData.length / 
32                   (double) sampleRate); 
33       } 
34    
35    
36       // A = transforms.fft(b); 
37    
38       public double getMin() { 
39           double min = audioData[0]; 
40           for (int i = 0; i < audioData.length; i++) { 
41               if (audioData[i] < min) 
42                   min = audioData[i]; 
43           } 
44           return min; 
45       } 
46    
47       public double getMax() { 
48           double max = audioData[0]; 
49           for (int i = 0; i < audioData.length; i++) { 
50               if (audioData[i] > max) 
51                   max = audioData[i]; 
52           } 
53           return max; 
54       } 
55    
56       public void normalize() { 
57           double min = Math.abs(getMin()); 
58           double max = Math.abs(getMax()); 
59           double biggest; 
60           double amp; 
61           if (min > max) 
62               biggest = min; 
63           else 
64               biggest = max; 
65           amp = 0.98 / biggest; 
66           System.out.println( 
67                   "Normalize:" + 
68                   "The min is:" + min + 
69                   "The max is:" + max); 
70           for (int i = 0; i < audioData.length; i++) 
71               audioData[i] = 
72                       audioData[i] * amp; 
73       } 
74    
75    
76   }