Comparing version 1.1.7 to 1.1.8
{ | ||
"name": "zzfx", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "A Tiny JavaScript Sound FX System", | ||
@@ -5,0 +5,0 @@ "main": "ZzFX.js", |
10
ZzFX.js
/* | ||
ZzFX - Zuper Zmall Zound Zynth v1.1.7 | ||
ZzFX - Zuper Zmall Zound Zynth v1.1.8 | ||
By Frank Force 2019 | ||
@@ -72,9 +72,9 @@ https://github.com/KilledByAPixel/ZzFX | ||
// play an array of samples | ||
playSamples: function(samples) | ||
playSamples: function(...samples) | ||
{ | ||
// play an array of audio samples | ||
const buffer = this.x.createBuffer(1, samples.length, this.sampleRate); | ||
// create buffer and source | ||
const buffer = this.x.createBuffer(samples.length, samples[0].length, this.sampleRate); | ||
const source = this.x.createBufferSource(); | ||
buffer.getChannelData(0).set(samples); | ||
samples.map((d,i)=> buffer.getChannelData(i).set(d)); | ||
source.buffer = buffer; | ||
@@ -81,0 +81,0 @@ source.connect(this.x.destination); |
@@ -5,5 +5,4 @@ // ZzFX - Zuper Zmall Zound Zynth - Micro Edition | ||
// This is a tiny build of zzfx with only a zzfx function to play sounds. | ||
// This is a minified build of zzfx for use in size coding projects. | ||
// You can use zzfxV to set volume. | ||
// There is a small bit of optional code to improve compatibility. | ||
// Feel free to minify it further for your own needs! | ||
@@ -15,3 +14,3 @@ | ||
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.1.7 | ||
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.1.8 | ||
@@ -21,10 +20,23 @@ // ==ClosureCompiler== | ||
// @output_file_name ZzFXMicro.min.js | ||
// @js_externs zzfx, zzfxV, zzfxX | ||
// @js_externs zzfx, zzfxG, zzfxP, zzfxV, zzfxX | ||
// @language_out ECMASCRIPT_2019 | ||
// ==/ClosureCompiler== | ||
const zzfx = (...z)=> zzfxP(zzfxG(...z)); // generate and play sound | ||
const zzfxV = .3; // volume | ||
const zzfxR = 44100; // sample rate | ||
const zzfxX = new (window.AudioContext||webkitAudioContext); // audio context | ||
const zzfxR = 44100; // sample rate | ||
const zzfxV = .3; // volume | ||
const zzfx = // play sound | ||
const zzfxP = (...samples)=> // play samples | ||
{ | ||
// create buffer and source | ||
let buffer = zzfxX.createBuffer(samples.length, samples[0].length, zzfxR), source = zzfxX.createBufferSource(); | ||
// copy samples to buffer and play | ||
samples.map((d,i)=> buffer.getChannelData(i).set(d)); | ||
source.buffer = buffer; | ||
source.connect(zzfxX.destination); | ||
source.start(); | ||
return source; | ||
} | ||
const zzfxG = // generate samples | ||
( | ||
@@ -41,3 +53,3 @@ // parameters | ||
* PI2 / zzfxR, | ||
b=[], t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length, buffer, source; | ||
b=[], t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length; | ||
@@ -107,11 +119,4 @@ // scale by sample rate | ||
} | ||
// play an array of audio samples | ||
buffer = zzfxX.createBuffer(1, length, zzfxR); | ||
buffer.getChannelData(0).set(b); | ||
source = zzfxX.createBufferSource(); | ||
source.buffer = buffer; | ||
source.connect(zzfxX.destination); | ||
source.start(); | ||
return source; | ||
return b; | ||
} |
@@ -7,3 +7,2 @@ // ZzFX - Zuper Zmall Zound Zynth - Micro Edition | ||
// You can use zzfxV to set volume. | ||
// There is a small bit of optional code to improve compatibility. | ||
// Feel free to minify it further for your own needs! | ||
@@ -13,3 +12,3 @@ | ||
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.1.7 | ||
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.1.8 | ||
zzfxV=.3 // volume | ||
@@ -16,0 +15,0 @@ zzfx= // play sound |
Sorry, the diff of this file is not supported yet
90126
332