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
PROPERTYType | Min | Max | Default | Number | 1 |
---|
defaultQuantum
PROPERTYType | Min | Max | Default | double | 1 |
---|
firstBeatMs
PROPERTYType | Min | Max | Default | Number | 0 |
---|
firstBeatMs
PROPERTYType | Min | Max | Default | double | 0 |
---|
fixDoubleOrHalfBPM
PROPERTYType | Min | Max | Default | Boolean | false |
---|
fixDoubleOrHalfBPM
PROPERTYType | Min | Max | Default | bool | false |
---|
formantCorrection
PROPERTYType | Min | Max | Default | Number | 0 | 1 | 0 |
---|
formantCorrection
PROPERTYType | Min | Max | Default | float | 0 | 1 | 0 |
---|
HLSAutomaticAlternativeSwitching
PROPERTYType | Min | Max | Default | bool | true |
---|
HLSBufferingSeconds
PROPERTYType | Min | Max | Default | int | HLSDownloadRemaining |
---|
HLSLiveLatencySeconds
PROPERTYType | Min | Max | Default | char | -1 |
---|
HLSMaximumDownloadAttempts
PROPERTYType | Min | Max | Default | int | 0 | 100 |
---|
loopOnEOF
PROPERTYType | Min | Max | Default | Boolean | false |
---|
loopOnEOF
PROPERTYType | Min | Max | Default | bool | false |
---|
originalBPM
PROPERTYType | Min | Max | Default | Number | A value below 20 will be automatically set to 0. | 300 | 0 (no bpm value known) |
---|
originalBPM
PROPERTYType | Min | Max | Default | double | A value below 20 will be automatically set to 0. | 300 | 0 (no bpm value known) |
---|
outputSamplerate
PROPERTYType | Min | Max | Default | Number |
---|
outputSamplerate
PROPERTYType | Min | Max | Default | unsigned int |
---|
pitchShiftCents
PROPERTYType | Min | Max | Default | Number | -2400 | 2400 | 0 |
---|
pitchShiftCents
PROPERTYType | Min | Max | Default | int | -2400 | 2400 | 0 |
---|
playbackRate
PROPERTYType | Min | Max | Default | Number | 0.00001 | MaxPlaybackRate | 1 |
---|
playbackRate
PROPERTYType | Min | Max | Default | double | 0.00001 | MaxPlaybackRate | 1 |
---|
reverseToForwardAtLoopStart
PROPERTYType | Min | Max | Default | Boolean | false |
---|
reverseToForwardAtLoopStart
PROPERTYType | Min | Max | Default | bool | false |
---|
syncMode
PROPERTYType | Min | Max | Default | AdvancedAudioPlayer.SyncMode.SyncMode_None AdvancedAudioPlayer.SyncMode.SyncMode_Tempo AdvancedAudioPlayer.SyncMode.SyncMode_TempoAndBeat | AdvancedAudioPlayer.SyncMode.SyncMode_None |
---|
syncMode
PROPERTYType | Min | Max | Default | AdvancedAudioPlayer::SyncMode::SyncMode_None AdvancedAudioPlayer::SyncMode::SyncMode_Tempo AdvancedAudioPlayer::SyncMode::SyncMode_TempoAndBeat | AdvancedAudioPlayer::SyncMode::SyncMode_None |
---|
syncToBpm
PROPERTYType | Min | Max | Default | Number | 0 | 0 |
---|
syncToBpm
PROPERTYType | Min | Max | Default | double | 0 | 0 |
---|
syncToMsElapsedSinceLastBeat
PROPERTYType | Min | Max | Default | Number | -1 |
---|
syncToMsElapsedSinceLastBeat
PROPERTYType | Min | Max | Default | double | -1 |
---|
syncToPhase
PROPERTYType | Min | Max | Default | Number | -1 | 1 | -1 |
---|
syncToPhase
PROPERTYType | Min | Max | Default | double | -1 | 1 | -1 |
---|
syncToQuantum
PROPERTYType | Min | Max | Default | Number | -1 |
---|
syncToQuantum
PROPERTYType | Min | Max | Default | double | -1 |
---|
timeStretching
PROPERTYType | Min | Max | Default | Boolean | true |
---|
timeStretching
PROPERTYType | Min | Max | Default | bool | true |
---|
timeStretchingSound
PROPERTYType | 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
PROPERTYType | 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 Number
The initial sample rate in Hz. cachedPointCount Number
How many positions can be cached in the memory. Jumping to a cached point happens with zero latency. Loops are automatically cached. internalBufferSizeSeconds Number
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 Number
The number of seconds of silence in the negative direction, before the beginning of the track. minimumTimestretchingPlaybackRate Number
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 Number
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 Boolean
If true and a Native Instruments STEMS file is loaded, output 4 stereo channels. Default: false (stereo master mix output). Type Description Superpowered.AdvancedAudioPlayer
The constructed instance. constructor
METHODCreates an instance of the AdvancedAudioPlayer class.ParametersReturnsName Type Default Description samplerate unsigned int
The initial sample rate in Hz. cachedPointCount unsigned char
How many positions can be cached in the memory. Jumping to a cached point happens with zero latency. Loops are automatically cached. internalBufferSizeSeconds unsigned int
2 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 int
0 The number of seconds of silence in the negative direction, before the beginning of the track. minimumTimestretchingPlaybackRate float
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. maximumTimestretchingPlaybackRate float
2 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 bool
false If true and a Native Instruments STEMS file is loaded, output 4 stereo channels. Default: false (stereo master mix output). Type Description Superpowered::AdvancedAudioPlayer
The constructed instance. afterSlipModeWillJumpBackToPositionMs
METHODThe position in milliseconds where the player will continue playback after slip mode ends.ParametersNoneReturnsType Description Number
afterSlipModeWillJumpBackToPositionMs
METHODThe position in milliseconds where the player will continue playback after slip mode ends.ParametersNoneReturnsType Description double
cachePosition
METHODCaches a position for zero latency seeking.ParametersReturnsName Type Description ms Number
Position in milliseconds. pointID Number
Use 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 double
Position in milliseconds. pointID unsigned char
Use 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 Number
The position in milliseconds where to find the closest beat. Type Description Number
closestBeatIndex
METHODReturns with the beat index of the closest beat.ParametersReturnsName Type Default Description ms double
The position in milliseconds where to find the closest beat. Type Description unsigned char
closestBeatMs
METHODReturns with the position of the closest beat.ParametersReturnsName Type Description ms Number
The position in milliseconds where to find the closest beat. beatIndex Number
Set to 1-4 to retrieve the position of a specific beat index relative to ms, or 0 for any beat index. Type Description Number
closestBeatMs
METHODReturns with the position of the closest beat.ParametersReturnsName Type Default Description ms double
The position in milliseconds where to find the closest beat. beatIndex unsined char
0 Set to 1-4 to retrieve the position of a specific beat index relative to ms, or 0 for any beat index. Type Description double
endContinuousPitchBend
METHODEnds pitch bend.ParametersNoneReturnsNoneendContinuousPitchBend
METHODEnds pitch bend.ParametersNoneReturnsNoneendScratch
METHODEnds scratching.ParametersReturnsName Type Description returnToStateBeforeScratch Boolean
Return to the previous playback state (direction, speed) or not. NoneendScratch
METHODEnds scratching.ParametersReturnsName Type Default Description returnToStateBeforeScratch bool
Return 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 Boolean
eofRecently
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 bool
exitLoop
METHODExit from the current loop.ParametersReturnsName Type Description synchronisedStart Boolean
Synchronized start or re-synchronization after the loop exit NoneexitLoop
METHODExit from the current loop.ParametersReturnsName Type Default Description synchronisedStart bool
false 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 Number
getAudioEndMs
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 double
getAudioStartMs
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 Number
getAudioStartMs
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 double
getBeatIndex
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 Number
getBeatIndex
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 float
getBendOffsetMs
METHODReturns with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersNoneReturnsType Description Number
getBendOffsetMs
METHODReturns with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersNoneReturnsType Description double
getBufferedEndPercent
METHODReturns with the end of the buffered part. Will always be 0 for non-network sources (such as local files).ParametersNoneReturnsType Description float
getBufferedStartPercent
METHODReturns with the beginning of the buffered part. Will always be 0 for non-network sources (such as local files).ParametersNoneReturnsType Description float
getCurrentBpm
METHODThe current bpm of the track (as changed by the playback rate).ParametersNoneReturnsType Description Number
getCurrentBpm
METHODThe current bpm of the track (as changed by the playback rate).ParametersNoneReturnsType Description double
getCurrentHLSBPS
METHODFor HLS only. Returns with the actual network throughput (for best stream selection).ParametersNoneReturnsType Description unsigned int
getCurrentPitchBendPercent
METHODReturns with the current pitch bend percent. Will be 1 if there is no pitch bend happening.ParametersNoneReturnsType Description Number
getCurrentPitchBendPercent
METHODReturns with the current pitch bend percent. Will be 1 if there is no pitch bend happening.ParametersNoneReturnsType Description float
getDisplayPositionMs
METHODThe current position in milliseconds, immediately updated after setPosition or seek. Use this for UI display.ParametersNoneReturnsType Description Number
getDisplayPositionMs
METHODThe current position in milliseconds, immediately updated after setPosition or seek. Use this for UI display.ParametersNoneReturnsType Description double
getDisplayPositionPercent
METHODSimilar to getDisplayPositionMs, but as a percentage (0 to 1).ParametersNoneReturnsType Description Number
getDisplayPositionPercent
METHODSimilar to getDisplayPositionMs, but as a percentage (0 to 1).ParametersNoneReturnsType Description float
getDisplayPositionSeconds
METHODSimilar to getDisplayPositionMs, but as seconds elapsed.ParametersNoneReturnsType Description Number
getDisplayPositionSeconds
METHODSimilar to getDisplayPositionMs, but as seconds elapsed.ParametersNoneReturnsType Description int
getDurationMs
METHODThe duration of the current track in milliseconds.ParametersNoneReturnsType Description Number
getDurationMs
METHODThe duration of the current track in milliseconds. Returns UINT_MAX for live streams.ParametersNoneReturnsType Description unsigned int
getDurationSeconds
METHODThe duration of the current track in seconds.ParametersNoneReturnsType Description Number
getDurationSeconds
METHODThe duration of the current track in seconds. Returns UINT_MAX for live streams.ParametersNoneReturnsType Description unsigned int
getFullyDownloadedFilePath
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 Number
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 double
getLatestEvent
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.PlayerEvent
getLatestEvent
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::PlayerEvent
getMsDifference
METHODReturns with the distance (in milliseconds) to a specific quantum and phase for quantized synchronization.ParametersReturnsName Type Description phase Number
The phase to calculate against. quantum Number
The quantum to calculate against. Type Description Number
getMsDifference
METHODReturns with the distance (in milliseconds) to a specific quantum and phase for quantized synchronization.ParametersReturnsName Type Default Description phase double
The phase to calculate against. quantum double
The quantum to calculate against. Type Description double
getMsElapsedSinceLastBeat
METHODHow many milliseconds elapsed since the last beat.ParametersNoneReturnsType Description Number
getMsElapsedSinceLastBeat
METHODHow many milliseconds elapsed since the last beat.ParametersNoneReturnsType Description double
getMsRemainingToSyncEvent
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 Number
getMsRemainingToSyncEvent
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 double
getOpenErrorCode
METHODIf getLatestEvent returns with OpenFailed, retrieve the error code or HTTP status code here.ParametersNoneReturnsType Description Number
getOpenErrorCode
METHODIf getLatestEvent returns with OpenFailed, retrieve the error code or HTTP status code here.ParametersNoneReturnsType Description int
getPhase
METHODReturns with the current phase for quantized synchronization, between 0 (beginning of the quantum) and 1 (end of the quantum).ParametersNoneReturnsType Description Number
getPhase
METHODReturns with the current phase for quantized synchronization, between 0 (beginning of the quantum) and 1 (end of the quantum).ParametersNoneReturnsType Description double
getPositionMs
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 Number
getPositionMs
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 double
getQuantum
METHODReturns with the current quantum for quantized synchronization, such as 2 for two beats, 4 for four beats, etc...ParametersNoneReturnsType Description Number
getQuantum
METHODReturns with the current quantum for quantized synchronization, such as 2 for two beats, 4 for four beats, etc...ParametersNoneReturnsType Description double
getStemColor
METHODReturns with a stem's color if a STEMS file was loaded, NULL otherwise.ParametersReturnsName Type Description index Number
The 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 char
The 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 Number
The 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 char
The index of the stem. Type Description const char *
The name. isLooping
METHODIndicates if looping is enabled.ParametersNoneReturnsType Description Boolean
isLooping
METHODIndicates if looping is enabled.ParametersNoneReturnsType Description bool
isPerformingSlip
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 Number
isPerformingSlip
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 boolean
isPlaying
METHODIndicates if the player is playing or paused.ParametersNoneReturnsType Description Boolean
isPlaying
METHODIndicates if the player is playing or paused.ParametersNoneReturnsType Description bool
isReverse
METHODIf true, the player is playing backwards.ParametersNoneReturnsType Description Boolean
isReverse
METHODIf true, the player is playing backwards.ParametersNoneReturnsType Description bool
isScratching
METHODIndicates if the player is in scratching mode.ParametersNoneReturnsType Description Boolean
isScratching
METHODIndicates if the player is in scratching mode.ParametersNoneReturnsType Description bool
isStems
METHODReturns true if a STEMS file was loaded (and the player was initialized with enableStems == true).ParametersNoneReturnsType Description Boolean
isStems
METHODReturns true if a STEMS file was loaded (and the player was initialized with enableStems == true).ParametersNoneReturnsType Description bool
isWaitingForBuffering
METHODIndicates if the player is waiting for data (such as waiting for a network download).ParametersNoneReturnsType Description Boolean
isWaitingForBuffering
METHODIndicates if the player is waiting for data (such as waiting for a network download).ParametersNoneReturnsType Description bool
jogTick
METHODA jog wheel should send some 'ticks' with the movement. A waveform's movement in pixels for example.ParametersReturnsName Type Description value Number
The ticks value. bendStretch Boolean
Use time-stretching for pitch bend or not (false makes it 'audible'). bendMaxPercent Number
The maximum playback rate change for pitch bend, should be between 0.01 and 0.3 (1% and 30%). bendHoldMs Number
How long to maintain the pitch bend state. A value >= 1000 will hold until endContinuousPitchBend is called. parameterModeIfNoJogTouchBegin Boolean
True: 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 int
The ticks value. bendStretch bool
Use time-stretching for pitch bend or not (false makes it 'audible'). bendMaxPercent float
The maximum playback rate change for pitch bend, should be between 0.01 and 0.3 (1% and 30%). bendHoldMs unsigned int
How long to maintain the pitch bend state. A value >= 1000 will hold until endContinuousPitchBend is called. parameterModeIfNoJogTouchBegin bool
True: 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 Number
Sets the sensitivity of the virtual wheel. Use around 2300 for pixel-perfect touchscreen waveform control. mode Number
Jog wheel mode (scratching, pitch bend, or parameter set in the 0-1 range). scratchSlipMs Number
Enables 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 int
Sets the sensitivity of the virtual wheel. Use around 2300 for pixel-perfect touchscreen waveform control. mode Superpowered::AdvancedAudioPlayer:JogMode
Jog wheel mode (scratching, pitch bend, or parameter set in the 0-1 range). scratchSlipMs unsigned int
0 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 Number
The decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart Boolean
Beat-synced start after decelerating. NonejogTouchEnd
METHODCall this when the jog touch ends.ParametersReturnsName Type Default Description decelerate float
The decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart bool
Beat-synced start after decelerating. Noneloop
METHODLoop from a start point to some length.ParametersReturnsName Type Description startMs Number
Loop from this milliseconds. lengthMs Number
Loop length in milliseconds. jumpToStartMs Boolean
If the playhead is within the loop, jump to startMs or not. pointID Number
Looping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart Boolean
Beat-synced start. numLoops Number
Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum Boolean
If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart Boolean
Wait or start immediately when synchronized. Noneloop
METHODLoop from a start point to some length.ParametersReturnsName Type Default Description startMs double
Loop from this milliseconds. lengthMs double
Loop length in milliseconds. jumpToStartMs bool
If the playhead is within the loop, jump to startMs or not. pointID Unsigned char
Looping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart bool
Beat-synced start. numLoops unsigned int
0 Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum bool
false If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart bool
false Wait or start immediately when synchronized. NoneloopBetween
METHODLoop between a start and end points.ParametersReturnsName Type Description startMs Number
Loop from this milliseconds. endMs Number
Loop to this milliseconds. jumpToStartMs Boolean
If the playhead is within the loop, jump to startMs or not. pointID Number
Looping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart Boolean
Beat-synced start. numLoops Number
Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum Boolean
If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart Boolean
Wait or start immediately when synchronized. NoneloopBetween
METHODLoop between a start and end points.ParametersReturnsName Type Default Description startMs double
Loop from this milliseconds. endMs double
Loop to this milliseconds. jumpToStartMs bool
If the playhead is within the loop, jump to startMs or not. pointID Unsigned char
Looping caches startMs, therefore you can specify a pointID too (or set to 255 if you don't care). synchronisedStart bool
Beat-synced start. numLoops unsigned int
0 Number of times to loop. 0 means: until exitLoop is called. forceDefaultQuantum bool
false If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart bool
false Wait or start immediately when synchronized. NonemsInLoop
METHODReturns true if a position is inside the current loop.ParametersNoneReturnsType Description Boolean
msInLoop
METHODReturns true if a position is inside the current loop.ParametersNoneReturnsType Description bool
onMediaserverInterrupt
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 bool
false If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd bool
false 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 int
The byte offset inside the path. length int
The 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 bool
false If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd bool
false 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 Boolean
If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd Boolean
If 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 bool
false If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd bool
false 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 Number
The sample rate in Hz. Valid from 8192 to 384000. durationFrames Number
The duration of the audio in frames. skipSilenceAtBeginning Boolean
If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd Boolean
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 Default Description pointer void *
Stereo interleaved 16-bit PCM audio. samplerate unsigned int
The sample rate in Hz. Valid from 8192 to 384000. durationFrames unsigned int
The duration of the audio in frames. skipSilenceAtBeginning bool
false If true, the player will set the position to skip the initial digital silence of the audio file (up to 10 seconds). measureSilenceAtEnd bool
false 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 Number
Optional momentum. 0 means to pause immediately. slipMs Number
Enable 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 float
0 Optional momentum. 0 means to pause immediately. slipMs unsigned int
0 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 Number
The maximum playback rate range for pitch bend, should be between 0.01f and 0.3f (1% and 30%). bendStretch Number
Use time-stretching for pitch bend or not (false makes it 'audible'). 1 or 0 faster Number
True (1): faster, false (0): slower. hostMs Number
NonepitchBend
METHODStarts on changes pitch bend (temporary playback rate change).ParametersReturnsName Type Default Description maxPercent float
The maximum playback rate range for pitch bend, should be between 0.01f and 0.3f (1% and 30%). bendStretch Boolean
Use time-stretching for pitch bend or not (false makes it 'audible'). 1 or 0 faster Boolean
True (1): faster, false (0): slower. hostMs unsigned int
Noneplay
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 Number
NoneplaySynchronizedToPosition
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 double
Noneprocess8Channels
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 Boolean
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. numberOfFrames Number
The number of frames requested. volume0 Number
Volume for buffer0. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume1 Number
Volume for buffer1. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume2 Number
Volume for buffer2. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume3 Number
Volume for buffer3. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description Boolean
true: 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 bool
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. numberOfFrames unsigned int
The number of frames requested. volume0 float
1.0f Volume for buffer0. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume1 float
1.0f Volume for buffer1. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume2 float
1.0f Volume for buffer2. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. volume3 float
1.0f Volume for buffer3. 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description bool
true: 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 Number
The number of frames requested. volume Number
Output 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 int
The number of frames requested. volume float
1.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 Boolean
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. numberOfFrames Number
The number of frames requested. volume Number
0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description Boolean
true: 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 bool
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. numberOfFrames unsigned int
The number of frames requested. volume float
1.0f 0 is silence, 1 is 'original volume'. Changes are automatically smoothed between consecutive processes. Type Description bool
true: 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 Number
resetBendMsOffset
METHODReset the pitch bend offset to the beatgrid to zero.ParametersNoneReturnsType Description double
scratch
METHODScratch movement.ParametersReturnsName Type Description pitch Number
The current speed. smoothing Number
Should be between 0.05f (max. smoothing) and 1.0f (no smoothing). Nonescratch
METHODScratch movement.ParametersReturnsName Type Default Description pitch double
The current speed. smoothing float
Should be between 0.05f (max. smoothing) and 1.0f (no smoothing). Noneseek
METHODSimple seeking to a percentage.ParametersReturnsName Type Description percent Number
Noneseek
METHODSimple seeking to a percentage.ParametersReturnsName Type Default Description percent double
NonesetBendOffsetMs
METHODSets with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersReturnsName Type Description ms Number
Value in milliseconds NonesetBendOffsetMs
METHODSets with the distance (in milliseconds) to the beatgrid while using pitch bend for correction.ParametersReturnsName Type Default Description ms double
Value in milliseconds NonesetPosition
METHODPrecise seeking.ParametersReturnsName Type Description ms Number
Position in milliseconds. andStop Boolean
If true, stops playback. synchronisedStart Boolean
If andStop is false, makes a beat-synced start possible. forceDefaultQuantum Boolean
If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart Boolean
Wait or start immediately when synchronized. NonesetPosition
METHODPrecise seeking.ParametersReturnsName Type Default Description ms double
Position in milliseconds. andStop bool
If true, stops playback. synchronisedStart bool
If andStop is false, makes a beat-synced start possible. forceDefaultQuantum bool
false If true and using quantized synchronization, will use the defaultQuantum instead of the syncToQuantum. preferWaitingforSynchronisedStart bool
false Wait or start immediately when synchronized. NonesetReverse
METHODSets playback direction.ParametersReturnsName Type Description reverse Number
True: reverse. False: forward. slipMs Number
Enable slip mode for a specific amount of time, or 0 to not slip. NonesetReverse
METHODSets playback direction.ParametersReturnsName Type Default Description reverse Boolean
True: reverse. False: forward. slipMs unsigned int
0 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 Number
The decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart Boolean
Beat-synced start after decelerating. NonestartScratch
METHODDirect turntable handling. Call this when scratching starts.ParametersReturnsName Type Default Description decelerate float
The decelerating rate for momentum. Set to 0.0f for automatic. synchronisedStart bool
Beat-synced start after decelerating. NonetogglePlayback
METHODToggle play/pause (no synchronization).ParametersNoneReturnsNonetogglePlayback
METHODToggle play/pause (no synchronization).ParametersNoneReturnsNone