Trouble Assigning ASCII Values to Jump Points in Audio File

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

Sign In or Register to comment.