-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadaptive-white-noise-v2.html
More file actions
2691 lines (2346 loc) · 119 KB
/
adaptive-white-noise-v2.html
File metadata and controls
2691 lines (2346 loc) · 119 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>
<!--
═══════════════════════════════════════════════════════════════════════
Adaptive White Noise Application
Copyright (C) 2025 Sarah Bass [Pseudonym: Evilegi]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 1 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see https://www.gnu.org/licenses/
═══════════════════════════════════════════════════════════════════════
NETWORK USE NOTICE (AGPL Requirement):
If you modify this program and let users interact with it remotely
through a computer network, you MUST provide them with a way to
download the complete source code of your modified version.
This can be as simple as:
- A "View Source" or "Download Source" link in your app
- A link to your GitHub repository with the modified code
- Offering the source code upon request
This ensures the software remains free for everyone.
═══════════════════════════════════════════════════════════════════════
Source Code: https://github.com/YOUR_USERNAME/adaptive-white-noise
Key Features & Innovations:
• Real-time adaptive noise detection with multiple intensity levels
• Natural sound recordings (rain, ocean, stream) with quality selection
• Synthesized adaptive noise that switches colors based on ambient noise
• Customizable thresholds and transition speeds
• Flexible sleep timer with favorites
• Custom day/night theme backgrounds
• Single-file architecture for maximum portability
═══════════════════════════════════════════════════════════════════════
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adaptive White Noise</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
padding: 20px;
transition: background 0.3s ease;
position: relative;
}
/* Custom background overlay for user images */
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: var(--day-bg, none);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
opacity: 0;
transition: opacity 0.5s ease;
z-index: -1;
}
body.has-light-bg::before {
opacity: 1;
}
body::after {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: var(--night-bg, none);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
opacity: 0;
transition: opacity 0.5s ease;
z-index: -1;
}
body.dark-theme::before {
opacity: 0;
}
body.dark-theme.has-dark-bg::after {
opacity: 1;
}
body.dark-theme {
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.bg-customization-row {
display: flex;
gap: 15px;
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.bg-preview-container {
flex: 1;
text-align: center;
}
.bg-preview-label {
font-size: 0.85em;
opacity: 0.8;
margin-bottom: 8px;
display: block;
}
.bg-thumbnail {
width: 100%;
height: 100px;
border-radius: 8px;
border: 2px solid rgba(255, 255, 255, 0.3);
position: relative;
overflow: hidden;
cursor: pointer;
transition: all 0.3s ease;
background: rgba(255, 255, 255, 0.1);
}
.bg-thumbnail:hover {
border-color: rgba(102, 126, 234, 0.8);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.bg-thumbnail-preview {
width: 100%;
height: 100%;
object-fit: cover;
display: none;
}
.bg-thumbnail-preview.active {
display: block;
}
.bg-thumbnail-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 2em;
opacity: 0.5;
}
.bg-edit-icon {
position: absolute;
top: 8px;
right: 8px;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(5px);
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1em;
transition: all 0.2s;
}
.bg-thumbnail:hover .bg-edit-icon {
background: rgba(102, 126, 234, 0.9);
transform: scale(1.1);
}
.bg-clear-btn {
margin-top: 5px;
padding: 4px 8px;
background: rgba(245, 87, 108, 0.3);
border: 1px solid rgba(245, 87, 108, 0.5);
border-radius: 6px;
color: white;
cursor: pointer;
font-size: 0.75em;
transition: all 0.2s;
display: none;
}
.bg-clear-btn.active {
display: inline-block;
}
.bg-clear-btn:hover {
background: rgba(245, 87, 108, 0.5);
transform: translateY(-1px);
}
.bg-file-input {
display: none;
}
.theme-toggle {
position: fixed;
top: 20px;
right: 20px;
background: rgba(255, 255, 255, 0.2);
border: none;
border-radius: 50%;
width: 50px;
height: 50px;
cursor: pointer;
font-size: 1.5em;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.theme-toggle:hover {
background: rgba(255, 255, 255, 0.3);
transform: scale(1.1);
}
.container {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 40px;
max-width: 500px;
width: 100%;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
margin-bottom: 10px;
font-size: 2em;
}
.subtitle {
text-align: center;
opacity: 0.8;
margin-bottom: 30px;
font-size: 0.9em;
}
.main-button {
width: 100%;
padding: 20px;
font-size: 1.5em;
font-weight: bold;
border: none;
border-radius: 15px;
cursor: pointer;
transition: all 0.3s;
margin-bottom: 20px;
}
.main-button.start {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.main-button.stop {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
color: white;
}
.main-button:hover {
transform: scale(1.05);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}
.status-panel {
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
}
.status-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.status-row:last-child {
border-bottom: none;
}
.status-label {
font-weight: 600;
opacity: 0.8;
}
.status-value {
font-weight: bold;
font-size: 1.1em;
}
#noiseType {
padding: 4px 12px;
border-radius: 12px;
font-size: 0.95em;
}
#noiseType.white {
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
color: #3730a3;
}
#noiseType.green {
background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
color: #065f46;
}
#noiseType.pink {
background: linear-gradient(135deg, #fce7f3 0%, #fbcfe8 100%);
color: #9f1239;
}
#noiseType.brown {
background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
color: #92400e;
}
.noise-meter {
height: 10px;
background: linear-gradient(to right,
#a7f3d0 0%, #a7f3d0 15%, /* White/Green zone */
#fdba74 15%, #fdba74 60%, /* Brown zone */
#fbcfe8 60%, #fbcfe8 100%); /* Pink zone */
border-radius: 5px;
overflow: hidden;
margin-top: 5px;
position: relative;
}
.noise-level {
height: 100%;
background: rgba(255, 255, 255, 0.9);
transition: width 0.3s;
border-radius: 5px;
box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}
.settings-panel {
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
padding: 20px;
}
.setting-row {
margin-bottom: 15px;
}
.setting-row:last-child {
margin-bottom: 0;
}
.setting-label {
display: block;
margin-bottom: 8px;
font-weight: 600;
opacity: 0.9;
}
input[type="range"] {
width: 100%;
height: 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.3);
outline: none;
-webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: white;
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 20px;
height: 20px;
border-radius: 50%;
background: white;
cursor: pointer;
border: none;
}
select {
width: 100%;
padding: 10px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.2);
color: white;
border: 1px solid rgba(255, 255, 255, 0.3);
font-size: 1em;
cursor: pointer;
outline: none;
}
select option {
background: #1e3c72;
color: white;
}
body.dark-theme select option {
background: #0f172a;
}
.sound-library-toggle {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 1em;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
.sound-library-toggle:hover {
transform: scale(1.02);
box-shadow: 0 5px 15px rgba(139, 92, 246, 0.3);
}
.sound-library-panel {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out;
margin-top: 0;
}
.sound-library-panel.open {
max-height: 600px;
margin-top: 15px;
}
.sound-color-section {
background: rgba(0, 0, 0, 0.2);
border-radius: 8px;
padding: 12px;
margin-bottom: 10px;
display: grid;
grid-template-columns: 120px 1fr auto;
gap: 10px;
align-items: center;
}
.sound-color-label {
font-weight: 600;
font-size: 0.9em;
}
.sound-variant-select {
padding: 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.15);
color: white;
border: 1px solid rgba(255, 255, 255, 0.2);
font-size: 0.9em;
cursor: pointer;
}
.preview-btn {
padding: 8px 15px;
background: rgba(255, 255, 255, 0.2);
color: white;
border: none;
border-radius: 6px;
font-size: 0.85em;
cursor: pointer;
transition: all 0.2s;
white-space: nowrap;
}
.preview-btn:hover {
background: rgba(255, 255, 255, 0.3);
}
.preview-btn.playing {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
.log-panel {
background: rgba(0, 0, 0, 0.4);
border-radius: 10px;
padding: 15px;
margin-top: 20px;
max-height: 150px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 0.85em;
}
.log-entry {
padding: 5px 0;
opacity: 0.8;
}
.log-entry.highlight {
color: #fbbf24;
font-weight: bold;
opacity: 1;
}
.info-text {
text-align: center;
opacity: 0.7;
font-size: 0.85em;
margin-top: 20px;
line-height: 1.6;
}
@keyframes flash {
0%, 100% { background-color: rgba(255, 255, 255, 0.1); }
50% { background-color: rgba(102, 126, 234, 0.4); }
}
.settings-panel.flash {
animation: flash 0.5s ease-in-out;
}
</style>
</head>
<body>
<button class="theme-toggle" id="themeToggle" title="Toggle dark/light theme">🌙</button>
<div class="container">
<h1>🌊 Adaptive White Noise</h1>
<p class="subtitle">Set it and sleep - automatically adjusts to mask noise</p>
<button class="main-button start" id="toggleBtn">Start Adaptive Mode</button>
<div class="status-panel">
<div class="status-row">
<span class="status-label">Status:</span>
<span class="status-value" id="status">Idle</span>
</div>
<div class="status-row">
<span class="status-label">Ambient Noise:</span>
<span class="status-value" id="ambientLevel">0</span>
<span style="font-size: 0.8em; opacity: 0.7; margin-left: 8px;">(Raw: <span id="rawLevel">0</span>)</span>
</div>
<div class="noise-meter">
<div class="noise-level" id="noiseMeter" style="width: 0%"></div>
</div>
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px; display: flex; justify-content: space-between;">
<span>0</span>
<span style="color: #a7f3d0;">15</span>
<span style="color: #fdba74;">Brown</span>
<span style="color: #fbcfe8;">60</span>
<span>100+</span>
</div>
<div class="status-row">
<span class="status-label">Output Volume:</span>
<span class="status-value" id="outputVolume">20%</span>
</div>
<div class="status-row">
<span class="status-label">Noise Type:</span>
<span class="status-value white" id="noiseType">White</span>
</div>
</div>
<div class="settings-panel">
<div class="setting-row">
<label class="setting-label">Baseline Volume: <span id="baselineValue">20%</span></label>
<input type="range" id="baselineVolume" min="5" max="60" value="20">
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">🎵 Sound Theme</label>
<select id="soundThemeSelect" style="width: 100%; padding: 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.1); color: white; border: 1px solid rgba(255, 255, 255, 0.2); font-size: 1em; cursor: pointer; margin-bottom: 10px;">
<option value="adaptive-noise">🌈 Adaptive Noise (White/Green/Brown/Pink)</option>
<option value="rain">🌧️ Rain - Natural rain recordings</option>
<option value="ocean">🌊 Ocean - Natural wave recordings</option>
<option value="stream">💧 Stream - Natural water recordings</option>
</select>
<button id="previewThemeBtn" style="width: 100%; padding: 12px; background: rgba(255, 255, 255, 0.2); color: white; border: none; border-radius: 8px; font-size: 1em; cursor: pointer; transition: all 0.2s;">
▶️ Preview Theme (plays all 3 intensities)
</button>
<div id="themeInfo" style="font-size: 0.85em; opacity: 0.8; margin-top: 10px; text-align: center; line-height: 1.6;">
<strong>Adaptive Noise:</strong> Synthesized noise that switches colors (White/Green/Brown/Pink) based on ambient noise type
</div>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">⏰ Sleep Timer</label>
<div id="timerFavorites" style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;">
<!-- Timer favorite buttons will be added here -->
</div>
<div id="timerStatus" style="font-size: 0.85em; opacity: 0.8; margin-top: 10px; text-align: center; display: none;">
⏰ Auto-stop in: <span id="timerRemaining">--:--</span>
</div>
</div>
<!-- Advanced Settings Toggle Button -->
<button id="advancedSettingsToggle" style="width: 100%; padding: 15px; margin-top: 20px; background: rgba(255, 255, 255, 0.15); color: white; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 10px; font-size: 1em; cursor: pointer; transition: all 0.3s; display: flex; align-items: center; justify-content: center; gap: 10px;">
<span>⚙️ Advanced Settings</span>
<span id="advancedSettingsArrow" style="transition: transform 0.3s;">▼</span>
</button>
<!-- Advanced Settings Panel (Hidden by default) -->
<div id="advancedSettingsPanel" style="max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out;">
<div style="padding-top: 15px;">
<div class="setting-row">
<label class="setting-label">Sensitivity: <span id="sensitivityValue">Medium</span></label>
<input type="range" id="sensitivity" min="1" max="3" value="2">
<div style="font-size: 0.8em; opacity: 0.7; margin-top: 5px; line-height: 1.4;">
Controls minimum ambient noise level to start reacting<br>
Low: Reacts at 50+ | Medium: Reacts at 35+ | High: Reacts at 25+<br>
<em style="opacity: 0.8;">Higher = more sensitive to quieter sounds</em>
</div>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">🎚️ Intensity Thresholds</label>
<div style="font-size: 0.85em; opacity: 0.7; margin-bottom: 12px; line-height: 1.5;">
Adjust when sounds switch between Light → Medium → Heavy
</div>
<div style="margin-bottom: 15px;">
<label class="setting-label" style="font-size: 0.9em;">Light → Medium at: <span id="threshold1Value">15</span></label>
<input type="range" id="threshold1" min="5" max="50" step="1" value="15" style="width: 100%;">
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px;">When to switch from quiet sounds to voice-masking</div>
</div>
<div style="margin-bottom: 5px;">
<label class="setting-label" style="font-size: 0.9em;">Medium → Heavy at: <span id="threshold2Value">60</span></label>
<input type="range" id="threshold2" min="30" max="100" step="5" value="60" style="width: 100%;">
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px;">When to switch to maximum intensity sounds</div>
</div>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">➕ Add Custom Timer</label>
<div style="background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; padding: 15px; margin-top: 10px;">
<div style="display: flex; justify-content: center; align-items: center; gap: 10px;">
<div style="text-align: center;">
<div style="font-size: 0.75em; color: #a7f3d0; margin-bottom: 5px;">hours</div>
<input type="number" id="timerHours" min="0" max="24" value="0" style="width: 60px; padding: 10px; font-size: 1.2em; text-align: center; background: rgba(0,0,0,0.3); color: white; border: 1px solid rgba(255,255,255,0.3); border-radius: 8px;">
</div>
<div style="font-size: 1.5em; opacity: 0.5; padding-top: 20px;">:</div>
<div style="text-align: center;">
<div style="font-size: 0.75em; color: #a7f3d0; margin-bottom: 5px;">minutes</div>
<input type="number" id="timerMinutes" min="0" max="59" value="0" style="width: 60px; padding: 10px; font-size: 1.2em; text-align: center; background: rgba(0,0,0,0.3); color: white; border: 1px solid rgba(255,255,255,0.3); border-radius: 8px;">
</div>
<button id="addTimerFavorite" style="margin-top: 20px; padding: 10px 20px; background: rgba(102, 126, 234, 0.4); color: white; border: 1px solid rgba(102, 126, 234, 0.8); border-radius: 8px; font-size: 0.9em; cursor: pointer; transition: all 0.2s;">
Add
</button>
</div>
</div>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">⚡ Transition Speed Controls</label>
<div style="font-size: 0.85em; opacity: 0.7; margin-bottom: 12px; line-height: 1.5;">
Control how quickly sounds adjust to noise changes
</div>
<div style="margin-bottom: 15px;">
<label class="setting-label" style="font-size: 0.9em;">Fade Up Speed: <span id="fadeUpValue">1.0s</span></label>
<input type="range" id="fadeUpSpeed" min="0.1" max="3.0" step="0.1" value="1.0" style="width: 100%;">
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px;">How fast sound increases when noise detected</div>
</div>
<div style="margin-bottom: 15px;">
<label class="setting-label" style="font-size: 0.9em;">Hold Duration: <span id="holdDurationValue">2.0s</span></label>
<input type="range" id="holdDuration" min="0.5" max="10.0" step="0.5" value="2.0" style="width: 100%;">
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px;">How long to stay at higher level before dropping</div>
</div>
<div style="margin-bottom: 5px;">
<label class="setting-label" style="font-size: 0.9em;">Fade Down Speed: <span id="fadeDownValue">3.0s</span></label>
<input type="range" id="fadeDownSpeed" min="0.5" max="10.0" step="0.5" value="3.0" style="width: 100%;">
<div style="font-size: 0.75em; opacity: 0.6; margin-top: 3px;">How fast sound decreases when noise stops</div>
</div>
</div>
<div class="setting-row" id="adaptiveNoiseSettings" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">Low Noise Type (for quiet environments)</label>
<select id="lowNoiseType" style="width: 100%; padding: 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.1); color: white; border: 1px solid rgba(255, 255, 255, 0.2); font-size: 1em; cursor: pointer;">
<option value="green">💚 Green Noise (softer, nature-like)</option>
<option value="white">🤍 White Noise (classic)</option>
</select>
<div style="font-size: 0.85em; opacity: 0.7; margin-top: 8px; text-align: center;">
Used when ambient noise is below threshold
</div>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label" style="font-size: 0.85em; opacity: 0.8;">
🌊 <strong>How Adaptive System Works:</strong><br>
<span style="font-size: 0.9em; font-weight: normal; line-height: 1.6;">
• <strong>Listens</strong> to ambient noise through your microphone<br>
• <strong>Adjusts</strong> volume and intensity automatically<br>
• <strong>Light</strong> (<threshold1) → <strong>Medium</strong> (threshold1-threshold2) → <strong>Heavy</strong> (threshold2+)<br>
<em style="opacity: 0.7;">Perfect for masking unwanted noise while you sleep!</em>
</span>
</label>
</div>
<div class="setting-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.1);">
<label class="setting-label">🖼️ Background Images</label>
<div style="font-size: 0.85em; opacity: 0.7; margin-bottom: 12px; line-height: 1.5;">
Customize backgrounds with your own images (pictures of loved ones, nature, etc.)
</div>
<div class="bg-customization-row">
<!-- Day Mode Background -->
<div class="bg-preview-container">
<span class="bg-preview-label">☀️ Day Mode</span>
<div class="bg-thumbnail" id="dayBgThumbnail">
<img class="bg-thumbnail-preview" id="dayBgPreview" alt="Day background">
<div class="bg-thumbnail-placeholder" id="dayBgPlaceholder">🌅</div>
<div class="bg-edit-icon">✏️</div>
</div>
<button class="bg-clear-btn" id="clearDayBg">Clear</button>
<input type="file" class="bg-file-input" id="dayBgInput" accept="image/*">
</div>
<!-- Night Mode Background -->
<div class="bg-preview-container">
<span class="bg-preview-label">🌙 Night Mode</span>
<div class="bg-thumbnail" id="nightBgThumbnail">
<img class="bg-thumbnail-preview" id="nightBgPreview" alt="Night background">
<div class="bg-thumbnail-placeholder" id="nightBgPlaceholder">🌌</div>
<div class="bg-edit-icon">✏️</div>
</div>
<button class="bg-clear-btn" id="clearNightBg">Clear</button>
<input type="file" class="bg-file-input" id="nightBgInput" accept="image/*">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="log-panel" id="logPanel">
<div class="log-entry">System ready. Click Start to begin monitoring.</div>
</div>
</div>
<script>
// Audio context and nodes
let audioContext = null;
let noiseNode = null;
let gainNode = null;
let filterNode = null;
let analyser = null;
let microphone = null;
let isRunning = false;
let animationFrame = null;
// Load preferences from localStorage
function loadPreferences() {
const saved = localStorage.getItem('adaptiveWhiteNoisePrefs');
if (saved) {
try {
return JSON.parse(saved);
} catch (e) {
return {};
}
}
return {};
}
// Save preferences to localStorage
function savePreferences() {
const prefs = {
baselineVolume: config.baselineVolume,
sensitivity: config.sensitivity,
lowNoiseType: config.lowNoiseType,
soundTheme: config.soundTheme,
sleepTimerMinutes: config.sleepTimerMinutes,
timerFavorites: config.timerFavorites,
fadeUpSpeed: config.fadeUpSpeed,
holdDuration: config.holdDuration,
fadeDownSpeed: config.fadeDownSpeed,
threshold1: config.threshold1,
threshold2: config.threshold2,
theme: document.body.classList.contains('dark-theme') ? 'dark' : 'light',
soundLibrary: config.soundLibrary,
dayModeBackground: config.dayModeBackground,
nightModeBackground: config.nightModeBackground
};
localStorage.setItem('adaptiveWhiteNoisePrefs', JSON.stringify(prefs));
}
// Load saved preferences
const savedPrefs = loadPreferences();
// Configuration
let config = {
baselineVolume: savedPrefs.baselineVolume || 0.2,
currentVolume: savedPrefs.baselineVolume || 0.2,
targetVolume: savedPrefs.baselineVolume || 0.2,
sensitivity: savedPrefs.sensitivity || 2, // 1=low, 2=medium, 3=high
noiseColor: 'green', // Current playing color: white, green, pink, brown
lowNoiseType: savedPrefs.lowNoiseType || 'green', // User's choice for low noise: white or green (DEFAULT: green)
lastColorSwitch: 0, // Timestamp of last color change
minVolume: 0.05,
maxVolume: 0.9,
volumeIncrement: 0.05,
volumeDecrement: 0.04,
smoothing: 0.1, // OPTIMIZED: Minimal smoothing for instant voice/noise detection (was 0.3)
fftSize: 1024, // OPTIMIZED: Faster response for voice detection (was 2048)
soundTheme: savedPrefs.soundTheme || 'adaptive-noise', // 'adaptive-noise', 'rain', 'ocean', 'wind'
currentIntensity: 'light', // Tracks current intensity for natural recordings
sleepTimerMinutes: savedPrefs.sleepTimerMinutes || 0, // Sleep timer in minutes (0 = no timer)
timerFavorites: savedPrefs.timerFavorites || [480, 20], // Default favorites: 8hr and 20min
fadeUpSpeed: savedPrefs.fadeUpSpeed || 1.0, // Seconds for fade up
holdDuration: savedPrefs.holdDuration || 2.0, // Seconds to hold at higher level
fadeDownSpeed: savedPrefs.fadeDownSpeed || 3.0, // Seconds for fade down
threshold1: savedPrefs.threshold1 || 15, // Light to Medium threshold
threshold2: savedPrefs.threshold2 || 60, // Medium to Heavy threshold
// Sound library preferences
soundLibrary: savedPrefs.soundLibrary || {
white: 'classic',
green: 'nature',
brown: 'deep',
pink: 'balanced',
rain: 'light',
ocean: 'gentle',
wind: 'breeze'
},
dayModeBackground: savedPrefs.dayModeBackground || null,
nightModeBackground: savedPrefs.nightModeBackground || null
};
// Audio recording URLs - Natural sound recordings
// Rain sounds are PERFECT from Mixkit - keeping these!
// Ocean & Wind now using Freesound.org previews
const audioLibrary = {
rain: {
light: 'https://assets.mixkit.co/active_storage/sfx/2393/2393-preview.mp3',
medium: 'https://assets.mixkit.co/active_storage/sfx/2394/2394-preview.mp3',
heavy: 'https://assets.mixkit.co/active_storage/sfx/2395/2395-preview.mp3'
},
ocean: {
// 🌊 MIXKIT OCEAN SOUNDS - Actual IDs from downloaded files!
light: 'https://assets.mixkit.co/active_storage/sfx/1208/1208-preview.mp3', // Small waves harbor rocks
medium: 'https://assets.mixkit.co/active_storage/sfx/1195/1195-preview.mp3', // Close sea waves loop
heavy: 'https://assets.mixkit.co/active_storage/sfx/1194/1194-preview.mp3' // Rough sea waves loop
},
stream: {
// 💧 MIXKIT STREAM/WATER SOUNDS - Actual IDs from downloaded files!
light: 'https://assets.mixkit.co/active_storage/sfx/1216/1216-preview.mp3', // River in the forest with birds
medium: 'https://assets.mixkit.co/active_storage/sfx/2454/2454-preview.mp3', // River water flowing
heavy: 'https://assets.mixkit.co/active_storage/sfx/2461/2461-preview.mp3' // Strong flowing waters noise
}
};
// Audio player for natural recordings - Uses Web Audio API for GAPLESS looping
class NaturalSoundPlayer {
constructor() {
this.audioBuffers = {}; // Stores decoded AudioBuffers
this.audioSources = {}; // Stores currently playing sources
this.gainNodes = {}; // Stores gain nodes for volume control
this.audioContext = null; // Web Audio context
this.currentTheme = null;
this.currentIntensity = null;
this.isLoaded = {};
this.fadeTime = 1.0; // SMOOTH: 1-second crossfade for seamless transitions
this.failedToLoad = {};
}
async preload(theme) {
if (this.isLoaded[theme]) {
log(`${theme} already loaded`, false);
return;
}
// Initialize AudioContext if not already done
if (!this.audioContext) {
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
log(`Loading ${theme} audio files...`, true);
this.audioBuffers[theme] = {};
this.audioSources[theme] = {};
this.gainNodes[theme] = {};
const loadResults = [];
for (const intensity of ['light', 'medium', 'heavy']) {
const url = audioLibrary[theme][intensity];
const loadPromise = (async () => {
try {
const timeout = new Promise((_, reject) =>
setTimeout(() => reject(new Error(`Timeout loading ${intensity} ${theme}`)), 15000)
);
const fetchPromise = fetch(url)
.then(response => {
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.arrayBuffer();
})
.then(arrayBuffer => this.audioContext.decodeAudioData(arrayBuffer));
const buffer = await Promise.race([fetchPromise, timeout]);
this.audioBuffers[theme][intensity] = buffer;
// Create a gain node for this intensity
this.gainNodes[theme][intensity] = this.audioContext.createGain();
this.gainNodes[theme][intensity].connect(this.audioContext.destination);
this.gainNodes[theme][intensity].gain.value = 0;
log(`✓ Loaded ${intensity} ${theme}`, false);
return { intensity, success: true };
} catch (error) {
log(`✗ Failed: ${intensity} ${theme} - ${error.message}`, true);
return { intensity, success: false, error: error.message };
}
})();
loadResults.push(loadPromise);
}
const results = await Promise.all(loadResults);
const failedCount = results.filter(r => !r.success).length;
if (failedCount === 3) {
this.failedToLoad[theme] = true;
throw new Error(`All ${theme} audio files failed to load. Check your internet connection or try a different browser.`);
} else if (failedCount > 0) {
log(`⚠️ ${failedCount}/3 ${theme} files failed to load`, true);
this.failedToLoad[theme] = false;
} else {
log(`✅ All ${theme} files ready!`, true);
this.failedToLoad[theme] = false;
}
this.isLoaded[theme] = true;
}
play(theme, intensity, targetVolume) {
if (!this.audioBuffers[theme]) {
log('⚠️ Audio not loaded - click Preview first', true);
return;
}
const buffer = this.audioBuffers[theme][intensity];
if (!buffer) {
log(`⚠️ ${intensity} audio unavailable`, true);
return;
}
// Resume AudioContext if suspended (required for user interaction)
if (this.audioContext.state === 'suspended') {
this.audioContext.resume();
}
// Crossfade between intensities
if (this.currentTheme === theme && this.currentIntensity !== intensity) {
const oldGain = this.gainNodes[theme][this.currentIntensity];
const newGain = this.gainNodes[theme][intensity];