MP3Decoder

The high-level D api for mp3 decoding. You construct it with a read and seek function, then inspect the members for info about the mp3, then call decodeNextFrame and frameSamplesFloat in a loop to get the data until frameSamplesFloat returns an empty array, indicating you've hit the end of file.

Constructors

this
this(int delegate(ubyte[] buf) reader, int delegate(ulong where) seeker)

Creates a mp3 decoder out of two functions: a reader and a seeker. Both must work together for things to work.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

close
void close()

Closes the decoder, freeing memory associated with it. Remember, this does NOT close any file you referred to in your reader and seeker delegates, it just frees internal memory.

decodeNextFrame
bool decodeNextFrame()
deprecated bool decodeNextFrame(ReadBufFn reader)

Decodes the next frame of data and stores it in frameSamplesFloat (also accessible through frameSamples as short[]).

restart
deprecated void restart(ReadBufFn reader)

Calls seek(0). This function is provided for compatibility with older versions of the MP3Decoder api and has no other use.

seek
bool seek(uint sampleNumber)

Seeks the decoder to the given sample number, so the next call to decodeNextFrame will move to that part of the file.

sync
deprecated void sync(ReadBufFn reader)

Does nothing. Only provided for compatibility with older versions of the MP3Decoder api.

Properties

bitrate
int bitrate [@property getter]

Returns the bitrate of the first frame, in kbps.

channels
ubyte channels [@property getter]

Returns the number of channels in the file. Note the channel data is interlaced, meaning the first sample is left channel, second sample right channel, then back and forth (assuming two channels, of course).

duration
float duration [@property getter]

Returns the duration of the mp3, in seconds, if available, or float.nan if it is unknown (unknown may happen because it is an unseekable stream without metadata).

frameSamples
short[] frameSamples [@property getter]

Returns the current frame, as prepared by decodeNextFrame, in signed 16 bit (short[]) format.

frameSamplesFloat
float[] frameSamplesFloat [@property getter]

Returns the current frame, as prepared by decodeNextFrame, in floating point (float[]) format.

sampleRate
uint sampleRate [@property getter]

Returns the sample rate, in hz, of the audio stream. Note that this is per channel, so if this returns 44,100 hz and channels returns 2, you'd have a total of 88,200 samples per second between the two channels.

samplesInFrame
int samplesInFrame [@property getter]

Returns the number of samples in the current frame, as prepared by decodeNextFrame.

valid
bool valid [@property getter]

Returns true if the object is in a valid state. May be false if the stream was corrupted or reached end-of-file.

Meta