faster trigger audio clips for 'drum roll'

Hi Everybody
My professor (Kate Hartman) has generously helped my team and I develop the following code, trying to get a single 'drum tap' thing going. However, there's an issue.

I'd like to be able to play the sound quickly, like a drum roll, but right now I'm unable. I believe currently, I can only re'trigger the sound once it's stopped playing, so I can't play it more than once every 1/4 second or so.

I think I may need to add 'restart' for play mode somewhere, but I'm not sure where. Can anyone assist me or point me in the right direction? 

Much much thanks.

.aS.



`function preload() {
  soundFormats('wav');
  sample = loadSound('snare.wav');
}

function setup() {
  createCanvas(displayWidth, displayHeight);
  //fullscreen(true);
  sample.play();
}

function draw() {

  if (sample.isPlaying()) {
    background('white');
    fill('blue');
    stroke('none');
    ellipse(windowWidth / 2, windowHeight / 2, 175, 175);
  } else {
    background('blue');
    noStroke();
    fill('white');
    ellipse(windowWidth / 2, windowHeight / 2, 175, 175);
  }

}

function mousePressed() {
  if (sample.isPlaying()) {
    //sample.pause();
    sample.playMode('restart');
    //do nothing!
  } else {
    sample.play();
}
}

`

Answers

  • edited October 2016

    Purely conceptual:

    • When a real drum roll happens, how many drum sticks are being used?
    • When a real individual strike happens, how long does the sound last?

    Maybe you should have two different samples -- sampleLeft, sampleRight, and "roll" them.

    R---|
      L---|
        R---|
          L---|
            R---|
              L---|
                ...
    

    Then make the sound files a lot shorter than 1/4 sec. Like 1/8th... so you can then roll two drumsticks (samples) at ~1/16th speed.

    There are other ways of approaching this problem, but I hope this is helpful.

  • P.S. Please edit your original post, highlight your code, and press CTRL-O. This will format it so that forum users can read, copy-paste, and test it easily.

  • Hi Jeremy, My apologies for the formatting. I just did the control-O.. Much better!

    Your idea is much appreciated, and I might try that... If I have two of the same sounds.. That might be just the ticket!

    Thanks Much,

    .aS.

  • Hi, I have seen a similar problem that the sound file is delayed in starting, even if the same file is re-played. see this thread https://forum.processing.org/two/discussion/18533/when-triggering-a-sound-file-there-is-a-delay-or-latency-can-this-be-reduced

    For overlaying multiple sounds, you could extend jeremydouglass suggestion by having an array of SoundFile and trigger each in turn, allowing the previous to run to completion.

  • @AMM01 --

    So, if I'm understanding, you, the rewind is taking too long, so you get this:

    |---S---|   |---S---|
    

    ...so if you load the same sound file into two different sound objects, you can eliminate the delay and get this:

    |---S1---|
             |---S2---|        
    

    Is this delay also happening with SoundFile.loop(), or just when you restart the sound manually by rewinding?

Sign In or Register to comment.