-
Notifications
You must be signed in to change notification settings - Fork 147
Decoder Class Reference
The Decoder
class is an abstract class that subclasses extend to implement actual audio decoding for various codecs (e.g. MP3, AAC, FLAC, etc.). Decoder
s receive data from the Demuxer and implement the readChunk
method to decode the audio data into Linear PCM to be passed to the audio hardware for playback, or other output destination.
When you implement your own decoders, remember to call Decoder.register(id, YourDecoder)
to register your decoder with the framework.
A Stream object containing the audio data.
A Bitstream object containing the audio data.
A boolean that keeps track of whether the decoder has been sent the final buffer from the Demuxer yet.
This method is optional and is called when a 'cookie' event is emitted by the Demuxer. The cookie is passed as a Buffer object.
readChunk
is required, and is called by the framework whenever decoding is necessary. readChunk
is responsible for decoding the audio data found in the stream
or bitstream
and emitting data events containing the decoded audio data as a Typed Array.
If not enough data is available in the stream at the time readChunk
is called, schedule it to be called later by registering readChunk
for the 'available' event once in the future, e.g. this.once('available', this.readChunk)
.
If there is an error in the decoding process, emit an error
event to stop the whole decoding process entirely.
You should emit the data
event whenever you have decoded some number of samples of Linear PCM audio data. You should include the data as a Typed Array.
This event is emitted by the Decoder
class whenever new data is available from the Demuxer.
You should emit the error
event whenever there is an error in the decoder. Emitting this event will halt the rest of the decoding process.
All Decoder subclasses should be registered with the Decoder class using this class method. You can register your decoder for multiple ids if you know that different containers use different FOURCCs for the codec, for example.
Finds a registered decoder using the 4 (or less) character FOURCC code the decoder registered itself as.