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

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

public class MP2Encoder
extends AudioEncoder

Implements an MPEG-1 Layer II encoder. The encoder supports the sample rates specified in the MPEG-1 standard: 32, 44.1 and 48 kHz. In addition, the MPEG-2 Lower Sampling Frequencies extension is supported in a degraded mode: for the sample rates 16, 22.05 and 24 kHz, the encoder by-passes the psychoacoustic model.

A basic usage scheme for the encoder:

     MP2Encoder mp2enc = new MP2Encoder(AudioEncoder.Mode.SINGLE_CHANNEL,
             AudioEncoder.SampleRate.SRATE_48000);
     double[] samples = new double[mp2enc.getSampleFrameSize()];

     mp2enc.setBitrate(192000);

     ...

     while (...) {
         AudioFrame aframe;

         ...

         /* Generate or read the samples. */

         aframe = mp2enc.encode(samples);
         ...
     }
 


Nested Class Summary
 
Nested classes/interfaces inherited from class fi.helsinki.cs.ohtu.mpeg2.audio.AudioEncoder
AudioEncoder.Mode, AudioEncoder.SampleRate
 
Field Summary
private  int bitrate
           
private  boolean crcProtected
           
private static int DEFAULT_BITRATE
           
private  double[][] delayBuf
           
private  AudioEncoder.SampleRate fs
           
private  AudioEncoder.Mode mode
           
static int MP2_FRAME
          Number of samples per input frame
private  PsychoacousticModel pam
           
private  PolyphaseQuadratureFilter[] pqf
           
private static int PQF_DELAY
           
private  QuantizationTables.QuantizationTable quantizationTable
           
static int SBLIMIT
          Number of sub-bands
static int SBSLIMIT
          Number of sub-band sections
static int SBSSAMPLES
          Number of samples per sub-band section
 
Constructor Summary
MP2Encoder(AudioEncoder.Mode mode, AudioEncoder.SampleRate fs)
          Creates a new MPEG-1 Layer II encoder instance.
 
Method Summary
 AudioFrame encode(double[][] samples)
          Encode 1152 input samples and pack them in an audio frame.
 int getBitrate()
          Returns the current bitrate of this encoder.
 int getSampleFrameSize()
          Returns size of next accepted sample frame.
 boolean isCRCProtected()
          Returns whether CRC checksums are calculated for audio frames.
 void setBitrate(int bitrate)
          Sets bitrate for this encoder.
 void setCRCProtection(boolean crcProtected)
          Sets whether to calculate CRC checksums for audio frames.
 
Methods inherited from class fi.helsinki.cs.ohtu.mpeg2.audio.AudioEncoder
encode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MP2_FRAME

public static final int MP2_FRAME
Number of samples per input frame

See Also:
Constant Field Values

SBLIMIT

public static final int SBLIMIT
Number of sub-bands

See Also:
Constant Field Values

SBSLIMIT

public static final int SBSLIMIT
Number of sub-band sections

See Also:
Constant Field Values

SBSSAMPLES

public static final int SBSSAMPLES
Number of samples per sub-band section

See Also:
Constant Field Values

DEFAULT_BITRATE

private static final int DEFAULT_BITRATE
See Also:
Constant Field Values

PQF_DELAY

private static final int PQF_DELAY
See Also:
Constant Field Values

pqf

private final PolyphaseQuadratureFilter[] pqf

pam

private final PsychoacousticModel pam

mode

private final AudioEncoder.Mode mode

fs

private final AudioEncoder.SampleRate fs

quantizationTable

private QuantizationTables.QuantizationTable quantizationTable

bitrate

private int bitrate

crcProtected

private boolean crcProtected

delayBuf

private double[][] delayBuf
Constructor Detail

MP2Encoder

public MP2Encoder(AudioEncoder.Mode mode,
                  AudioEncoder.SampleRate fs)
Creates a new MPEG-1 Layer II encoder instance. The default bitrate for the encoder is 128 kbit/s. Only constant bitrate (CBR) coding is supported at the moment.

Parameters:
mode - Encoding mode, @see AudioEncoder.Mode
fs - Sample rate, @see AudioEncoder.SampleRate
Method Detail

isCRCProtected

public boolean isCRCProtected()
Returns whether CRC checksums are calculated for audio frames.

Returns:
true if and only if CRC checksums are calculated.

getBitrate

public int getBitrate()
Returns the current bitrate of this encoder.

Returns:
Bitrate in bits per second.

getSampleFrameSize

public final int getSampleFrameSize()
Description copied from class: AudioEncoder
Returns size of next accepted sample frame.

Specified by:
getSampleFrameSize in class AudioEncoder

setBitrate

public void setBitrate(int bitrate)
Sets bitrate for this encoder.

Parameters:
bitrate - Bitrate in bits per second

setCRCProtection

public void setCRCProtection(boolean crcProtected)
Sets whether to calculate CRC checksums for audio frames.

Parameters:
crcProtected - true is CRC protection should be used; false otherwise

encode

public AudioFrame encode(double[][] samples)
Encode 1152 input samples and pack them in an audio frame.

Specified by:
encode in class AudioEncoder
Parameters:
samples - 1152 input PCM samples in ]-1, 1[.