Class: Decoder
Overview
Audio file decoder. Provides raw PCM audio and metadata from various compressed formats.
The Superpowered decoder is independent from the standard decodeAudioData Web Audio API, which means it has identical codec support across web browsers. The Decoder can be used in Workers and Worklets too which allow for multiple threaded decoding, preventing blocking in the main thread.
Alternatively, if you'd like to fetch audio and decode in one step then please see:
Supported file formats
- Stereo or mono pcm WAV and AIFF (16-bit int, 24-bit int, 32-bit int or 32-bit IEEE float).
- MP3: MPEG-1 Layer III (sample rates: 32000 Hz, 44100 Hz, 48000 Hz). MPEG-2 Layer III is not supported (mp3 with sample rates below 32000 Hz).
- AAC or HE-AAC in M4A container (iTunes) or ADTS container (.aac).
iOS, macOS and tvOS: ALAC/Apple Lossless support.
How to implement
// Decodes an entire audio file in memory to AudioInMemory format in a single call. The output can be loaded by the AdvancedAudioPlayer.let pointerToAudioInMemory = Superpowered.Decoder.decodeToAudioInMemory(pointer, // Pointer to an audio file loaded onto the WebAssembly Linear Memory.1000000 // The audio file length in bytes.);// Constructor. Has no additional parameters.let decoder = new Superpowered.Decoder();// Opens a memory location in Superpowered AudioInMemory format for decoding.let openErrorCode = decoder.openMemory(pointer, // Pointer to information in Superpowered AudioInMemory format on the WebAssembly Linear Memory.false // If true, it opens the file for fast metadata reading only, not for decoding audio.);// Opens a memory location for decoding.let openErrorCode = decoder.openAudioFileInMemory(pointer, // Pointer to an audio file loaded onto the WebAssembly Linear Memory.1000000, // The audio file length in bytes.false // If true, it opens the file for fast metadata reading only, not for decoding audio.);// Error codes for the openMemory() method:Superpowered.Decoder.OpenSuccess;Superpowered.Decoder.OpenError_OutOfMemory; // Some memory allocation failed. Recommended action: check for memory leaks.Superpowered.Decoder.OpenError_PathIsNull; // Path is NULL.Superpowered.Decoder.OpenError_ID3VersionNotSupported; // ID3 version 2.2, 2.3 and 2.4 are supported only.Superpowered.Decoder.OpenError_ID3ReadError; // File read error while reading the ID3 tag.Superpowered.Decoder.OpenError_FileFormatNotRecognized; // The decoder is not able to decode this file format.Superpowered.Decoder.OpenError_FileTooShort; // The file has just a few bytes of data.Superpowered.Decoder.OpenError_ImplementationError0; // Should never happen. But if it does, please let us know.Superpowered.Decoder.OpenError_ImplementationError1; // Should never happen. But if it does, please let us know.Superpowered.Decoder.OpenError_ImplementationError2; // Should never happen. But if it does, please let us know.// Returns with a human readable error string.let pointer = Superpowered.Decoder.statusCodeToString(openErrorCode // The error code.)// Returns with how many frames are in one chunk of the source file. For example: MP3 files store 1152 audio frames in a chunk.let fc = decoder.getFramesPerChunk();// Decodes audio.let decodeErrorCode = decoder.decodeAudio(pointer, // Pointer to 16-bit signed integer numbers. The output. Must be at least numberOfFrames * 4 + 16384 bytes big.fc // The requested number of frames. Should NOT be less than the value returned by getFramesPerChunk().);// Error codes for the decodeAudio(), getAudioStartFrame() and getAudioEndFrame() methods:Superpowered.Decoder.EndOfFile; // End-of-file reached.Superpowered.Decoder.BufferingTryAgainLater; // Buffering (waiting for the network to pump enough data).Superpowered.Decoder.Error; // Decoding error.// Returns with the duration of the current file in frames.// Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.let df = decoder.getDurationFrames();// Returns with the duration of the current file in seconds.// Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.let ds = decoder.getDurationSeconds();// Returns with the current position in frames. The postion may change after each decode() or seekTo().let pos = decoder.getPositionFrames();// Returns with the sample rate of the current file.let sr = decoder.getSamplerate();// Returns with the format of the current file.let f = decoder.getFormat();// File/decoder formant constants:Superpowered.Decoder.Format_MP3; // MP3Superpowered.Decoder.Format_AAC; // AAC, HE-AACSuperpowered.Decoder.Format_AIFF; // AIFFSuperpowered.Decoder.Format_WAV; // WAV// Jumps to the specified position's chunk (frame) beginning.// Some codecs (such as MP3) contain audio in chunks (frames). This method will not jump precisely to the specified position, but to the chunk's beginning the position belongs to.// Returns with success (true) or failure (false).let success = decoder.setPositionQuick(10052 // The requested position in frames.);// Jumps to a specific position. This method is a little bit slower than setPositionQuick().// Returns with success (true) or failure (false).let success = decoder.setPositionPrecise(10052 // The requested position in frames.);// Detects silence at the beginning. This function changes the position!// The return value can be:// - A positive number or zero: the frame index where audio starts.// - Superpowered.Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioStartFrame() or getAudioEndFrame() later (it's recommended to wait at least 0.1 seconds).// - Superpowered.Decoder.NetworkError: network (download) error.// - Superpowered.Decoder.Error: internal decoder error.let start = decoder.getAudioStartFrame(0, // Limit frames. How far to search for. 0 means "the entire audio file".0 // Loudness threshold in decibel. 0 means "any non-zero audio". The value -49 is useful for vinyl rips having vinyl noise (crackles).);// Detects silence at the end. This function changes the position!// The return value can be:// - A positive number or zero: the frame index where audio ends.// - Superpowered.Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioEndFrame() later (it's recommended to wait at least 0.1 seconds).// - Superpowered.Decoder.NetworkError: network (download) error.// - Superpowered.Decoder.Error: internal decoder error.let end = decoder.getAudioEndFrame(0, // Limit frames. How far to search for from the end (the duration in frames). 0 means "the entire audio file".0 // Loudness threshold in decibel. 0 means "any non-zero audio". The value -49 is useful for vinyl rips having vinyl noise (crackles).);
#include "SuperpoweredDecoder.h"// Decodes an entire audio file in memory to AudioInMemory format in a single call. The output can be loaded by the AdvancedAudioPlayer.void *pointerToAudioInMemory = Superpowered::Decoder::decodeToAudioInMemory(pointer, // Pointer to an audio file loaded into the memory.1000000 // The audio file length in bytes.);// Constructor. Has no additional parameters.Superpowered::Decoder *decoder = new Superpowered::Decoder();// Opens a memory location in Superpowered AudioInMemory format for decoding.int openErrorCode = decoder->openMemory(pointer, // Pointer to information in Superpowered AudioInMemory formatfalse // If true, it opens the file for fast metadata reading only, not for decoding audio.);// Opens a memory location for decoding.int openErrorCode2 = decoder->openAudioFileInMemory(pointer, // Pointer to an audio file loaded into memory1000000, // The audio file length in bytes.false // If true, it opens the file for fast metadata reading only, not for decoding audio.);// Returns with a human readable error string.const char *errorString = Superpowered::Decoder::statusCodeToString(openErrorCode // The error code.);// Returns with how many frames are in one chunk of the source file. For example: MP3 files store 1152 audio frames in a chunk.int fc = decoder->getFramesPerChunk();// Decodes audio.int decodeErrorCode = decoder->decodeAudio(pointer2, // Pointer to 16-bit signed integer numbers. The output. Must be at least numberOfFrames * 4 + 16384 bytes big.fc // The requested number of frames. Should NOT be less than the value returned by getFramesPerChunk().);// Returns with the duration of the current file in frames.// Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.int df = decoder->getDurationFrames();// Returns with the duration of the current file in seconds.// Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.double ds = decoder->getDurationSeconds();// Returns with the current position in frames. The postion may change after each decode() or seekTo().int pos = decoder->getPositionFrames();// Returns with the sample rate of the current file.unsigned int sr = decoder->getSamplerate();// Returns with the format of the current file.Superpowered::Decoder::Format f = decoder->getFormat();// Jumps to the specified position's chunk (frame) beginning.// Some codecs (such as MP3) contain audio in chunks (frames). This method will not jump precisely to the specified position, but to the chunk's beginning the position belongs to.// Returns with success (true) or failure (false).bool success = decoder->setPositionQuick(10052 // The requested position in frames.);// Jumps to a specific position. This method is a little bit slower than setPositionQuick().// Returns with success (true) or failure (false).bool success2 = decoder->setPositionPrecise(10052 // The requested position in frames.);// Detects silence at the beginning. This function changes the position!// The return value can be:// - A positive number or zero: the frame index where audio starts.// - Superpowered.Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioStartFrame() or getAudioEndFrame() later (it's recommended to wait at least 0.1 seconds).// - Superpowered.Decoder.NetworkError: network (download) error.// - Superpowered.Decoder.Error: internal decoder error.int start = decoder->getAudioStartFrame(0, // Limit frames. How far to search for. 0 means "the entire audio file".0 // Loudness threshold in decibel. 0 means "any non-zero audio". The value -49 is useful for vinyl rips having vinyl noise (crackles).);// Detects silence at the end. This function changes the position!// The return value can be:// - A positive number or zero: the frame index where audio ends.// - Superpowered.Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioEndFrame() later (it's recommended to wait at least 0.1 seconds).// - Superpowered.Decoder.NetworkError: network (download) error.// - Superpowered.Decoder.Error: internal decoder error.int end = decoder->getAudioEndFrame(0, // Limit frames. How far to search for from the end (the duration in frames). 0 means "the entire audio file".0 // Loudness threshold in decibel. 0 means "any non-zero audio". The value -49 is useful for vinyl rips having vinyl noise (crackles).);
Accessing metadata
// Parses all ID3 frames. Do not use startReadingID3/readNextID3Frame after this.decoder.parseAllID3Frames(true, // Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU.16384, // The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images).);// Starts reading ID3 frames. Use readNextID3Frame() in an iteration after this.decoder.startParsingID3Frames(true, // Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU.16384, // The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images).);// Reads the next ID3 frame and returns with its data size or -1 if finished reading.let frameSizeBytes = decoder.readNextID3Frame();// Returns with the current ID3 frame name (four char). To be used with readNextID3Frame().let frameName = decoder.getID3FrameName();// Returns with the raw data of the current ID3 frame. To be used with readNextID3Frame().let pointerToFrame = decoder.getID3FrameData();// Returns with the current ID3 frame data length.let frameDataLengthBytes = decoder.getID3FrameDataLengthBytes();// Returns with the text inside the current ID3 frame. To be used with readNextID3Frame(). Use it for frames containing text only!// Returns a pointer to the text in UTF-8 encoding (you take ownership on the data, don't forget to free() when done to prevent memory leaks), or NULL if empty.let pointer = decoder.getID3FrameAsString(0 // Offset. Parse from this byte index.);// Returns with the contents "best" artist tag (TP1-4, TPE1-4, QT atoms). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let pointer = decoder.getArtist(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the contents "best" title tag (TT1-3, TIT1-3, QT atoms). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let pointer = decoder.getTitle(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the contents of the TALB tag (or QT atom). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let pointer = decoder.getAlbum(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the track index (track field or TRCK).// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let ti = decoder.getTrackIndex();// Returns with the contents "best" image tag (PIC, APIC, QT atom). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let pointer = decoder.getImage(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the the size of the image returned by getImage(). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let imageSizeBytes = decoder.getImageSizeBytes();// Returns with the bpm value of the "best" bpm tag (TBP, TBPM, QT atom). May return 0.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().let bpm = decoder.getBPM();
// Parses all ID3 frames. Do not use startReadingID3/readNextID3Frame after this.decoder->parseAllID3Frames(true, // Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU.16384 // The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images).);// Starts reading ID3 frames. Use readNextID3Frame() in an iteration after this.decoder->startParsingID3Frames(true, // Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU.16384 // The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images).);// Reads the next ID3 frame and returns with its data size or -1 if finished reading.unsigned int frameSizeBytes = decoder->readNextID3Frame();// Returns with the current ID3 frame name (four char). To be used with readNextID3Frame().unsigned int frameName = decoder->getID3FrameName();// Returns with the raw data of the current ID3 frame. To be used with readNextID3Frame().void *pointerToFrame = decoder->getID3FrameData();// Returns with the current ID3 frame data length.unsigned int frameDataLengthBytes = decoder->getID3FrameDataLengthBytes();// Returns with the text inside the current ID3 frame. To be used with readNextID3Frame(). Use it for frames containing text only!// Returns a pointer to the text in UTF-8 encoding (you take ownership on the data, don't forget to free() when done to prevent memory leaks), or NULL if empty.char *frame = decoder->getID3FrameAsString(0 // Offset. Parse from this byte index.);// Returns with the contents "best" artist tag (TP1-4, TPE1-4, QT atoms). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().char *artist = decoder->getArtist(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the contents "best" title tag (TT1-3, TIT1-3, QT atoms). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().char *title = decoder->getTitle(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the contents of the TALB tag (or QT atom). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().char *album = decoder->getAlbum(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the track index (track field or TRCK).// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().unsigned int ti = decoder->getTrackIndex();// Returns with the contents "best" image tag (PIC, APIC, QT atom). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().void *image = decoder->getImage(false // Take ownership. For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks).);// Returns with the the size of the image returned by getImage(). May return NULL.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().unsigned int imageSizeBytes = decoder->getImageSizeBytes();// Returns with the bpm value of the "best" bpm tag (TBP, TBPM, QT atom). May return 0.// Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().float bpm = decoder->getBPM();
Clearing up memory
// Destructor (to free up memory).decoder.destruct();
delete decoder;
Constants
- Superpowered.DecoderCONSTANTSConstants in the main Decoder namespace.- Value - Description - Format_MP3 - MP3 - Format_AAC - AAC, HE-AAC. - Format_AIFF - AIFF - Format_WAV - WAV - Format_MediaServer - Other format decoded by iOS, macOS or tvOS. - Format_HLS - HTTP Live Streaming. - EndOfFile - End-of-file reached. - BufferingTryAgainLater - Buffering (waiting for the network to pump enough data). - NetworkError - Network (download) error. - Error - Decoding error. - OpenSuccess - Opened successfully. - OpenError_OutOfMemory - Some memory allocation failed. Recommended action: check for memory leaks. - OpenError_PathIsNull - Path is NULL. - OpenError_FastMetadataNotLocal - metaOnly was true, but it works on local files only. - OpenError_ID3VersionNotSupported - ID3 version 2.2, 2.3 and 2.4 are supported only. - OpenError_ID3ReadError - File read error while reading the ID3 tag. - OpenError_FileFormatNotRecognized - The decoder is not able to decode this file format. - OpenError_FileOpenError - Such as fopen() failed. Recommended action: check if the path and read permissions are correct. - OpenError_FileLengthError - Such as fseek() failed. Recommended action: check if read permissions are correct. - OpenError_FileTooShort - The file has just a few bytes of data. - OpenError_AppleAssetFailed - The Apple system codec could not create an AVURLAsset on the resource. Wrong file format? - OpenError_AppleMissingTracks - The Apple system codec did not found any audio tracks. Wrong file format? - OpenError_AppleDecoding - The Apple system codec could not get the audio frames. Wrong file format? - OpenError_ImplementationError0 - Should never happen. But if it does, please let us know. - OpenError_ImplementationError1 - Should never happen. But if it does, please let us know. - OpenError_ImplementationError2 - Should never happen. But if it does, please let us know. - OpenError_UseSetTempFolder - Call AdvancedAudioPlayer.setTempFolder first. 
- Superpowered::DecoderCONSTANTSConstants in the main Decoder namespace.- Value - Description - Format_MP3 - MP3 - Format_AAC - AAC, HE-AAC. - Format_AIFF - AIFF - Format_WAV - WAV - Format_MediaServer - Other format decoded by iOS, macOS or tvOS. - Format_HLS - HTTP Live Streaming. - EndOfFile - End-of-file reached. - BufferingTryAgainLater - Buffering (waiting for the network to pump enough data). - NetworkError - Network (download) error. - Error - Decoding error. - OpenSuccess - Opened successfully. - OpenError_OutOfMemory - Some memory allocation failed. Recommended action: check for memory leaks. - OpenError_PathIsNull - Path is NULL. - OpenError_FastMetadataNotLocal - metaOnly was true, but it works on local files only. - OpenError_ID3VersionNotSupported - ID3 version 2.2, 2.3 and 2.4 are supported only. - OpenError_ID3ReadError - File read error while reading the ID3 tag. - OpenError_FileFormatNotRecognized - The decoder is not able to decode this file format. - OpenError_FileOpenError - Such as fopen() failed. Recommended action: check if the path and read permissions are correct. - OpenError_FileLengthError - Such as fseek() failed. Recommended action: check if read permissions are correct. - OpenError_FileTooShort - The file has just a few bytes of data. - OpenError_AppleAssetFailed - The Apple system codec could not create an AVURLAsset on the resource. Wrong file format? - OpenError_AppleMissingTracks - The Apple system codec did not found any audio tracks. Wrong file format? - OpenError_AppleDecoding - The Apple system codec could not get the audio frames. Wrong file format? - OpenError_ImplementationError0 - Should never happen. But if it does, please let us know. - OpenError_ImplementationError1 - Should never happen. But if it does, please let us know. - OpenError_ImplementationError2 - Should never happen. But if it does, please let us know. - OpenError_UseSetTempFolder - Call AdvancedAudioPlayer::setTempFolder first. 
Static Methods
- decodeToAudioInMemoryMETHODDecodes an entire audio file in memory to AudioInMemory format in a single call. The output can be loaded by the AdvancedAudioPlayer.ParametersReturns- Name - Type - Description - pointer - Number (pointer in Linear Memory)- Pointer to an audio file loaded onto the WebAssembly Linear Memory. The Decoder will free() this data. - sizeBytes - Number- The audio file length in bytes. - Type - Description - Number (pointer in Linear Memory)- Linear Memory pointer or 0 on error. 
- decodeToAudioInMemoryMETHODDecodes an entire audio file in memory to AudioInMemory format in a single call. The output can be loaded by the AdvancedAudioPlayer.ParametersReturns- Name - Type - Default - Description - pointer - void *- Pointer to an audio file loaded onto the heap. Should be allocated using malloc() (and not _aligned_malloc() or similar). The Decoder will free() this data. - sizeBytes - unsigned int- The audio file length in bytes. - Type - Description - void *- Pointer or NULL on error. 
- statusCodeToStringMETHODReturns with a human readable error string.ParametersReturns- Name - Type - Description - code - Number- The return value of the open...() method. - Type - Description - Number (pointer in Linear Memory)- You can use Superpowered.toString(this_pointer) to create a JavaScript string from it. 
- statusCodeToStringMETHODReturns with a human readable error string.ParametersReturns- Name - Type - Default - Description - code - int- The return value of the open...() method. - Type - Description - const char *- A human readable error string. 
Properties
HLSAutomaticAlternativeSwitching
PROPERTYIf true, then the decoder will automatically switch between the HLS alternatives according to the available network bandwidth.
| Type | Min | Max | Default | bool | true | 
|---|
HLSBufferingSeconds
PROPERTYHow many seconds ahead of the playback position to download.
| Type | Min | Max | Default | int | HLS_DOWNLOAD_REMAINING | 
|---|
HLSMaximumDownloadAttempts
PROPERTYHow many times to retry if a HLS segment download fails.
| Type | Min | Max | Default | int | 100 | 
|---|
Methods
- constructorMETHODCreates an instance of the Decoder class.ParametersNoneReturns- Type - Description - Superpowered.Decoder- The constructed instance. 
- constructorMETHODCreates an instance of the Decoder class.ParametersNoneReturns- Type - Description - Superpowered::Decoder- The constructed instance. 
- decodeAudioMETHODDecodes audio.ParametersReturns- Name - Type - Description - output - Number (pointer in Linear Memory)- Allocated memory to store the output. Must be at least numberOfFrames * 4 + 16384 bytes big. - numberOfFrames - Number- The requested number of frames. Should NOT be less than the value returned by getFramesPerChunk(). - Type - Description - Number- A positive number above zero: the number of frames decoded.
- Decoder.EndOfFile: end of file reached, there is nothing more to decode. Use setPosition.
- Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry decodeAudio() later (it's recommended to wait at least 0.1 seconds).
- Decoder.NetworkError: network (download) error.
- Decoder.Error: internal decoder error.
 
- decodeAudioMETHODDecodes audio.ParametersReturns- Name - Type - Default - Description - output - short int *- Allocated memory to store the output. Must be at least numberOfFrames * 4 + 16384 bytes big. - numberOfFrames - unsigned int- The requested number of frames. Should NOT be less than the value returned by getFramesPerChunk(). - Type - Description - int- A positive number above zero: the number of frames decoded.
- Decoder.EndOfFile: end of file reached, there is nothing more to decode. Use setPosition.
- Decoder.BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry decodeAudio() later (it's recommended to wait at least 0.1 seconds).
- Decoder.NetworkError: network (download) error.
- Decoder.Error: internal decoder error.
 
- destructMETHODDestructor to free Linear Memory.ParametersNoneReturnsNone
- getAlbumMETHODReturns with the contents of the TALB tag (or QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Description - takeOwnership - Boolean- For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - Number (pointer in Linear Memory)- The string or 0 if not found. 
- getAlbumMETHODReturns with the contents of the TALB tag (or QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Default - Description - takeOwnership - bool- false - For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - char *- The string or NULL if not found. 
- getArtistMETHODReturns with the contents "best" artist tag (TP1-4, TPE1-4, QT atoms). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Description - takeOwnership - Boolean- For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - Number (pointer in Linear Memory)- The string or 0 if not found. 
- getArtistMETHODReturns with the contents "best" artist tag (TP1-4, TPE1-4, QT atoms). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Default - Description - takeOwnership - bool- false - For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - char *- The string or NULL if not found. 
- getAudioEndFrameMETHODDetects silence at the end. WARNING! This function changes the position!ParametersReturns- Name - Type - Description - limitFrames - Number- Optional. How far to search for from the end (the duration in frames). 0 means 'the entire audio file'. - thresholdDb - Number- Optional. Loudness threshold in decibel. 0 means 'any non-zero audio'. The value -49 is useful for vinyl rips having vinyl noise (crackles). - Type - Description - Number- A positive number or zero: the frame index where audio ends.
- Decoder::BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioEndFrame()later (it's recommended to wait at least 0.1 seconds).
- Decoder::NetworkError: network (download) error.
- Decoder::Error: internal decoder error.
 
- getAudioEndFrameMETHODDetects silence at the end. WARNING! This function changes the position!ParametersReturns- Name - Type - Default - Description - limitFrames - unsigned int- 0 - Optional. How far to search for from the end (the duration in frames). 0 means 'the entire audio file'. - thresholdDb - int- 0 - Optional. Loudness threshold in decibel. 0 means 'any non-zero audio'. The value -49 is useful for vinyl rips having vinyl noise (crackles). - Type - Description - int- A positive number or zero: the frame index where audio ends.
- Decoder::BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioEndFrame()later (it's recommended to wait at least 0.1 seconds).
- Decoder::NetworkError: network (download) error.
- Decoder::Error: internal decoder error.
 
- getAudioStartFrameMETHODDetects silence at the beginning. WARNING! This function changes the position!ParametersReturns- Name - Type - Description - limitFrames - Number- Optional. How far to search for from the end (the duration in frames). 0 means 'the entire audio file'. - thresholdDb - Number- Optional. Loudness threshold in decibel. 0 means 'any non-zero audio'. The value -49 is useful for vinyl rips having vinyl noise (crackles). - Type - Description - Number- A positive number or zero: the frame index where audio ends.
- Decoder::BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioStartFrame()later (it's recommended to wait at least 0.1 seconds).
- Decoder::NetworkError: network (download) error.
- Decoder::Error: internal decoder error.
 
- getAudioStartFrameMETHODDetects silence at the beginning. WARNING! This function changes the position!ParametersReturns- Name - Type - Default - Description - limitFrames - unsigned int- Optional. How far to search for from the end (the duration in frames). 0 means 'the entire audio file'. - thresholdDb - int- Optional. Loudness threshold in decibel. 0 means 'any non-zero audio'. The value -49 is useful for vinyl rips having vinyl noise (crackles). - Type - Description - int- A positive number or zero: the frame index where audio ends.
- Decoder::BufferingTryAgainLater: the decoder needs more data to be downloaded. Retry getAudioStartFrame()later (it's recommended to wait at least 0.1 seconds).
- Decoder::NetworkError: network (download) error.
- Decoder::Error: internal decoder error.
 
- getBPMMETHODReturns with the bpm value of the "best" bpm tag (TBP, TBPM, QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - Number- BPM or 0. 
- getBPMMETHODReturns with the bpm value of the "best" bpm tag (TBP, TBPM, QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - float- BPM or 0. 
- getBufferedEndPercentMETHODIndicates which part of the file has fast access. For local files it will always be 1.0f.ParametersNoneReturns- Type - Description - float- Percentage between 0 and 1. 
- getBufferedStartPercentMETHODIndicates which part of the file has fast access. For local files it will always be 0.0f.ParametersNoneReturns- Type - Description - float- Percentage between 0 and 1. 
- getCurrentBpsMETHODReturns with the current download speed.ParametersNoneReturns- Type - Description - unsigned int- Current download speed in bytes per second. 
- getDurationFramesMETHODReturns with the duration of the current file in frames. Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.ParametersNoneReturns- Type - Description - Number- Duration of the current file in frames. 
- getDurationFramesMETHODReturns with the duration of the current file in frames. Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.ParametersNoneReturns- Type - Description - int- Duration of the current file in frames. 
- getDurationSecondsMETHODReturns with the duration of the current file in seconds. Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.ParametersNoneReturns- Type - Description - Number- Duration of the current file in seconds. 
- getDurationSecondsMETHODReturns with the duration of the current file in seconds. Duration may change after each decode() or seekTo(), because some audio formats doesn't contain precise length information.ParametersNoneReturns- Type - Description - double- Duration of the current file in seconds. 
- getFormatMETHODReturns with the format of the current file.ParametersNoneReturns- Type - Description - Superpowered.Decoder.Format- Format of the current file. 
- getFormatMETHODReturns with the format of the current file.ParametersNoneReturns- Type - Description - Superpowered::Decoder::Format- Format of the current file. 
- getFramesPerChunkMETHODReturns with how many frames are in one chunk of the source file. For example: MP3 files store 1152 audio frames in a chunk.ParametersNoneReturns- Type - Description - Number- Number of frames in one chunk. 
- getFramesPerChunkMETHODReturns with how many frames are in one chunk of the source file. For example: MP3 files store 1152 audio frames in a chunk.ParametersNoneReturns- Type - Description - unsigned int- Number of frames in one chunk. 
- getFullyDownloadedPathMETHODThe file system path of the fully downloaded audio file for progressive downloads.ParametersNoneReturns- Type - Description - const char *- Path of the fully downloaded audio file or NULL until the download finishes. 
- getID3FrameAsStringMETHODReturns with the text inside the current ID3 frame. To be used with readNextID3Frame(). Use it for frames containing text only!ParametersReturns- Name - Type - Description - offset - Number- Parse from this byte index. - Type - Description - Number (pointer in Linear Memory)- The text in UTF-8 encoding (you take ownership on the data, don't forget to free() when done to prevent memory leaks), or 0 if empty. You can use Superpowered.toString(this_pointer) to create a JavaScript string from it. 
- getID3FrameAsStringMETHODReturns with the text inside the current ID3 frame. To be used with readNextID3Frame(). Use it for frames containing text only!ParametersReturns- Name - Type - Default - Description - offset - int- 0 - Parse from this byte index. - Type - Description - char *- A pointer to the text in UTF-8 encoding (you take ownership on the data, don't forget to free() when done to prevent memory leaks), or NULL if empty. 
- getID3FrameDataMETHODReturns with the raw data of the current ID3 frame. To be used with readNextID3Frame().ParametersNoneReturns- Type - Description - Number (pointer in Linear Memory)- The data. 
- getID3FrameDataMETHODReturns with the raw data of the current ID3 frame. To be used with readNextID3Frame().ParametersNoneReturns- Type - Description - void *- The data. 
- getID3FrameDataLengthBytesMETHODReturns with the current ID3 frame data length.ParametersNoneReturns- Type - Description - Number- Length of the current ID3 frame in bytes. 
- getID3FrameDataLengthBytesMETHODReturns with the current ID3 frame data length.ParametersNoneReturns- Type - Description - unsigned int- Length of the current ID3 frame in bytes. 
- getID3FrameNameMETHODReturns with the current ID3 frame name. To be used with readNextID3Frame().ParametersNoneReturns- Type - Description - Number- Name of the current ID3 frame as a "four char". 
- getID3FrameNameMETHODReturns with the current ID3 frame name. To be used with readNextID3Frame().ParametersNoneReturns- Type - Description - unsigned int- Name of the current ID3 frame as a "four char". 
- getImageMETHODReturns with the contents 'best' image tag (PIC, APIC, QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Description - takeOwnership - Boolean- For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - Number (pointer in Linear Memory)- Pointer to the image or 0 if not found. 
- getImageMETHODReturns with the contents 'best' image tag (PIC, APIC, QT atom). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Default - Description - takeOwnership - bool- false - For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - void *- Pointer to the image or NULL if not found. 
- getImageSizeBytesMETHODReturns with the the size of the image returned by getImage(). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - Number- The size of the ID3 image in bytes or 0 if not found. 
- getImageSizeBytesMETHODReturns with the the size of the image returned by getImage(). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - unsigned int- The size of the ID3 image in bytes or 0 if not found. 
- getPositionFramesMETHODReturns with the current position in frames. The postion may change after each decode() or seekTo().ParametersNoneReturns- Type - Description - Number- Current position in frames. 
- getPositionFramesMETHODReturns with the current position in frames. The postion may change after each decode() or seekTo().ParametersNoneReturns- Type - Description - int- Current position in frames. 
- getSampleRateMETHODReturns with the sample rate of the current file.ParametersNoneReturns- Type - Description - Number- Sample rate of the current file. 
- getSampleRateMETHODReturns with the sample rate of the current file.ParametersNoneReturns- Type - Description - unsigned int- Sample rate of the current file. 
- getStemsJSONStringMETHODReturns with the JSON metadata string for the Native Instruments Stems format.ParametersNoneReturns- Type - Description - Number (pointer in Linear Memory)- Linear Memory pointer or 0 if the file is not Stems. You can use Superpowered.toString(this_pointer) to create a JavaScript string from it. 
- getStemsJSONStringMETHODReturns with the JSON metadata string for the Native Instruments Stems format.ParametersNoneReturns- Type - Description - const char *- JSON metadata string or NULL if the file is not Stems. 
- getTitleMETHODReturns with the contents "best" title tag (TT1-3, TIT1-3, QT atoms). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Description - takeOwnership - Boolean- For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - Number (pointer in Linear Memory)- The string or 0 if not found. 
- getTitleMETHODReturns with the contents "best" title tag (TT1-3, TIT1-3, QT atoms). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersReturns- Name - Type - Default - Description - takeOwnership - bool- false - For advanced use. If true, you take ownership on the data (don't forget to free() when done to prevent memory leaks). - Type - Description - char *- The string or NULL if not found. 
- getTrackIndexMETHODReturns with the track index (track field or TRCK). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - Number- ID3 track index 
- getTrackIndexMETHODReturns with the track index (track field or TRCK). Call this after parseAllID3Frames() OR finished reading all ID3 frames with readNextID3Frame().ParametersNoneReturns- Type - Description - unsigned int- ID3 track index 
- openMETHODOpen a file for decoding.ParametersReturns- Name - Type - Default - Description - path - const char *- Full file system path or progressive download path (http or https). - metaOnly - bool- If true, it opens the file for fast metadata reading only, not for decoding audio. Available for fully available local files only (no network access). - offset - int- 0 - Byte offset in the file. Primarily designed to open raw files from an apk. - length - int- 0 - Byte length from offset. Set offset and length to 0 to read the entire file. - stemsIndex - int- 0 - Stems track index for Native Instruments Stems format. - customHTTPRequest - Superpowered::httpRequest *- 0 - If custom HTTP communication is required (such as sending http headers for authorization), pass a fully prepared http request object. The decoder will copy this object. - Type - Description - int
- The return value can be grouped into four categories:
- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- The return value can be grouped into four categories:
- openAudioFileInMemoryMETHODOpens a memory location for decoding.ParametersReturns- Name - Type - Description - pointer - Number (pointer in Linear Memory)- An audio file loaded onto Linear Memory. The Decoder will take ownership on this data. - sizeBytes - Number- The audio file length in bytes. - metaOnly - Boolean- If true, it opens the file for fast metadata reading only, not for decoding audio. - Type - Description - Number- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- openAudioFileInMemoryMETHODOpens a memory location for decoding.ParametersReturns- Name - Type - Default - Description - pointer - void *- An audio file loaded onto the heap. Should be allocated using malloc() (and not _aligned_malloc() or similar). The Decoder will take ownership on this data. - sizeBytes - unsigned int- The audio file length in bytes. - metaOnly - bool- false - If true, it opens the file for fast metadata reading only, not for decoding audio. - Type - Description - int- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- openHLSMETHODOpens a HTTP Live Streaming stream.ParametersReturns- Name - Type - Default - Description - url - const char *- Stream URL. - liveLatencySeconds - char- -1 - When connecting or reconnecting to a HLS live stream, the decoder will try to skip audio to maintain this latency. Default: -1 (the decoder wil not skip audio and the live stream starts at the first segment specified by the server). - customHTTPRequest - Superpowered::httpRequest *- 0 - If custom HTTP communication is required (such as sending http headers for authorization), pass a fully prepared http request object. The decoder will copy this object. - Type - Description - int
- The return value can be grouped into four categories:
- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- The return value can be grouped into four categories:
- openMemoryMETHODOpens a memory location in Superpowered AudioInMemory format for decoding.ParametersReturns- Name - Type - Description - pointer - Number (pointer in Linear Memory)- Data in Superpowered AudioInMemory format. Ownership is controlled by the AudioInMemory format. - metaOnly - Boolean- If true, it opens the file for fast metadata reading only, not for decoding audio. - Type - Description - Number- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- openMemoryMETHODOpens a memory location in Superpowered AudioInMemory format for decoding.ParametersReturns- Name - Type - Default - Description - pointer - void *- Data in Superpowered AudioInMemory format. Ownership is controlled by the AudioInMemory format. - metaOnly - bool- false - If true, it opens the file for fast metadata reading only, not for decoding audio. - Type - Description - int- Decoder::OpenSuccess: successful open.
- httpResponse::StatusCode_Progress: the open method needs more time opening an audio file from the network. In this case retry open() later until it returns something else than StatusCode_Progress (it's recommended to wait at least 0.1 seconds).
- A value above 1000: internal decoder error.
- A HTTP status code for network errors.
 
- parseAllID3FramesMETHODParses all ID3 frames. Do not use startReadingID3/readNextID3Frame after this.ParametersReturns- Name - Type - Description - skipImages - Boolean- Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU. - maxFrameDataSize - Number- The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images). None
- parseAllID3FramesMETHODParses all ID3 frames. Do not use startReadingID3/readNextID3Frame after this.ParametersReturns- Name - Type - Default - Description - skipImages - bool- Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU. - maxFrameDataSize - unsigned int- false - The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images). None
- readNextID3FrameMETHODReads the next ID3 frame.ParametersNoneReturns- Type - Description - Number- ID3 frame data size or -1 if finished reading. 
- readNextID3FrameMETHODReads the next ID3 frame.ParametersNoneReturns- Type - Description - usigned int- ID3 frame data size or -1 if finished reading. 
- reconnectToMediaserverMETHODApple's built-in codec may be used in some cases, such as decoding ALAC files. Call this after a media server reset or audio session interrupt to resume playback.ParametersNoneReturnsNone
- setPositionPreciseMETHODJumps to a specific position. This method is a little bit slower than setPositionQuick().ParametersReturns- Name - Type - Description - positionFrames - Number- The requested position. - Type - Description - Boolean- Returns with success (true) or failure (false). 
- setPositionPreciseMETHODJumps to a specific position. This method is a little bit slower than setPositionQuick().ParametersReturns- Name - Type - Default - Description - positionFrames - int- The requested position. - Type - Description - bool- Returns with success (true) or failure (false). 
- setPositionQuickMETHODJumps to the specified position's chunk (frame) beginning. Some codecs (such as MP3) contain audio in chunks (frames). This method will not jump precisely to the specified position, but to the chunk's beginning the position belongs to.ParametersReturns- Name - Type - Description - positionFrames - Number- The requested position. - Type - Description - Boolean- Returns with success (true) or failure (false). 
- setPositionQuickMETHODJumps to the specified position's chunk (frame) beginning. Some codecs (such as MP3) contain audio in chunks (frames). This method will not jump precisely to the specified position, but to the chunk's beginning the position belongs to.ParametersReturns- Name - Type - Default - Description - positionFrames - int- The requested position. - Type - Description - bool- Returns with success (true) or failure (false). 
- startParsingID3FramesMETHODStarts reading ID3 frames. Use readNextID3Frame() in an iteration after this.ParametersReturns- Name - Type - Description - skipImages - Boolean- Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU. - maxFrameDataSize - Number- The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images). None
- startParsingID3FramesMETHODStarts reading ID3 frames. Use readNextID3Frame() in an iteration after this.ParametersReturns- Name - Type - Default - Description - skipImages - bool- Parsing ID3 image frames is significantly slower than parsing other frames. Set this to true if not interested in image information to save CPU. - maxFrameDataSize - unsigned int- The maximum frame size in bytes to retrieve if the decoder can not memory map the entire audio file. Affects memory usage. Useful to skip large payloads (such as images). None
FAQ
Do you know where I can find example code for decoding a MP3 file to PCM for Android?
Do you support FLAC or OGG format?
Is BIFS decoding for mp4 available?
Is there a different version of Superpowered SDK / codecs that support Dolby 5.1 channel audio format?
The tempo and pitch of the dumped audio file sounds changed while listening with other raw supported player. Approx pitch by +4 and tempo by +10