Skip to content

StreamDecoder

Melchor Garau Madrigal edited this page Oct 25, 2017 · 4 revisions

A stream.Transform class that converts a flac encoded input to PCM output, all in memory, suitable for connecting to other streams.

StreamDecoder(options)

You can pass all the options that can expect the Transform object, but also you can pass:

  • oggStream: Boolean
    • Determines if the Input data is an OGG Stream
    • Defaults to false
  • metadata: Array or Boolean
    • If is an array, tells the decoder to emit metadata when metadata blocks of the types passed are found
    • If is true, tells the decoder to emit metadata on all metadata blocks found
    • Defaults to STREAMINFO only
  • outputAs32: Boolean
    • Tells the decoder that the output is in bitsPerSamples but must store it in 32 bit integer. Default value is false except if the bitsPerSamples is 24.
    • Optional

Buffer? StreamDecoder.read()

Reads a chunk of decoded audio, in interleaved PCM format, on which every sample has the bit depth from StreamDecoder.getBitsPerSample(). As example, a 16bit stream with 2 channels will produce the following structure in the buffer:

 --------------------------------------------------
| Left | Right | Left | Right | Left | Right | ... | 2 bytes per sample
|    Frame 0   |    Frame 1   |    Frame 2   | ... | 4 bytes per frame
 --------------------------------------------------

Here, frame means a pack of one sample for every channel. Differs from FLAC frame that is other thing.

Number StreamDecoder.getTotalSamples()

Gets the number of samples stored in the stream, or 0 if it's undefined.

Number StreamDecoder.getChannels()

Gets the number of channels stored in the stream.

Number StreamDecoder.getChannelAssignment()

Returns the channel assignment of the stream. Values are from bindings.format.ChannelAssignment.

Number StreamDecoder.getBitsPerSample()

Gets the bits per sample of the stream.

Event metadata

When some metadata has been read, is emitted in a event and it passes an JS representation of it.

Clone this wiki locally