-
Notifications
You must be signed in to change notification settings - Fork 1
Using maxiPitchShift on a sample
Kevin Lewis edited this page Feb 12, 2017
·
2 revisions
Step 0 - Set up your sample
var audio = new maximJs.maxiAudio();
function setup() {
audio.play = playLoop;
audio.init();
sound = new maximJs.maxiSample();
audio.loadSample("assets/piano.mp3", sound);
}
function playLoop() {
if(sound.isReady()) {
this.output = sound.play();
} else {
this.output = 0;
}
}
Step 1 - Create a pitchShift object as a global variable
var pitchShifter = new maximJs.maxiPitchShift();
Step 2 - Create a conditional which only happens once, in the play loop
In this conditional, we will set the sample of our pitchShifter object. We will use boolean logic to ensure this is only triggered once.
// GLOBAL var samplePlayerSet = false; function playLoop() { if(!samplePlayerSet) { pitchShifter.setSample(sound); samplePlayerSet = true; } if(sound.isReady()) { this.output = sound.play(); } else { this.output = 0; } }
Step 3 - Play the pitchShifter object
function playLoop() { if(!samplePlayerSet) { pitchShifter.setSample(sound); samplePlayerSet = true; } if(sound.isReady()) { this.output = pitchShifter.play(0.5, 0.1, 2, 0); } else { this.output = 0; } }
The value underlined is the only one which matters for a basic pitch shift. It sets the pitch relative to the usual pitch of the sample, where 1 is normal, 0.5 is half and 2 is double.