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
435
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.1484064494 to 0.1.0-prerelease.1484089659

src/DrumPlayer.js

2

package.json
{
"name": "scratch-audio",
"version": "0.1.0-prerelease.1484064494",
"version": "0.1.0-prerelease.1484089659",
"description": "audio engine for scratch 3.0",

@@ -5,0 +5,0 @@ "main": "dist.js",

@@ -5,3 +5,3 @@ /*

-100 puts the audio on the left channel, 0 centers it, 100 makes puts it on the right.
-100 puts the audio on the left channel, 0 centers it, 100 puts it on the right.

@@ -8,0 +8,0 @@ Clamped -100 to 100

@@ -15,3 +15,11 @@ var log = require('./log');

var InstrumentPlayer = require('./InstrumentPlayer');
var DrumPlayer = require('./DrumPlayer');
/* Audio Engine
The Scratch runtime has a single audio engine that handles global audio properties and effects,
and creates the instrument player and a drum player, used by all play note and play drum blocks
*/
function AudioEngine () {

@@ -32,12 +40,23 @@

// alternate version without effects:
// this.input = new Tone.Gain();
// this.input.connect(Tone.Master);
// global tempo in bpm (beats per minute)
this.currentTempo = 60;
this.minTempo = 10;
this.maxTempo = 1000;
// instrument player for play note blocks
this.instrumentPlayer = new InstrumentPlayer(this.input);
// drum player for play drum blocks
this.drumPlayer = new DrumPlayer(this.input);
}
AudioEngine.prototype.setTempo = function (value) {
// var newTempo = this._clamp(value, this.minTempo, this.maxTempo);
this.currentTempo = value;
};
AudioEngine.prototype.changeTempo = function (value) {
this.setTempo(this.currentTempo + value);
};
AudioEngine.prototype.createPlayer = function () {

@@ -47,2 +66,11 @@ return new AudioPlayer(this);

/* Audio Player
Each sprite has an audio player
Clones receive a reference to their parent's audio player
the audio player currently handles sound loading and playback, sprite-specific effects
(pitch and pan) and volume
*/
function AudioPlayer (audioEngine) {

@@ -125,4 +153,4 @@

AudioPlayer.prototype.playDrumForBeats = function (beats) {
// this.drumSamplers[drumNum].triggerAttack();
AudioPlayer.prototype.playDrumForBeats = function (drum, beats) {
this.audioEngine.drumPlayer.play(drum, this.effectsNode);
return this.waitForBeats(beats);

@@ -145,8 +173,3 @@ };

AudioPlayer.prototype.stopAllSounds = function () {
// stop drum notes
// for (var i = 0; i<this.drumSamplers.length; i++) {
// this.drumSamplers[i].triggerRelease();
// }
// stop sounds triggered with playSound
// stop all sound players
for (var i=0; i<this.soundPlayers.length; i++) {

@@ -156,6 +179,8 @@ this.soundPlayers[i].stop();

// stop soundfont notes
// if (this.instrument) {
// this.instrument.stop();
// }
// stop all instruments
this.audioEngine.instrumentPlayer.stopAll();
// stop drum notes
this.audioEngine.drumPlayer.stopAll();
};

@@ -235,12 +260,2 @@

AudioPlayer.prototype.setTempo = function (value) {
var newTempo = this._clamp(value, 10, 1000);
this.audioEngine.currentTempo = newTempo;
};
AudioPlayer.prototype.changeTempo = function (value) {
var newTempo = this._clamp(this.audioEngine.currentTempo + value, 10, 1000);
this.audioEngine.currentTempo = newTempo;
};
AudioPlayer.prototype._clamp = function (input, min, max) {

@@ -247,0 +262,0 @@ return Math.min(Math.max(input, min), max);

@@ -39,2 +39,10 @@ var Tone = require('tone');

InstrumentPlayer.prototype.stopAll = function () {
for (var i=0; i<this.instruments.length; i++) {
if (this.instruments[i]) {
this.instruments[i].stop();
}
}
};
module.exports = InstrumentPlayer;

Sorry, the diff of this file is too big to display

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