-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWLEDAudioSync.js
1883 lines (1423 loc) · 44.9 KB
/
WLEDAudioSync.js
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
/*
a:zak45
d:25/01/2023
v:2.1.0
Chataigne Module for WLED Sound Reactive
Send sound card audio data via UDP.
This script will take Audio data provided by Chataigne and try to map them to WLED values.
It also provide some real time sound data analysis (e.g Pitch, FFT, BPM, etc..).
Classical (Classique) : 60-120 BPM
Jazz : 80-140 BPM
Blues : 60-120 BPM
Rock : 100-160 BPM
Pop : 90-130 BPM
R&B : 60-100 BPM
Hip Hop : 60-100 BPM
Electronic (EDM, Trance, House) : 120-140 BPM (varie selon les sous-genres)
Country : 60-120 BPM
Reggae : 70-100 BPM
Funk : 90-120 BPM
Metal : 100-200 BPM (varie selon les sous-genres)
Punk : 150-200 BPM
Salsa : 150-250 BPM
Ballad : 60-80 BPM
Names of frequency responses
20 - 40 Hz Low Bass
40 - 80 Hz Mid Bass
80 - 160 Hz Upper Bass
160 - 320 Hz Lower Midrange
320 - 640 Hz Middle Midrange
640 Hz - 1.28 кHz Upper Midrange
1.28 - 2.56 кHz Lower Treble
2.56 - 5.12 кHz Middele Treble
5.12 - 10.2 кHz Upper Treble
10.2 - 20.4 кHz Top Octave
The UDP Multicast IP is 239.0.0.1, and the default UDP port is 11988.
// From WLED Infos
UDP port can be changed in WLED config pages, for example to have several groups of devices by assigning different UDP ports to each group.
the software sends/receives one packet every 20 milliseconds (approx). An external sender may be slower, but not faster than 20ms = 50fps
//
-------------------------------------- BIN -----------------
// Range
fftCalc[0] = (fftAdd(3,4)) /2; // 60 - 100
fftCalc[1] = (fftAdd(4,5)) /2; // 80 - 120
fftCalc[2] = (fftAdd(5,7)) /3; // 100 - 160
fftCalc[3] = (fftAdd(7,9)) /3; // 140 - 200
fftCalc[4] = (fftAdd(9,12)) /4; // 180 - 260
fftCalc[5] = (fftAdd(12,16)) /5; // 240 - 340
fftCalc[6] = (fftAdd(16,21)) /6; // 320 - 440
fftCalc[7] = (fftAdd(21,28)) /8; // 420 - 600
fftCalc[8] = (fftAdd(28,37)) /10; // 580 - 760
fftCalc[9] = (fftAdd(37,48)) /12; // 740 - 980
fftCalc[10] = (fftAdd(48,64)) /17; // 960 - 1300
fftCalc[11] = (fftAdd(64,84)) /21; // 1280 - 1700
fftCalc[12] = (fftAdd(84,111)) /28; // 1680 - 2240
fftCalc[13] = (fftAdd(111,147)) /37; // 2220 - 2960
fftCalc[14] = (fftAdd(147,194)) /48; // 2940 - 3900
fftCalc[15] = (fftAdd(194, 255)) /62; // 3880 - 5120 // avoid the last 5 bins, which are usually inaccurate
//
fftCalc[ 0] = fftAddAvg(1,2); // 1 43 - 86 sub-bass
fftCalc[ 1] = fftAddAvg(2,3); // 1 86 - 129 bass
fftCalc[ 2] = fftAddAvg(3,5); // 2 129 - 216 bass
fftCalc[ 3] = fftAddAvg(5,7); // 2 216 - 301 bass + midrange
fftCalc[ 4] = fftAddAvg(7,10); // 3 301 - 430 midrange
fftCalc[ 5] = fftAddAvg(10,13); // 3 430 - 560 midrange
fftCalc[ 6] = fftAddAvg(13,19); // 5 560 - 818 midrange
fftCalc[ 7] = fftAddAvg(19,26); // 7 818 - 1120 midrange -- 1Khz should always be the center !
fftCalc[ 8] = fftAddAvg(26,33); // 7 1120 - 1421 midrange
fftCalc[ 9] = fftAddAvg(33,44); // 9 1421 - 1895 midrange
fftCalc[10] = fftAddAvg(44,56); // 12 1895 - 2412 midrange + high mid
fftCalc[11] = fftAddAvg(56,70); // 14 2412 - 3015 high mid
fftCalc[12] = fftAddAvg(70,86); // 16 3015 - 3704 high mid
fftCalc[13] = fftAddAvg(86,104); // 18 3704 - 4479 high mid
fftCalc[14] = fftAddAvg(104,165) * 0.88f; // 61 4479 - 7106 high mid + high -- with slight damping
// don't use the last bins from 216 to 255. They are usually contaminated by aliasing (aka noise)
fftCalc[15] = fftAddAvg(165,215) * 0.70f; // 50 7106 - 9259 high -- with some damping
*/
// sound Card
var SCexist = false;
// osc
var OSCModule = null;
var OSCIP = "127.0.0.1";
// TMPDIR
var tempDIR = "";
//HOME Location
//%USERPROFILE% for WIN and $HOME for others
var homeDIR = "";
var winHOME = "";
// Volume
var wledVol = 0;
// Volume Multiplier
var volMultiplier = 512;
// Global FFT Multiplier
var fftMultiplier = 254;
// FFT Data
var FFTWLED = [];
// FFT Max Freq / Magnitude
var fftSoundMaxFreqMagnitude = 0;
var fftSoundMaxFreqIndex = 0;
// FFT Mode
var fftMode = "";
//minAudio/max DB
var minDB = -50;
var maxDB = 0;
// Frequence table
var FREQTABLE = [];
// samplePeak
var wledPeak = 0;
// Wled Freq/Mag
var wledFreq = 0;
var wledMag = 0;
// UDP
var multicastIP = "239.0.0.1";
var uDPPort = 11988;
var myIP = "127.0.0.1";
// Init Flag
// to made some logic only once at init
var isInit = true;
// snapshot
var snapshot = false;
//replay
var replay = false;
var duration = 0;
var previousFile = "";
var SOUNDDATA = [];
// UDP Data
var UDP_AUDIO_SYNC = [];
var UDP_AUDIO_SYNC_V2 = [];
// BPM
var aubioCmdName = "aubio.cmd";
var aubioProcName = "WLEDAudioSyncRTBeat";
// Friture
var fritureCmdName = "friture.cmd";
// RTMGC
var rtmgcCmdName = "rtmgc.cmd";
var rtmgcProcName = "WrtmgcSRV";
// RTMMD
var rtmmdCmdName = "rtmmd.cmd";
// multicast
var multicastCmdName = "multicast.cmd";
// module
var moduleDIR = "/Chataigne/modules/WLEDAudioSync/";
var options = "";
// SCAnalyzer test
var SCAModule = false;
//We create necessary entries in module.
function init ()
{
script.log("-- Custom command called init()");
local.scripts.wLEDAudioSync.updateRate.setAttribute("readOnly",false);
var infos = util.getOSInfos();
script.log("Hello "+infos.username);
script.log("We run under : "+infos.name);
if ( infos.name.contains("Win") )
{
homeDIR = util.getEnvironmentVariable("USERPROFILE") + "/Documents";
winHOME = util.getEnvironmentVariable("USERPROFILE");
} else {
homeDIR = util.getEnvironmentVariable("$HOME");
}
// update rate (no more than 50fps but let choice)
script.setUpdateRate(50);
}
function update ()
{
// Send audio data and return
if (SCexist &&
root.modules.soundCard.values.volume.get()!= 0 &&
replay === false &&
local.parameters.live.get() == 1 &&
local.parameters.beatParams.syncToBeat.get() == 0
)
{
sendAudio(false);
return;
} else if (replay === true){
if ( duration > 0 )
{
sendAudio(true);
} else {
replay = false;
for ( var k = 0; k < 10; k += 1 )
{
sendAudio(false);
}
script.setUpdateRate(50);
}
return;
}
// Initialize only once some Params when script run for first time
if (isInit === true)
{
script.log('Initialize');
isInit = false;
// Module test
OSCModule = root.modules.getItemWithName("OSC");
SCAModule = root.modules.getItemWithName("SCAnalyzer");
if (OSCModule.name == "osc")
{
script.log("Module OSC exist");
} else {
script.log("Module OSC do not exist");
}
if (SCAModule.name != "undefined")
{
script.log("Module SCAnalyzer exist");
} else {
script.log("Module SCAnalyzer does not exist");
}
if (checkModuleExist("OS"))
{
script.log("Module OS exist");
} else {
root.modules.addItem("OS");
}
if (checkModuleExist("Sound Card"))
{
script.log("Sound Card present");
SCexist = true;
} else {
script.log("No Sound Card present");
var newSCModule = root.modules.addItem("Sound Card");
if (newSCModule.name != "undefined")
{
SCexist = true;
} else {
SCexist = false;
}
}
if (SCexist === true)
{
root.modules.soundCard.parameters.pitchDetectionMethod.set("MPM");
root.modules.soundCard.parameters.activityThreshold.set(0.075);
}
// if run from portable version need to set right script path
// and execute BPM if not running
if (local.parameters.beatParams.useBPM.get() == 1)
{
var checkProcess = root.modules.os.getRunningProcesses("*");
var aubioIsRunning = false;
var aubioProcessName = "";
var aubiodevice = local.parameters.beatParams.inputAudio.get();
if (aubiodevice == null)
{
aubiodevice = 0;
}
addOSCScript('OSCBPM');
root.modules.osc.scripts.oscbpm.reload.trigger();
for ( var i = 0; i < checkProcess.length; i ++)
{
if (checkProcess[i].contains(aubioProcName))
{
aubioIsRunning = true;
aubioProcessName = checkProcess[i];
script.log("aubio is running");
break;
}
}
if (aubioIsRunning === false ) {
options = " beat -s " + OSCIP + " " + root.modules.osc.parameters.oscInput.localPort.get() + ' "/WLEDAudioSync/beat/BPM"' +
" -d " + aubiodevice +
" -b " + local.parameters.beatParams.aubioBuffer.get();
var command = homeDIR + moduleDIR + aubioCmdName + options;
script.log("command to run : " + command);
root.modules.os.launchCommand(command, true);
}
}
// retreive all IPs
var ips = util.getIPs();
local.parameters.ipAddressToBind.removeOptions();
for( var i=0; i<ips.length; i +=1 )
{
local.parameters.ipAddressToBind.addOption(ips[i],i);
}
local.parameters.ipAddressToBind.set(root.modules.os.values.networkInfos.ip.get());
multicastIP = local.parameters.output.remoteHost.get();;
uDPPort = local.parameters.output.remotePort.get();
myIP = local.parameters.ipAddressToBind.get();
// MultiCast
testMultiCast();
// if no FFT then create FFT : new
var testFFT = root.modules.soundCard.parameters.fftAnalysis.getItemWithName("Analyzer 1");
if (testFFT.name != "undefined")
{
script.log("FFT already there !!");
} else {
createWLEDFFT(false);
root.modules.soundCard.parameters.fftAnalysis.enabled.set(1);
}
// Remove read only from rate
local.scripts.wLEDAudioSync.updateRate.setAttribute("readOnly",false);
// add WLEDAudioSync to SCAnalyzer options
if (SCAModule.name != "undefined")
{
SCAModule.parameters.wLEDAudioSyncParams.moduleName.addOption(local.name, local.name);
var mycontainer = SCAModule.parameters.getChild("WLEDAudioSync Params");
mycontainer.setCollapsed(false);
}
// end
}
}
// check modifications made on module Params
function moduleParameterChanged (param)
{
script.log("Param changed : "+param.name);
if (param.name == "volumeMultiplier")
{
volMultiplier = local.parameters.volumeMultiplier.get();
} else if (param.name == "frequencyMagnitudeMultiplier"){
fftMultiplier = local.parameters.frequencyMagnitudeMultiplier.get();
} else if (param.name == "remoteHost"){
multicastIP = local.parameters.output.remoteHost.get();
} else if (param.name == "remotePort"){
uDPPort = local.parameters.output.remotePort.get();
} else if (param.name == "ipAddressToBind"){
myIP = local.parameters.ipAddressToBind.get();
} else if (param.name == "sendTestMessage"){
testMultiCast();
} else if (param.name == "local"){
if (local.parameters.output.local.get() == 1){
multicastIP = "127.0.0.1";
} else {
multicastIP = local.parameters.output.remoteHost.get();
}
} else if (param.name == "takeSnapshot"){
snapshot = true;
} else if (param.name == "useBPM" && isInit === false){
var checkProcess = root.modules.os.getRunningProcesses("*");
var aubioIsRunning = false;
var aubioProcessName = "";
for ( var i = 0; i < checkProcess.length; i ++)
{
if (checkProcess[i].contains(aubioProcName))
{
aubioIsRunning = true;
aubioProcessName = checkProcess[i];
script.log("aubio is running");
break;
}
}
addOSCScript("OSCBPM");
if (local.parameters.beatParams.useBPM.get() == 1)
{
// find aubio devices list
aubioDevicesList();
script.log("run aubio");
// find sound card input audio
var scInput = audioFindInput();
if (scInput == "")
{
script.log("Input device not defined in Sound card module");
util.showMessageBox("WLEDAudioSync ! ", "Input device not defined in Sound card module", "info", "Got it");
local.parameters.beatParams.useBPM.set(0);
} else {
script.log("Sound card input device : " + scInput);
var aubioDevices = local.parameters.beatParams.inputAudio.getAllOptions();
var audioDeviceIndex = 0;
for ( var i = 0; i < aubioDevices.length; i++)
{
if (scInput.contains(aubioDevices[i].key.substring(4,(aubioDevices[i].key.length)-1)))
{
script.log("Aubio device number : " + aubioDevices[i].value);
break;
}
}
if (aubioDevices[i].value != undefined)
{
audioDeviceIndex = aubioDevices[i].value;
}
if (aubioIsRunning === false)
{
options = " beat -s " + OSCIP + " " + root.modules.osc.parameters.oscInput.localPort.get() + ' "/WLEDAudioSync/beat/BPM"' +
" -d " + audioDeviceIndex +
" -b " + local.parameters.beatParams.aubioBuffer.get();
var command = homeDIR + moduleDIR + aubioCmdName + options;
script.log("command to run : " + command);
root.modules.os.launchCommand(command, true);
} else {
script.log("aubio is already running");
}
}
} else {
if (aubioIsRunning === true)
{
script.log("killing aubio : " + aubioProcessName);
var killCmd = root.modules.os.commandTester.setCommand("OS","Process","Kill App");
killCmd.target.set(aubioProcessName);
killCmd.hardKill.set(1);
root.modules.os.commandTester.trigger.trigger();
} else {
script.log("nothing to kill");
}
local.parameters.beatParams.syncToBeat.set(0);
}
} else if (param.name == "syncToBeat"){
if (param.get() == 1){
script.setUpdateRate(1);
} else {
script.setUpdateRate(50);
}
} else if (param.name == "forceReload"){
var checkProcess = root.modules.os.getRunningProcesses("*");
var aubioProcessName = "";
addOSCScript("OSCBPM");
for ( var i = 0; i < checkProcess.length; i ++)
{
if (checkProcess[i].contains(aubioProcName))
{
aubioProcessName = checkProcess[i];
script.log("aubio is running");
script.log("killing aubio : " + aubioProcessName);
var killCmd = root.modules.os.commandTester.setCommand("OS","Process","Kill App");
killCmd.target.set(aubioProcessName);
killCmd.hardKill.set(1);
root.modules.os.commandTester.trigger.trigger();
break;
}
}
options = " beat -s " + OSCIP + " " + root.modules.osc.parameters.oscInput.localPort.get() + ' "/WLEDAudioSync/beat/BPM"' +
" -d " + local.parameters.beatParams.inputAudio.get() +
" -b " + local.parameters.beatParams.aubioBuffer.get();
var command = homeDIR + moduleDIR + aubioCmdName + options;
script.log("command to run : " + command);
root.modules.os.launchCommand(command, true);
} else if (param.name == "live") {
// find sound card input audio
var scInput = audioFindInput();
if (scInput == "")
{
script.log("Input device not defined in Sound card module");
util.showMessageBox("WLEDAudioSync ! ", "Input device not defined in Sound card module", "info", "Got it");
}
} else if (param.name == "visualizeLiveAudio") {
//execute Friture
var exeCMD = homeDIR + moduleDIR + fritureCmdName;
if (util.fileExists(exeCMD)){
var launchresult = root.modules.os.launchProcess(exeCMD, false);
} else {
util.showMessageBox("Friture not found ", "file name : " + exeCMD , "warning", "Ok");
}
} else if (param.name == "useRTMGC") {
if ( local.parameters.rtmgcParams.useRTMGC.get() == 1)
{
var checkProcess = root.modules.os.getRunningProcesses("*");
var rtmgcRun = false;
for ( var i = 0; i < checkProcess.length; i ++)
{
if (checkProcess[i].contains(rtmgcProcName))
{
script.log("RTMGC is already running");
var rtmgcRun = true;
break;
}
}
if (rtmgcRun === false)
{
addOSCScript("OSCRTMGC");
var oscPort = OSCModule.parameters.oscInput.localPort.get();
options = " " + local.parameters.rtmgcParams.serverPort.get() + " " + OSCIP + " " + oscPort;
}
} else {
options = " kill ";
}
var command = homeDIR + moduleDIR + rtmgcCmdName + options;
script.log("command to run : " + command);
if (util.fileExists(homeDIR + moduleDIR + rtmgcCmdName)){
root.modules.os.launchProcess(command, false);
} else {
script.log('Command file do not exist : ' + homeDIR + moduleDIR + rtmgcCmdName);
}
} else if (param.name == "useRTMMD") {
if ( local.parameters.rtmmdParams.useRTMMD.get() == 1)
{
addOSCScript("OSCRTMMD");
var showScreen = local.parameters.rtmmdParams.showScreen.get();
if (showScreen){
showScreen = 'Y';
} else {
showScreen = 'N';
}
var verbose = local.parameters.rtmmdParams.verbose.get();
if (verbose){
verbose = 'Y';
} else {
verbose = 'N';
}
options = " " + showScreen + " " + verbose;
} else {
script.log('killing Emotion Color Map');
options = " kill ";
}
var command = homeDIR + moduleDIR + rtmmdCmdName + options;
script.log("command to run : " + command);
if (util.fileExists(homeDIR + moduleDIR + rtmmdCmdName)){
root.modules.os.launchCommand(command, true);
} else {
script.log('Command file do not exist : ' + homeDIR + moduleDIR + rtmmdCmdName);
}
}
}
// called each time a beat value changed
function moduleValueChanged(param)
{
if (param.name == "beat" &&
local.parameters.beatParams.syncToBeat.get() == 1){
if (local.parameters.beatParams.beatType.get() == 0 ){
sendAudio(false);
} else if (local.parameters.beatParams.beatType.get() == 1 &&
param.get() == 1 ) {
sendAudio(false);
} else if (local.parameters.beatParams.beatType.get() == 2 &&
param.get() == 0 ) {
sendAudio(false);
}
}
}
// send audio data with optional delay
function sendAudio(replay)
{
// translate audio data to UDP message
var udpdataV1 = udpAudioSyncV1(replay);
if (replay)
{
duration -= 100;
}
// optional delay: audio datas during the delay are lost
var mydelay = local.parameters.delay.get();
if (replay === false && mydelay > 0)
{
util.delayThreadMS(mydelay);
}
// v1 message
if (local.parameters.audioV1.get() == 1)
{
local.sendBytesTo (multicastIP,uDPPort,udpdataV1);
}
// v2 message
if (local.parameters.audioV2.get() == 1)
{
var udpdataV2 = udpAudioSyncV2(udpdataV1);
local.sendBytesTo (multicastIP,uDPPort,udpdataV2);
}
}
/*
Sound Card
*/
// Create 16 FFT analysis entries with default name : adjustable size - custom
function createFFT(size)
{
removeFFT();
root.modules.soundCard.parameters.fftAnalysis.minDB.set(minDB);
root.modules.soundCard.parameters.fftAnalysis.maxDB.set(maxDB);
fftMode = "custom";
if (size > 1)
{
size = 1;
} else if (size == 0) {
size = 0.1;
}
for (var i = 0; i < 16; i += 1)
{
var bin = root.modules.soundCard.parameters.fftAnalysis.addItem();
bin.position.set(0.0625 * i);
bin.size.set(size);
updateFreqTable(fftMode, i);
}
}
// Create 16 FFT analysis entries with default name : WLED OLD/NEW -- true/false
function createWLEDFFT(old)
{
removeFFT();
root.modules.soundCard.parameters.fftAnalysis.minDB.set(minDB);
root.modules.soundCard.parameters.fftAnalysis.maxDB.set(maxDB);
if (old)
{
fftMode = "old";
} else {
fftMode = "new";
}
for (var i = 0; i < 16; i += 1)
{
var bin = root.modules.soundCard.parameters.fftAnalysis.addItem();
if (i == 0)
{
if (old)
{
bin.position.set(0.020);
bin.size.set(0.030);
} else {
bin.position.set(0.020);
bin.size.set(0.020);
}
} else if (i == 1) {
if (old)
{
bin.position.set(0.030);
bin.size.set(0.030);
} else {
bin.position.set(0.030);
bin.size.set(0.020);
}
} else if (i == 2) {
if (old)
{
bin.position.set(0.040);
bin.size.set(0.030);
} else {
bin.position.set(0.045);
bin.size.set(0.020);
}
} else if (i == 3) {
if (old)
{
bin.position.set(0.045);
bin.size.set(0.030);
} else {
bin.position.set(0.065);
bin.size.set(0.020);
}
} else if (i == 4) {
if (old)
{
bin.position.set(0.060);
bin.size.set(0.030);
} else {
bin.position.set(0.090);
bin.size.set(0.020);
}
} else if (i == 5) {
if (old)
{
bin.position.set(0.075);
bin.size.set(0.030);
} else {
bin.position.set(0.110);
bin.size.set(0.040);
}
} else if (i == 6) {
if (old)
{
bin.position.set(0.090);
bin.size.set(0.040);
} else {
bin.position.set(0.160);
bin.size.set(0.040);
}
} else if (i == 7) {
if (old)
{
bin.position.set(0.120);
bin.size.set(0.040);
} else {
bin.position.set(0.215);
bin.size.set(0.050);
}
} else if (i == 8) {
if (old)
{
bin.position.set(0.150);
bin.size.set(0.040);
} else {
bin.position.set(0.265);
bin.size.set(0.050);
}
} else if (i == 9) {
if (old)
{
bin.position.set(0.190);
bin.size.set(0.040);
} else {
bin.position.set(0.340);
bin.size.set(0.050);
}
} else if (i == 10) {
if (old)
{
bin.position.set(0.245);
bin.size.set(0.040);
} else {
bin.position.set(0.410);
bin.size.set(0.050);
}
} else if (i == 11) {
if (old)
{
bin.position.set(0.310);
bin.size.set(0.040);
} else {
bin.position.set(0.490);
bin.size.set(0.050);
}
} else if (i == 12) {
if (old)
{
bin.position.set(0.390);
bin.size.set(0.060);
} else {
bin.position.set(0.570);
bin.size.set(0.060);
}
} else if (i == 13) {
if (old)
{
bin.position.set(0.480);
bin.size.set(0.060);
} else {
bin.position.set(0.645);
bin.size.set(0.070);
}
} else if (i == 14) {
if (old)
{
bin.position.set(0.590);
bin.size.set(0.030);
} else {
bin.position.set(0.830);
bin.size.set(0.070);
}
} else if (i == 15) {
if (old)
{
bin.position.set(0.700);
bin.size.set(0.050);
} else {
bin.position.set(0.915);
bin.size.set(0.070);
}
}
updateFreqTable(fftMode, i);
}
}
// update Frequences Table depend on FFT mode
function updateFreqTable(fftMode, index)
{
if ( index == 0 )
{
if ( fftMode == "new" )
{
FREQTABLE[index] = 86;
} else if ( fftMode == "old" ) {
FREQTABLE[index] = 100;
} else if ( fftMode == "custom" ) {
FREQTABLE[index] = 50;
}
} else if ( index == 1 ) {