From b64152637e8918b20270636e7ec9198844d3f1de Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 14 Nov 2017 14:39:11 -0500 Subject: [PATCH] Play drums! --- src/extensions/scratch3_music/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index 84bd46798..874dbe4fc 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -428,15 +428,22 @@ class Scratch3MusicBlocks { drum = MathUtil.wrapClamp(drum, 0, this.DRUM_INFO.length - 1); let beats = Cast.toNumber(args.BEATS); beats = this._clampBeats(beats); - if (util.target.audioPlayer !== null) { - util.target.audioPlayer.playDrumForBeats(drum, beats); - } + this._playDrumNum(util, drum); this._startStackTimer(util, this._beatsToSec(beats)); } else { this._checkStackTimer(util); } } + _playDrumNum (util, drumNum) { + if (util.target.audioPlayer === null) return; + const outputNode = util.target.audioPlayer.getInputNode(); + const bufferSource = this.runtime.audioEngine.audioContext.createBufferSource(); + bufferSource.buffer = this._drumBuffers[drumNum]; + bufferSource.connect(outputNode); + bufferSource.start(); + } + /** * Rest for some number of beats. * @param {object} args - the block arguments.