-
Notifications
You must be signed in to change notification settings - Fork 1
Playing multiple samples controlled with the playhead
Kevin Lewis edited this page Feb 5, 2017
·
1 revision
var audio = new maximJs.maxiAudio(); var timer = new maximJs.maxiOsc(); var currentCount; var isTriggered; var playhead = 0; function setup() { audio.play = playLoop; audio.init(); click = new maximJs.maxiSample(); audio.loadSample("assets/click.mp3", click); kick = new maximJs.maxiSample(); audio.loadSample("assets/kick.mp3", kick); } function playLoop(){ currentCount = timer.phasor(8); if(currentCount < 0.5 && !isTriggered && click.isReady()) { playhead = (playhead+1)%16; isTriggered = true; if(playhead % 2 == 0) { click.trigger(); } if(playhead % 4 == 0) { kick.trigger(); } } else if (currentCount > 0.5) { isTriggered = false; } this.output = (click.playOnce() + kick.playOnce()) / 2; }
- Create a new
maximJs.maxiSample()
object. - Load a sample into the object.
- Use the playhead position to trigger the new sample.
- Don't forget to divide your
this.output
by the total number of samples.