Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scratch-audio

Package Overview
Dependencies
Maintainers
1
Versions
432
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scratch-audio - npm Package Compare versions

Comparing version 0.1.0-prerelease.1510703529 to 0.1.0-prerelease.1511290007

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc