fi.helsinki.cs.ohtu.mpeg2.audio.mpa
Class MP2Data

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.audio.mpa.MP2Data

public class MP2Data
extends java.lang.Object

This class encodes compressed audio data to binary form. TODO: Add support for joint stereo.


Nested Class Summary
static class MP2Data.Channel
          Represents a single audio channel.
 
Field Summary
private  MP2Data.Channel[] channels
          Audio channels for this audio data chunk
private  int jsbound
          From which sub-band the sub-band data is joint between channels
private  QuantizationTables.QuantizationTable qTable
          Quantization table for this audio data chunk
 
Constructor Summary
MP2Data(MP2Data.Channel[] channels, QuantizationTables.QuantizationTable qTable)
          Creates a new AudioData instance from given channels using given quantization table.
MP2Data(MP2Data.Channel[] channels, QuantizationTables.QuantizationTable qTable, int jsbound)
          Creates a new AudioData instance from given channels with a joint stereo bound, using a given quantization table.
MP2Data(MP2Data.Channel channel, QuantizationTables.QuantizationTable qTable)
          Creates a new AudioData instance from given channel using given quanization table.
 
Method Summary
private  void encodeBitAllocation(BitOutputStream stream, CRC16 crc16)
          Writes the bit allocation of current audio data chunk to given stream and updates CRC-16 checksum.
private  void encodeSamples(BitOutputStream stream)
          Writes the samples of current audio data chunk to given stream.
private  void encodeScaleFactors(BitOutputStream stream, CRC16 crc16)
          Writes the scale factors of current audio data chunk to given stream and updates CRC-16 checksum.
 void writeTo(BitOutputStream stream)
          Writes this audio data chunk to given stream.
 void writeTo(BitOutputStream stream, CRC16 crc16)
          Writes this audio data chunk to given stream and updates CRC-16 checksum.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channels

private final MP2Data.Channel[] channels
Audio channels for this audio data chunk


jsbound

private final int jsbound
From which sub-band the sub-band data is joint between channels


qTable

private final QuantizationTables.QuantizationTable qTable
Quantization table for this audio data chunk

Constructor Detail

MP2Data

public MP2Data(MP2Data.Channel[] channels,
               QuantizationTables.QuantizationTable qTable,
               int jsbound)
Creates a new AudioData instance from given channels with a joint stereo bound, using a given quantization table. Starting from sub-band jsbound the first channel is used as a data source. The scale factor information is a slight exception as both the channels have their own scale factors. To keep things somewhat consistent, the joint sub-bands have to have equal bit allocations. Otherwise undefined behaviour will occur.

Parameters:
channels - the array of compressed audio channels
qTable - the quantization table for the audio samples
jsbound - the joint stereo bound of the sub-bands

MP2Data

public MP2Data(MP2Data.Channel[] channels,
               QuantizationTables.QuantizationTable qTable)
Creates a new AudioData instance from given channels using given quantization table.

Parameters:
channels - An array of compressed audio channels
qTable - Quantization table for the audio samples

MP2Data

public MP2Data(MP2Data.Channel channel,
               QuantizationTables.QuantizationTable qTable)
Creates a new AudioData instance from given channel using given quanization table.

Parameters:
channel - An audio channel
qTable - Quantization table for the audio samples
Method Detail

encodeBitAllocation

private void encodeBitAllocation(BitOutputStream stream,
                                 CRC16 crc16)
                          throws java.io.IOException
Writes the bit allocation of current audio data chunk to given stream and updates CRC-16 checksum.

Parameters:
stream - Stream in to which the bit allocation is written
crc16 - CRC-16 instance to update
Throws:
java.io.IOException

encodeScaleFactors

private void encodeScaleFactors(BitOutputStream stream,
                                CRC16 crc16)
                         throws java.io.IOException
Writes the scale factors of current audio data chunk to given stream and updates CRC-16 checksum.

Parameters:
stream - Stream in to which the scale factors are written
crc16 - CRC-16 instance to update
Throws:
java.io.IOException

encodeSamples

private void encodeSamples(BitOutputStream stream)
                    throws java.io.IOException
Writes the samples of current audio data chunk to given stream.

Parameters:
stream - Stream in to which the samples are written
Throws:
java.io.IOException

writeTo

public void writeTo(BitOutputStream stream,
                    CRC16 crc16)
             throws java.io.IOException
Writes this audio data chunk to given stream and updates CRC-16 checksum.

Parameters:
stream - Stream in to which this audio data chunk is written
crc16 - CRC-16 instance to update
Throws:
java.io.IOException

writeTo

public void writeTo(BitOutputStream stream)
             throws java.io.IOException
Writes this audio data chunk to given stream.

Parameters:
stream - Stream in to which this audio data chunk is written
Throws:
java.io.IOException