-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundsofhealing
More file actions
5463 lines (4608 loc) · 222 KB
/
Copy pathsoundsofhealing
File metadata and controls
5463 lines (4608 loc) · 222 KB
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 xmlns="https://www.w3.org/1999/xhtml" lang="en">
<head>
<!-- TO DO : See what libraries are needed when no generator is loaded -->
<!-- Google Fonts : display=block,swap,fallback,optional -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kavivanar&family=Merriweather+Sans:ital,wght@0,300;1,300&display=block" rel="stylesheet">
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="Dr. Ir. Stéphane Pigeon">
<link rel="canonical" href="https://mynoise.net/NoiseMachines/solfeggioTonesGenerator.php">
<!-- Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#0088ff">
<meta name="theme-color" content="#000000">
<!-- Open Graph -->
<meta property="og:image" content="https://mynoise.net/Data/SOLFEGGIO/fb.jpg">
<link rel="image_src" href="https://mynoise.net/Data/SOLFEGGIO/fb.jpg">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@audiosampling">
<meta name="twitter:title" content="Solfeggio Healing Tones Generator — Online & Free">
<meta name="twitter:description" content="Solfeggio tones were introduced by Dr. Joseph Puleo and Dr. Leonard Horowitz in the seventies. Each slider controls a particular Solfeggio frequency, and you can play several of them simultaneously if you like!">
<meta name="twitter:image" content="https://mynoise.net/Data/SOLFEGGIO/fb.jpg">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="myNoise RSS Feed" href="https://mynoise.net/rss.xml">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Common Frameworks // jquery was 2.2.4 // 3.5.1 might not be compatible with jScrollPane jQuery UI Touch Punch MouseWheel plugin -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-powertip/1.2.0/jquery.powertip.min.js"></script>
<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length).replace(/%2C/g,","); // if cookie has been set from the cloud, the %2C needs to be replaced by a comma;
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
<!-- Font Awesome -->
<link href="/CSS/fontawesome/css/fontawesome.css" rel="stylesheet" />
<link href="/CSS/fontawesome/css/solid.css" rel="stylesheet" />
<link href="/CSS/fontawesome/css/regular.css" rel="stylesheet" />
<link href="/CSS/fontawesome/css/brands.css" rel="stylesheet" />
<!-- Additional if iOS Universal Link Enabled -->
<!-- Additional if Generator is playing -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/JQ/jquery-ui-1.10.3/themes/base/jquery-ui.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jScrollPane/2.2.2/script/jquery.jscrollpane.min.js"></script>
<link href="/CSS/jquery.jscrollpane.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/mousetrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script defer>
// Cleverly designed, badly programmed by Stephane Pigeon
// (c) Dr. Ir. Stephane Pigeon - myNoise.net 2013-25 - stephane at mynoise.net
// Last update 2025-10-09
var iNUMBERBANDS=10;
var bCALIBRATE=0;
var bMUTE=0;
var bMUTEsaved=0;
var bANIMATE=0;
var bDISABLED=0;
var bMEDITATIONSESSION=0;
var bFINISHEDLOADING=0;
var bSUPPORTOGG=0;
var bSUPPORTMP3=0;
var bSUSPENDED=0;
var bSTARTMUTED=0;
var sSYNCHRO="0123456789";
var bPITCHRAN=0;
var bOSAUTO=0;
var bEQ=0;
var bWAVEVISUALIZER=0;
var iINITIALANIMATIONSPEED=32;
var fMASTERGAIN=0.7;
var fTARGETSLIDERLEVEL=0.5; // average slider level when loading a preset
var fAUDIOFADETIME=0.1;
var timeOutOS=new Array();
var iTimer=-1;
var iMTimer=-1;
var epoch=0;
var fileExt=".mp3";
var voiceover=new Array();
var allContents;
var sto=new Array();
var fCONTEXTSTART;
var fLevelMultiplier=1.1;
var iAnimationFactor=1;
var iAnimationMode="s";
var iCurrentAnimationSpeed=iINITIALANIMATIONSPEED;
var timerTimeout, modulationTimeout, fadeTimeOut, meditationInterval, meditationInterval2, osInterval;
var interval=new Array();
var nextA=new Array();
var nextB=new Array();
var lastPlayedA=new Array();
var lastPlayedB=new Array();
var lastPlayedOS=[1,1,1,1,1,1,1,1,1,1];
var randomCounter=0;
var currentLevel=new Array();
var savedCurrentLevel=new Array();
var savedLevel=new Array();
var randomLevel=new Array();
var animationProfileLow=[0,0,0,0,0,0,0,0,0,0];
var animationProfileHigh=[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5];
var bANIMATIONPROFILESET=0;
var bANIMATIONUSERPROFILESET=0;
var cloneURL, cookieURL, appShareURL;
var detune="0";
if (detune.length<2) detune=parseInt(detune);
var selSliders=[1,1,1,1,1,1,1,1,1,1,0];
var playbackFactor=new Array();
var iNowMovingTo=0;
var iFadeState=0;
var mmMin, mmMax;
mmMin=1;
mmMax=0;
var nzSliderIndex=new Array();
var lastSlider;
var uIDS="";
var pitchTable=[1];
var meditationBell, bogus;
var URLlevels="";
var URLanimate="";
var URLmute="";
var URLbell="";
var URLtimer="";
var URLdetune="";
var URLmagic="";
var URLtitle="";
var URLwidth="";
var URLanimateProfileLo="";
var URLanimateProfileHigh="";
var os;
var bDOWNLOADED=new Array();
var iSTARTED=new Array();
var iLOADED=new Array();
var iTOTAL=new Array();
var totSizeMP3=1504156;
var totSizeOGG=717027;
var serverTotal=totSizeMP3;
var dlMonitorThrottle=-500;
var averageSliderLevel=0.4;
var samplesArray;
var longPressTimer;
var isLongPress=false;
var fSTEREOWIDTH=1;
var gainForEQ=1;
var animatedIndices=[];
function enableButton(ids,bEnable) {
const method=bEnable?"removeClass":"addClass";
const pointer=bEnable?"auto":"none";
for (const id of ids) {
const el=document.getElementById(id);
if (el) {
el.style.pointerEvents=pointer;
$("#"+id)[method]("disabled");
}
}
}
function activateButton(ids,bActivate) {
const method=bActivate?"addClass":"removeClass";
for (const id of ids) {
$("#"+id)[method]("active");
}
}
function msg(content) {
if (!bSUSPENDED) {
document.getElementById("msg").innerHTML=content;
}
}
var stretch=[1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4];
// Web Audio API
var sourceFileA = new Array();
var sourceFileB = new Array();
var sourceA = new Array();
var sourceB = new Array();
var l = new Array();
var movedSlider;
var masterGain;
var faderGain;
var dynCompressor;
// Nodes for MS Coding/Decoding
var splitterNode = null;
var mergerNode = null;
var midGain = null;
var sideGain = null;
var inverterGain = null;
var invertedSide = null;
function getUrlVars(str) {
str=str||window.location.href; // if empty, use URL
const vars={};
str.replace(/[?&]+([^=&]+)=([^&]*)/gi,(m,key,value)=>{
vars[key]=value;
});
return vars;
}
// SOUNDS
function assignSources(){
if (bSUPPORTOGG) fileExt=".ogg";
console.log('with '+fileExt+' files');
console.log('Code : SOLFEGGIO');
// Initialize the bell sound
meditationBell = new Audio('/Audio/bell' + fileExt);
meditationBell.preload = 'auto';
// Generate source files A and B dynamically
sourceFileA = [];
sourceFileB = [];
sourceFileA[0] = 'https://mynoise.world/Data/SOLFEGGIO/0a' + fileExt;
sourceFileB[0] = 'https://mynoise.world/Data/SOLFEGGIO/0b' + fileExt;
sourceFileA[1] = 'https://mynoise.world/Data/SOLFEGGIO/1a' + fileExt;
sourceFileB[1] = 'https://mynoise.world/Data/SOLFEGGIO/1b' + fileExt;
sourceFileA[2] = 'https://mynoise.world/Data/SOLFEGGIO/2a' + fileExt;
sourceFileB[2] = 'https://mynoise.world/Data/SOLFEGGIO/2b' + fileExt;
sourceFileA[3] = 'https://mynoise.world/Data/SOLFEGGIO/3a' + fileExt;
sourceFileB[3] = 'https://mynoise.world/Data/SOLFEGGIO/3b' + fileExt;
sourceFileA[4] = 'https://mynoise.world/Data/SOLFEGGIO/4b' + fileExt;
sourceFileB[4] = 'https://mynoise.world/Data/SOLFEGGIO/4a' + fileExt;
sourceFileA[5] = 'https://mynoise.world/Data/SOLFEGGIO/5b' + fileExt;
sourceFileB[5] = 'https://mynoise.world/Data/SOLFEGGIO/5a' + fileExt;
sourceFileA[6] = 'https://mynoise.world/Data/SOLFEGGIO/6a' + fileExt;
sourceFileB[6] = 'https://mynoise.world/Data/SOLFEGGIO/6b' + fileExt;
sourceFileA[7] = 'https://mynoise.world/Data/SOLFEGGIO/7b' + fileExt;
sourceFileB[7] = 'https://mynoise.world/Data/SOLFEGGIO/7a' + fileExt;
sourceFileA[8] = 'https://mynoise.world/Data/SOLFEGGIO/8b' + fileExt;
sourceFileB[8] = 'https://mynoise.world/Data/SOLFEGGIO/8a' + fileExt;
sourceFileA[9] = 'https://mynoise.world/Data/SOLFEGGIO/9a' + fileExt;
sourceFileB[9] = 'https://mynoise.world/Data/SOLFEGGIO/9b' + fileExt;
}
// WEBAUDIO LOADER
var gainNode = new Array();
var stemAnalyser = new Array();
var eqNode = new Array();
var bufferList = new Array();
var loadCount=0;
var context;
function loadWebAudioSound(url,i) {
var request=new XMLHttpRequest();
request.open('GET',url,true);
request.responseType='arraybuffer';
// See https://javascript.info/xmlhttprequest
request.onload=function() {
context.decodeAudioData(request.response,function(decodedData) {
bufferList[i]=decodedData;
countIn(i);
});
};
request.onerror=function() {
console.log('Problem detected >>> loading audio file from origin server instead.');
var cdn="https://mynoise.world";
if (url.indexOf(cdn)>-1) {
url=url.substring(cdn.length);
loadWebAudioSound(url,i); // load from one.com
}
};
request.onprogress=function(event) {
// ++ throttling every xxxms
if (!this.NextSecond) this.NextSecond=0;
if (Date.now()<this.NextSecond) return;
this.NextSecond=Date.now()+dlMonitorThrottle;
if (dlMonitorThrottle<1000) dlMonitorThrottle++;
// ++
dlMonitor(i,event,request,url);
};
bDOWNLOADED[i]=0;
iSTARTED[i]=Date.now();
request.send();
}
function resumeContext() {
if (bSUSPENDED==1) {
// we deliberately suspended the context
bSUSPENDED=0;
context.resume();
if ("mediaSession" in navigator) navigator.mediaSession.playbackState="playing";
$("#mute").unbind("click");
$("#mute").click(toggleMute);
nowPlaying();
}
else {
// the context could be already running, or be suspended against our will (like phone lock-screen)
if (context.state !== 'running') context.resume();
}
console.log("Audio Engine: resumed");
}
function nowPlaying() {
if (bCALIBRATE==0) {
msg("Now Playing...");
} else {
msg("1. Turn up your computer volume until you hear the static 2. Adjust each slider individually.");
}
enableButton(["reset","anim","volDown","volUp","mute","fftCanvas","timer","bell","calib","play0","play1","play2","play3","play4","play5","play6","play7","play8","play9"],1);
if (bCALIBRATE==0) {
document.getElementById("mute").style.display="none";
document.getElementById("fftCanvas").style.display="block";
}
enableSliders();}
function loadAllSounds() {
for (let i=0; i<iNUMBERBANDS; ++i) {
loadWebAudioSound(sourceFileA[i],i);
}
for (let i=0; i<iNUMBERBANDS; ++i) {
loadWebAudioSound(sourceFileB[i],i+iNUMBERBANDS);
}
}
function playAllSounds() {
for (let i=0; i<iNUMBERBANDS; ++i) {
startWebAudio(i);
}
}
function playOS(stem){
var colorTable=["100,50,0","200,0,0","255,128,0","150,190,0","0,200,0","0,200,170","0,140,220","0,0,255","140,0,170","200,140,255"];
var duration=0;
playbackFactor[stem]= pitchTable[Math.floor(Math.random() * pitchTable.length)]
if (lastPlayedOS[stem]) {
webAudioPlayBAt(stem,context.currentTime);
duration=sourceB[stem].buffer.duration;
msg($('#s'+stem).attr('aria-label')+' • A • '+playbackFactor[stem]);
}
else {
webAudioPlayAAt(stem,context.currentTime);
duration=sourceA[stem].buffer.duration;
msg($('#s'+stem).attr('aria-label')+' • B • '+playbackFactor[stem]);
}
lastPlayedOS[stem]=1-lastPlayedOS[stem];
$("#play"+stem).css('background', 'rgb('+colorTable[stem]+')');
clearTimeout(timeOutOS[stem]);
timeOutOS[stem]=setTimeout(function(){
$("#play"+stem).css('background', 'rgba(0,0,0,0)');
if (bOSAUTO) { playOS(Math.floor(Math.random()*10)); }
},duration*1000/playbackFactor[stem]);
}
function experimentalPitchRandom(){
bPITCHRAN++;
if (bPITCHRAN==7) bPITCHRAN=0;
switch(bPITCHRAN){
case 0: pitchTable=[1]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 1: pitchTable=[0.5]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 2: pitchTable=[2]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 3: pitchTable=[0.5,1]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 4: pitchTable=[0.5,1,2]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 5: pitchTable=[0.5,1,1.5]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 6: pitchTable=[0.5,1,1.5,2]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
case 7: pitchTable=[0.5,0.75,1,1.5,2]; msg('<span class="lowlight">'+pitchTable.toString().replace(/,/g,' ')+'</span>'); break;
}
}
function experimentalOSauto(){
bOSAUTO=1-bOSAUTO;
if (bOSAUTO) msg('[Auto Play] ON'); else msg('[Auto Play] OFF');
}
function startWebAudio(i) {
if (stretch[i]==0) sourceA[i].loop=1;
nextA[i]=Math.ceil(context.currentTime);
// take duration of the leader of the sync group
const j=sSYNCHRO.indexOf(sSYNCHRO.charAt(i));
nextB[i]=nextA[i]+Math.round(sourceA[j].buffer.duration*10)/20*stretch[j]/playbackFactor[j];
sourceA[i].start(nextA[i]);
lastPlayedA[i]=nextA[i];
if (stretch[i]!=0) {
webAudioPlayBAt(i,nextB[i]);
lastPlayedB[i]=nextB[i];
} else {
sourceB[i].loop=1;
sourceB[i].playbackRate.value=playbackFactor[i];
sourceB[i].start(nextA[i]);
lastPlayedB[i]=nextA[i];
}
}
function computeIntervals(){
// stems repeat every ((A+B)/2)*stretch and B starts after A/2*stretch - see doc.
var durA, durB;
for (var i = 0; i < iNUMBERBANDS; ++i) {
// buffer durations vary across browsers! Critical for sync gens, rounding off to 16th note
durA=Math.round(sourceA[i].buffer.duration*8)/8;
durB=Math.round(sourceB[i].buffer.duration*8)/8;
interval[i]=(durA+durB)/2*stretch[i]/playbackFactor[i];
}
}
function webAudioPlayAAt(item,onContextTime){
// console.log('A@ '+context.currentTime+' for '+onContextTime+' on stem '+item);
if (item==sSYNCHRO.indexOf(sSYNCHRO.charAt(item))) { // this is the first occurrence of the Sync group
nextB[item]+=interval[item];
sourceB[item].onended=function(){webAudioPlayBAt(item,nextB[item])};
// This one and all others (sync)
for (var i = sSYNCHRO.indexOf(sSYNCHRO.charAt(item)); i < iNUMBERBANDS; ++i) {
if (sSYNCHRO.charAt(item)==sSYNCHRO.charAt(i)) { // belongs to the same group
sourceA[i].disconnect(0); // canary crashed with sourceA[i].noteOff(0);
sourceA[i] = context.createBufferSource();
sourceA[i].buffer = bufferList[i];
sourceA[i].playbackRate.value=playbackFactor[i];
if ((bCALIBRATE==1)&&(i!=movedSlider)&&(movedSlider>-1)) gainNode[i].gain.setTargetAtTime(0,context.currentTime,0);
sourceA[i].connect(gainNode[i]);
if (bWAVEVISUALIZER) sourceA[i].connect(stemAnalyser[i]);
sourceA[i].start(onContextTime);
lastPlayedA[i]=onContextTime;
}
}
}
monitor();}
function webAudioPlayBAt(item,onContextTime){
// console.log('B@ '+context.currentTime+' for '+onContextTime+' on stem '+item);
if (item==sSYNCHRO.indexOf(sSYNCHRO.charAt(item))) { // this is the first occurrence of the Sync group.
nextA[item]+=interval[item];
sourceA[item].onended=function(){webAudioPlayAAt(item,nextA[item])};
// This one and all others (sync)
for (var i = sSYNCHRO.indexOf(sSYNCHRO.charAt(item)); i < iNUMBERBANDS; ++i) {
if (sSYNCHRO.charAt(item)==sSYNCHRO.charAt(i)) { // belongs to the same group
sourceB[i].disconnect(0); // canary crashed with sourceB[i].noteOff(0);
sourceB[i] = context.createBufferSource();
sourceB[i].buffer = bufferList[i+iNUMBERBANDS];
sourceB[i].playbackRate.value=playbackFactor[i];
if ((bCALIBRATE==1)&&(i!=movedSlider)&&(movedSlider>-1)) gainNode[i].gain.setTargetAtTime(0,context.currentTime,0);
sourceB[i].connect(gainNode[i]);
if (bWAVEVISUALIZER) sourceB[i].connect(stemAnalyser[i]);
sourceB[i].start(onContextTime);
lastPlayedB[i]=onContextTime;
}
}
}
monitor();}
function playBell() {
// using simple html5 audio
if (meditationBell.paused&&!bMUTE) {
meditationBell.volume=Math.max(0.1,averageSliderLevel);
meditationBell.play();
}
}
function stemDrop() {
var i=Math.floor(Math.random(1)*10);
console.log("Dropping stem "+i);
sourceA[i].disconnect(0);
sourceB[i].disconnect(0);
}
function countIn(index) {
bDOWNLOADED[index]=1;
var str="";
for (var i=0; i<2*iNUMBERBANDS; ++i) if (bDOWNLOADED[i]) str=str+"+"; else str=str+"-";
if (++launchCounter==iNUMBERBANDS*2) finishedLoading();
else {
var percent=Math.round(launchCounter/20*100);
var str="<span style='color:#EEE;'>"
+"•".repeat(launchCounter)
+"</span>"+percent+"% <span style='color:#777;'>"
+"•".repeat(Math.max(0,20-launchCounter))
+"</span>";
msg("Greasing Sliders "+str);
}
}
function dlMonitor(index,report,initiator,url) {
var grandTotal=0;
var loaded=0;
// restart if stalled
var timeOut=10000; // 10s
if (((Date.now()-iSTARTED[index])>timeOut)&&(iLOADED[index]==report.loaded)) {
// stalled
console.log(index+" TIME OUT");
initiator.abort();
loadWebAudioSound(url,index);
} else {
if (report.lengthComputable) { // myNoise Servers should return Content-Length
iTOTAL[index]=report.total;
iLOADED[index]=report.loaded;
// compute grand total
for (var i=0; i<2*iNUMBERBANDS; ++i) {
if (iTOTAL[i]) { grandTotal+=iTOTAL[i]; loaded+=iLOADED[i]; }
}
if (grandTotal>serverTotal) serverTotal=grandTotal;
var loadedMB=Math.floor(loaded/1048576);
var grandTotalMB=Math.floor(grandTotal/1048576);
var serverTotalMB=Math.floor(serverTotal/1048576);
var percent=serverTotal?Math.round(loaded/serverTotal*100):0;
var str="<span style='color:#EEE;'>"
+"•".repeat(loadedMB)
+"</span>"+percent+"% <span style='color:#777;'>"
+"•".repeat(Math.max(0,grandTotalMB-loadedMB))
+"</span><span style='color:#333;'>"
+"•".repeat(Math.max(0,serverTotalMB-grandTotalMB))
+"</span>";
document.getElementById("bgimage").style.opacity=percent/100;
msg("Loading "+str);
}
}
}
function monitor() {
const currentTime=context.currentTime;
for (let i=0; i<iNUMBERBANDS; ++i) {
if (interval[i]>0) {
const elapsed=Math.min(currentTime-lastPlayedA[i],currentTime-lastPlayedB[i]);
if (elapsed>(interval[i]*1.01)) {
console.log("Stem "+i+" was lost. Now restarting.");
lastPlayedA[i]=currentTime;
lastPlayedB[i]=currentTime;
restartWebAudio(i);
}
}
}
}
function restartWebAudio(i) {
sourceA[i].onended=null;
sourceB[i].onended=null;
sourceA[i].disconnect(0);
sourceB[i].disconnect(0);
sourceA[i]=context.createBufferSource();
sourceA[i].buffer=bufferList[i];
sourceA[i].playbackRate.value=playbackFactor[i];
sourceA[i].connect(gainNode[i]);
sourceB[i]=context.createBufferSource();
sourceB[i].buffer=bufferList[i+iNUMBERBANDS];
sourceB[i].playbackRate.value=playbackFactor[i];
sourceB[i].connect(gainNode[i]);
startWebAudio(i);
}
function killWebAudio() {
context.close();
for (let i=0; i<iNUMBERBANDS; ++i) {
sourceA[i].disconnect(0); sourceB[i].disconnect(0);
sourceA[i]=null; sourceB[i]=null;
bufferList[i]=null; bufferList[i+iNUMBERBANDS]=null;
gainNode[i].disconnect();
gainNode[i]=null;
}
bufferList=null; gainNode=null; sourceA=null; sourceB=null;
}
var bDynamics=1;
function deactivateDynCompressor(){
if (bDynamics){
dynCompressor.disconnect(context.destination);
mergerNode.disconnect(dynCompressor);
mergerNode.connect(context.destination);
msg('[Dynamic Compressor] Bypassed');
bDynamics=0;
masterGain.gain.value=fMASTERGAIN;
}
else {
mergerNode.disconnect(context.destination);
mergerNode.connect(dynCompressor);
dynCompressor.connect(context.destination);
msg('[Dynamic Compressor] Activated');
bDynamics=1;
masterGain.gain.value=0.5;
}
}
// INIT
var launchCounter=0;
function init() {
// initializing jQuery sliders
for (let i=0; i<iNUMBERBANDS; ++i) {
$("#s"+i).slider({
orientation:"vertical",
range:"min",
min:0,
max:0.99,
value:0,
step:0.001,
animate:"slow",
slide:function(event,ui){sliderChange(event.target.id);},
change:function(event,ui){sliderChange(event.target.id);}
});
}
// Redirect if cookies not enabled
if (!navigator.cookieEnabled) { window.location.href="/showMessage.php?msgID=4"; }
// Check audio file compatibility
var a=document.createElement("audio");
if (!!(a.canPlayType&&a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/,""))){ bSUPPORTOGG=1; serverTotal=totSizeOGG; }
if (!!(a.canPlayType&&a.canPlayType("audio/mpeg;").replace(/no/,""))){ bSUPPORTMP3=1; }
// Check and initialize Web Audio API
const AC=window.AudioContext||window.webkitAudioContext;
if (!AC) {
msg('<span style="color:red">ERROR : Web Audio API not found.</span> Switch to a modern browser.');
console.log("Cannot initialize the audio engine. Web Audio API required.");
return;
}
context=new AC();
console.log("Web Audio [mynoise.world]");
console.log(navigator.userAgent);
tmp=readCookie("LVL");
if (tmp!=null) {
if (tmp==1) fTARGETSLIDERLEVEL=0.33;
if (tmp==2) fTARGETSLIDERLEVEL=0.5;
if (tmp==3) fTARGETSLIDERLEVEL=0.66;
}
initTuning();
msg("... now loading ...");
assignSources();
enableButton(["reset","anim","volDown","volUp","mute","fftCanvas","timer","bell","calib","play0","play1","play2","play3","play4","play5","play6","play7","play8","play9"],0);
disableSliders();
checkFavGen(); // Highlight Fav icon
loadAllSounds();
setPreset(0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3);
if (!bANIMATIONUSERPROFILESET) {
for (let i=0; i<iNUMBERBANDS; ++i) {
animationProfileHigh[i]=Math.min(currentLevel[i]*1.25,0.99);
animationProfileLow[i]=currentLevel[i]*0.5;
}
}
// migrateCookies();
}
function finishedLoading() {
masterGain=context.createGain();
masterGain.gain.value=0.5;
// Compatibilty with mono files
for (let i=0; i<bufferList.length; i++) {
const buf=bufferList[i];
// if mono buffer, duplicate as stereo
if (buf&&buf.numberOfChannels===1) {
const stereo=context.createBuffer(2,buf.length,buf.sampleRate);
const mono=buf.getChannelData(0);
stereo.copyToChannel(mono,0);
stereo.copyToChannel(mono,1);
bufferList[i]=stereo;
}
}
function makeSource(buffer,rate) {
const src=context.createBufferSource();
src.buffer=buffer; // let Web Audio up-mix mono automatically
src.playbackRate.value=rate;
// src.loop=true; src.loopStart=...; src.loopEnd=...; // if needed
return src;
}
for (let i=0; i<iNUMBERBANDS; i++) {
sourceA[i]=makeSource(bufferList[i],playbackFactor[i]);
gainNode[i]=context.createGain();
gainNode[i].gain.value=0;
sourceA[i].connect(gainNode[i]).connect(masterGain);
}
for (let i=0; i<iNUMBERBANDS; i++) {
sourceB[i]=makeSource(bufferList[i+iNUMBERBANDS],playbackFactor[i]);;
sourceB[i].connect(gainNode[i]).connect(masterGain);
}
// add mastering compressor
dynCompressor=new DynamicsCompressorNode(context, {
// working as a limiter
threshold: -12,
knee: 6,
ratio: 10,
attack: 0.05,
release: 2
});
dynCompressor.connect(context.destination);
// add the MS coding/decoding part for width
splitterNode=context.createChannelSplitter(2); // splits stereo into L and R
mergerNode=context.createChannelMerger(2,2);
midGain=context.createGain();
sideGain=context.createGain();
inverterGain=context.createGain();
inverterGain.gain.value=-1;
inverteedSide=context.createGain();
inverteedSide.gain.value=-1;
if (bCALIBRATE==0) {
masterGain.connect(splitterNode);
// Connect splitterNode to mid and side gain nodes
splitterNode.connect(midGain,0); // Left channel -> Mid
splitterNode.connect(midGain,1); // Right channel -> Mid
// Connect splitterNode to mid and side gain nodes
splitterNode.connect(sideGain,0); // Left channel -> Side
splitterNode.connect(inverterGain,1); // Minus Right -> Side-
inverterGain.connect(sideGain);
sideGain.connect(inverteedSide);
// Connect mid and side gain nodes to mergerNode
midGain.connect(mergerNode,0,0); // Mid -> Left
midGain.connect(mergerNode,0,1); // Mid -> Right
sideGain.connect(mergerNode,0,0); // Side -> Left
inverteedSide.connect(mergerNode,0,1); // Inverted Side -> Right
// Connect mergerNode to context.destination
mergerNode.connect(dynCompressor);
} else masterGain.connect(dynCompressor);
computeIntervals();
getCurrentLevelsFromSliders();
updateDocumentLinks();
playAllSounds();setAllLevels();
bFINISHEDLOADING=1;
// SuperGens - Calling Parent Function
if (window.parent!=window) window.parent.count();
// Visualizer - Experimental
if (bCALIBRATE==0) {
var analyser=context.createAnalyser();
analyser.fftSize=32;
analyser.smoothingTimeConstant=0;
mergerNode.connect(analyser);
var fftData=new Float32Array(analyser.frequencyBinCount);
var c=document.getElementById("fftCanvas");
var ctx=c.getContext("2d");
var pos=[0,0,0,0];
var posOld=[0,0,0,0];
const WARMUP_MS = 2000;
const startTs = performance.now();
function updatefftData() {
setTimeout(function(){ // throttle requestAnimationFrame
requestAnimationFrame(updatefftData);
},100);
analyser.getFloatFrequencyData(fftData);
pos[0]=(fftData[0]+75)/2;
pos[1]=(Math.max(fftData[2],fftData[3])+77)/2;
pos[2]=(Math.max(fftData[5],fftData[6],fftData[7])+81)/2;
pos[3]=(Math.max(fftData[9],fftData[10],fftData[11],fftData[12],fftData[13],fftData[14],fftData[15])+89)/2;
let gainReduction = (dynCompressor && typeof dynCompressor.reduction === "number")
? -dynCompressor.reduction
: 0;
const now = performance.now();
let inWarmup = (now - startTs) < WARMUP_MS;
if (inWarmup==1) gainReduction=0;
const distortedGain=3; //db - highlights fully red
let t=gainReduction/distortedGain;
if (t<0) t=0;
if (t>1) t=1;
let r=Math.round(255*t);
let g=0;
let b=0;
let color="rgb(" + r + "," + g + "," + b + ")";
ctx.beginPath();
ctx.rect(0,0,c.width,c.height);
ctx.fillStyle="#eee";
ctx.fill();
ctx.closePath();
var order=[3,1,0,2];
for (var j=0; j<4; ++j) {
i=order[j];
if (pos[i]>posOld[i]) posOld[i]=pos[i]; else posOld[i]--;
if (posOld[i]<0) posOld[i]=0;
if (posOld[i]>15) posOld[i]=15;
ctx.beginPath();
ctx.rect(9+j*5,(c.height-posOld[i]-10),2,posOld[i]);
ctx.fillStyle=color;
ctx.fill();
ctx.closePath();
}
// individual levels
if (bWAVEVISUALIZER) {
for (var i=0; i<iNUMBERBANDS; ++i) {
stemAnalyser[i].getByteTimeDomainData(samplesArray);
var nrg=0;
for (var k=0; k<stemAnalyser[i].frequencyBinCount; ++k) {
var sample=(samplesArray[k]-128);
nrg+=(sample*sample);
}
nrg=nrg/(128*128);
var pixels=13-10*Math.pow(nrg,0.5);
pixels=Math.max(pixels,4);
document.getElementById("s"+i).lastChild.style.boxShadow="inset 0 0 0 "+pixels+"px rgb(25,27,29)";
}
}
}
updatefftData();
}
// Load GLOBAL parameter settings (if exist)
// iEQ auto start for patrons
tmp=readCookie("IEQ");
if (tmp!=null) emphasisEQ(parseFloat(tmp));
// Stereo Width auto start for patrons
tmp=readCookie("WID");
if (tmp!=null) {
if (tmp==1) setStereoWidth(0);
if (tmp==2) setStereoWidth(0.5);
if (tmp==3) setStereoWidth(1);
if (tmp==4) setStereoWidth(1.8);
}
// Load URL parameter settings
var args=getUrlVars();
loadURLsettings(args);
// wheel events
document.getElementById("s0").addEventListener("wheel",function(e){wheeLvl(0,e);});
document.getElementById("s1").addEventListener("wheel",function(e){wheeLvl(1,e);});
document.getElementById("s2").addEventListener("wheel",function(e){wheeLvl(2,e);});
document.getElementById("s3").addEventListener("wheel",function(e){wheeLvl(3,e);});
document.getElementById("s4").addEventListener("wheel",function(e){wheeLvl(4,e);});
document.getElementById("s5").addEventListener("wheel",function(e){wheeLvl(5,e);});
document.getElementById("s6").addEventListener("wheel",function(e){wheeLvl(6,e);});
document.getElementById("s7").addEventListener("wheel",function(e){wheeLvl(7,e);});
document.getElementById("s8").addEventListener("wheel",function(e){wheeLvl(8,e);});
document.getElementById("s9").addEventListener("wheel",function(e){wheeLvl(9,e);});
$("#bgimage").addClass("animated");
sliderOpacity();
addMediaSession();
// Suspended Policy by Mobile Browsers and Chrome!
msg("Hit Play or allow Auto-Play for myNoise.net in your browser settings.");
if (context.state=="suspended") {
// bug mobile safari - context can be suspended, and sounds playing!
// so we need to force suspend even if suspended is detected.
context.suspend();
if ("mediaSession" in navigator) navigator.mediaSession.playbackState="paused";
bSUSPENDED=1;
enableButton(["mute"],1);
$("#mute").click(resumeContext);
console.log("This browser doesn't trust myNoise and has suspended the audio context.");
} else {
$("#mute").click(toggleMute);
}
// Enable Buttons
if (!bSUSPENDED) nowPlaying();
// Timer Gens
if (bSTARTMUTED==1) forceMute(1);
}
function waveVisualizer() {
bWAVEVISUALIZER=1-bWAVEVISUALIZER;
if (bWAVEVISUALIZER) {
msg("Visualizer ON [V]");
for (let i=0; i<iNUMBERBANDS; ++i) {
if (!stemAnalyser[i]) {
stemAnalyser[i]=context.createAnalyser();
stemAnalyser[i].fftSize=512;
if (i==0) samplesArray=new Uint8Array(stemAnalyser[i].frequencyBinCount); // create once
}
sourceA[i].connect(stemAnalyser[i]);
sourceB[i].connect(stemAnalyser[i]);
}
} else {
msg("Visualizer OFF [V]");
for (let i=0; i<iNUMBERBANDS; ++i) {
document.getElementById("s"+i).lastChild.style.boxShadow="inset 0 0 0 4px rgb(25,27,29)";
}
for (let i=0; i<iNUMBERBANDS; ++i) {
sourceA[i].disconnect(stemAnalyser[i]);
sourceB[i].disconnect(stemAnalyser[i]);
}
}
}
function wheeLvl(i,e) {
e.preventDefault();
let offset=-e.deltaY/1000;
currentLevel[i]=Math.max(0,Math.min(0.99,currentLevel[i]+offset));
savedLevel[i]=Math.max(0,Math.min(0.99,currentLevel[i]+offset));
randomCounter=0; // anim
$("#s"+i).slider("value",currentLevel[i]);
}
function pad(num) {
let s="000"+num;