From 193a9f181b9c5d9b6ad169348d4fe449a151d169 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 10 Jan 2017 11:35:03 -0500 Subject: [PATCH] initial experiment with drumplayer ( --- src/DrumPlayer.js | 16 ++++++++++++++++ src/index.js | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/DrumPlayer.js diff --git a/src/DrumPlayer.js b/src/DrumPlayer.js new file mode 100644 index 0000000..1a22b9f --- /dev/null +++ b/src/DrumPlayer.js @@ -0,0 +1,16 @@ +var SoundPlayer = require('./SoundPlayer'); +var Tone = require('tone'); + +function DrumPlayer (outputNode) { + this.outputNode = outputNode; + + this.snare = new SoundPlayer(this.outputNode); + var snareUrl = 'https://raw.githubusercontent.com/LLK/scratch-audio/develop/sound-files/drums/SnareDrum(1)_22k.wav'; + this.snare.setBuffer(new Tone.Buffer(snareUrl)); +} + +DrumPlayer.prototype.start = function () { + this.snare.start(); +}; + +module.exports = DrumPlayer; diff --git a/src/index.js b/src/index.js index c15542c..29712d9 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ var ReverbEffect = require('./effects/ReverbEffect'); var SoundPlayer = require('./SoundPlayer'); var ADPCMSoundLoader = require('./ADPCMSoundLoader'); var InstrumentPlayer = require('./InstrumentPlayer'); +var DrumPlayer = require('./DrumPlayer'); function AudioEngine () { @@ -36,6 +37,8 @@ function AudioEngine () { this.currentTempo = 60; this.instrumentPlayer = new InstrumentPlayer(this.input); + + this.drumPlayer = new DrumPlayer(this.input); } AudioEngine.prototype.createPlayer = function () { @@ -119,8 +122,8 @@ AudioPlayer.prototype.playNoteForBeats = function (note, beats) { return this.waitForBeats(beats); }; -AudioPlayer.prototype.playDrumForBeats = function (beats) { - // this.drumSamplers[drumNum].triggerAttack(); +AudioPlayer.prototype.playDrumForBeats = function (drum, beats) { + this.audioEngine.drumPlayer.start(); return this.waitForBeats(beats); };