Source Class: Advanced Audio Player
Interactive example
Overview
The Superpowered Advanced Audio Player is an extremely flexible, high performance and feature rich method of audio playback across all platforms. Here a taste of what's possible:
- Time-stretching and pitch shifting,
- Beat and tempo sync,
- Scratching,
- Tempo bend,
- Looping,
- Slip mode,
- Fast seeking (cached points),
- Momentum and jog wheel handling,
- Zero latency, real-time operation.
In short, the Superpowered Advanced Audio Player is the BEST way to accurately play back audio on the web!
You should note that there are some slight unavoidable differences between the JS and C++ implementation in contrast to it's native C++ version.
When using the WebAssembly library you cannot:
- Directly read files from the file system, due to Javascript sandbox security design. You must load audio from decoded audio buffers in the AudioInMemory format, please see SuperpoweredTrackLoader to see our background worker for help that with that.
- Open streaming HLS audio urls.
The AdvancedAudioPlayer can be used in a real-time audio processing context or offline processing.
- Time-stretching and pitch shifting,
- Beat and tempo sync,
- Scratching,
- Tempo bend,
- Looping,
- Slip mode,
- Fast seeking (cached points),
- Momentum and jog wheel handling,
- Zero latency, real-time operation,
- Low memory usage,
- Thread safety (all methods are thread-safe),
- Direct iPod music library access.
You may find our loading audio guides useful for more code examples
Supported file formats
The AdvancedAudioPlayer supports playback of the following audio 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).
- Native Instruments STEMS.
- 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).
- ALAC/Apple Lossless (on iOS only).
- HTTP Live Streaming (HLS): VOD/live/event streams, AAC-LC/MP3 in audio files or MPEG-TS audio. Support for byte ranges and AES-128 encryption.
- Native Instruments STEMS.
Time-stretching and pitch-shifting
The AdvancedAudioPlayer conveniently exposes an internal instance of the Superpowered TimeStretching class, giving you time and pitch manipulation directly from the player. The timeStretching property should be set to true for this.
playbackRate allows control of the speed of the playback in the time domain, while pitchShiftCents allows control of the pitch in the frequency domain. Use them to control speed and pitch individually, but do not use them together to achieve vinyl sound (just turn off timeStretching for that case).Cents divide each musical note (half step or semitone) on the keyboard into 100. A full octave is represented by 1200 cents. To shift up one note (halfstep or semitone) would be
+100. To shift down two notes would be-200.
Setting formantCorrection between 0.0 and 1.0 will adjust the intensity of formant correction that is applied to treat some vocal distortion caused with the application of pitch shifting.
The internal time-stretching algorithm can be changed with timeStretchingSound which internally is referencing the sound property of the Superpowered TimeStretching class, meaning the following values are available:
0- best to save CPU with slightly lower audio quality.1- best for DJ apps, modern and "complete" music.2- best for instrumental loops and single instruments.
The rate limits of time stretching are set in the AdvancedAudioPlayer constructor parameters. The lower limit defaults to 0.501 and the upper limit defaults to 2.0. If playbackRate goes above or below these values, then the audio will audibly slow down or speed up.
Pitch bend
On top of the time-stretching and pitch shifting metioned above, you can also apply temporary pitch bends to the audio being played. This is akin to a pitch adjustment slider on a turntable.
Use the pitchBend() method to start the pitch bend, use getCurrentPitchBendPercent() to get the current value and use endContinuousPitchBend() to cancel any pitch bends currently taking effect.
We've put together a little example of that working in practise which you might find useful.
Quantum and Phase
This class is capable of synchronizing with quantum and phase, which is also the primary synchronization concept of Ableton Link and other standards. It means that complete loops can be synchronized too, not just individual beats.
Quantum is the "loop size" in this environment, in other words it's the timespan the player is synchronizing to. Quantum can have any arbitrary value, but the most common practice is setting quantum to the beat length of the loop. For example, if quantum is set to 4, then the quantum length is four beats.
Phase is the position inside the quantum as a percentage, therefore it can have values from 0 (the beginning of the quantum) to 1 (the end of the quantum). For example, if quantum is set to 4, then 0 phase means the beginning of the first beat, 0.25 is the second beat, 0.5 is the third beat and 0.75 is the fourth beat.
Implementation example
import {SuperpoweredWebAudio, SuperpoweredTrackLoader} from 'your superpowered code location path';class YourCustomProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {...// onReady is called by the Superpowered WebAudioManager when its ready to start processing audio.onReady() {// Here we create an instance of the AdvancedAudioPlayer which will use later to play the decoded audio buffer.this.player = new this.Superpowered.AdvancedAudioPlayer(this.samplerate, 2, 2, 0, 0.501, 2, false);}// Runs before the node is destroyed.// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).onDestruct() {this.player.destruct();}// Called from within this class.loadAudio(url) {// Notice that we pass in a reference to 'this',// which is used to call the onMessageFromMainScope callback within this call instance when loaded.// The fetching and decoding of the audio takes place on dedicated workers, spawned from the main thread. This prevents any blocking.this.Superpowered.downloadAndDecode(url, this);}// SuperpoweredTrackLoader calls this when its finished loading and decoding audio.onMessageFromMainScope(message) {if (message.SuperpoweredLoaded) {const buffer = message.SuperpoweredLoaded.buffer; // ArrayBuffer with the downloaded and decoded audio in AudioInMemory format.const url = message.SuperpoweredLoaded.url; // The original url of the audio file fetched.// Once we have the pointer to the buffer, we pass the decoded audio into the AAP instance.this.player.openMemory(this.Superpowered.arrayBufferToWASM(buffer), false, false);// Play the audio once loaded. (optional of course).this.player.play();}}processAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callbackthis.player.outputSamplerate = this.samplerate;// Generate the output buffersif (!this.player.processStereo(outputBuffer.pointer, false, buffersize, 1)) {this.Superpowered.memorySet(outputBuffer.pointer, 0, buffersize * 8); // 8 bytes for each frame (1 channel is 4 bytes)}}
Loading audio
The downloading and decoding of an external asset can be triggered from any worker or worklet, just import SuperpoweredTrackLoader from the library helper files and use it like this:
this.Superpowered.downloadAndDecode('./music/track.mp3', self.onmessage);self.onmessage = function(message) {if (message.SuperpoweredLoaded) {let buffer = message.SuperpoweredLoaded.buffer; // ArrayBuffer with the downloaded and decoded audio in AudioInMemory format.let url = message.SuperpoweredLoaded.url; // The url of the audio file ('./music/track.mp3' in this example).// Player example loading the contents of the buffer:this.player.openMemory(this.Superpowered.arrayBufferToWASM(message.SuperpoweredLoaded.buffer), false, false);}}
Additional pseudo code examples
// Creates a player instance.let player = new Superpowered.AdvancedAudioPlayer(48000, // The initial sample rate of the player output in hz.2, // How many positions can be cached in the memory. Jumping to a cached point happens with zero latency. Loops are automatically cached.2, // The number of seconds to buffer internally for playback and cached points. Minimum 2, maximum 60. Default: 2.0, // The number of seconds of silence in the negative direction, before the beginning of the track.0.501, // Will not time-stretch but resample below this playback rate. Default: 0.501f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching. Default: 0.501f2, // Will not time-stretch but resample above this playback rate. Default: 2.0f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching.false // If true and a Native Instruments STEMS file is loaded, output 4 stereo channels. Default: false (stereo master mix output).);player.outputSamplerate = 48000; // The player output sample rate in Hz.player.timeStretching = true; // Enable/disable time-stretching. Default: true.player.formantCorrection = false; // Amount of formant correction, between 0 (none) and 1 (full). Default: 0.player.originalBPM = 120.3; // The original bpm of the current music. There is no auto-bpm detection inside, this must be set to a correct value for syncing. Maximum 300. A value below 20 will be automatically set to 0. Default: 0 (no bpm value known).player.fixDoubleOrHalfBPM = false; // If true and playbackRate is above 1.4f or below 0.6f, it will sync the tempo as half or double. Default: false.player.firstBeatMs = 50.24; // Tells where the first beat is (the beatgrid starts). Must be set to a correct value for syncing. Default: 0.player.defaultQuantum = 4; // Sets the quantum for quantized synchronization. Example: 4 means 4 beats.player.syncToBpm = 130.14; // A bpm value to sync with. Use 0.0f for no syncing.player.syncToMsElapsedSinceLastBeat = 89.445; // The number of milliseconds elapsed since the last beat on audio the player has to sync with. Use -1.0 to ignore.player.syncToPhase = 0.2344; // Used for quantized synchronization. The phase to sync with.player.syncToQuantum = 8; // Used for quantized synchronization. The quantum to sync with.player.pitchShiftCents = 0; // Pitch shift cents, from -2400 (two octaves down) to 2400 (two octaves up). Use values representing notes (multiply of 100), between -1200 and 1200 for low CPU load. Default: 0 (no pitch shift).player.loopOnEOF = true; // If true, jumps back and continues playback. If false, playback stops. Default: false.player.reverseToForwardAtLoopStart = true; // If this is true with playing backwards and looping, then reaching the beginning of the loop will change playback direction to forwards. Default: false.player.timeStretchingSound = 1; // The sound parameter of the internal TimeStretching instance.player.playbackRate = 1.05; // The playback rate. Must be positive and above 0.00001. Default: 1.Superpowered.AdvancedAudioPlayer.MaxPlaybackRate; // The maximum playback rate or scratching speed: 20.// Opens a memory location in Superpowered AudioInMemory format, with playback paused.// Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.player.openMemory(pointer, // Pointer to a location in WebAssembly Linear Memory. Data in the Superpowered AudioInMemory format.false, // If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds).false // If true, the player will check the length of the digital silence at the end of the audio file.);// Opens a memory location, with playback paused.// Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.player.openPCM16AudioInMemory(pointer, // Pointer to 16-bit integer numbers, raw stereo interleaved pcm audio.44100, // The sample rate in Hz. Valid from 8192 to 384000.1000000, // The duration of the audio in frames.false, // If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds).false // If true, the player will check the length of the digital silence at the end of the audio file.);// Returns with the latest player event. This method should be used in a periodically running code, at one place only, because it returns a specific event just once per open() call.let event = player.getLatestEvent();// If getLatestEvent returns with OpenFailed, retrieve the error code or HTTP status code here.let ec = player.getOpenErrorCode();// Player events.Superpowered.AdvancedAudioPlayer.PlayerEvent_None; // Open was not called yet.Superpowered.AdvancedAudioPlayer.PlayerEvent_Opening; // Trying to open the content.Superpowered.AdvancedAudioPlayer.PlayerEvent_OpenFailed; // Failed to open the content.Superpowered.AdvancedAudioPlayer.PlayerEvent_Opened; // Successfully opened the content, playback can start.// Returns with a human readable error string.let pointer = Superpowered.AdvancedAudioPlayer.statusCodeToString(ec // The error code.)// Returns true if end-of-file has been reached recently (will never indicate end-of-file if loopOnEOF is true). This method should be used in a periodically running code at one place only, because it returns a specific end-of-file event just once.let eof = player.eofRecently();player.syncMode = Superpowered.AdvancedAudioPlayer.SyncMode_TempoAndBeat; // The current sync mode (off, tempo, or tempo+beat). Default: off.// Synchronization modes.Superpowered.AdvancedAudioPlayer.SyncMode_None; // No synchronization.Superpowered.AdvancedAudioPlayer.SyncMode_Tempo; // Sync tempo only.Superpowered.AdvancedAudioPlayer.SyncMode_TempoAndBeat; // Sync tempo and beat.// Indicates if the player is waiting for data (such as waiting for a network download).let waiting = player.isWaitingForBuffering();// Returns with the length of the digital silence at the beginning of the file if open...() was called with skipSilenceAtBeginning = true, 0 otherwise.let start = player.getAudioStartMs();// Returns with the length of the digital silence at the end of the file if open...() was called with measureSilenceAtEnd = true, 0 otherwise.let end = player.getAudioEndMs();// The current playhead position in milliseconds. Not changed by any pending setPosition() or seek() call, always accurate regardless of time-stretching and other transformations.let ms = player.getPositionMs();// The current position in milliseconds, immediately updated after setPosition() or seek(). Use this for UI display.let ms = player.getDisplayPositionMs();// Similar to getDisplayPositionMs(), but as a percentage (0 to 1).let p = player.getDisplayPositionPercent();// Similar to getDisplayPositionMs(), but as seconds elapsed.let sec = player.getDisplayPositionSeconds();// The position in milliseconds where the player will continue playback after slip mode ends.let ms = player.afterSlipModeWillJumpBackToPositionMs();// The duration of the current track in milliseconds. Returns UINT_MAX for live streams.let durms = player.getDurationMs();// The duration of the current track in seconds. Returns UINT_MAX for live streams.let dursec = player.getDurationSeconds();// Starts playback immediately without any synchronization.player.play();// Starts beat or tempo synchronized playback.player.playSynchronized();// Starts playback at a specific position. isPlaying() will return false and the position will not be updated until this function succeeds starting playback at the specified position.// You can call this in a real-time thread (audio processing callback) with a continuously updated time for a precise on-the-fly launch.player.playSynchronizedToPosition(123454 // Start position in milliseconds.);// Pause playback. There is no need for a "stop" method, this player is very efficient with the battery and has no significant "stand-by" processing.player.pause(0, // Momentum in seconds. 0 means to pause immediately.0 // Enable slip mode for a specific amount of time, or 0 to not slip.);// Toggle play/pause (no synchronization).player.togglePlayback();// Indicates if the player is playing or paused.let playing = player.isPlaying();// Simple seeking to a percentage.player.seek(0.1 // The position in percentage.);// Precise seeking.player.setPosition(1000, // Position in milliseconds.false, // If true, stops playback.true, // If the value above is false, makes a beat-synced start possible.false, // If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum.false // Wait or start immediately when synchronized.);// Caches a position for zero latency seeking.player.cachePosition(2000, // Position in milliseconds.255, // Position identification number. Use this to provide a custom identifier, so you can overwrite the same point later. Use 255 for a point with no identifier.);// Processes audio, stereo version. If the return value is true, the buffer has audio output from the player. If false, then the contents of buffer were not changed (typically happens when the player is paused).// Duration may change to a more precise value after this, because some file formats have no precise duration information.let notSilence = player.processStereo(outputPointer, // Pointer to floating point numbers. 32-bit interleaved stereo input/output buffer. Should be numberOfFrames * 8 + 64 bytes big.false, // If true, the player output will be mixed with the contents of buffer. If false, the contents of buffer will be overwritten with the player output.128, // The number of frames requested.1 // Volume. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.);// Processes audio, 8 channels version. If the return value is true, the buffer has audio output from the player. If false, then the contents of buffer were not changed (typically happens when the player is paused).// Duration may change to a more precise value after this, because some file formats have no precise duration information.let notSilence = player.process8Channels(outputPointer0, // Pointer to floating point numbers. 32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big.outputPointer1, // Pointer to floating point numbers. 32-bit interleaved stereo input/output buffer for the 2nd stereo channels. Should be numberOfFrames * 8 + 64 bytes big.outputPointer2, // Pointer to floating point numbers. 32-bit interleaved stereo input/output buffer for the 3rd stereo channels. Should be numberOfFrames * 8 + 64 bytes big.outputPointer3, // Pointer to floating point numbers. 32-bit interleaved stereo input/output buffer for the 4th stereo channels. Should be numberOfFrames * 8 + 64 bytes big.false, // If true, the player output will be added to the contents of buffers. If false, the contents of buffers will be overwritten with the player output.128, // The number of frames requested.1, // Volume for buffer0. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.1, // Volume for buffer1. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.1, // Volume for buffer2. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.1 // Volume for buffer3. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.);// Returns true if a STEMS file was loaded (and the player was initialized with enableStems == true).let stems = player.isStems();// Performs the last stage of STEMS processing, the master compressor and limiter. Works only if a STEMS file was loaded.player.processSTEMSMaster(input // Pointer to floating point numbers. 32-bit interleaved stereo input buffer.output // Pointer to floating point numbers. 32-bit interleaved stereo output buffer.128, // The number of frames to process.1 // Volume. 0 is silence, 1 is "original volume". Changes are automatically smoothed between consecutive processes.);// Returns with a stem's name if a STEMS file was loaded, NULL otherwise.let pointer = player.getStemName(0 // The index of the stem.);// Returns with a stem's color if a STEMS file was loaded, NULL otherwise.let pointer = player.getStemColor(0 // The index of the stem.);// The current bpm of the track (as changed by the playback rate).let bpm = player.getCurrentBpm();// How many milliseconds have elapsed since the last beat.let ms = player.getMsElapsedSinceLastBeat();// Which beat has just happened. Possible values:// 0 : unknown// 1 - 1.999: first beat// 2 - 2.999: second beat// 3 - 3.999: third beat// 4 - 4.999: fourth beatlet i = player.getBeatIndex();// Returns with the current phase for quantized synchronization.let phase = player.getPhase();// Returns with the current quantum for quantized synchronization.let quantum = player.getQuantum();// Returns with the distance (in milliseconds) to a specific quantum and phase for quantized synchronization.let ms = player.getMsDifference(0.5, // The phase to calculate against.4 // The quantum to calculate against.);// If the player is waiting to a synchronization event (such as synchronized playback start or restarting a loop), the return value indicates the time remaining in milliseconds (continously updated). 0 means not waiting to such event.let ms = player.getMsRemainingToSyncEvent();// Loop from a start point to some length.player.loop(0, // Loop from this milliseconds.1100, // Loop length in milliseconds.true, // If the playhead is within the loop, jump to the start or not.1, // Position identifier. Looping caches startMs, therefore you can specify an identifier (or set to 255 if you don't care).true, // Beat-synced start (true) or immediate (false).0, // Number of times to loop. 0 means: until exitLoop() is called.false, // If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum.false // Wait (true) or start immediately (false) when synchronized.);// Loop between a start and end points.player.loopBetween(0, // Loop from this milliseconds.4000, // Loop to this milliseconds.true, // If the playhead is within the loop, jump to the start or not.1, // Position identifier. Looping caches startMs, therefore you can specify an identifier (or set to 255 if you don't care).true, // Beat-synced start (true) or immediate (false).0, // Number of times to loop. 0 means: until exitLoop() is called.false, // If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum.false // Wait (true) or start immediately (false) when synchronized.);// Exit from the current loop.player.exitLoop(false // If true, synchronized start or re-synchronization after the loop exit.);// Indicates if looping is enabled.let looping = player.isLooping();// Returns true if a position is inside the current loop.let inside = player.msInLoop(150 // The position in milliseconds.);// Returns with the position of the closest beat.let ms = player.closestBeatMs(6002, // The position in milliseconds where to find the closest beat.0 // Set to 1-4 to retrieve the position of a specific beat index relative to ms, or 0 for any beat index.);// Returns with the beat index of the closest beat.let bi = player.closestBeatIndex(50 // The position in milliseconds where to find the closest beat.);// Sets playback direction.player.setReverse(false, // True: reverse. False: forward.0 // Enable slip mode for a specific amount of time, or 0 to not slip.);// If true, the player is playing backwards.let rev = player.isReverse();// Starts on changes pitch bend (temporary playback rate change).player.pitchBend(0.1, // The maximum playback rate range for pitch bend, should be between 0.01 and 0.3 (1% and 30%).false, // Use time-stretching for pitch bend or not (false makes it "audible").true, // True: faster, false: slower.500 // How long to maintain the pitch bend state in milliseconds. A value >= 1000 will hold until endContinuousPitchBend is called.);// Ends pitch bend.player.endContinuousPitchBend();// Returns with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.let ms = player.getBendOffsetMs();// Reset the pitch bend offset to the beatgrid to zero.player.resetBendMsOffset();// Indicates if returning from scratching or reverse playback will maintain the playback position as if the player had never entered into scratching or reverse playback.let slip = player.isPerformingSlip();// "Virtual jog wheel" or "virtual turntable" handling.player.jogTouchBegin(300, // Sets the sensitivity of the virtual wheel. Use around 2300 for pixel-perfect touchscreen waveform control.Superpowered.AdvancedAudioPlayer.Jogmode_Scratch, // Jog wheel mode (scratching, pitch bend, or parameter set in the 0-1 range).1000, // Enables slip mode for a specific amount of time for scratching, or 0 to not slip.);// A jog wheel should send some "ticks" with the movement. A waveform's movement in pixels for example.player.jogTick(600, // The ticks value.true, // Use time-stretching for pitch bend or not (false makes it "audible").0.1, // The maximum playback rate change for pitch bend, should be between 0.01f and 0.3f (1% and 30%).20, // How long to maintain the pitch bend state in milliseconds. A value >= 1000 will hold until endContinuousPitchBend is called.false, // True: if there was no jogTouchBegin, turn to JogMode_Parameter mode. False: if there was no jogTouchBegin, turn to JogMode_PitchBend mode.);// Call this when the jog touch ends.player.jogTouchEnd(0, // The decelerating rate for momentum. Set to 0 for automatic.true // Beat-synced start after decelerating.);// Direct turntable handling. Call this when scratching starts. This is an advanced method, use it only if not using the jogT... methods.player.startScratch(0, // Enable slip mode for a specific amount of time for scratching, or 0 to not slip.true // Stop playback or not.);// Scratch movement. This is an advanced method, use it only if not using the jogT... methods.player.scratch(1.1, // The current speed (pitch).0.5 // Smoothing factor. Should be between 0.05 (max. smoothing) and 1.0 (no smoothing).);// Ends scratching. This is an advanced method, use it only if not using the jogT... methods.player.endScratch(true // Return to the previous playback state (direction, speed) or not.);// Indicates if the player is in scratching mode.let scratching = player.isScratching();// If jog wheel mode is JogMode_Parameter, returns with the current parameter typically in the range of -1 to 1, or less than -1000000.0 if there was no jog wheel movement. processStereo or processMulti updates this value, therefore we recommend reading it after those calls were made, in the same thread.let p = player.getJogParameter();// Jog Wheel Mode, to be used with the jogT... methods.Superpowered.AdvancedAudioPlayer.Jogmode_Scratch; // Jog wheel controls scratching.Superpowered.AdvancedAudioPlayer.Jogmode_PitchBend; // Jog wheel controls pitch bend.Superpowered.AdvancedAudioPlayer.Jogmode_Parameter; // Jog wheel changes a parameter.// Destructor (to free up memory).player.destruct();
Please note that the player has an internal message queue to achieve thread safety without blocking, and the actual work is performed by the processStereo or processMulti methods. Therefore, those methods must be continously called in a real-time thread (such as the audio processing callback) to maintain operation, even if the player doesn't play anything!
void playMusic() {player = new Superpowered::AdvancedAudioPlayer(44100, 0);player->open("lycka.mp3");player->play();}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {// Ensure the samplerate is in sync on every audio processing callbackplayer->outputSamplerate = samplerate;// Check for latest events on the playerif (player->getLatestEvent() == Superpowered::AdvancedAudioPlayer::PlayerEvent_Opened) {// Audio file has been opened}// Generate the output buffersbool silence = !player->processStereo(interleavedOutput, false, numberOfFrames, volume);}
Properties
defaultQuantum
PROPERTY| Type | Min | Max | Default | Number | 1 |
|---|
defaultQuantum
PROPERTY| Type | Min | Max | Default | double | 1 |
|---|
firstBeatMs
PROPERTY| Type | Min | Max | Default | Number | 0 |
|---|
firstBeatMs
PROPERTY| Type | Min | Max | Default | double | 0 |
|---|
fixDoubleOrHalfBPM
PROPERTY| Type | Min | Max | Default | Boolean | false |
|---|
fixDoubleOrHalfBPM
PROPERTY| Type | Min | Max | Default | bool | false |
|---|
formantCorrection
PROPERTY| Type | Min | Max | Default | Number | 0 | 1 | 0 |
|---|
formantCorrection
PROPERTY| Type | Min | Max | Default | float | 0 | 1 | 0 |
|---|
HLSAutomaticAlternativeSwitching
PROPERTY| Type | Min | Max | Default | bool | true |
|---|
HLSBufferingSeconds
PROPERTY| Type | Min | Max | Default | int | HLSDownloadRemaining |
|---|
HLSLiveLatencySeconds
PROPERTY| Type | Min | Max | Default | char | -1 |
|---|
HLSMaximumDownloadAttempts
PROPERTY| Type | Min | Max | Default | int | 0 | 100 |
|---|
loopOnEOF
PROPERTY| Type | Min | Max | Default | Boolean | false |
|---|
loopOnEOF
PROPERTY| Type | Min | Max | Default | bool | false |
|---|
originalBPM
PROPERTY| Type | Min | Max | Default | Number | A value below 20 will be automatically set to 0. | 300 | 0 (no bpm value known) |
|---|
originalBPM
PROPERTY| Type | Min | Max | Default | double | A value below 20 will be automatically set to 0. | 300 | 0 (no bpm value known) |
|---|
outputSamplerate
PROPERTY| Type | Min | Max | Default | Number |
|---|
outputSamplerate
PROPERTY| Type | Min | Max | Default | unsigned int |
|---|
pitchShiftCents
PROPERTY| Type | Min | Max | Default | Number | -2400 | 2400 | 0 |
|---|
pitchShiftCents
PROPERTY| Type | Min | Max | Default | int | -2400 | 2400 | 0 |
|---|
playbackRate
PROPERTY| Type | Min | Max | Default | Number | 0.00001 | MaxPlaybackRate | 1 |
|---|
playbackRate
PROPERTY| Type | Min | Max | Default | double | 0.00001 | MaxPlaybackRate | 1 |
|---|
reverseToForwardAtLoopStart
PROPERTY| Type | Min | Max | Default | Boolean | false |
|---|
reverseToForwardAtLoopStart
PROPERTY| Type | Min | Max | Default | bool | false |
|---|
syncMode
PROPERTY| Type | Min | Max | Default | AdvancedAudioPlayer.SyncMode.SyncMode_None AdvancedAudioPlayer.SyncMode.SyncMode_Tempo AdvancedAudioPlayer.SyncMode.SyncMode_TempoAndBeat | AdvancedAudioPlayer.SyncMode.SyncMode_None |
|---|
syncMode
PROPERTY| Type | Min | Max | Default | AdvancedAudioPlayer::SyncMode::SyncMode_None AdvancedAudioPlayer::SyncMode::SyncMode_Tempo AdvancedAudioPlayer::SyncMode::SyncMode_TempoAndBeat | AdvancedAudioPlayer::SyncMode::SyncMode_None |
|---|
syncToBpm
PROPERTY| Type | Min | Max | Default | Number | 0 | 0 |
|---|
syncToBpm
PROPERTY| Type | Min | Max | Default | double | 0 | 0 |
|---|
syncToMsElapsedSinceLastBeat
PROPERTY| Type | Min | Max | Default | Number | -1 |
|---|
syncToMsElapsedSinceLastBeat
PROPERTY| Type | Min | Max | Default | double | -1 |
|---|
syncToPhase
PROPERTY| Type | Min | Max | Default | Number | -1 | 1 | -1 |
|---|
syncToPhase
PROPERTY| Type | Min | Max | Default | double | -1 | 1 | -1 |
|---|
syncToQuantum
PROPERTY| Type | Min | Max | Default | Number | -1 |
|---|
syncToQuantum
PROPERTY| Type | Min | Max | Default | double | -1 |
|---|
timeStretching
PROPERTY| Type | Min | Max | Default | Boolean | true |
|---|
timeStretching
PROPERTY| Type | Min | Max | Default | bool | true |
|---|
timeStretchingSound
PROPERTY| Type | Min | Max | Default | 0 (best to save CPU with slightly lower audio quality) 1 (best for DJ apps, modern and "complete" music) 2 (best for instrumental loops and single instruments) | 1 |
|---|
timeStretchingSound
PROPERTY| Type | Min | Max | Default | 0 (best to save CPU with slightly lower audio quality) 1 (best for DJ apps, modern and "complete" music) 2 (best for instrumental loops and single instruments) | 1 |
|---|
Constants
Superpowered.AdvancedAudioPlayer
CONSTANTSConstants in the main AdvancedAudioPlayer namespace.Value Description Jogmode_Parameter Jog wheel changes a parameter. Jogmode_PitchBend Jog wheel controls pitch bend. Jogmode_Scratch Jog wheel controls scratching. PlayerEvent_None Open was not called yet. PlayerEvent_Opened Successfully opened the content, playback can start. PlayerEvent_OpenFailed Failed to open the content. PlayerEvent_Opening Trying to open the content. PlayerEvent_ConnectionLost Network connection lost to the HLS stream or progressive download. Can only be "recovered" by a new open(). May happen after PlayerEvent_Opened has been delivered. PlayerEvent_ProgressiveDownloadFinished The content has finished downloading and is fully available locally. May happen after PlayerEvent_Opened has been delivered. SyncMode_None No synchronization. SyncMode_Tempo Sync tempo only. SyncMode_TempoAndBeat Sync tempo and beat. MaxPlaybackRate The maximum playback rate or scratching speed: 20. HLSDownloadEverything Will download everything after the playback position until the end. HLSDownloadRemaining Downloads everything from the beginning to the end, regardless the playback position. Superpowered::AdvancedAudioPlayer
CONSTANTSConstants in the main AdvancedAudioPlayer namespace.Value Description Jogmode_Parameter Jog wheel changes a parameter. Jogmode_PitchBend Jog wheel controls pitch bend. Jogmode_Scratch Jog wheel controls scratching. PlayerEvent_None Open was not called yet. PlayerEvent_Opened Successfully opened the content, playback can start. PlayerEvent_OpenFailed Failed to open the content. PlayerEvent_Opening Trying to open the content. PlayerEvent_ConnectionLost Network connection lost to the HLS stream or progressive download. Can only be "recovered" by a new open(). May happen after PlayerEvent_Opened has been delivered. PlayerEvent_ProgressiveDownloadFinished The content has finished downloading and is fully available locally. May happen after PlayerEvent_Opened has been delivered. SyncMode_None No synchronization. SyncMode_Tempo Sync tempo only. SyncMode_TempoAndBeat Sync tempo and beat. MaxPlaybackRate The maximum playback rate or scratching speed: 20. HLSDownloadEverything Will download everything after the playback position until the end. HLSDownloadRemaining Downloads everything from the beginning to the end, regardless the playback position.
Methods
constructor
METHODCreates an instance of the AdvancedAudioPlayer class.ParametersReturnsName Type Description samplerate NumberThe initial sample rate in Hz. cachedPointCount NumberHow many positions can be cached in the memory. Jumping to a cached point happens with zero latency. Loops are automatically cached. internalBufferSizeSeconds NumberThe number of seconds to buffer internally for playback and cached points. The value 0 enables "offline mode", where the player can not be used for real-time playback, but can process audio in an iteration. If not zero, the AdvancedAudioPlayer can only be used for real-time playback. Default: 2. negativeSeconds NumberThe number of seconds of silence in the negative direction, before the beginning of the track. minimumTimestretchingPlaybackRate NumberWill not time-stretch but resample below this playback rate. Default: 0.501f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching. maximumTimestretchingPlaybackRate NumberWill not time-stretch but resample above this playback rate. Default: 2.0f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching. enableStems BooleanIf true and a Native Instruments STEMS file is loaded, output 4 stereo channels. Default: false (stereo master mix output). Type Description Superpowered.AdvancedAudioPlayerThe constructed instance. constructor
METHODCreates an instance of the AdvancedAudioPlayer class.ParametersReturnsName Type Default Description samplerate unsigned intThe initial sample rate in Hz. cachedPointCount unsigned charHow many positions can be cached in the memory. Jumping to a cached point happens with zero latency. Loops are automatically cached. internalBufferSizeSeconds unsigned int2 The number of seconds to buffer internally for playback and cached points. The value 0 enables "offline mode", where the player can not be used for real-time playback, but can process audio in an iteration. If not zero, the AdvancedAudioPlayer can only be used for real-time playback. Default: 2. negativeSeconds unsigned int0 The number of seconds of silence in the negative direction, before the beginning of the track. minimumTimestretchingPlaybackRate float0.501 Will not time-stretch but resample below this playback rate. Default: 0.501f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching. maximumTimestretchingPlaybackRate float2 Will not time-stretch but resample above this playback rate. Default: 2.0f (the recommended value for low CPU load on older mobile devices, such as the first iPad). Will be applied after changing playbackRate or scratching. enableStems boolfalse If true and a Native Instruments STEMS file is loaded, output 4 stereo channels. Default: false (stereo master mix output). Type Description Superpowered::AdvancedAudioPlayerThe constructed instance. afterSlipModeWillJumpBackToPositionMs
METHODThe position in milliseconds where the player will continue playback after slip mode ends.ParametersNoneReturnsType Description NumberafterSlipModeWillJumpBackToPositionMs
METHODThe position in milliseconds where the player will continue playback after slip mode ends.ParametersNoneReturnsType Description doublecachePosition
METHODCaches a position for zero latency seeking.ParametersReturnsName Type Description ms NumberPosition in milliseconds. pointID NumberUse this to provide a custom identifier, so you can overwrite the same point later. Use 255 for a point with no identifier. NonecachePosition
METHODCaches a position for zero latency seeking.ParametersReturnsName Type Default Description ms doublePosition in milliseconds. pointID unsigned charUse this to provide a custom identifier, so you can overwrite the same point later. Use 255 for a point with no identifier. NoneclosestBeatIndex
METHODReturns with the beat index of the closest beat.ParametersReturnsName Type Description ms NumberThe position in milliseconds where to find the closest beat. Type Description NumberclosestBeatIndex
METHODReturns with the beat index of the closest beat.ParametersReturnsName Type Default Description ms doubleThe position in milliseconds where to find the closest beat. Type Description unsigned charclosestBeatMs
METHODReturns with the position of the closest beat.ParametersReturnsName Type Description ms NumberThe position in milliseconds where to find the closest beat. beatIndex NumberSet to 1-4 to retrieve the position of a specific beat index relative to ms, or 0 for any beat index. Type Description NumberclosestBeatMs
METHODReturns with the position of the closest beat.ParametersReturnsName Type Default Description ms doubleThe position in milliseconds where to find the closest beat. beatIndex unsined char0 Set to 1-4 to retrieve the position of a specific beat index relative to ms, or 0 for any beat index. Type Description doubleendContinuousPitchBend
METHODEnds pitch bend.ParametersNoneReturnsNoneendContinuousPitchBend
METHODEnds pitch bend.ParametersNoneReturnsNoneendScratch
METHODEnds scratching.ParametersReturnsName Type Description returnToStateBeforeScratch BooleanReturn to the previous playback state (direction, speed) or not. NoneendScratch
METHODEnds scratching.ParametersReturnsName Type Default Description returnToStateBeforeScratch boolReturn to the previous playback state (direction, speed) or not. NoneeofRecently
METHODReturns true if end-of-file has been reached just now or a few moments before (will never indicate end-of-file if loopOnEOF is true). This method should be used in a periodically running code at one place only, because it returns a specific end-of-file event just once. Best to be used in a UI loop.ParametersNoneReturnsType Description BooleaneofRecently
METHODReturns true if end-of-file has been reached just now or a few moments before (will never indicate end-of-file if loopOnEOF is true). This method should be used in a periodically running code at one place only, because it returns a specific end-of-file event just once. Best to be used in a UI loop.ParametersNoneReturnsType Description boolexitLoop
METHODExit from the current loop.ParametersReturnsName Type Description synchronisedStart BooleanSynchronized start or re-synchronization after the loop exit NoneexitLoop
METHODExit from the current loop.ParametersReturnsName Type Default Description synchronisedStart boolfalse Synchronized start or re-synchronization after the loop exit NonegetAudioEndMs
METHODReturns with the length of the digital silence at the end of the file if open... was called with measureSilenceAtEnd = true, 0 otherwise.ParametersNoneReturnsType Description NumbergetAudioEndMs
METHODReturns with the length of the digital silence at the end of the file if open... was called with measureSilenceAtEnd = true, 0 otherwise.ParametersNoneReturnsType Description doublegetAudioStartMs
METHODReturns with the length of the digital silence at the beginning of the file if open... was called with skipSilenceAtBeginning = true, 0 otherwise.ParametersNoneReturnsType Description NumbergetAudioStartMs
METHODReturns with the length of the digital silence at the beginning of the file if open... was called with skipSilenceAtBeginning = true, 0 otherwise.ParametersNoneReturnsType Description doublegetBeatIndex
METHODWhich beat has just happened. Possible values: 0 : unknown, 1 - 1.999: first beat, 2 - 2.999: second beat, 3 - 3.999: third beat, 4 - 4.999: fourth beatParametersNoneReturnsType Description NumbergetBeatIndex
METHODWhich beat has just happened. Possible values: 0 : unknown, 1 - 1.999: first beat, 2 - 2.999: second beat, 3 - 3.999: third beat, 4 - 4.999: fourth beatParametersNoneReturnsType Description floatgetBendOffsetMs
METHODReturns with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersNoneReturnsType Description NumbergetBendOffsetMs
METHODReturns with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersNoneReturnsType Description doublegetBufferedEndPercent
METHODReturns with the end of the buffered part. Will always be 0 for non-network sources (such as local files).ParametersNoneReturnsType Description floatgetBufferedStartPercent
METHODReturns with the beginning of the buffered part. Will always be 0 for non-network sources (such as local files).ParametersNoneReturnsType Description floatgetCurrentBpm
METHODThe current bpm of the track (as changed by the playback rate).ParametersNoneReturnsType Description NumbergetCurrentBpm
METHODThe current bpm of the track (as changed by the playback rate).ParametersNoneReturnsType Description doublegetCurrentHLSBPS
METHODFor HLS only. Returns with the actual network throughput (for best stream selection).ParametersNoneReturnsType Description unsigned intgetCurrentPitchBendPercent
METHODReturns with the current pitch bend percent. Will be 1 if there is no pitch bend happening.ParametersNoneReturnsType Description NumbergetCurrentPitchBendPercent
METHODReturns with the current pitch bend percent. Will be 1 if there is no pitch bend happening.ParametersNoneReturnsType Description floatgetDisplayPositionMs
METHODThe current position in milliseconds, immediately updated after setPosition or seek. Use this for UI display.ParametersNoneReturnsType Description NumbergetDisplayPositionMs
METHODThe current position in milliseconds, immediately updated after setPosition or seek. Use this for UI display.ParametersNoneReturnsType Description doublegetDisplayPositionPercent
METHODSimilar to getDisplayPositionMs, but as a percentage (0 to 1).ParametersNoneReturnsType Description NumbergetDisplayPositionPercent
METHODSimilar to getDisplayPositionMs, but as a percentage (0 to 1).ParametersNoneReturnsType Description floatgetDisplayPositionSeconds
METHODSimilar to getDisplayPositionMs, but as seconds elapsed.ParametersNoneReturnsType Description NumbergetDisplayPositionSeconds
METHODSimilar to getDisplayPositionMs, but as seconds elapsed.ParametersNoneReturnsType Description intgetDurationMs
METHODThe duration of the current track in milliseconds.ParametersNoneReturnsType Description NumbergetDurationMs
METHODThe duration of the current track in milliseconds. Returns UINT_MAX for live streams.ParametersNoneReturnsType Description unsigned intgetDurationSeconds
METHODThe duration of the current track in seconds.ParametersNoneReturnsType Description NumbergetDurationSeconds
METHODThe duration of the current track in seconds. Returns UINT_MAX for live streams.ParametersNoneReturnsType Description unsigned intgetFullyDownloadedFilePath
METHODReturns with the full filesystem path of the locally cached file if the player is in the PlayerEvent_Opened_ProgressiveDownloadFinished state, NULL otherwise.ParametersNoneReturnsType Description const char *getJogParameter
METHODIf jog wheel mode is JogMode_Parameter, returns with the current parameter typically in the range of -1 to 1, or less than -1000000.0 if there was no jog wheel movement. processStereo or processMulti updates this value, therefore it's recommended to read it after those calls were made, in the same thread.ParametersNoneReturnsType Description NumbergetJogParameter
METHODIf jog wheel mode is JogMode_Parameter, returns with the current parameter typically in the range of -1 to 1, or less than -1000000.0 if there was no jog wheel movement. processStereo or processMulti updates this value, therefore it's recommended to read it after those calls were made, in the same thread.ParametersNoneReturnsType Description doublegetLatestEvent
METHODReturns with the latest player event. This method should be used in a periodically running code, at one place only, because it returns a specific event just once per open call. Best to be used in a UI loop.ParametersNoneReturnsType Description Superpowered.AdvancedAudioPlayer.PlayerEventgetLatestEvent
METHODReturns with the latest player event. This method should be used in a periodically running code, at one place only, because it returns a specific event just once per open call. Best to be used in a UI loop.ParametersNoneReturnsType Description Superpowered::AdvancedAudioPlayer::PlayerEventgetMsDifference
METHODReturns with the distance (in milliseconds) to a specific quantum and phase for quantized synchronization.ParametersReturnsName Type Description phase NumberThe phase to calculate against. quantum NumberThe quantum to calculate against. Type Description NumbergetMsDifference
METHODReturns with the distance (in milliseconds) to a specific quantum and phase for quantized synchronization.ParametersReturnsName Type Default Description phase doubleThe phase to calculate against. quantum doubleThe quantum to calculate against. Type Description doublegetMsElapsedSinceLastBeat
METHODHow many milliseconds elapsed since the last beat.ParametersNoneReturnsType Description NumbergetMsElapsedSinceLastBeat
METHODHow many milliseconds elapsed since the last beat.ParametersNoneReturnsType Description doublegetMsRemainingToSyncEvent
METHODIf the player is waiting to a synchronization event (such as synchronized playback start or restarting a loop), the return value indicates the time remaining in milliseconds (continously updated). 0 means not waiting to such event.ParametersNoneReturnsType Description NumbergetMsRemainingToSyncEvent
METHODIf the player is waiting to a synchronization event (such as synchronized playback start or restarting a loop), the return value indicates the time remaining in milliseconds (continously updated). 0 means not waiting to such event.ParametersNoneReturnsType Description doublegetOpenErrorCode
METHODIf getLatestEvent returns with OpenFailed, retrieve the error code or HTTP status code here.ParametersNoneReturnsType Description NumbergetOpenErrorCode
METHODIf getLatestEvent returns with OpenFailed, retrieve the error code or HTTP status code here.ParametersNoneReturnsType Description intgetPhase
METHODReturns with the current phase for quantized synchronization, between 0 (beginning of the quantum) and 1 (end of the quantum).ParametersNoneReturnsType Description NumbergetPhase
METHODReturns with the current phase for quantized synchronization, between 0 (beginning of the quantum) and 1 (end of the quantum).ParametersNoneReturnsType Description doublegetPositionMs
METHODThe current playhead position in milliseconds. Not changed by any pending setPosition or seek call, always accurate regardless of time-stretching and other transformations.ParametersNoneReturnsType Description NumbergetPositionMs
METHODThe current playhead position in milliseconds. Not changed by any pending setPosition or seek call, always accurate regardless of time-stretching and other transformations.ParametersNoneReturnsType Description doublegetQuantum
METHODReturns with the current quantum for quantized synchronization, such as 2 for two beats, 4 for four beats, etc...ParametersNoneReturnsType Description NumbergetQuantum
METHODReturns with the current quantum for quantized synchronization, such as 2 for two beats, 4 for four beats, etc...ParametersNoneReturnsType Description doublegetStemColor
METHODReturns with a stem's color if a STEMS file was loaded, NULL otherwise.ParametersReturnsName Type Description index NumberThe index of the stem. Type Description Number (pointer in Linear Memory)Linear Memory pointer. You can use Superpowered.toString(this_pointer) to create a JavaScript string from it. getStemColor
METHODReturns with a stem's color if a STEMS file was loaded, NULL otherwise.ParametersReturnsName Type Default Description index unsigned charThe index of the stem. Type Description const char *The color as string. getStemName
METHODReturns with a stem's name if a STEMS file was loaded, NULL otherwise.ParametersReturnsName Type Description index NumberThe index of the stem. Type Description Number (pointer in Linear Memory)Linear Memory pointer. You can use Superpowered.toString(this_pointer) to create a JavaScript string from it. getStemName
METHODReturns with a stem's name if a STEMS file was loaded, NULL otherwise.ParametersReturnsName Type Default Description index unsigned charThe index of the stem. Type Description const char *The name. isLooping
METHODIndicates if looping is enabled.ParametersNoneReturnsType Description BooleanisLooping
METHODIndicates if looping is enabled.ParametersNoneReturnsType Description boolisPerformingSlip
METHODIndicates if returning from scratching or reverse playback will maintain the playback position as if the player had never entered into scratching or reverse playback.ParametersNoneReturnsType Description NumberisPerformingSlip
METHODIndicates if returning from scratching or reverse playback will maintain the playback position as if the player had never entered into scratching or reverse playback.ParametersNoneReturnsType Description booleanisPlaying
METHODIndicates if the player is playing or paused.ParametersNoneReturnsType Description BooleanisPlaying
METHODIndicates if the player is playing or paused.ParametersNoneReturnsType Description boolisReverse
METHODIf true, the player is playing backwards.ParametersNoneReturnsType Description BooleanisReverse
METHODIf true, the player is playing backwards.ParametersNoneReturnsType Description boolisScratching
METHODIndicates if the player is in scratching mode.ParametersNoneReturnsType Description BooleanisScratching
METHODIndicates if the player is in scratching mode.ParametersNoneReturnsType Description boolisStems
METHODReturns true if a STEMS file was loaded (and the player was initialized with enableStems == true).ParametersNoneReturnsType Description BooleanisStems
METHODReturns true if a STEMS file was loaded (and the player was initialized with enableStems == true).ParametersNoneReturnsType Description boolisWaitingForBuffering
METHODIndicates if the player is waiting for data (such as waiting for a network download).ParametersNoneReturnsType Description BooleanisWaitingForBuffering
METHODIndicates if the player is waiting for data (such as waiting for a network download).ParametersNoneReturnsType Description booljogTick
METHODA jog wheel should send some 'ticks' with the movement. A waveform's movement in pixels for example.ParametersReturnsName Type Description value NumberThe ticks value. bendStretch BooleanUse time-stretching for pitch bend or not (false makes it 'audible'). bendMaxPercent NumberThe maximum playback rate change for pitch bend, should be between 0.01 and 0.3 (1% and 30%). bendHoldMs NumberHow long to maintain the pitch bend state. A value >= 1000 will hold until endContinuousPitchBend is called. parameterModeIfNoJogTouchBegin BooleanTrue: if there was no jogTouchBegin, turn to JogMode_Parameter mode. False: if there was no jogTouchBegin, turn to JogMode_PitchBend mode. NonejogTick
METHODA jog wheel should send some 'ticks' with the movement. A waveform's movement in pixels for example.ParametersReturnsName Type Default Description value intThe ticks value. bendStretch boolUse time-stretching for pitch bend or not (false makes it 'audible'). bendMaxPercent floatThe maximum playback rate change for pitch bend, should be between 0.01 and 0.3 (1% and 30%). bendHoldMs unsigned intHow long to maintain the pitch bend state. A value >= 1000 will hold until endContinuousPitchBend is called. parameterModeIfNoJogTouchBegin boolTrue: if there was no jogTouchBegin, turn to JogMode_Parameter mode. False: if there was no jogTouchBegin, turn to JogMode_PitchBend mode. NonejogTouchBegin
METHOD'Virtual jog wheel' or 'virtual turntable' handling.ParametersReturnsName Type Description ticksPerTurn NumberSets the sensitivity of the virtual wheel. Use around 2300 for pixel-perfect touchscreen waveform control. mode NumberJog wheel mode (scratching, pitch bend, or parameter set in the 0-1 range). scratchSlipMs NumberEnables slip mode for a specific amount of time for scratching, or 0 to not slip. NonejogTouchBegin
METHOD'Virtual jog wheel' or 'virtual turntable' handling.ParametersReturnsName Type Default Description ticksPerTurn intSets the sensitivity of the virtual wheel. Use around 2300 for pixel-perfect touchscreen waveform control. mode Superpowered::AdvancedAudioPlayer:JogModeJog wheel mode (scratching, pitch bend, or parameter set in the 0-1 range). scratchSlipMs unsigned int0 Enables slip mode for a specific amount of time for scratching, or 0 to not slip. NonejogTouchEnd
METHODCall this when the jog touch ends.ParametersReturnsName Type Description decelerate NumberThe decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart BooleanBeat-synced start after decelerating. NonejogTouchEnd
METHODCall this when the jog touch ends.ParametersReturnsName Type Default Description decelerate floatThe decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart boolBeat-synced start after decelerating. Noneloop
METHODLoop from a start point to some length.ParametersReturnsName Type Description startMs NumberLoop from this milliseconds. lengthMs NumberLoop length in milliseconds. jumpToStartMs BooleanIf the playhead is within the loop, jump to startMs or not. pointID NumberLooping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart BooleanBeat-synced start. numLoops NumberNumber of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum BooleanIf true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart BooleanWait or start immediately when synchronized. Noneloop
METHODLoop from a start point to some length.ParametersReturnsName Type Default Description startMs doubleLoop from this milliseconds. lengthMs doubleLoop length in milliseconds. jumpToStartMs boolIf the playhead is within the loop, jump to startMs or not. pointID Unsigned charLooping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart boolBeat-synced start. numLoops unsigned int0 Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum boolfalse If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart boolfalse Wait or start immediately when synchronized. NoneloopBetween
METHODLoop between a start and end points.ParametersReturnsName Type Description startMs NumberLoop from this milliseconds. endMs NumberLoop to this milliseconds. jumpToStartMs BooleanIf the playhead is within the loop, jump to startMs or not. pointID NumberLooping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart BooleanBeat-synced start. numLoops NumberNumber of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum BooleanIf true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart BooleanWait or start immediately when synchronized. NoneloopBetween
METHODLoop between a start and end points.ParametersReturnsName Type Default Description startMs doubleLoop from this milliseconds. endMs doubleLoop to this milliseconds. jumpToStartMs boolIf the playhead is within the loop, jump to startMs or not. pointID Unsigned charLooping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart boolBeat-synced start. numLoops unsigned int0 Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum boolfalse If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart boolfalse Wait or start immediately when synchronized. NonemsInLoop
METHODReturns true if a position is inside the current loop.ParametersNoneReturnsType Description BooleanmsInLoop
METHODReturns true if a position is inside the current loop.ParametersNoneReturnsType Description boolonMediaserverInterrupt
METHODApple'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.ParametersNoneReturnsNoneopen [1/2]
METHODOpens an audio file with playback paused. Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Default Description path const char *Full file system path or progressive download path (http or https). 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 player will copy this object. skipSilenceAtBeginning boolfalse If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd boolfalse If true, the player will check the length of the digital silence at the end of the audio file. Noneopen [2/2]
METHODOpens an audio file with playback paused. Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Default Description path const char *Full file system path or progressive download path (http or https). offset intThe byte offset inside the path. length intThe byte length from the offset. 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 player will copy this object. skipSilenceAtBeginning boolfalse If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd boolfalse If true, the player will check the length of the digital silence at the end of the audio file. NoneopenHLS
METHODOpens a HTTP Live Streaming stream with playback paused. Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new one. Do not call openHLS in the audio processing thread.ParametersReturnsName Type Default Description url const char *Stream URL. 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 player will copy this object. NoneopenMemory
METHODOpens a memory location in Superpowered AudioInMemory format, with playback paused. This feature supports progressive loading via AudioInMemory::append (and the AudioInMemory doesn't even need to hold any data when openMemory is called). Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Description pointer Number (pointer in Linear Memory)Pointer to data in Superpowered AudioInMemory format, pointing to stereo interleaved 16-bit PCM audio inside. skipSilenceAtBeginning BooleanIf true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd BooleanIf true, the player will check the length of the digital silence at the end of the audio file. NoneopenMemory
METHODOpens a memory location in Superpowered AudioInMemory format, with playback paused. This feature supports progressive loading via AudioInMemory::append (and the AudioInMemory doesn't even need to hold any data when openMemory is called). Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Default Description pointer void *Pointer to data in Superpowered AudioInMemory format, pointing to stereo interleaved 16-bit PCM audio inside. skipSilenceAtBeginning boolfalse If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd boolfalse If true, the player will check the length of the digital silence at the end of the audio file. NoneopenPCM16AudioInMemory
METHODOpens raw 16-bit sterteo PCM audio in memory, with playback paused. Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Description pointer Number (pointer in Linear Memory)Stereo interleaved 16-bit PCM audio. samplerate NumberThe sample rate in Hz. Valid from 8192 to 384000. durationFrames NumberThe duration of the audio in frames. skipSilenceAtBeginning BooleanIf true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd BooleanIf true, the player will check the length of the digital silence at the end of the audio file. NoneopenPCM16AudioInMemory
METHODOpens raw 16-bit sterteo PCM audio in memory, with playback paused. Playback rate, pitchShift, timeStretching and syncMode are NOT changed if you open a new file.ParametersReturnsName Type Default Description pointer void *Stereo interleaved 16-bit PCM audio. samplerate unsigned intThe sample rate in Hz. Valid from 8192 to 384000. durationFrames unsigned intThe duration of the audio in frames. skipSilenceAtBeginning boolfalse If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd boolfalse If true, the player will check the length of the digital silence at the end of the audio file. Nonepause
METHODPause playback. There is no need for a 'stop' method, this player is very efficient with the battery and has no significant 'stand-by' processing.ParametersReturnsName Type Description decelerateSeconds NumberOptional momentum. 0 means to pause immediately. slipMs NumberEnable slip mode for a specific amount of time, or 0 to not slip. Nonepause
METHODPause playback. There is no need for a 'stop' method, this player is very efficient with the battery and has no significant 'stand-by' processing.ParametersReturnsName Type Default Description decelerateSeconds float0 Optional momentum. 0 means to pause immediately. slipMs unsigned int0 Enable slip mode for a specific amount of time, or 0 to not slip. NonepitchBend
METHODStarts on changes pitch bend (temporary playback rate change).ParametersReturnsName Type Description maxPercent NumberThe maximum playback rate range for pitch bend, should be between 0.01f and 0.3f (1% and 30%). bendStretch NumberUse time-stretching for pitch bend or not (false makes it 'audible'). 1 or 0 faster NumberTrue (1): faster, false (0): slower. hostMs NumberNonepitchBend
METHODStarts on changes pitch bend (temporary playback rate change).ParametersReturnsName Type Default Description maxPercent floatThe maximum playback rate range for pitch bend, should be between 0.01f and 0.3f (1% and 30%). bendStretch BooleanUse time-stretching for pitch bend or not (false makes it 'audible'). 1 or 0 faster BooleanTrue (1): faster, false (0): slower. hostMs unsigned intNoneplay
METHODStarts playback immediately without any synchronization.ParametersNoneReturnsNoneplay
METHODStarts playback immediately without any synchronization.ParametersNoneReturnsNoneplaySynchronized
METHODStarts beat or tempo synchronized playback.ParametersNoneReturnsNoneplaySynchronized
METHODStarts beat or tempo synchronized playback.ParametersNoneReturnsNoneplaySynchronizedToPosition
METHODStarts playback at a specific position. isPlaying will return false and the position will not be updated until this function succeeds starting playback at the specified position. You can call this in a real-time thread (audio processing callback) with a continuously updated time for a precise on-the-fly launch.ParametersReturnsName Type Description positionMs NumberNoneplaySynchronizedToPosition
METHODStarts playback at a specific position. isPlaying will return false and the position will not be updated until this function succeeds starting playback at the specified position. You can call this in a real-time thread (audio processing callback) with a continuously updated time for a precise on-the-fly launch.ParametersReturnsName Type Default Description positionMs doubleNoneprocess8Channels
METHODOutputs audio, 8 channels version.ParametersReturnsName Type Description buffer0 Number (pointer in Linear Memory)32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer1 Number (pointer in Linear Memory)32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer2 Number (pointer in Linear Memory)32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer3 Number (pointer in Linear Memory)32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. mix BooleanIf true, the player output will be mixed with the contents of buffer. If false, the contents of buffer will be overwritten with the player output. numberOfFrames NumberThe number of frames requested. volume0 NumberVolume for buffer0. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume1 NumberVolume for buffer1. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume2 NumberVolume for buffer2. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume3 NumberVolume for buffer3. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description Booleantrue: buffers have audio output from the player. false: the contents of the buffers were not changed (typically happens when the player is paused). process8Channels
METHODOutputs audio, 8 channels version.ParametersReturnsName Type Default Description buffer0 float *32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer1 float *32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer2 float *32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. buffer3 float *32-bit interleaved stereo input/output buffer for the 1st stereo channels. Should be numberOfFrames * 8 + 64 bytes big. mix boolIf true, the player output will be mixed with the contents of buffer. If false, the contents of buffer will be overwritten with the player output. numberOfFrames unsigned intThe number of frames requested. volume0 float1.0f Volume for buffer0. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume1 float1.0f Volume for buffer1. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume2 float1.0f Volume for buffer2. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume3 float1.0f Volume for buffer3. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description booltrue: buffers have audio output from the player. false: the contents of the buffers were not changed (typically happens when the player is paused). processSTEMSMaster
METHODPerforms the last stage of STEMS processing, the master compressor and limiter. Works only if a STEMS file was loaded.ParametersReturnsName Type Description input Number (pointer in Linear Memory)32-bit interleaved stereo input buffer. output Number (pointer in Linear Memory)32-bit interleaved stereo output buffer. numberOfFrames NumberThe number of frames requested. volume NumberOutput volume. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. NoneprocessSTEMSMaster
METHODPerforms the last stage of STEMS processing, the master compressor and limiter. Works only if a STEMS file was loaded.ParametersReturnsName Type Default Description input float *32-bit interleaved stereo input buffer. output float *32-bit interleaved stereo output buffer. numberOfFrames unsigned intThe number of frames requested. volume float1.0f Output volume. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. NoneprocessStereo
METHODOutputs audio, stereo version.ParametersReturnsName Type Description buffer Number (pointer in Linear Memory)32-bit interleaved stereo input/output buffer. Should be numberOfFrames * 8 + 64 bytes big. mix BooleanIf true, the player output will be mixed with the contents of buffer. If false, the contents of buffer will be overwritten with the player output. numberOfFrames NumberThe number of frames requested. volume Number0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description Booleantrue: buffer has audio output from the player. false: the contents of buffer were not changed (typically happens when the player is paused). processStereo
METHODOutputs audio, stereo version.ParametersReturnsName Type Default Description buffer float *32-bit interleaved stereo input/output buffer. Should be numberOfFrames * 8 + 64 bytes big. mix boolIf true, the player output will be mixed with the contents of buffer. If false, the contents of buffer will be overwritten with the player output. numberOfFrames unsigned intThe number of frames requested. volume float1.0f 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description booltrue: buffer has audio output from the player. false: the contents of buffer were not changed (typically happens when the player is paused). resetBendMsOffset
METHODReset the pitch bend offset to the beatgrid to zero.ParametersNoneReturnsType Description NumberresetBendMsOffset
METHODReset the pitch bend offset to the beatgrid to zero.ParametersNoneReturnsType Description doublescratch
METHODScratch movement.ParametersReturnsName Type Description pitch NumberThe current speed. smoothing NumberShould be between 0.05f (max. smoothing) and 1.0f (no smoothing). Nonescratch
METHODScratch movement.ParametersReturnsName Type Default Description pitch doubleThe current speed. smoothing floatShould be between 0.05f (max. smoothing) and 1.0f (no smoothing). Noneseek
METHODSimple seeking to a percentage.ParametersReturnsName Type Description percent NumberNoneseek
METHODSimple seeking to a percentage.ParametersReturnsName Type Default Description percent doubleNonesetBendOffsetMs
METHODSets with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersReturnsName Type Description ms NumberValue in milliseconds NonesetBendOffsetMs
METHODSets with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersReturnsName Type Default Description ms doubleValue in milliseconds NonesetPosition
METHODPrecise seeking.ParametersReturnsName Type Description ms NumberPosition in milliseconds. andStop BooleanIf true, stops playback. synchronisedStart BooleanIf andStop is false, makes a beat-synced start possible. forceDefaultQuantum BooleanIf true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart BooleanWait or start immediately when synchronized. NonesetPosition
METHODPrecise seeking.ParametersReturnsName Type Default Description ms doublePosition in milliseconds. andStop boolIf true, stops playback. synchronisedStart boolIf andStop is false, makes a beat-synced start possible. forceDefaultQuantum boolfalse If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart boolfalse Wait or start immediately when synchronized. NonesetReverse
METHODSets playback direction.ParametersReturnsName Type Description reverse NumberTrue: reverse. False: forward. slipMs NumberEnable slip mode for a specific amount of time, or 0 to not slip. NonesetReverse
METHODSets playback direction.ParametersReturnsName Type Default Description reverse BooleanTrue: reverse. False: forward. slipMs unsigned int0 Enable slip mode for a specific amount of time, or 0 to not slip. NonestartScratch
METHODDirect turntable handling. Call this when scratching starts.ParametersReturnsName Type Description decelerate NumberThe decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart BooleanBeat-synced start after decelerating. NonestartScratch
METHODDirect turntable handling. Call this when scratching starts.ParametersReturnsName Type Default Description decelerate floatThe decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart boolBeat-synced start after decelerating. NonetogglePlayback
METHODToggle play/pause (no synchronization).ParametersNoneReturnsNonetogglePlayback
METHODToggle play/pause (no synchronization).ParametersNoneReturnsNone