001/**
002 * Portions Copyright 2001 Sun Microsystems, Inc.
003 * Portions Copyright 1999-2001 Language Technologies Institute, 
004 * Carnegie Mellon University.
005 * All Rights Reserved.  Use is subject to license terms.
006 * 
007 * See the file "license.terms" for information on usage and
008 * redistribution of this file, and for a DISCLAIMER OF ALL 
009 * WARRANTIES.
010 */
011package com.sun.speech.freetts.relp;
012
013
014import java.nio.ByteBuffer;
015import java.io.IOException;
016import java.io.DataOutputStream;
017import java.io.DataInputStream;
018
019/**
020 * Describes global sample parameters. A sample info is generally added
021 * to an utterance to describe the type of unit data that has been
022 * generated.
023 *
024 */
025public class SampleInfo {
026    public final static String UTT_NAME = "SampleInfo";
027
028    private final int sampleRate;
029    private final int numberOfChannels;
030    private final int residualFold;
031    private final float coeffMin;
032    private final float coeffRange;
033    private final float postEmphasis;
034
035    /**
036     * Creates a new sample info.
037     *
038     * @param sampleRate the sample rate
039     * @param numberOfChannels the number of channels
040     * @param residualFold the residual fold
041     * @param coeffMin the minimum coefficient
042     * @param coeffRange the range of coefficients
043     */
044    public SampleInfo(int sampleRate, int numberOfChannels,
045            int residualFold, float coeffMin, 
046            float coeffRange, float postEmphasis) {
047        this.sampleRate = sampleRate;
048        this.numberOfChannels = numberOfChannels;
049        this.residualFold = residualFold;
050        this.coeffMin = coeffMin;
051        this.coeffRange = coeffRange;
052        this.postEmphasis = postEmphasis;
053    }
054
055    /**
056     * Constructs a sample info from the given byte buffer.
057     *
058     * @param bb the byte buffer
059     *
060     * @throws IOException if an input error occurs
061     */
062    public SampleInfo(ByteBuffer bb) throws IOException {
063        numberOfChannels = bb.getInt();
064        sampleRate = bb.getInt();
065        coeffMin = bb.getFloat();
066        coeffRange = bb.getFloat();
067        postEmphasis = bb.getFloat();
068        residualFold = bb.getInt();
069    }
070
071    /**
072     * Constructs a sample info from the given input stream
073     *
074     * @param is the input stream
075     *
076     * @throws IOException if an input error occurs
077     */
078    public SampleInfo(DataInputStream is) throws IOException {
079        numberOfChannels = is.readInt();
080        sampleRate = is.readInt();
081        coeffMin = is.readFloat();
082        coeffRange = is.readFloat();
083        postEmphasis = is.readFloat();
084        residualFold = is.readInt();
085    }
086
087    /**
088     * Returns the sample rate.
089     *
090     * @return the sample rate
091     */
092    public final int getSampleRate() {
093        return sampleRate;
094    }
095    
096    /**
097     * Returns the number of channels.
098     *
099     * @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