Class: AutomaticVocalPitchCorrection
Interactive example
Get some headphone on, clear your throat and hit microphone on the input stage! It'd be rude to not give singing a try, wouldn't it?
Overview
The Automatic Vocal Pitch Correction (Automatic Tune) class applies realtime pitch correction to an input signal based on the following three parameters:
scale
- Which scale (or set of custom notes) to snap the input signal to.range
- Tells the effect what frequency range it's dealing with to improve accuracy.speed
- How fast the pitch transform is applied.clamp
- Controls the incoming pitch variance threshold for switching to a new note for the output..
In this example, we're taking the output from the AutomaticVocalPitchCorrection and feeding it into a Superpowered Compressor, Superpowered Reverb and finally to the speakers.
One instance allocates around 20kb memory.
Please note
The Superpowered Automatic Vocal Pitch Correction effect will always work best with simple monophonic tones, such as the human voice. It will struggle with the piano due to the number of harmonics present in the notes.
We’d like to draw attention to the clamp setting, which we find sounds best when set to LOOSE
. This is to prevent the corrections from changing too quickly and will sound more natural. We advise testing different clamp settings using your microphone on the interactive audio example above.
It's also worth noting that this effect is not designed to produce the heavily overtuned robotic sound you may associate with this kind of effect category. Setting the speed
property to EXTREME
and clamp
to OFF
will put the effect in it's most extreme configuration.
Overall, our pitch correction algorithms are quite new. We believe the audio quality is of a good standard but we are striving to continue to improve over time.
Sound sources
This effect is designed for monophonic audio vocal sources. By monophonic, we mean any sound that has a single dominant frequency, such as a single solo human voice. A choir of singers on the other hand has potentially many simultaneous notes being sang at once, so can be considered polyphonic. The autotune cannot process polyphonic audio reliably, so please consider carefully where and when this effect is being applied in your application. That being said, there's nothing wrong with experimentation, maybe you'll find some interesting results.
Scales
The effect allows you to define the musical notes (key) that you'd like the input signal to snap to. You can either set to common major and minor keys by setting scale
with one of the constants
, or your can define your own note range by setting scale
to CUSTOM
and then using the setCustomScaleNote()
method to set each required note enabled or disabled between C and B (on all octaves), with note numbers 0 - 11.
Range and speed
By supplying range, you'll find the effect if more capable of snapping the input source to the desired notes. It's not always possible to know the range of the input vocals, so we've provided WIDE
, which tries it's best with most of the vocal ranges you can throw at it, but might still struggle with the death metal growls.
The speed
parameter defines how quickly the pitch transform takes place on the original signal ranging from SUBTLE
for a more natural sound, MEDIUM
and EXTREME
for a robotic more pronounced stylised sound.
Altering frequencyOfA
will set the reference pitch the effect is using internally between 470Hz and 410Hz
Clamp range
As of Superpowered v2.6.2
, you can now define the clamp
parameter. This parameter defines how much pitch varience must be detected before the effect with repitch up or down to the next note. The parameter defaults to LOOSE
, which will swich to another not if the incoming pitch detected is 0.7
semitones above or below from the currently held pitch. In other words, it establishs a stable area 1.4
semitones wide centered around the current note.
How to implement
You'll find the constants required for scale
, range
, clamp
and speed
under the main class. Please use these when setting properties, as demonstrated below.
Please also not that unlike the other effect, this class does not have a return value from the process
method.
class SuperpoweredAutomaticVocalPitchCorrectionProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {// Runs after the constructoronReady() {this.effect = new this.Superpowered.AutomaticVocalPitchCorrection(this.samplerate);this.effect.scale = this.Superpowered.AutomaticVocalPitchCorrection.DMINOR;this.effect.range = this.Superpowered.AutomaticVocalPitchCorrection.ALTO;this.effect.speed = this.Superpowered.AutomaticVocalPitchCorrection.MEDIUM;this.effect.clamp = this.Superpowered.AutomaticVocalPitchCorrection.LOOSE;this.sendMessageToMainScope({ event: 'ready' });}// Runs before the node is destroyed.onDestruct() {this.effect.destruct();}applyCustomNotes(activeNotes) {// scaled to midi note numbersfor (let index = 0; index < 12; index++) {if (activeNotes.includes(index+48)) {this.effect.setCustomScaleNote(index, // The note (between 0..11).1 // Note enabled or not.);} else {this.effect.setCustomScaleNote(index, // The note (between 0..11).0 // Note enabled or not.);}}}// messages are received from the main scope through this method.onMessageFromMainScope(message) {if (typeof message.range !== "undefined") this.effect.range = this.Superpowered.AutomaticVocalPitchCorrection[message.range];if (typeof message.speed !== "undefined") this.effect.speed = this.Superpowered.AutomaticVocalPitchCorrection[message.speed];if (typeof message.clamp !== "undefined") this.effect.clamp = this.Superpowered.AutomaticVocalPitchCorrection[message.clamp];if (typeof message.frequencyOfA !== "undefined") this.effect.frequencyOfA = message.frequencyOfA;if (typeof message.scale !== "undefined") this.effect.scale = this.Superpowered.AutomaticVocalPitchCorrection[message.scale];if (typeof message.activeNotes !== "undefined") this.applyCustomNotes(message.activeNotes)}processAudio(inputBuffer, outputBuffer, buffersize, parameters) {// Ensure the samplerate is in sync on every audio processing callback// this.effect.samplerate = this.samplerate;// Render the output buffersthis.effect.process(inputBuffer.pointer,outputBuffer.pointer,true,buffersize);// if (!) this.Superpowered.memoryCopy(outputBuffer.pointer, inputBuffer.pointer, buffersize * 8);}}
#include "SuperpoweredAutomaticVocalPitchCorrection.h"Superpowered::AutomaticVocalPitchCorrection *autotune = new Superpowered::AutomaticVocalPitchCorrection();// Do this when the sample rate changes.autotune->samplerate = 48000;// Set the music scale.autotune->scale = Superpowered::AutomaticVocalPitchCorrection::CMAJOR;// Custom scale can also be used.autotune->scale = Superpowered::AutomaticVocalPitchCorrection::CUSTOM;autotune->setCustomScaleNote(0, // The note (between 0..11).true // Note enabled or not.);// Query the custom scale.bool note_0_enabled = autotune->getCustomScaleNote(0 // The note (between 0..11).);// Set the vocal range of the singer.autotune->range = Superpowered::AutomaticVocalPitchCorrection::TENOR;// How fast auto-tune should adapt, how "strong" it is.autotune->speed = Superpowered::AutomaticVocalPitchCorrection::SUBTLE;// Controls the incoming pitch variance threshold for switching to a new note for the output.autotune->clamp = Superpowered::AutomaticVocalPitchCorrection::LOOSE;// Middle A is not 440 Hz? No problem:autotune->frequencyOfA = 430;// Processes the audio. Has no return value.// It's never blocking for real-time usage. You can change any properties concurrently with process().autotune->process(input, // Input pointer (audio in 32-bit floating point numbers).output, // Output pointer (audio in 32-bit floating point numbers).true, // True: input and output are interleaved stereo. False: mono.128 // Number of frames to process.);// Set all internals to initial state.autotune->reset();
Constants
Superpowered.AutomaticVocalPitchCorrection
CONSTANTSScaleValue Description CHROMATIC CMAJOR AMINOR CSHARPMAJOR ASHARPMINOR DMAJOR BMINOR DSHARPMAJOR CMINOR EMAJOR CSHARPMINOR FMAJOR DMINOR FSHARPMAJOR DSHARPMINOR GMAJOR EMINOR GSHARPMAJOR FMINOR AMAJOR FSHARPMINOR ASHARPMAJOR GMINOR BMAJOR GSHARPMINOR CUSTOM Superpowered::AutomaticVocalPitchCorrection
CONSTANTSScaleValue Description CHROMATIC CMAJOR AMINOR CSHARPMAJOR ASHARPMINOR DMAJOR BMINOR DSHARPMAJOR CMINOR EMAJOR CSHARPMINOR FMAJOR DMINOR FSHARPMAJOR DSHARPMINOR GMAJOR EMINOR GSHARPMAJOR FMINOR AMAJOR FSHARPMINOR ASHARPMAJOR GMINOR BMAJOR GSHARPMINOR CUSTOM Superpowered.AutomaticVocalPitchCorrection
CONSTANTSRangeValue Description WIDE Wide range, 40 to 3000 Hz BASS Bass singer, 40 to 350 Hz TENOR Tenor, 100 to 600 Hz ALTO Alto, 150 to 1400 Hz SOPRANO Soprano, 200 to 3000 Hz Superpowered::AutomaticVocalPitchCorrection
CONSTANTSRangeValue Description WIDE Wide range, 40 to 3000 Hz BASS Bass singer, 40 to 350 Hz TENOR Tenor, 100 to 600 Hz ALTO Alto, 150 to 1400 Hz SOPRANO Soprano, 200 to 3000 Hz Superpowered.AutomaticVocalPitchCorrection
CONSTANTSSpeedValue Description SUBTLE Subtle pitch correction MEDIUM Medium pitch correction EXTREME Classic pitch correction effect Superpowered::AutomaticVocalPitchCorrection
CONSTANTSSpeedValue Description SUBTLE Subtle pitch correction MEDIUM Medium pitch correction EXTREME Classic pitch correction effect Superpowered.AutomaticVocalPitchCorrection
CONSTANTSClampValue Description OFF Always switch to the nearest key in the selected scale as output note LOOSE Switch if the detected key is 0.7 semitones above or below the current output note. TIGHT Switch if the detected key is 1.2 semitones above or below the current output note, stable area centered around current note is 2.4 semitones Superpowered::AutomaticVocalPitchCorrection
CONSTANTSClampValue Description OFF Always switch to the nearest key in the selected scale as output note LOOSE Switch if the detected key is 0.7 semitones above or below the current output note. TIGHT Switch if the detected key is 1.2 semitones above or below the current output note, stable area centered around current note is 2.4 semitones
Properties
clamp
PROPERTYType | Min | Max | Default | Number | OFF | TIGHT | LOOSE |
---|
clamp
PROPERTYType | Min | Max | Default | Superpowered.AutomaticVocalPitchCorrection | OFF | TIGHT | LOOSE |
---|
frequencyOfA
PROPERTYType | Min | Max | Default | Number | 410 | 470 | 440 |
---|
frequencyOfA
PROPERTYType | Min | Max | Default | float | 410 | 470 | 440 |
---|
range
PROPERTYType | Min | Max | Default | Number | WIDE (40 to 3000 Hz) |
---|
range
PROPERTYType | Min | Max | Default | Superpowered.AutomaticVocalPitchCorrection | WIDE (40 to 3000 Hz) |
---|
samplerate
PROPERTYType | Min | Max | Default | Number | 48000 |
---|
samplerate
PROPERTYType | Min | Max | Default | unsigned int | 48000 |
---|
scale
PROPERTYType | Min | Max | Default | Number | CHROMATIC (all twelve keys of the octave are allowed) |
---|
scale
PROPERTYType | Min | Max | Default | Superpowered.AutomaticVocalPitchCorrection | CHROMATIC (all twelve keys of the octave are allowed) |
---|
speed
PROPERTYType | Min | Max | Default | Number | EXTREME |
---|
speed
PROPERTYType | Min | Max | Default | Superpowered.AutomaticVocalPitchCorrection | EXTREME |
---|
Methods
constructor
METHODCreates an instance of the AutomaticVocalPitchCorrection class.ParametersNoneReturnsType Description Superpowered.AutomaticVocalPitchCorrection
The constructed instance. constructor
METHODCreates an instance of the AutomaticVocalPitchCorrection class.ParametersNoneReturnsType Description Superpowered::AutomaticVocalPitchCorrection
The constructed instance. destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNonegetCustomScaleNote
METHODGet note (on all octaves) for scale == CUSTOM.ParametersReturnsName Type Description note Number
The note (between 0..11). NonegetCustomScaleNote
METHODGet note (on all octaves) for scale == CUSTOM.ParametersReturnsName Type Default Description note unsigned char
The note (between 0..11). Noneprocess
METHODIt's never blocking for real-time usage. You can change any properties concurrently with process().ParametersReturnsName Type Description input Number (pointer in Linear Memory)
32-bit input. output Number (pointer in Linear Memory)
32-bit output. stereo Boolean
Interleaved stereo or mono input and output. numberOfFrames Number
Number of frames to process. Noneprocess
METHODIt's never blocking for real-time usage. You can change any properties concurrently with process().ParametersReturnsName Type Default Description input float *
32-bit input. output float *
32-bit output. stereo bool
Interleaved stereo or mono input and output. numberOfFrames unsigned int
Number of frames to process. Nonereset
METHODSet all internals to initial state.ParametersNoneReturnsNonereset
METHODSet all internals to initial state.ParametersNoneReturnsNonesetCustomScaleNote
METHODSet note (on all octaves) for scale == CUSTOM.ParametersReturnsName Type Description note Number
The note (between 0..11). enabled Boolean
Note enabled or not. NonesetCustomScaleNote
METHODSet note (on all octaves) for scale == CUSTOM.ParametersReturnsName Type Default Description note unsigned char
The note (between 0..11). enabled bool
Note enabled or not. None