Class OggVorbisAudioDecoder

java.lang.Object
com.microej.audiomockoggvorbis.OggVorbisAudioDecoder
All Implemented Interfaces:
com.microej.audiomockdecoder.AudioDecoder

public class OggVorbisAudioDecoder extends Object implements com.microej.audiomockdecoder.AudioDecoder
AudioDecoder implementation that decodes Ogg Vorbis streams using the JOrbis library.

Typical usage:

  1. Call setInputStream(InputStream) with the Ogg Vorbis stream.
  2. Call setParameters(int[]) with the sample rate and channel count.
  3. Call getOutputFormat() to retrieve the configured AudioFormat.
  4. Call getNextFrame() repeatedly to obtain decoded PCM frames.
The three Vorbis header packets are read lazily on the first call to getNextFrame().
Since:
3.0.0
  • Constructor Details

    • OggVorbisAudioDecoder

      public OggVorbisAudioDecoder()
      Creates an OggVorbisAudioDecoder and initializes the JOgg sync state.
      Since:
      3.0.0
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface com.microej.audiomockdecoder.AudioDecoder
    • setInputStream

      public void setInputStream(InputStream inputStream)
      Sets the Ogg Vorbis input stream to decode.

      Must be called before getNextFrame().

      Specified by:
      setInputStream in interface com.microej.audiomockdecoder.AudioDecoder
      Parameters:
      inputStream - the input stream providing the Ogg Vorbis encoded audio data.
      Since:
      3.0.0
    • setParameters

      public void setParameters(int[] params)
      Configures the output AudioFormat from the given parameters.

      params[0] is the sample rate in Hz and params[1] is the number of channels.

      Specified by:
      setParameters in interface com.microej.audiomockdecoder.AudioDecoder
      Parameters:
      params - an array where params[0] is the sample rate (Hz) and params[1] is the channel count.
      Since:
      3.0.0
    • getOutputFormat

      public AudioFormat getOutputFormat()
      Returns the output AudioFormat previously configured via setParameters(int[]) or setOutputFormat(AudioFormat).
      Specified by:
      getOutputFormat in interface com.microej.audiomockdecoder.AudioDecoder
      Returns:
      the configured output format.
      Since:
      3.0.0
    • setOutputFormat

      public void setOutputFormat(AudioFormat newAudioFormat)
      Overrides the output AudioFormat directly.
      Specified by:
      setOutputFormat in interface com.microej.audiomockdecoder.AudioDecoder
      Parameters:
      newAudioFormat - the new output format to use.
      Since:
      3.0.0
    • getNextFrame

      public byte[] getNextFrame() throws IOException
      Decodes and returns the next available PCM frame from the Ogg Vorbis stream.

      On the first call, the three Vorbis header packets are read from the stream and the JOrbis DSP state is initialised. Subsequent calls decode audio data pages. setInputStream(InputStream) and setParameters(int[]) must have been called before the first invocation.

      Specified by:
      getNextFrame in interface com.microej.audiomockdecoder.AudioDecoder
      Returns:
      a byte array containing the next decoded PCM frame, or an empty array when the current page yields no output yet.
      Throws:
      IOException - if an error occurs while reading or decoding the stream.
      Since:
      3.0.0