This commit is contained in:
Eric Rosenbaum 2017-06-21 10:46:42 -04:00
parent 2974a5e65b
commit 43e0408434
4 changed files with 9 additions and 8 deletions

View file

@ -38,7 +38,7 @@ class DrumPlayer {
// download and decode the drum sounds
// @todo: use scratch-storage to manage these sound files
const url = baseUrl + fileNames[i] + '_22k.wav';
const url = `${baseUrl}${fileNames[i]}_22k.wav`;
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';

View file

@ -9,7 +9,7 @@ class InstrumentPlayer {
* play note or set instrument block runs, causing a delay of a few seconds.
* Using this library we don't have a way to set the volume, sustain the note beyond the sample
* duration, or run it through the sprite-specific audio effects.
* @param {AudioNode} outputNode - a webAudio node that the instrument will send its output to
* @param {AudioContext} context - a webAudio context
* @constructor
*/
constructor (context) {

View file

@ -59,7 +59,7 @@ class PitchEffect {
* @returns {number} a frequency ratio
*/
intervalToFrequencyRatio (interval) {
return Math.pow(2, (interval/12));
return Math.pow(2, (interval / 12));
}
/**

View file

@ -149,7 +149,7 @@ class AudioPlayer {
*/
class AudioEngine {
constructor () {
var AudioContext = window.AudioContext || window.webkitAudioContext;
const AudioContext = window.AudioContext || window.webkitAudioContext;
this.context = new AudioContext();
this.input = this.context.createGain();
@ -200,7 +200,7 @@ class AudioEngine {
let loaderPromise = null;
// Make a copy of the buffer because decoding detaches the original buffer
var bufferCopy = sound.data.buffer.slice(0);
const bufferCopy = sound.data.buffer.slice(0);
switch (sound.format) {
case '':
@ -296,13 +296,14 @@ class AudioEngine {
// the microphone has not been set up, try to connect to it
if (!this.mic && !this.connectingToMic) {
this.connectingToMic = true; // prevent multiple connection attempts
navigator.mediaDevices.getUserMedia({audio : true}).then(stream => {
navigator.mediaDevices.getUserMedia({audio: true}).then(stream => {
this.mic = this.context.createMediaStreamSource(stream);
this.analyser = this.context.createAnalyser();
this.mic.connect(this.analyser);
this.micDataArray = new Float32Array(this.analyser.fftSize);
}).catch(err => {
log.warn(err)
})
.catch(err => {
log.warn(err);
});
}