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.
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package com.sun.speech.freetts.relp;
14 import java.nio.ByteBuffer;
15 import java.io.IOException;
16 import java.io.DataOutputStream;
17 import java.io.DataInputStream;
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
25 public class SampleInfo {
26 public final static String UTT_NAME = "SampleInfo";
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;
36 * Creates a new sample info.
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
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;
56 * Constructs a sample info from the given byte buffer.
58 * @param bb the byte buffer
60 * @throws IOException if an input error occurs
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();
72 * Constructs a sample info from the given input stream
74 * @param is the input stream
76 * @throws IOException if an input error occurs
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();
88 * Returns the sample rate.
90 * @return the sample rate
92 public final int getSampleRate() {
97 * Returns the number of channels.
99 * @return the number of channels.
101 public final int getNumberOfChannels() {
102 return numberOfChannels;
106 * Returns the residual fold.
108 * @return the residual fold
110 public final int getResidualFold() {
115 * Returns the minimum for linear predictive coding.
117 * @return the minimum for linear predictive coding.
119 public final float getCoeffMin() {
124 * Returns the range for linear predictive coding.
126 * @return the range for linear predictive coding.
128 public final float getCoeffRange() {
133 * Returns the post emphasis
135 * @return the post emphasis
137 public final float getPostEmphasis() {
143 * Dump a binary form of the sample rate
144 * to the given output stream
146 * @param os the output stream
148 * @throws IOException if an error occurs
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);