upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / relp / SampleInfo.java
1 /**
2  * Portions Copyright 2001 Sun Microsystems, Inc.
3  * Portions Copyright 1999-2001 Language Technologies Institute, 
4  * Carnegie Mellon University.
5  * All Rights Reserved.  Use is subject to license terms.
6  * 
7  * See the file "license.terms" for information on usage and
8  * redistribution of this file, and for a DISCLAIMER OF ALL 
9  * WARRANTIES.
10  */
11 package com.sun.speech.freetts.relp;
12
13
14 import java.nio.ByteBuffer;
15 import java.io.IOException;
16 import java.io.DataOutputStream;
17 import java.io.DataInputStream;
18
19 /**
20  * Describes global sample parameters. A sample info is generally added
21  * to an utterance to describe the type of unit data that has been
22  * generated.
23  *
24  */
25 public class SampleInfo {
26     public final static String UTT_NAME = "SampleInfo";
27
28     private final int sampleRate;
29     private final int numberOfChannels;
30     private final int residualFold;
31     private final float coeffMin;
32     private final float coeffRange;
33     private final float postEmphasis;
34
35     /**
36      * Creates a new sample info.
37      *
38      * @param sampleRate the sample rate
39      * @param numberOfChannels the number of channels
40      * @param residualFold the residual fold
41      * @param coeffMin the minimum coefficient
42      * @param coeffRange the range of coefficients
43      */
44     public SampleInfo(int sampleRate, int numberOfChannels,
45             int residualFold, float coeffMin, 
46             float coeffRange, float postEmphasis) {
47         this.sampleRate = sampleRate;
48         this.numberOfChannels = numberOfChannels;
49         this.residualFold = residualFold;
50         this.coeffMin = coeffMin;
51         this.coeffRange = coeffRange;
52         this.postEmphasis = postEmphasis;
53     }
54
55     /**
56      * Constructs a sample info from the given byte buffer.
57      *
58      * @param bb the byte buffer
59      *
60      * @throws IOException if an input error occurs
61      */
62     public SampleInfo(ByteBuffer bb) throws IOException {
63         numberOfChannels = bb.getInt();
64         sampleRate = bb.getInt();
65         coeffMin = bb.getFloat();
66         coeffRange = bb.getFloat();
67         postEmphasis = bb.getFloat();
68         residualFold = bb.getInt();
69     }
70
71     /**
72      * Constructs a sample info from the given input stream
73      *
74      * @param is the input stream
75      *
76      * @throws IOException if an input error occurs
77      */
78     public SampleInfo(DataInputStream is) throws IOException {
79         numberOfChannels = is.readInt();
80         sampleRate = is.readInt();
81         coeffMin = is.readFloat();
82         coeffRange = is.readFloat();
83         postEmphasis = is.readFloat();
84         residualFold = is.readInt();
85     }
86
87     /**
88      * Returns the sample rate.
89      *
90      * @return the sample rate
91      */
92     public final int getSampleRate() {
93         return sampleRate;
94     }
95     
96     /**
97      * Returns the number of channels.
98      *
99      * @return the number of channels.
100      */
101     public final int getNumberOfChannels() {
102         return numberOfChannels;
103     }
104
105     /**
106      * Returns the residual fold.
107      *
108      * @return the residual fold
109      */
110     public final int getResidualFold() {
111         return residualFold;
112     }
113     
114     /**
115      * Returns the minimum for linear predictive coding.
116      *
117      * @return the minimum for linear predictive coding.
118      */
119     public final float getCoeffMin() {
120         return coeffMin;
121     }
122
123     /**
124      * Returns the range for linear predictive coding.
125      *
126      * @return the range for linear predictive coding.
127      */
128     public final float getCoeffRange() {
129         return coeffRange;
130     }
131
132     /**
133      * Returns the post emphasis
134      *
135      * @return the post emphasis
136      */
137     public final float getPostEmphasis() {
138         return postEmphasis;
139     }
140
141     
142     /**
143      * Dump a binary form of the sample rate
144      * to the given output stream
145      *
146      * @param os the output stream
147      * 
148      * @throws IOException if an error occurs
149      */
150     public void dumpBinary(DataOutputStream os) throws IOException {
151         os.writeInt(numberOfChannels);
152         os.writeInt(sampleRate);
153         os.writeFloat(coeffMin);
154         os.writeFloat(coeffRange);
155         os.writeFloat(postEmphasis);
156         os.writeInt(residualFold);
157     }
158 }
159
160