Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.monte.media.mp3
Class MP3ElementaryInputStream

    java.lang.Object
      java.io.InputStream
          java.io.FilterInputStream
              org.monte.media.mp3.MP3ElementaryInputStream

All Implemented Interfaces:
  java.io.Closeable

    public class MP3ElementaryInputStream

extends java.io.FilterInputStream

Facilitates reading of an MP3 elementary stream frame by frame.

An MP3 frame has a 32-bit header with the following contents in big endian order:

- bit 31-21, MP3 Sync Word, all bits must be set
- bit 20-19, Version, 00=MPEG 2.5,01=reserved,10=MPEG 2, 11=MPEG 1
- bit 18-17, Layer, 00=reserved, 01=layer 3, 10=layer 2, 11=layer 1
- bit 16, Error protection, 0=16 bit CRC follows header, 1=Not protected
- bit 15-12, Bit Rate in kbps, interpretation depends on version and layer
- bit 11-10, Frequency, interpretation depends on version
- bit 9, Pad Bit, 0=frame is not padded, 1=frame is padded to exactly fit the bit rate
- bit 8, Private bit, only informative
- bit 7-6, Channel Mode, 00=stereo, 01=joint stereo, 10=dual channel (2 mono channels), 11=single channel (mono)
- bit 5-4, Mode Extension (only used with Joint Stereo), interpretation depends on version and layer
- bit 3, Copyright, 0=not copyrighted, 1=copyrighted
- bit 2, Original, 0=Copy of original media,1=original media
- bit 1-0, Emphasis, 00=none,01=50/15ms,10=reserved,11=CCIT J.17

Reference:
http://en.wikipedia.org/wiki/MP3
http://www.datavoyage.com/mpgscript/mpeghdr.htm
http://www.mp3-tech.org/programmer/frame_header.html
http://lame.sourceforge.net/tech-FAQ.txt
http://www.altera.com/literature/dc/1.4-2005_Taiwan_2nd_SouthernTaiwanU-web.pdf

Version:
  1.1 2011-01-17 Renamed getHeader() to getHeaderCode().
  1.0 2011-01-03 Created.
Author:
  Werner Randelshofer

Nested Class Summary
`static class` | `MP3ElementaryInputStream.Frame` An elementary frame.

Field Summary
`static javax.sound.sampled.AudioFormat.Encoding` | `MP3` Defines the "MP3" encoding.

Fields inherited from class java.io.FilterInputStream
`in`

Constructor Summary
`MP3ElementaryInputStream(java.io.File file)`
`MP3ElementaryInputStream(java.io.InputStream in)`

Method Summary
`javax.sound.sampled.AudioFormat` | `getFormat()` Gets the format of the current frame.
`MP3ElementaryInputStream.Frame` | `getFrame()` Returns the current frame.
`MP3ElementaryInputStream.Frame` | `getNextFrame()` Gets the next frame from the input stream.
`long` | `getStreamPosition()` Returns the current position in the stream.
`int` | `read()` Reads a byte from the current frame (its header and its data).
`int` | `read(byte[] b, int off, int len)` Reads up to `len` bytes from the current frame (its header and its data).
`void` | `readFully(byte[] b)` Reads `b.length` bytes from the current frame (its header and its data).
`void` | `readFully(byte[] b, int off, int len)` Reads `len` bytes from the current frame (its header and its data).
`long` | `skip(long n)` Skips up to `n` bytes from the current frame (its header and its data).

Methods inherited from class java.io.FilterInputStream
`available, close, mark, markSupported, read, reset`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MP3

    public static final javax.sound.sampled.AudioFormat.Encoding MP3

  Defines the "MP3" encoding.

Constructor Detail

### MP3ElementaryInputStream

    public MP3ElementaryInputStream(java.io.File file)
                             throws java.io.IOException

Throws:
  `java.io.IOException`

### MP3ElementaryInputStream

    public MP3ElementaryInputStream(java.io.InputStream in)

Method Detail

### getNextFrame

    public MP3ElementaryInputStream.Frame getNextFrame()
                                                throws java.io.IOException

  Gets the next frame from the input stream. Positions the stream in front of the frame header.

  Throws:
    `java.io.IOException`

### getFrame

    public MP3ElementaryInputStream.Frame getFrame()

  Returns the current frame.

### getFormat

    public javax.sound.sampled.AudioFormat getFormat()

  Gets the format of the current frame. Returns null if the input stream is not positioned on a frame, or the frame is not valid.

  Returns:
    AudioFormat of current frame or null.

### read

    public int read()
             throws java.io.IOException

  Reads a byte from the current frame (its header and its data). Returns -1 on an attempt to read past the end of the frame.

  Overrides:
    `read` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Reads up to `len` bytes from the current frame (its header and its data). May read less then `len` bytes. Returns the actual number of bytes read. Returns -1 on an attempt to read past the end of the frame.

  Overrides:
    `read` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### readFully

    public final void readFully(byte[] b)
                         throws java.io.IOException

  Reads `b.length` bytes from the current frame (its header and its data).

  Throws:
    `{@code` - IOException} on an attempt to read past the end of the frame.
    `java.io.IOException`

### readFully

    public final void readFully(byte[] b,
                                int off,
                                int len)
                         throws java.io.IOException

  Reads `len` bytes from the current frame (its header and its data).

  Throws:
    `{@code` - IOException} on an attempt to read past the end of the frame.
    `java.io.IOException`

### skip

    public long skip(long n)
              throws java.io.IOException

  Skips up to `n` bytes from the current frame (its header and its data). Returns the actual number of bytes that have been skipped. Returns -1 on an attempt to skip past the end of the frame.

  Overrides:
    `skip` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### getStreamPosition

    public long getStreamPosition()

  Returns the current position in the stream.

  Returns:
    The stream position.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD