libgdx API

com.badlogic.gdx.audio.io
Class Mpg123Decoder

java.lang.Object
  extended by com.badlogic.gdx.audio.io.Mpg123Decoder
All Implemented Interfaces:
Decoder, Disposable

public class Mpg123Decoder
extends java.lang.Object
implements Decoder

A Decoder implementation that decodes MP3 files via libmpg123 natively.

Author:
mzechner

Field Summary
 long handle
           
 
Constructor Summary
Mpg123Decoder(java.lang.String filename)
          Opens the given file for mp3 decoding.
 
Method Summary
 void dispose()
          Disposes the decoder and frees all associated resources
 float getLength()
          
 int getNumChannels()
          
 int getRate()
          
 int readSamples(java.nio.ShortBuffer samples)
          Reads in samples.capacity() samples in 16-bit signed PCM format from the decoder.
 int skipSamples(int numSamples)
          Skips numSamples samples.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handle

public final long handle
Constructor Detail

Mpg123Decoder

public Mpg123Decoder(java.lang.String filename)
Opens the given file for mp3 decoding. Throws an IllegalArugmentException in case the file could not be opened.

Parameters:
filename - the filename
Method Detail

readSamples

public int readSamples(java.nio.ShortBuffer samples)
Reads in samples.capacity() samples in 16-bit signed PCM format from the decoder. Returns the actual number read in. If this number is smaller than the capacity of the buffer then the end of stream has been reached. The provided ShortBuffer must be a direct buffer.

Specified by:
readSamples in interface Decoder
Parameters:
samples - The number of read samples.

skipSamples

public int skipSamples(int numSamples)
Skips numSamples samples. If the decoded file is in stereo the left and right channel samples are counted as 2 samples.

Specified by:
skipSamples in interface Decoder
Parameters:
numSamples - the number of samples to skip
Returns:
the number of samples actually skipped. If this is < numSamples then the end of the file has been reached.

getNumChannels

public int getNumChannels()

Specified by:
getNumChannels in interface Decoder
Returns:
the number of channels

getRate

public int getRate()

Specified by:
getRate in interface Decoder
Returns:
the sampling rate in herz, e.g. 44100

getLength

public float getLength()

Specified by:
getLength in interface Decoder
Returns:
the length of the file in seconds

dispose

public void dispose()
Disposes the decoder and frees all associated resources

Specified by:
dispose in interface Decoder
Specified by:
dispose in interface Disposable

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)