Class: Analyzer
Overview
Performs bpm and key detection, loudness/peak analysis. Provides compact waveform data (150 points/sec and 1 point/sec resolution), beatgrid information.
Offline analysis example
The following code sandbox shows you how to take an audio file, convert it to the right format and pass the entire song into the Superpowered Analyser
to extract information. This example is in Javascript, but the order and way methods are called is common across both web and native.
We display the various wavesform data on canvases and the audio features that are extracted in a table. We also show you how you might start to display the detected data provided by the getNotes()
method.
How to implement
// Constructor.let analyzer = new Superpowered.Analyzer(44100, // The sample rate of the audio input.60 // The length in seconds of the audio input. The analyzer will not be able to process more audio than this. You can change this value in the process() method.);// Processes some audio. This method can be used in a real-time audio thread if lengthSeconds is -1. Has no return value.analyzer.process(input, // Pointer to floating point numbers. 32-bit interleaved stereo input.128, // Number of frames to process.-1 // If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread.);// Makes results from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. Has no return value.analyzer.makeResults(60, // Detected bpm will be more than or equal to this. Recommended value: 60.200, // Detected bpm will be less than or equal to this. Recommended value: 200.0, // If you know the bpm set it here. Use 0 otherwise.0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.true, // True: calculate beatgridStartMs. False: save some CPU with not calculating it.0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.true, // True: make overviewWaveform. False: save some CPU and memory with not making it.true, // True: make the low/mid/high waveforms. False: save some CPU and memory with not making them.true // True: calculate keyIndex. False: save some CPU with not calculating it.);analyzer.peakDb; // Peak volume in decibels. Available after calling makeResults().analyzer.averageDb; // Average volume in decibels. Available after calling makeResults().analyzer.loudpartsAverageDb; // The average volume of the "loud" parts in decibel. (Quiet parts excluded.) Available after calling makeResults().analyzer.bpm; // Beats per minute. Available after calling makeResults().analyzer.beatgridStartMs; // Where the beatgrid starts (first beat) in milliseconds. Available after calling makeResults().analyzer.keyIndex; // The dominant key (chord) of the music. 0..11 are major keys from A to G#, 12..23 are minor keys from A to G#.analyzer.waveformSize; // The number of bytes in the peak, average, low, mid and high waveforms and notes.let w = analyzer.getPeakWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the peak volume. Each byte represents one "pixel". Available after calling makeResults().let w = analyzer.getAverageWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the average volume. Each byte represents one "pixel". Available after calling makeResults().let w = analyzer.getLowWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the low frequencies (below 200 Hz). Each byte represents one "pixel". Available after calling makeResults().let w = analyzer.getMidWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the mid frequencies (200-1600 Hz). Each byte represents one "pixel". Available after calling makeResults().let w = analyzer.getHighWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the high frequencies (above 1600 Hz). Each byte represents one "pixel". Available after calling makeResults().let n = analyzer.getNotes(); // Superpowered.Uint8Buffer. 150 points/sec data displaying the bass and mid keys. Upper 4 bits are the bass notes 0 to 11, lower 4 bits are the mid notes 0 to 11 (C, C#, D, D#, E, F, F#, G, G#, A, A#, B). The note value is 12 means "unknown note due low volume". Available after calling makeResults().analyzer.overviewSize; // The number bytes in overviewWaveform.let w = analyzer.getOverviewWaveform(); // Superpowered.Uint8Buffer. 1 point/sec waveform data displaying the average volume in decibels. Useful for displaying the overall structure of a track. Int8Array. Each byte has the value of -128 to 0, in decibels.// Destructor (to free up memory).analyzer.destruct();// Helper arrays to display keyIndex in musical, Camelot and Open Key formats:let musicalChordNames = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", /// major"Am", "A#m", "Bm", "Cm", "C#m", "Dm", "D#m", "Em", "Fm", "F#m", "Gm", "G#m" /// minor];let camelotChordNames = ["11B", "6B", "1B", "8B", "3B", "10B", "5B", "12B", "7B", "2B", "9B", "4B", /// major"8A", "3A", "10A", "5A", "12A", "7A", "2A", "9A", "4A", "11A", "6A", "1A" /// minor];let openkeyChordNames = ["4d", "11d", "6d", "1d", "8d", "3d", "10d", "5d", "12d", "7d", "2d", "9d", /// major"1m", "8m", "3m", "10m", "5m", "12m", "7m", "2m", "9m", "4m", "11m", "6m" /// minor];
#include "SuperpoweredAnalyzer.h"// Constructor.Superpowered::Analyzer *analyzer = new Superpowered::Analyzer(44100, // The sample rate of the audio input.60 // The length in seconds of the audio input. The analyzer will not be able to process more audio than this. You can change this value in the process() method.);// Processes some audio. This method can be used in a real-time audio thread if lengthSeconds is -1. Has no return value.analyzer->process(input, // Pointer to floating point numbers. 32-bit interleaved stereo input.128, // Number of frames to process.-1 // If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread.);// Makes results from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. Has no return value.analyzer->makeResults(60, // Detected bpm will be more than or equal to this. Recommended value: 60.200, // Detected bpm will be less than or equal to this. Recommended value: 200.0, // If you know the bpm set it here. Use 0 otherwise.0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.true, // True: calculate beatgridStartMs. False: save some CPU with not calculating it.0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.true, // True: make overviewWaveform. False: save some CPU and memory with not making it.true, // True: make the low/mid/high waveforms. False: save some CPU and memory with not making them.true // True: calculate keyIndex. False: save some CPU with not calculating it.);analyzer->peakDb; // Peak volume in decibels. Available after calling makeResults().analyzer->averageDb; // Average volume in decibels. Available after calling makeResults().analyzer->loudpartsAverageDb; // The average volume of the "loud" parts in decibel. (Quiet parts excluded.) Available after calling makeResults().analyzer->bpm; // Beats per minute. Available after calling makeResults().analyzer->beatgridStartMs; // Where the beatgrid starts (first beat) in milliseconds. Available after calling makeResults().analyzer->keyIndex; // The dominant key (chord) of the music. 0..11 are major keys from A to G#, 12..23 are minor keys from A to G#. Check the static constants in this header for musical, Camelot and Open Key notations.analyzer->waveformSize; // The number of bytes in the peak, average, low, mid and high waveforms and notes.unsigned char *w = analyzer->getPeakWaveform(); // 150 points/sec waveform data displaying the peak volume. Each byte represents one "pixel". Available after calling makeResults().unsigned char *w = analyzer->getAverageWaveform(); // 150 points/sec waveform data displaying the average volume. Each byte represents one "pixel". Available after calling makeResults().unsigned char *w = analyzer->getLowWaveform(); // 150 points/sec waveform data displaying the low frequencies (below 200 Hz). Each byte represents one "pixel". Available after calling makeResults().unsigned char *w = analyzer->getMidWaveform(); // 150 points/sec waveform data displaying the mid frequencies (200-1600 Hz). Each byte represents one "pixel". Available after calling makeResults().unsigned char *w = analyzer->getHighWaveform(); // 150 points/sec waveform data displaying the high frequencies (above 1600 Hz). Each byte represents one "pixel". Available after calling makeResults().unsigned char *n = analyzer->getNotes(); // Superpowered.Uint8Buffer. 150 points/sec data displaying the bass and mid keys. Upper 4 bits are the bass notes 0 to 11, lower 4 bits are the mid notes 0 to 11 (C, C#, D, D#, E, F, F#, G, G#, A, A#, B). The note value is 12 means "unknown note due low volume". Available after calling makeResults().analyzer->overviewSize; // The number bytes in overviewWaveform.char *w = analyzer->getOverviewWaveform(); // 1 point/sec waveform data displaying the average volume in decibels. Useful for displaying the overall structure of a track. Int8Array. Each byte has the value of -128 to 0, in decibels.// Helper arrays to display keyIndex in musical, Camelot and Open Key formats:const char *musicalChordNames[24] = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", /// major"Am", "A#m", "Bm", "Cm", "C#m", "Dm", "D#m", "Em", "Fm", "F#m", "Gm", "G#m" /// minor};const char *camelotChordNames[24] = {"11B", "6B", "1B", "8B", "3B", "10B", "5B", "12B", "7B", "2B", "9B", "4B", /// major"8A", "3A", "10A", "5A", "12A", "7A", "2A", "9A", "4A", "11A", "6A", "1A" /// minor};const char *openkeyChordNames[24] = {"4d", "11d", "6d", "1d", "8d", "3d", "10d", "5d", "12d", "7d", "2d", "9d", /// major"1m", "8m", "3m", "10m", "5m", "12m", "7m", "2m", "9m", "4m", "11m", "6m" /// minor};
Properties
Methods
constructor
METHODCreates instance of Analyzer classParametersReturnsName Type Description samplerate Number
The sample rate of the audio input. lengthSeconds Number
The length in seconds of the audio input. The analyzer will not be able to process more audio than this. You can change this value in the process() method. Type Description Superpowered.Analyzer
The constructed instance. constructor
METHODCreates instance of Analyzer classParametersReturnsName Type Default Description samplerate unsigned int
The sample rate of the audio input. lengthSeconds int
The length in seconds of the audio input. The analyzer will not be able to process more audio than this. You can change this value in the process() method. Type Description Superpowered::Analyzer
The constructed instance. destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNonegetAverageWaveform
METHODReturns with 150 points/sec waveform data displaying the average volume. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getAverageWaveform
METHODReturns with 150 points/sec waveform data displaying the average volume. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getHighWaveform
METHODReturns with 150 points/sec waveform data displaying the high frequencies above 1600 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getHighWaveform
METHODReturns with 150 points/sec waveform data displaying the high frequencies above 1600 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getLowWaveform
METHODReturns with 150 points/sec waveform data displaying the low frequencies below 200 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getLowWaveform
METHODReturns with 150 points/sec waveform data displaying the low frequencies below 200 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getMidWaveform
METHODReturns with 150 points/sec waveform data displaying the frequencies between 200 and 1600 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getMidWaveform
METHODReturns with 150 points/sec waveform data displaying the frequencies between 200 and 1600 Hz. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getNotes
METHODReturns with 150 points/sec waveform data displaying the bass and mid keys. Each bytes is further divided to 4-4 bits, representing one "pixel". Upper 4 bits are the bass notes 0 to 11, lower 4 bits are the mid notes 0 to 11 (C, C#, D, D#, E, F, F#, G, G#, A, A#, B). The note value is 12 means "unknown note due low volume". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getNotes
METHODReturns with 150 points/sec waveform data displaying the bass and mid keys. Each bytes is further divided to 4-4 bits, representing one "pixel". Upper 4 bits are the bass notes 0 to 11, lower 4 bits are the mid notes 0 to 11 (C, C#, D, D#, E, F, F#, G, G#, A, A#, B). The note value is 12 means "unknown note due low volume". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getOverviewWaveform
METHODReturns with 1 point/sec waveform data displaying the average volume in decibels. Useful for displaying the overall structure of a track. Each number is a signed byte (8-bits), representing one "pixel". Values are between -128 and 0, in decibels. Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getOverviewWaveform
METHODReturns with 1 point/sec waveform data displaying the average volume in decibels. Useful for displaying the overall structure of a track. Each number is a signed byte (8-bits), representing one "pixel". Values are between -128 and 0, in decibels. Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data getPeakWaveform
METHODReturns with 150 points/sec waveform data displaying the peak volume. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Description takeOwnership Boolean
If true, you take ownership on the data, so don't forget to call the free() method of the returned Superpowered.Uint8Buffer the memory to prevent memory leaks. Type Description Superpowered.Uint8Buffer
150 points/sec waveform data getPeakWaveform
METHODReturns with 150 points/sec waveform data displaying the peak volume. Each number is an unsigned byte (8-bits), representing one "pixel". Available after calling makeResults().ParametersReturnsName Type Default Description takeOwnership bool
false If true, you take ownership on the data, so don't forget to free() the memory to prevent memory leaks. Use _aligned_free() on Windows. Type Description unsigned char *
150 points/sec waveform data makeResults
METHODMakes results from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. It is difficult for the algorithm to determine the time signature of music, so if the calculated BPM is far from the one expected, please provide a shorter range through the minimumBpm and maximumBpm or aroundBpm arguments.ParametersReturnsName Type Description minimumBpm Number
Detected bpm will be more than or equal to this. Recommended value: 60. maximumBpm Number
Detected bpm will be less than or equal to this. Recommended value: 200. knownBpm Number
If you know the bpm set it here. Use 0 otherwise. aroundBpm Number
Provides a "hint" for the analyzer with this. Use 0 otherwise. getBeatgridStartMs Boolean
True: calculate beatgridStartMs. False: save some CPU with not calculating it. aroundBeatgridStartMs Number
Provides a "hint" for the analyzer with this. Use 0 otherwise. makeOverviewWaveform Boolean
True: make overviewWaveform. False: save some CPU and memory with not making it. makeLowMidHighWaveforms Boolean
True: make the low/mid/high waveforms. False: save some CPU and memory with not making them. getKeyIndex Boolean
True: calculate keyIndex. False: save some CPU with not calculating it. NonemakeResults
METHODMakes results from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. It is difficult for the algorithm to determine the time signature of music, so if the calculated BPM is far from the one expected, please provide a shorter range through the minimumBpm and maximumBpm or aroundBpm arguments.ParametersReturnsName Type Default Description minimumBpm float
Detected bpm will be more than or equal to this. Recommended value: 60. maximumBpm float
Detected bpm will be less than or equal to this. Recommended value: 200. knownBpm float
If you know the bpm set it here. Use 0 otherwise. aroundBpm float
Provides a "hint" for the analyzer with this. Use 0 otherwise. getBeatgridStartMs bool
True: calculate beatgridStartMs. False: save some CPU with not calculating it. aroundBeatgridStartMs float
Provides a "hint" for the analyzer with this. Use 0 otherwise. makeOverviewWaveform bool
True: make overviewWaveform. False: save some CPU and memory with not making it. makeLowMidHighWaveforms bool
True: make the low/mid/high waveforms. False: save some CPU and memory with not making them. getKeyIndex bool
True: calculate keyIndex. False: save some CPU with not calculating it. Noneprocess
METHODProcesses some audio. This method can be used in a real-time audio thread if lengthSeconds is -1.ParametersReturnsName Type Description input Number (pointer in Linear Memory)
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames Number
Number of frames to process. lengthSeconds Number
If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread. Noneprocess
METHODProcesses some audio. This method can be used in a real-time audio thread if lengthSeconds is -1.ParametersReturnsName Type Default Description input float *
32-bit interleaved stereo input. Special case: set to 0 to empty all buffered content. numberOfFrames unsigned int
Number of frames to process. lengthSeconds int
-1 If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread. None