We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I am trying to make a simple audio sampler by triggering 1 second segments of a 10 second audio file from the computer keyboard. In the code below, I'm trying to trigger second 1 of the file with the 'a' key, second 2 with the 's' key, and so on.
At the moment, this code doesn't make any sound, though I got the keyTyped() example to trigger changes in a sketch. Is the problem in my use of song.playMode('restart')
? Or should I preload()
the sound? Or do I need to assign number ASCII values to the samples?
Thanks for any help!
var song;
function setup(){
song = loadSound('10sec.mp3');
}
function keyTyped() {
song.playMode('restart');
if (keyCode === 'a') {
song.jump(0, 1);
} else if (keyCode === 's') {
song.jump(5, 1);
} else if (keyCode === 'd') {
song.jump(2, 1);
}
}
Answers
song.play();