-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.html
2258 lines (1826 loc) · 121 KB
/
docs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>Superpowered Web Audio JavaScript and WebAssembly SDK Documentation</title>
<link rel="stylesheet" href="docs_js_css/main.css" />
<link rel="stylesheet" href="docs_js_css/prism.css" />
</head>
<body id="top">
<main>
<h1>Superpowered Web Audio JavaScript and WebAssembly SDK</h1>
<p>Welcome to high performance, interactive audio in the browser built on Superpowered Audio + Web Audio + WebAssembly.</p>
<p>WebAssembly is a new, rapidly evolving technology with great momentum. It's promise to bring interactive, low latency multi-media capabilities to the browser.</p>
<p>In short: what needed to be done in a native app, will now be possible in the browser.</p>
<p>Our Superpowered implementation is not dumbed down and makes no compromises: audio quality is identical to our "native" platform versions. All data processing is performed in WebAssembly for high performance, and typical performance is less than 10% slower vs Superpowered native performance (only because WebAssembly SIMD features are not ready for prime-time yet).</p>
<p>Example measurement: Superpowered Reverb 0.033ms vs. 0.03ms for 128 frames on the highest spec 2017 Retina Macbook Pro.</p>
<p>We're shipping our Superpowerered Javascript/WebAssembly SDK with a new documentation approach: <em>all features are documented by pseudo-examples</em>. This is a JavaScript API, to be primarily used with Web Audio, ScriptProcessorNode, Worklet and Audio Worklet. The library is also available in Emscripten Bitcode format for custom WASM builds.</p>
<p>Browser support: official public stable versions of all major web browsers, including desktop and mobile variants (iOS, Android), such as Chrome, Safari, Firefox and Opera. The only exception is Microsoft Edge, that requires developer build version 74 minimum.</p>
<div id="tocbox"></div>
<h2>Basics</h2>
<p>Superpowered files:</p>
<dl>
<dt>superpowered.wasm</dt><dd>WebAssembly binary.</dd>
<dt>SuperpoweredGlue.js (class SuperpoweredGlue)</dt><dd>The JavaScript loader/glue around Superpowered WebAssembly, to be used with importScripts (such as Workers).</dd>
<dt>SuperpoweredGlueModule.js</dt><dd>Same as above, but for module import.</dd>
<dt>SuperpoweredWebAudio.js (class SuperpoweredWebAudio)</dt><dd>Helper to set up Web Audio context, supports the Audio Worklet and ScriptProcessorNode.</dd>
<dt>SuperpoweredTrackLoader.js (class SuperpoweredTrackLoader)</dt><dd>Helper to load and decode audio in the background, to be used with importScripts.</dd>
<dt>SuperpoweredTrackLoaderModule.js</dt><dd>Same as above, but for module import.</dd>
<dt>SuperpoweredTrackLoaderWorker.js</dt><dd>The Worker used by SuperpoweredTrackLoader.</dd>
</dl>
<h3>Initialization</h3>
<pre><code class="language-js">
// Most common: import Superpowered and the Superpowered Web Audio helper:
import { SuperpoweredGlue, SuperpoweredWebAudio } from './superpowered/SuperpoweredWebAudio.js';
// Most major web browsers can not import modules in Worker scripts, therefore the import above may not work.
importScripts('./superpowered/SuperpoweredGlue.js');
// Create a SuperpoweredGlue instance and load WebAssembly:
var Superpowered = await SuperpoweredGlue.fetch('./superpowered/superpowered.wasm');
// Initialize Superpowered.
Superpowered.Initialize({
licenseKey: 'ExampleLicenseKey-WillExpire-OnNextUpdate',
enableAudioAnalysis: false,
enableFFTAndFrequencyDomain: false,
enableAudioTimeStretching: true,
enableAudioEffects: true,
enableAudioPlayerAndDecoder: true,
enableCryptographics: false,
enableNetworking: false
});
</code></pre>
<h3>Linear Memory</h3>
<p>Most Superpowered APIs work on arrays of floating point numbers representing PCM audio. A simple buffer containing audio input for example. But WebAssembly can not access traditional JavaScript Float32Arrays directly and efficiently.</p>
<p>In the low-level memory model of WebAssembly, memory is represented as a contiguous range of untyped bytes called Linear Memory, which is a standard ArrayBuffer.
<p>Memory can be "allocated" in the Linear Memory, returning with a pointer to the allocated region. This pointer can be used to represent an array of data, such as an array of floating point numbers.</p>
<p>The following example demonstrates how to allocate a region in the Linear Memory and how to create a Float32Array "view" of this region with standard WebAssembly JavaScript:</p>
<pre><code class="language-js">
let length = 128; // We want the buffer to store 128 floating point numbers.
let pointer = Superpowered.malloc(length * 4); // A floating point number is 4 bytes, therefore we allocate length * 4 bytes of memory.
// You can use "pointer" to pass audio to most Superpowered APIs.
// Maybe we want to directly manipulate this data from JavaScript as well. Let's create a Float32Array view of this region.
let arrayView = new Float32Array(
Superpowered.linearMemory, // Standard WebAssembly Module access to the Linear Memory buffer as floating point numbers.
pointer, // The allocated region.
length // The length of the region.
);
// Now this is possible:
arrayView[0] = 0.5;
// Deallocate the region when we don't need it anymore.
Superpowered.free(pointer);
</code></pre>
<p>SuperpoweredGlue offers some APIs to make this allocation process a little bit easier:</p>
<pre><code class="language-js">
// Total memory consumption in this example: 256 * 4 = 1024 bytes.
let someBuffer = new Superpowered.Float32Buffer(256);
someBuffer.pointer; // Getting the linear memory index (pointer).
someBuffer.length; // Getting the length of the buffer.
someBuffer.array[0] = 0.5; // Accessing the buffer as a Float32Array (standard web TypedArray).
someBuffer.free(); // Deallocate everything.
// Other types are also available, because every web standard TypedArray specialization is supported:
new Superpowered.Uint8Buffer(...)
new Superpowered.Int32Buffer(...)
...
</code></pre>
<h3>Web Audio</h3>
<p>The SuperpoweredWebAudio class contains helper functions for easier Web Audio initialization. The returned objects are standard Web Audio objects without any quirks. <em>Please note that Web Audio requires a secure context: HTTPS or localhost.</em></p>
<p>Visit the effects example project to see these in context for better understanding.</p>
<pre><code class="language-js">
var webaudioManager = new SuperpoweredWebAudio(
44100, // The minimum sample rate of the AudioContext. The actual sample rate may be equal or higher.
Superpowered // The SuperpoweredGlue instance.
);
// Returns with a standard AudioContext. Reference: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext
let audioContext = webaudioManager.audioContext;
// Prompts the user for permission to use a media input (typically the microphone) with an audio track and no video tracks. Has no return value.
// This function was made to help with browser-specific quirks.
// Reference https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
webaudioManager.getUserMediaForAudio(
{ // navigator.mediaDevices.getUserMedia constraints
'echoCancellation': false
},
function(stream) {
// Called when the user provided permission (for the microphone).
// stream is a standard MediaStream object:
// https://developer.mozilla.org/en-US/docs/Web/API/MediaStream
},
function(error) {
// Called when the user refused the (microphone) permission.
// Visit the reference above on what error represents.
}
);
// Asynchronous version of getUserMediaForAudio.
// Returns with a standard MediaStream object or undefined on error.
let audioInputStream = await webaudioManager.getUserMediaForAudioAsync(
{ // navigator.mediaDevices.getUserMedia constraints or "fastAndTransparentAudio" to disable all processing on the audio input
'fastAndTransparentAudio': true
},
)
.catch((error) => {
// Called when the user provided permission (typically for the microphone).
});
if (!audioInputStream) return; // Program flow will reach this point even on error.
// Creates an Audio Worklet (for new browsers) or an audio processing ScriptProcessorNode (for older browsers).
// This function was made to help with browser-specific quirks and to properly initialize Superpowered in an Audio Worklet context.
var myAudioNode = null;
webaudioManager.createAudioNode(
'/example_effects/processor.js', // The JavaScript module source of the node.
'MyProcessor', // The registered processor name.
function(newNode) {
// Runs after the audio node is created.
// newNode is a standard AudioNode or a ScriptProcessorNode.
myAudioNode = newNode;
},
function(message) {
// Runs in the main scope (main thread) when the audio node sends a message.
// message is a standard JavaScript object.
// Let's send some data to the audio scope (audio thread).
// This method accepts any object (string, array, etc.) as it's single input parameter.
myAudioNode.sendMessageToAudioScope({
someText: "Hey!"
});
}
);
// Asynchronous version of createAudioNode.
// Returns with a standard AudioNode or ScriptProcessorNode.
let audioNode = await webaudioManager.createAudioNodeAsync(
audioContext, // The standard AudioContext instance.
'/example_effects/processor.js', // The JavaScript module source of the node.
'MyProcessor', // The registered processor name.
function(message) {
// Runs in the main scope (main thread) when the audio node sends a message.
// message is a standard JavaScript object.
}
);
</code></pre>
<h3>AudioWorkletProcessor</h3>
<p>The easiest way to use Superpowered features in a Web Audio AudioNode is the SuperpoweredWebAudio.AudioWorkletProcessor class.</p>
<p>It can be created by createAudioNode (see the example above) and should be loaded from a dedicated .js file, because it's a JS module in modern browsers.</p>
<pre><code class="language-js">
class MyProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
onReady() {
// Runs after the constructor. This is "your" constructor basically.
}
onMessageFromMainScope(message) {
// Runs when a message (data) is received from the main scope (main thread).
// Let's figure out the samplerate we're working with.
let samplerate = this.Superpowered.samplerate;
// Let's send some data back to the main scope (main thread).
// This method accepts any object (string, array, etc.) as it's single input parameter.
this.sendMessageToMainScope({
someText: "Got your message!",
hz: samplerate
});
}
processAudio(inputBuffer, outputBuffer, buffersize, parameters) {
// The audio processing callback running in the audio thread.
// buffersize is the current number of frames, typically 128.
// parameters is a map of string keys and associated Float32Arrays, as standardized by W3:
// https://www.w3.org/TR/webaudio/#AudioNode-methods (see the process() method)
// parameters are not very useful here, because they don't work for older browsers with ScriptProcessorNode.
// Superpowered objects are automatically smoothing parameter changes as required, so there is no need to use the AudioParam features of Web Audio.
// Use sendMessageToAudioScope() to send parameters instead, as you can find in the example projects.
// inputBuffer and outputBuffer contain stereo interleaved 32-bit floating point audio.
// They have both direct WASM linear memory index (pointer) access and JavaScript Float32Array access.
// Typically, Superpowered objects require direct WASM linear memory indexes (pointers) for audio input and/or output:
SomeSuperpoweredObject.process(inputBuffer.pointer, outputBufer.pointer, buffersize);
// Direct JavaScript Float32Array access to audio input and/or output:
let firstInputSampleLeft = inputBuffer.array[0];
let firstInputSampleRight = inputBuffer.array[1];
outputBuffer.array[0] = firstInputSampleLeft;
outputBuffer.array[1] = firstInputSampleRight;
}
}
</code></pre>
<h2>Simple Features</h2>
<h3>Functions</h3>
<p>Fast utility functions for transforming audio.</p>
<pre><code class="language-js">
// Applies volume on a single stereo interleaved buffer. Has no return value.
Superpowered.Volume(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can be equal to input (in-place processing).
0.1, // Volume for the first frame.
0.9 // Volume for the last frame. Volume will be smoothly calculated between the first and last frames.
128 // The number of frames to process.
);
// Applies volume on a single stereo interleaved buffer. Has no return value.
Superpowered.ChangeVolume(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can be equal to input (in-place processing).
0.1, // Volume for the first frame.
0.02 // Change volume by this amount for every frame. In this example the first frame will be multiplied by 0.1, the second by 0.12 and so on.
128 // The number of frames to process.
);
// Applies volume on a single stereo interleaved buffer and adds it to the audio in the output buffer. Has no return value.
Superpowered.VolumeAdd(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output.
0.1, // Volume for the first frame.
0.9 // Volume for the last frame. Volume will be smoothly calculated between the first and last frames.
128 // The number of frames to process.
);
// Applies volume on a single stereo interleaved buffer and adds it to the audio in the output buffer. Has no return value.
Superpowered.ChangeVolumeAdd(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can be equal to input (in-place processing).
0.1, // Volume for the first frame.
0.02 // Change volume by this amount for every frame. In this example the first frame will be multiplied by 0.1, the second by 0.12 and so on.
128 // The number of frames to process.
);
// Returns the peak absolute value. Useful for metering.
let peak = Superpowered.Peak(
input, // Pointer to floating point numbers.
256, // The number of values to process. For a stereo input this value should be 2 * numberOfFrames. Must be a multiply of 8.
);
// Converts 8-bit audio to 32-bit floating point. Has no return value.
Superpowered.CharToFloat(
input, // Pointer to signed bytes. 8-bit input.
output, // Pointer to floating point numbers. 32-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 8-bit audio to 32-bit floating point. Has no return value.
Superpowered.FloatToChar(
input, // Pointer to floating point numbers. 32-bit input.
output, // Pointer to signed bytes. 8-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 24-bit audio to 32-bit floating point. Has no return value.
Superpowered.24bitToFloat(
input, // Input buffer pointer.
output, // Pointer to floating point numbers. 32-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 32-bit floating point audio to 24-bit. Has no return value.
Superpowered.FloatTo24bit(
input, // Pointer to floating point numbers. 32-bit input.
output, // Output buffer pointer.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 32-bit integer audio to 32-bit floating point. Has no return value.
Superpowered.IntToFloat(
input, // Pointer to integer numbers. 32-bit input.
output, // Pointer to floating point numbers. 32-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 32-bit floating point audio to 32-bit integer. Has no return value.
Superpowered.FloatToInt(
input, // Pointer to floating point numbers. 32-bit input.
output, // Pointer to integer numbers. 32-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts 32-bit float input to 16-bit signed integer output. Has no return value.
Superpowered.FloatToShortInt(
input, // Pointer to floating point numbers. 32-bit input.
output, // Pointer to short integer numbers. 16-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Converts two 32-bit mono float input channels to stereo interleaved 16-bit signed integer output. Has no return value.
Superpowered.FloatToShortIntInterleave(
inputLeft, // Pointer to floating point numbers. 32-bit input for the left side. Should be numberOfFrames + 8 big minimum.
inputRight, // Pointer to floating point numbers. 32-bit input for the right side. Should be numberOfFrames + 8 big minimum.
output, // Pointer to short integer numbers. Stereo interleaved 16-bit output. Should be numberOfFrames * 2 + 16 big minimum.
128 // The number of frames to process.
);
// Converts stereo interleaved 16-bit signed integer input to stereo interleaved 32-bit float output, and provides peak measurement. Has no return value.
Superpowered.ShortIntToFloat(
input, // Pointer to short integer numbers. Stereo interleaved 16-bit input. Should be numberOfFrames + 8 big minimum.
output, // Pointer to floating point numbers. Stereo interleaved 32-bit output. Should be numberOfFrames + 8 big minimum.
128, // The number of frames to process.
peaks // Pointer to two floating point numbers. Peak value result (left, right).
);
// Converts 16-bit signed integer input to 32-bit float output. Has no return value.
Superpowered.ShortIntToFloat(
input, // Pointer to short integer numbers. Stereo interleaved 16-bit input.
output, // Pointer to floating point numbers. Stereo interleaved 32-bit output.
128, // The number of frames to process.
2 // The number of channels.
);
// Makes an interleaved stereo output from two mono input channels. Has no return value.
Superpowered.Interleave(
left, // Pointer to floating point numbers. Mono input for left channel.
right, // Pointer to floating point numbers. Mono input for right channel.
output, // Pointer to floating point numbers. Stereo interleaved output.
128 // The number of frames to process.
);
// Makes an interleaved stereo output from two mono input channels and adds the result to the audio in the output buffer. Has no return value.
Superpowered.InterleaveAdd(
left, // Pointer to floating point numbers. Mono input for left channel.
right, // Pointer to floating point numbers. Mono input for right channel.
output, // Pointer to floating point numbers. Stereo interleaved output.
128 // The number of frames to process.
);
// Makes an interleaved output from two input channels and measures the volume. Has no return value.
Superpowered.InterleaveAndGetPeaks(
left, // Pointer to floating point numbers. Mono input for left channel.
right, // Pointer to floating point numbers. Mono input for right channel.
output, // Pointer to floating point numbers. Stereo interleaved output.
128, // The number of frames to process.
peaks // Pointer to two floating point numbers. Peak value result (left, right).
);
// Deinterleaves an interleaved stereo input to two mono output channels. Has no return value.
Superpowered.DeInterleave(
input, // Pointer to floating point numbers. Stereo interleaved input.
left, // Pointer to floating point numbers. Mono output for left channel.
right, // Pointer to floating point numbers. Mono output for right channel.
128 // The number of frames to process.
);
// Deinterleaves an interleaved stereo input to two mono output channels and multiplies the output (gain). Has no return value.
Superpowered.DeInterleaveMultiply(
input, // Pointer to floating point numbers. Stereo interleaved input.
left, // Pointer to floating point numbers. Mono output for left channel.
right, // Pointer to floating point numbers. Mono output for right channel.
128, // The number of frames to process.
2.0 // Multiply each output sample with this value.
);
// Deinterleaves an interleaved stereo input and adds the results to the two mono output channels. Has no return value.
Superpowered.DeInterleaveAdd(
input, // Pointer to floating point numbers. Stereo interleaved input.
left, // Pointer to floating point numbers. Mono output for left channel.
right, // Pointer to floating point numbers. Mono output for right channel.
128 // The number of frames to process.
);
// Deinterleaves an interleaved stereo input to two mono output channels, multiplies the result (gain) and and adds the results to the two mono output channels. Has no return value.
Superpowered.DeInterleaveMultiplyAdd(
input, // Pointer to floating point numbers. Stereo interleaved input.
left, // Pointer to floating point numbers. Mono output for left channel.
right, // Pointer to floating point numbers. Mono output for right channel.
128, // The number of frames to process.
2.0 // Multiply each output sample with this value.
);
// Checks if the audio samples has non-valid values, such as infinity or NaN (not a number). Returns with true or false.
let invalid = Superpowered.HasNonFinite(
buffer, // Pointer to floating point numbers to check.
numberOfItems // Number of items in the buffer. Please note, this is NOT numberOfFrames. You need to provide the number of numbers in the buffer.
);
// Makes mono output from stereo interleaved input. Has no return value.
Superpowered.StereoToMono(
input, // Pointer to floating point numbers. Stereo interleaved input.
output, // Pointer to floating point numbers. Mono output.
0, // Gain of the first sample on the left channel.
1, // Gain for the last sample on the left channel. Gain will be smoothly calculated between start end end. This example shows a fade-in (0 to 1).
0, // Gain of the first sample on the right channel.
1, // Gain for the last sample on the right channel. Gain will be smoothly calculated between start end end. This example shows a fade-in (0 to 1).
128 // The number of frames to process.
);
// Crossfades two mono input channels into a mono output. Has no return value.
Superpowered.CrossMono(
inputA, // Pointer to floating point numbers. First mono input.
inputB, // Pointer to floating point numbers. Second mono input.
output, // Pointer to floating point numbers. Mono output.
0, // Gain of the first sample on the first input.
0.9, // Gain for the last sample on the first input. Gain will be smoothly calculated between start end end.
0.9, // Gain of the first sample on the second input.
0, // Gain for the last sample on the second input. Gain will be smoothly calculated between start end end.
128 // The number of frames to process.
);
// Crossfades two stereo inputs into a stereo output. Has no return value.
Superpowered.CrossStereo(
inputA, // Pointer to floating point numbers. Interleaved stereo input (first).
inputB, // Pointer to floating point numbers. Interleaved stereo input (second).
output, // Pointer to floating point numbers. Interleaved stereo output.
0, // Gain of the first sample on the first input.
0.9, // Gain for the last sample on the first input. Gain will be smoothly calculated between start end end.
0.9, // Gain of the first sample on the second input.
0, // Gain for the last sample on the second input. Gain will be smoothly calculated between start end end.
128 // The number of frames to process.
);
// Adds the values in input to the values in output. Has no return value.
// output[n] += input[n]
Superpowered.Add1(
input, // Pointer to floating point numbers. Input data.
output, // Pointer to floating point numbers. Output data.
256 // The length of input.
);
// Adds the values in two inputs to the values in output. Has no return value.
// output[n] += inputA[n] + inputB[n]
Superpowered.Add2(
inputA, // Pointer to floating point numbers. Input data.
inputB, // Pointer to floating point numbers. Input data.
output, // Pointer to floating point numbers. Output data.
256 // The length of input.
);
// Adds the values in four inputs to the values in output. Has no return value.
// output[n] += inputA[n] + inputB[n] + inputC[n] + inputD[n]
Superpowered.Add4(
inputA, // Pointer to floating point numbers. Input data.
inputB, // Pointer to floating point numbers. Input data.
inputC, // Pointer to floating point numbers. Input data.
inputD, // Pointer to floating point numbers. Input data.
output, // Pointer to floating point numbers. Output data.
256 // The length of input.
);
// Converts a stereo signal to mid-side. Has no return value.
Superpowered.StereoToMidSide(
input, // Pointer to floating point numbers. Interleaved stereo input.
output, // Pointer to floating point numbers. Mid-side interleaved output. Can be equal to input (in-place processing).
128 // The number of frames to process.
);
// Converts a mid-side signal to stereo. Has no return value.
Superpowered.MidSideToStereo(
input, // Pointer to floating point numbers. Mid-side interleaved input.
output, // Pointer to floating point numbers. Interleaved stereo output. Can be equal to input (in-place processing).
128 // The number of frames to process.
);
// Calculates the dot product of two vectors.
let dotproduct = Superpowered.DotProduct(
inputA, // Pointer to floating point numbers. First input vector.
inputB, // Pointer to floating point numbers. Second input vector.
128 // Number of value pairs to process.
);
// Returns the current version of the Superpowered SDK.
// The returned value is: major version * 10000 + minor version * 100 + revision
// Example: 10402 means 1.4.2
let version = Superpowered.Version();
// Returns the frequency of a specific note.
let hz = Superpowered.frequencyOfNote(
0 // The number of the note. Note 0 is the standard A note at 440 Hz.
);
</code></pre>
<h3>FFT</h3>
<p>Super fast FFT. Single threaded.</p>
<pre><code class="language-js">
// Complex in-place FFT. Has no return value.
// Data packing is same as Apple's vDSP. Check the "Using Fourier Transforms" page of Apple's vDSP documentation ("Data Packing for Real FFTs").
Superpowered.FFTComplex(
real, // Pointer to floating point numbers. Real part.
imag, // Pointer to floating point numbers. Imaginary part.
9, // Log size. Should be between 4 and 12 (FFT sizes 16 - 4096).
true // Forward (true) or inverse (false).
);
// Real in-place FFT. Has no return value.
// Data packing is same as Apple's vDSP. Check the "Using Fourier Transforms" page of Apple's vDSP documentation ("Data Packing for Real FFTs").
Superpowered.FFTReal(
real, // Pointer to floating point numbers. Real part.
imag, // Pointer to floating point numbers. Imaginary part.
9, // Log size. Should be 5 - 13 (FFT sizes 32 - 8192).
true // Forward (true) or inverse (false).
);
// Polar FFT. Has no return value.
// Data packing is same as Apple's vDSP. Check the "Using Fourier Transforms" page of Apple's vDSP documentation ("Data Packing for Real FFTs").
Superpowered.PolarFFT(
mag, // Pointer to floating point numbers. Input: split real part. Output: magnitudes.
phase, // Pointer to floating point numbers. Input: split real part. Output: phases.
9, // Should be 5 - 13 (FFT sizes 32 - 8192).
true, // Forward (true) or inverse (false). Inverse PolarFFT will clear (zero) the DC offset.
0 // Value of pi: The function can translate pi to any value (Google: the tau manifesto). Use 0 for pi.
);
</code></pre>
<h3>StereoMixer</h3>
<p>Mixes up to 4 stereo inputs. From the traditional mixer hardware point of view, every input and the output has dedicated metering, gain and pan controls.</p>
<p>One instance allocates just a few bytes of memory, therefore combining multiple instances of the StereoMixer is the recommended way to support more than 4 channels.</p>
<pre><code class="language-js">
// Constructor. Has no additional parameters.
let mixer = new Superpowered.StereoMixer();
// Gain per input channel, 8 values (2 per input). Default value for all: 1. Changes between consecutive process() calls are automatically smoothed.
mixer.inputGain[2] = 0.5; // left side of the second input
mixer.inputGain[3] = 0.5; // right side of the second input
// Output gain. Default value for all: 1. Changes between consecutive process() calls are automatically smoothed.
mixer.outputGain[0] = 0.9; // left side
mixer.outputGain[1] = 0.8; // right side
// Processes the audio. Has no return value.
mixer.process(
input0, // Pointer to floating point numbers. 32-bit interleaved stereo input buffer for the first input. Can be null.
input1, // Pointer to floating point numbers. 32-bit interleaved stereo input buffer for the second input. Can be null.
input2, // Pointer to floating point numbers. 32-bit interleaved stereo input buffer for the third input. Can be null.
input3, // Pointer to floating point numbers. 32-bit interleaved stereo input buffer for the fourth input. Can be null.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output buffer.
128 // Number of frames to process. Must be an even number.
);
// The peak absolute audio volume per input channel, updated after every process() call, measured before any gain.
let second_input_left_side = mixer.inputPeak[2];
let second_input_right_side = mixer.inputPeak[3];
// The peak absolute audio volume for the output, updated after every process() call.
let output_left_side = mixer.outputPeak[0];
let output_right_side = mixer.outputPeak[1];
// Destructor (to free up memory).
mixer.destruct();
</code></pre>
<h3>MonoMixer</h3>
<p>Mixes up to 4 mono inputs. Every input and the output has individual gain control.</p>
<p>One instance allocates just a few bytes of memory, therefore combining multiple instances of the MonoMixer is the recommended way to support more than 4 channels.</p>
<pre><code class="language-js">
// Constructor. Has no additional parameters.
let mixer = new Superpowered.MonoMixer();
// Gain per input channel. Default value for all: 1. Changes between consecutive process() calls are automatically smoothed.
mixer.inputGain[2] = 0.5; // third input
// Gain for the output. Default value: 1. Changes between consecutive process() calls are automatically smoothed.
mixer.outputGain = 2;
// Mixes up to 4 mono inputs into a mono output. Has no return value.
mixer.process(
input0, // Pointer to floating point numbers. 32-bit input buffer for the first input. Can be null.
input1, // Pointer to floating point numbers. 32-bit input buffer for the second input. Can be null.
input2, // Pointer to floating point numbers. 32-bit input buffer for the third input. Can be null.
input3, // Pointer to floating point numbers. 32-bit input buffer for the fourth input. Can be null.
output, // Pointer to floating point numbers. 32-bit output buffer.
128 // Number of frames to process. Must be a multiple of 4.
);
// Destructor (to free up memory).
mixer.destruct();
</code></pre>
<h2>Audio Analysis</h2>
<h3>Waveform</h3>
<p>Provides waveform data in 150 points/sec resolution.</p>
<pre><code class="language-js">
// Constructor.
let waveform = new Superpowered.Waveform(
44100, // The sample rate of the audio input.
60 // The length in seconds of the audio input. It will not be able to process more audio than this. You can change this value in the process() method.
);
// Processes some audio. This method can be used in a real-time audio thread if lengthSeconds is -1. Has no return value.
waveform.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
128, // Number of frames to process.
-1 // If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread.
);
// Makes the result from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. Has no return value.
waveform.makeResult();
let w = waveform.getPeakWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the peak volume. Uint8Array. Each byte represents one "pixel". Available after calling makeResult().
waveform.waveformSize; // The number of bytes in the peak, average, low, mid and high waveforms and notes.
// Destructor (to free up memory).
waveform.destruct();
</code></pre>
<h3>BandpassFilterbank</h3>
<p>Efficient bandpass filter bank for real-time zero latency frequency analysis. Each band is a separated bandpass filter with custom width and center frequency.</p>
<pre><code class="language-js">
// Constructor.
let frequencies = new Superpowered.Float32Buffer(8), widths = new Superpowered.Float32Buffer(8);
for (let n = 0; n < 8; n++) {
frequencies.array[n] = n * 1000;
widths.array[n] = 1;
}
let filterbank = new Superpowered.BandpassFilterbank(
8, // The number of bands. Must be a multiply of 8.
frequencies.pointer, // Center frequencies of each band in Hz.
widths.pointer, // Widths of each band in octave (1.0 is one octave, 1.0 / 12.0 is one halfnote).
44100, // The initial sample rate in Hz.
0 // numGroups: for advanced use.
// The filter bank can be set up with multiple frequency + width groups, then process() or processNoAdd() can be performed with one specific frequency + width group. For example, set up one group with wide frequency coverage for the 20-20000 Hz range and three additional groups for 20-200 Hz, 200-2000 Hz and 2000-20000 Hz. When processing with the wide group of 20-20000 Hz and the highest magnitude can be found at 1000 Hz, use the 200-2000 Hz group for the next process() or processNoAdd() call, so the filter bank will have a "focus" on a narrower range.
// If numGroups > 0, then the number of frequencies and widths should be numGroups * numBands. Example: for numBands = 8 and numGroups = 2, provide 8 + 8 frequencies and 8 + 8 widths.
);
Superpowered.free(frequencies);
Superpowered.free(widths);
// Do this when the sample rate changes.
filterbank.samplerate = 48000;
// Processes the audio. Has no return value.
// It will ADD to the current magnitude in bands (like bands[0] += 0.123), so you can "measure" the magnitude of each frequency for a longer period of time.
// To calculate a result between 0 and 1 for multiple consecutive process() calls, divide each value in bands with the total number of frames passed to the consecutive process() calls.
filterbank.process(
input, // Input pointer (audio in 32-bit floating point numbers, stereo, interleaved).
128, // Number of frames to process.
0 // The group index for advanced "grouped" usage.
);
// Processes the audio. Has no return value.
filterbank.processNoAdd(
input, // Input pointer (audio in 32-bit floating point numbers, stereo, interleaved).
128, // Number of frames to process.
0 // The group index for advanced "grouped" usage.
);
// The magnitude of the frequency bands. Will be updated after each process() or processNoAdd() call.
let bands = filterbank.getBands(); // Superpowered.Float32Buffer
let band0_magnitude = bands.array[0];
// Sets all values of bands to 0. Has no return value.
filterbank.resetBands();
// Returns with the average volume of all audio passed to all previous process() or processNoAdd() calls.
let averageVolume = filterbank.getAverageVolume();
// Returns with the cumulated absolute value of all audio passed to all previous process() or processNoAdd() calls. Like you would add the absolute value of all audio samples together.
let sumAudio = filterbank.getSumVolume();
// Resets the sum and average volume value to start measurement anew. Has no return value.
filterbank.resetSumAndAverageVolume();
// Returns with the peak volume of all audio passed to all previous process() or processNoAdd() calls.
let peakVolume = filterbank.getPeakVolume();
// Resets the peak volume value to start measurement anew. Has no return value.
filterbank.resetPeakVolume();
// Destructor (to free up memory).
filterbank.destruct();
</code></pre>
<h3>Analyzer</h3>
<p>Performs bpm and key detection, loudness/peak analysis. Provides compact waveform data (150 points/sec and 1 point/sec resolution), beatgrid information.</p>
<pre><code class="language-js">
// Constructor.
let analyzer = new Superpowered.Analyzer(
44100, // The sample rate of the audio input.
60 // The length in seconds of the audio input. The analyzer will not be able to process more audio than this. You can change this value in the process() method.
);
// Processes some audio. This method can be used in a real-time audio thread if lengthSeconds is -1. Has no return value.
analyzer.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
128, // Number of frames to process.
-1 // If the audio input length may change, set this to the current length. Use -1 otherwise. If this value is not -1, this method can NOT be used in a real-time audio thread.
);
// Makes results from the collected data. This method should NOT be used in a real-time audio thread, because it allocates memory. Has no return value.
analyzer.makeResults(
60, // Detected bpm will be more than or equal to this. Recommended value: 60.
200, // Detected bpm will be less than or equal to this. Recommended value: 200.
0, // If you know the bpm set it here. Use 0 otherwise.
0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.
true, // True: calculate beatgridStartMs. False: save some CPU with not calculating it.
0, // Provides a "hint" for the analyzer with this. Use 0 otherwise.
true, // True: make overviewWaveform. False: save some CPU and memory with not making it.
true, // True: make the low/mid/high waveforms. False: save some CPU and memory with not making them.
true // True: calculate keyIndex. False: save some CPU with not calculating it.
);
analyzer.peakDb; // Peak volume in decibels. Available after calling makeResults().
analyzer.averageDb; // Average volume in decibels. Available after calling makeResults().
analyzer.loudpartsAverageDb; // The average volume of the "loud" parts in decibel. (Quiet parts excluded.) Available after calling makeResults().
analyzer.bpm; // Beats per minute. Available after calling makeResults().
analyzer.beatgridStartMs; // Where the beatgrid starts (first beat) in milliseconds. Available after calling makeResults().
analyzer.keyIndex; // The dominant key (chord) of the music. 0..11 are major keys from A to G#, 12..23 are minor keys from A to G#. Check the static constants in this header for musical, Camelot and Open Key notations.
analyzer.waveformSize; // The number of bytes in the peak, average, low, mid and high waveforms and notes.
let w = analyzer.getPeakWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the peak volume. Each byte represents one "pixel". Available after calling makeResults().
let w = analyzer.getAverageWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the average volume. Each byte represents one "pixel". Available after calling makeResults().
let w = analyzer.getLowWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the low frequencies (below 200 Hz). Each byte represents one "pixel". Available after calling makeResults().
let w = analyzer.getMidWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the mid frequencies (200-1600 Hz). Each byte represents one "pixel". Available after calling makeResults().
let w = analyzer.getHighWaveform(); // Superpowered.Uint8Buffer. 150 points/sec waveform data displaying the high frequencies (above 1600 Hz). Each byte represents one "pixel". Available after calling makeResults().
let n = analyzer.getNotes(); // Superpowered.Uint8Buffer. 150 points/sec data displaying the bass and mid keys. Upper 4 bits are the bass notes 0 to 11, lower 4 bits are the mid notes 0 to 11 (C, C#, D, D#, E, F, F#, G, G#, A, A#, B). The note value is 12 means "unknown note due low volume". Available after calling makeResults().
analyzer.overviewSize; // The number bytes in overviewWaveform.
let w = analyzer.getOverviewWaveform(); // Superpowered.Uint8Buffer. 1 point/sec waveform data displaying the average volume in decibels. Useful for displaying the overall structure of a track. Int8Array. Each byte has the value of -128 to 0, in decibels.
// Destructor (to free up memory).
analyzer.destruct();
// Helper arrays to display keyIndex in musical, Camelot and Open Key formats:
let musicalChordNames = [
"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", /// major
"Am", "A#m", "Bm", "Cm", "C#m", "Dm", "D#m", "Em", "Fm", "F#m", "Gm", "G#m" /// minor
];
let camelotChordNames = [
"11B", "6B", "1B", "8B", "3B", "10B", "5B", "12B", "7B", "2B", "9B", "4B", /// major
"8A", "3A", "10A", "5A", "12A", "7A", "2A", "9A", "4A", "11A", "6A", "1A" /// minor
];
let openkeyChordNames = [
"4d", "11d", "6d", "1d", "8d", "3d", "10d", "5d", "12d", "7d", "2d", "9d", /// major
"1m", "8m", "3m", "10m", "5m", "12m", "7m", "2m", "9m", "4m", "11m", "6m" /// minor
];
</code></pre>
<h2>Effects</h2>
<h3>Three Band EQ</h3>
<p>Classic three-band equalizer with unique characteristics and total kills.</p>
<p>It doesn't allocate any internal buffers and needs just a few bytes of memory.</p>
<pre><code class="language-js">
// Constructor. Enabled is false by default.
let eq = new Superpowered.ThreeBandEQ(
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
eq.samplerate = 48000;
// Turns the effect on/off. False by default. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
eq.enabled = true;
// Low gain. Read-write. 1 is "flat", 2 is +6db. Kill is enabled under -40 db (0.01). Default: 1. Limits: 0 and 8.
eq.low = 0.5;
eq.mid = 1; // Mid gain. See low for details.
eq.high = 1.2; // High gain. See low for details.
// Processes the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation.
// It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().
// If process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, the contents of output are not changed.
let changedOutput = eq.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can point to the same location with input (in-place processing).
128 // Number of frames to process. Recommendation for best performance: multiply of 4, minimum 64.
);
// Destructor (to free up memory).
eq.destruct();
</code></pre>
<h3>Bitcrusher</h3>
<p>Bit crusher with adjustable frequency and bit depth. Simulates an old-school digital sound card. It doesn't allocate any internal buffers and needs just a few bytes of memory.</p>
<pre><code class="language-js">
// Constructor. Enabled is false by default.
let bc = new Superpowered.Bitcrusher(
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
bc.samplerate = 48000;
// Turns the effect on/off. False by default. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
bc.enabled = true;
bc.frequency = 9000; // Frequency in Hz, from 20 Hz to the half of the samplerate.
bc.bits = 8; // Bit depth, from 1 to 16.
// Processes the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation.
// It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().
// If process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, the contents of output are not changed.
let changedOutput = bc.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can point to the same location with input (in-place processing).
128 // Number of frames to process. Recommendations for best performance: multiply of 4.
);
// Destructor (to free up memory).
bc.destruct();
</code></pre>
<h3>Echo</h3>
<p>Simple echo ("delay effect"). One instance allocates around 770 kb memory.</p>
<pre><code class="language-js">
// Constructor. Enabled is false by default.
let echo = new Superpowered.Echo(
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
echo.samplerate = 48000;
// Turns the effect on/off. False by default. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
echo.enabled = true;
echo.dry = 0.9; // >= 0 and <= 1. Read-write.
echo.wet = 0.5; // >= 0 and <= 1. Read-write.
echo.bpm = 128.1; // >= 40 and <= 250. Read-write.
echo.beats = 0.5; // Delay in beats, >= 0.03125 and <= 2.0. Read-write.
echo.decay = 0.5; // >= 0 and <= 0.99. Read-write.
// Sets dry and wet simultaneously with a good balance between them. Wet always equals to mix, but dry changes with a curve.
echo.setMix(
0.5 // >= 0 and <= 1.
);
// Processes the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation.
// It's never blocking for real-time usage. You can change all properties and call setMix() on any thread, concurrently with process().
// If process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, the contents of output are not changed.
let changedOutput = echo.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input. Can point to the same location with output (in-place processing). Special case: input can be null, the effect will output the tail only in this case.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output.
128 //Number of frames to process. Recommendation for best performance: multiply of 4, minimum 64.
);
// Destructor (to free up memory).
echo.destruct();
</code></pre>
<h3>Delay</h3>
<p>Simple delay with minimum memory operations.</p>
<pre><code class="language-js">
let delay = new Superpowered.Delay(
100, // Maximum delay in milliseconds. Higher values increase memory usage.
48000, // Maximum sample rate to support. Higher values increase memory usage.
1024, // Maximum number of frames for the process() call. Has minimum effect on memory usage.
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
delay.samplerate = 48000;
// Delay in milliseconds.
delay.delayMs = 50.1;
// Processes the audio.
// It's never blocking for real-time usage. You can change any properties concurrently with process().
// Returns with a pointer to floating point numbers, which is the output with numberOfFrames audio available in it. It is valid until the next call to process().
let output = delay.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input. Special case: set to null to empty all buffered content.
128 // Number of frames to input and output.
);
// If you want to "convert" the returned pointer to a JavaScript Float32Array, do this:
let jsArray = new Float32Array(
Superpowered.buffer, // Linear memory buffer of the Superpowered module instance.
output, // This linear memory index was returned by delay.process().
128 * 2 // Number of frames multiplied by the number of channels. In this example, 128 * 2.
);
// Destructor (to free up memory).
delay.destruct();
</code></pre>
<h3>Flanger</h3>
<p>Flanger with aggressive sound ("jet"). One instance allocates around 80 kb memory.</p>
<pre><code class="language-js">
// Constructor.
let flanger = new Superpowered.Flanger(
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
flanger.samplerate = 48000;
// Turns the effect on/off. False by default. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
flanger.enabled = true;
flanger.wet = 0.5; // 0 to 1.
flanger.depth = 0.5; // 0 to 1 (0 is 0.3 ms, 1 is 8 ms).
flanger.lfoBeats = 16; // The length in beats between the "lowest" and the "highest" jet sound, >= 0.25 and <= 128.
flanger.bpm = 128; // The bpm of the current audio. Limited to >= 40 and <= 250.
flanger.stereo = true; // True: stereo, false: mono.
flanger.clipperThresholdDb = -3; // The flanger has a Clipper inside to prevent overdrive. This is the thresholdDb parameter.
flanger.clipperMaximumDb = 6; // The flanger has a Clipper inside to prevent overdrive. This is the maximumDb parameter.
// Returns with the current depth in milliseconds, 0.3f to 8.0f (0.3 ms to 8 ms).
let flanger_depth_ms = flanger.getDepthMs();
// Processes the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation.
// It's never blocking for real-time usage. You can change all properties and call getDepthMs() on any thread, concurrently with process().
// If process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, the contents of output are not changed.
let changedOutput = flanger.process(
input, // Pointer to floating point numbers. 32-bit interleaved stereo input.
output, // Pointer to floating point numbers. 32-bit interleaved stereo output. Can point to the same location with input (in-place processing).
128 // Number of frames to process. Recommendations for best performance: multiply of 4, minimum 64.
);
// Destructor (to free up memory).
flanger.destruct();
</code></pre>
<h3>Gate</h3>
<p>Simple gate effect. It doesn't allocate any internal buffers and needs just a few bytes of memory.</p>
<pre><code class="language-js">
// Constructor. Enabled is false by default.
let gate = new Superpowered.Gate(
44100 // The initial sample rate in Hz.
);
// Do this when the sample rate changes.
gate.samplerate = 48000;
// Turns the effect on/off. False by default. The actual switch will happen on the next process() call for smooth, audio-artifact free operation.
gate.enabled = true;
gate.wet = 0.5; // Limited to >= 0 and <= 1.
gate.bpm = 128; // Limited to >= 40 and <= 250.
gate.beats = 1; // The rhythm in beats to open and close the "gate". From 1/64 beats to 4 beats. (>= 0.015625 and <= 4)
// Processes the audio. Always call it in the audio processing callback, regardless if the effect is enabled or not for smooth, audio-artifact free operation.
// It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process().
// If process() returns with true, the contents of output are replaced with the audio output. If process() returns with false, the contents of output are not changed.