scratch-audio
Advanced tools
Comparing version 0.1.0-prerelease.1510703529 to 0.1.0-prerelease.1511290007
{ | ||
"name": "scratch-audio", | ||
"version": "0.1.0-prerelease.1510703529", | ||
"version": "0.1.0-prerelease.1511290007", | ||
"description": "audio engine for scratch 3.0", | ||
@@ -5,0 +5,0 @@ "main": "dist.js", |
@@ -12,4 +12,2 @@ const StartAudioContext = require('startaudiocontext'); | ||
const ADPCMSoundDecoder = require('./ADPCMSoundDecoder'); | ||
const InstrumentPlayer = require('./InstrumentPlayer'); | ||
const DrumPlayer = require('./DrumPlayer'); | ||
@@ -96,14 +94,2 @@ /** | ||
/** | ||
* Play a drum sound. The AudioEngine contains the DrumPlayer, but the AudioPlayer | ||
* calls this function so that it can pass a reference to its own effects node. | ||
* @param {number} drum - a drum number (0-indexed) | ||
* @param {number} beats - a duration in beats | ||
* @return {Promise} a Promise that resolves after the duration has elapsed | ||
*/ | ||
playDrumForBeats (drum, beats) { | ||
this.audioEngine.drumPlayer.play(drum, this.effectsNode); | ||
return this.audioEngine.waitForBeats(beats); | ||
} | ||
/** | ||
* Stop all sounds, notes and drums that are playing | ||
@@ -161,4 +147,3 @@ */ | ||
* There is a single instance of the AudioEngine. It handles global audio properties and effects, | ||
* loads all the audio buffers for sounds belonging to sprites, and creates a single instrument player | ||
* and a drum player, used by all play note and play drum blocks. | ||
* loads all the audio buffers for sounds belonging to sprites. | ||
*/ | ||
@@ -173,14 +158,2 @@ class AudioEngine { | ||
// global tempo in bpm (beats per minute) | ||
this.currentTempo = 60; | ||
// instrument player for play note blocks | ||
this.instrumentPlayer = new InstrumentPlayer(this.audioContext); | ||
this.instrumentPlayer.outputNode = this.input; | ||
this.numInstruments = this.instrumentPlayer.instrumentNames.length; | ||
// drum player for play drum blocks | ||
this.drumPlayer = new DrumPlayer(this.audioContext); | ||
this.numDrums = this.drumPlayer.drumSounds.length; | ||
// a map of soundIds to audio buffers, holding sounds for all sprites | ||
@@ -281,55 +254,2 @@ this.audioBuffers = {}; | ||
/** | ||
* Play a note for a duration on an instrument with a volume | ||
* @param {number} note - a MIDI note number | ||
* @param {number} beats - a duration in beats | ||
* @param {number} inst - an instrument number (0-indexed) | ||
* @param {number} vol - a volume level (0-100%) | ||
* @return {Promise} a Promise that resolves after the duration has elapsed | ||
*/ | ||
playNoteForBeatsWithInstAndVol (note, beats, inst, vol) { | ||
const sec = this.beatsToSec(beats); | ||
this.instrumentPlayer.playNoteForSecWithInstAndVol(note, sec, inst, vol); | ||
return this.waitForBeats(beats); | ||
} | ||
/** | ||
* Convert a number of beats to a number of seconds, using the current tempo | ||
* @param {number} beats number of beats to convert to secs | ||
* @return {number} seconds number of seconds `beats` will last | ||
*/ | ||
beatsToSec (beats) { | ||
return (60 / this.currentTempo) * beats; | ||
} | ||
/** | ||
* Wait for some number of beats | ||
* @param {number} beats number of beats to wait for | ||
* @return {Promise} a Promise that resolves after the duration has elapsed | ||
*/ | ||
waitForBeats (beats) { | ||
const storedContext = this; | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, storedContext.beatsToSec(beats) * 1000); | ||
}); | ||
} | ||
/** | ||
* Set the global tempo in bpm (beats per minute) | ||
* @param {number} value - the new tempo to set | ||
*/ | ||
setTempo (value) { | ||
this.currentTempo = value; | ||
} | ||
/** | ||
* Change the tempo by some number of bpm (beats per minute) | ||
* @param {number} value - the number of bpm to change the tempo by | ||
*/ | ||
changeTempo (value) { | ||
this.setTempo(this.currentTempo + value); | ||
} | ||
/** | ||
* Get the current loudness of sound received by the microphone. | ||
@@ -336,0 +256,0 @@ * Sound is measured in RMS and smoothed. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
22
486321
47
2430