mercury-engine 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/mercury.js +31 -1
- package/dist/mercury.min.es5.js +1 -1
- package/dist/mercury.min.js +1 -1
- package/examples/hydra/index.html +83 -0
- package/examples/interface/index.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -180,6 +180,36 @@ Stop the recording and download the file `myRecording.webm`
|
|
|
180
180
|
Engine.record(false, 'myRecording');
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
+
### Meter
|
|
184
|
+
|
|
185
|
+
You can add a meter to the main audio output and poll for the amplitude value from the meter to for example create audio-reactive visuals in other programming languages such as Hydra or P5.js.
|
|
186
|
+
|
|
187
|
+
First add the meter, optionally with a smoothing factor (default=0.7)
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
Engine.addMeter();
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Get the meter value as floating-point between 0-1
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
Engine.getMeter();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Store the meters amplitude value in a global variable for usage in other places and update regularly with a setInterval at a defined interval in milliseconds.
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
let amp;
|
|
203
|
+
|
|
204
|
+
setInterval(() => amp = Engine.getMeter(), 100);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
For example control some visual parameter in [Hydra](https://hydra.ojack.xyz)
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
osc(10, 0.2, () => amp * 20).out();
|
|
211
|
+
```
|
|
212
|
+
|
|
183
213
|
### MIDI
|
|
184
214
|
|
|
185
215
|
WebMIDI is included and started if the browser is compatible with it. If not, an error will be printed to the console. You can provide a callback function `onmidi` to execute some code when the WebMIDI enabling was succesful.
|
package/dist/mercury.js
CHANGED
|
@@ -17000,6 +17000,11 @@ function atodb(a=0){
|
|
|
17000
17000
|
return 20 * Math.log(a);
|
|
17001
17001
|
}
|
|
17002
17002
|
|
|
17003
|
+
// convert dbFS to amplitude
|
|
17004
|
+
function dbtoa(db=0){
|
|
17005
|
+
return 10 ** (db/20);
|
|
17006
|
+
}
|
|
17007
|
+
|
|
17003
17008
|
// clip a value between a specified range
|
|
17004
17009
|
function clip(v, l, h){
|
|
17005
17010
|
return Math.max(l, Math.min(h, v));
|
|
@@ -17198,7 +17203,7 @@ function log(msg){
|
|
|
17198
17203
|
}
|
|
17199
17204
|
}
|
|
17200
17205
|
|
|
17201
|
-
module.exports = { mapDefaults, atodb, clip, assureNum, lookup, randLookup, isRandom, getParam, toArray, msToS, formatRatio, divToS, divToF, toMidi, mtof, noteToMidi, noteToFreq, assureWave, log }
|
|
17206
|
+
module.exports = { mapDefaults, atodb, dbtoa, clip, assureNum, lookup, randLookup, isRandom, getParam, toArray, msToS, formatRatio, divToS, divToF, toMidi, mtof, noteToMidi, noteToFreq, assureWave, log }
|
|
17202
17207
|
},{"total-serialism":47}],67:[function(require,module,exports){
|
|
17203
17208
|
module.exports={
|
|
17204
17209
|
"uptempo" : 10,
|
|
@@ -17591,6 +17596,9 @@ class Mercury extends MercuryInterpreter {
|
|
|
17591
17596
|
this.highPassF = new Tone.Filter(5, 'highpass');
|
|
17592
17597
|
Tone.Destination.chain(this.lowPassF, this.highPassF, this.gain);
|
|
17593
17598
|
|
|
17599
|
+
// an RMS meter for reactive visuals
|
|
17600
|
+
this.meter;
|
|
17601
|
+
|
|
17594
17602
|
// a recorder for the sound
|
|
17595
17603
|
this.recorder = new Tone.Recorder({ mimeType: 'audio/webm' });
|
|
17596
17604
|
this.gain.connect(this.recorder);
|
|
@@ -17870,6 +17878,28 @@ class Mercury extends MercuryInterpreter {
|
|
|
17870
17878
|
isRecording(){
|
|
17871
17879
|
return this.recorder.state;
|
|
17872
17880
|
}
|
|
17881
|
+
|
|
17882
|
+
// add a Tone RMS meter to use for signal analysis
|
|
17883
|
+
addMeter(smooth=0.7){
|
|
17884
|
+
this.meter = new Tone.Meter(smooth);
|
|
17885
|
+
this.meter.normalRange = true;
|
|
17886
|
+
this.gain.connect(this.meter);
|
|
17887
|
+
}
|
|
17888
|
+
|
|
17889
|
+
// return the meter value as float betwee 0-1
|
|
17890
|
+
getMeter(){
|
|
17891
|
+
return this.meter.getValue();
|
|
17892
|
+
}
|
|
17893
|
+
|
|
17894
|
+
// get the webaudio context Mercury is producing sound on
|
|
17895
|
+
// getContext(){
|
|
17896
|
+
// return Tone.getContext();
|
|
17897
|
+
// }
|
|
17898
|
+
|
|
17899
|
+
// get the destination output Mercury is sending sound to
|
|
17900
|
+
// getDestination(){
|
|
17901
|
+
// return Tone.getDestination();
|
|
17902
|
+
// }
|
|
17873
17903
|
}
|
|
17874
17904
|
module.exports = { Mercury };
|
|
17875
17905
|
},{"./core/Util.js":66,"./interpreter":68,"tone":44,"webmidi":55}]},{},[69])(69)
|