-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
696 lines (583 loc) · 25.6 KB
/
script.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
// Get HTML elements
const audioFileInput = document.getElementById('audioFileInput');
const audioElement = document.getElementById('audioElement');
const speedControl = document.getElementById('speedControl');
const speedValue = document.getElementById('speedValue');
// Noise Reduction
const noiseReduction = document.getElementById('noiseReduction');
const noiseReductionLevel = document.getElementById('noiseReductionLevel');
const noiseReductionValue = document.getElementById('noiseReductionValue');
// Phase Vocoder
const phaseVocoder = document.getElementById('phaseVocoder');
const phaseVocoderLevel = document.getElementById('phaseVocoderLevel');
const phaseVocoderValue = document.getElementById('phaseVocoderValue');
// Formant Preservation
const formantPreservation = document.getElementById('formantPreservation');
const formantPreservationLevel = document.getElementById('formantPreservationLevel');
const formantPreservationValue = document.getElementById('formantPreservationValue');
// Dynamic Equalization
const dynamicEqualization = document.getElementById('dynamicEqualization');
const dynamicEqIntensity = document.getElementById('dynamicEqIntensity');
const dynamicEqIntensityValue = document.getElementById('dynamicEqIntensityValue');
// Psychoacoustic Modeling
const psychoacousticModeling = document.getElementById('psychoacousticModeling');
const psychoacousticModelingLevel = document.getElementById('psychoacousticModelingLevel');
const psychoacousticModelingValue = document.getElementById('psychoacousticModelingValue');
// Spectral Shaping
const spectralShaping = document.getElementById('spectralShaping');
const spectralShapingLevel = document.getElementById('spectralShapingLevel');
const spectralShapingValue = document.getElementById('spectralShapingValue');
// Transient Enhancement
const transientEnhancement = document.getElementById('transientEnhancement');
const transientEnhancementLevel = document.getElementById('transientEnhancementLevel');
const transientEnhancementValue = document.getElementById('transientEnhancementValue');
// Automatic Gain Control
const automaticGainControl = document.getElementById('automaticGainControl');
const agcTargetLevel = document.getElementById('agcTargetLevel');
const agcTargetValue = document.getElementById('agcTargetValue');
// Consonant Emphasis
const consonantEmphasis = document.getElementById('consonantEmphasis');
const emphasisFrequency = document.getElementById('emphasisFrequency');
const emphasisGain = document.getElementById('emphasisGain');
const emphasisFreqValue = document.getElementById('emphasisFreqValue');
const emphasisGainValue = document.getElementById('emphasisGainValue');
// Temporal Smoothing
const temporalSmoothing = document.getElementById('temporalSmoothing');
const temporalSmoothingLevel = document.getElementById('temporalSmoothingLevel');
const temporalSmoothingValue = document.getElementById('temporalSmoothingValue');
// Frequency Compression
const frequencyCompression = document.getElementById('frequencyCompression');
const frequencyCompressionLevel = document.getElementById('frequencyCompressionLevel');
const frequencyCompressionValue = document.getElementById('frequencyCompressionValue');
// Dynamic Range Compression
const dynamicCompression = document.getElementById('dynamicCompression');
const compressionThreshold = document.getElementById('compressionThreshold');
const compressionRatio = document.getElementById('compressionRatio');
const compressionThresholdValue = document.getElementById('compressionThresholdValue');
const compressionRatioValue = document.getElementById('compressionRatioValue');
// Save and Load Settings
const saveSettingsButton = document.getElementById('saveSettings');
const loadSettingsButton = document.getElementById('loadSettings');
// Web Audio API context and nodes
let audioContext;
let sourceNode;
let gainNode;
// Noise Reduction
let noiseReductionNode;
// Automatic Gain Control
let agcNode;
// Dynamic Range Compression
let compressorNode;
// Phase Vocoder (Simplified)
let phaseVocoderNode;
// Formant Preservation
let formantPreservationNode;
// Temporal Smoothing
let temporalSmoothingNode;
// Dynamic Equalization
let dynamicEqFilters = [];
// Spectral Shaping
let spectralShapingNode;
// Consonant Emphasis
let consonantEmphasisNode;
// Frequency Compression
let frequencyCompressionNode;
// Transient Enhancement
let transientEnhancementNode;
// Psychoacoustic Modeling
let psychoacousticNode;
// Initialize audio context and nodes
function initAudio() {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
// Create source node from the audio element
sourceNode = audioContext.createMediaElementSource(audioElement);
// Create gain node
gainNode = audioContext.createGain();
// Noise Reduction Node
noiseReductionNode = audioContext.createBiquadFilter();
noiseReductionNode.type = 'lowpass';
// Automatic Gain Control Node
agcNode = audioContext.createGain();
// Dynamic Range Compression Node
compressorNode = audioContext.createDynamicsCompressor();
// Phase Vocoder Node (Simplified)
phaseVocoderNode = audioContext.createDelay();
// Formant Preservation Node
formantPreservationNode = audioContext.createBiquadFilter();
formantPreservationNode.type = 'allpass';
// Temporal Smoothing Node
temporalSmoothingNode = audioContext.createBiquadFilter();
temporalSmoothingNode.type = 'lowpass';
// Initialize Dynamic Equalization filters
initDynamicEqualizationFilters();
// Spectral Shaping Node
spectralShapingNode = audioContext.createBiquadFilter();
spectralShapingNode.type = 'peaking';
// Consonant Emphasis Node
consonantEmphasisNode = audioContext.createBiquadFilter();
consonantEmphasisNode.type = 'peaking';
// Frequency Compression Node
frequencyCompressionNode = audioContext.createWaveShaper();
// Transient Enhancement Node
transientEnhancementNode = audioContext.createDynamicsCompressor();
// Psychoacoustic Modeling Node
psychoacousticNode = audioContext.createWaveShaper();
// Connect source node to gain node
sourceNode.connect(gainNode);
// Set up initial audio routing
updateAudioRouting();
}
// Initialize Dynamic Equalization filters
function initDynamicEqualizationFilters() {
const frequencies = [250, 500, 1000, 2000, 4000, 8000];
dynamicEqFilters = frequencies.map(frequency => {
const filter = audioContext.createBiquadFilter();
filter.type = 'peaking';
filter.frequency.setValueAtTime(frequency, audioContext.currentTime);
filter.Q.setValueAtTime(1, audioContext.currentTime);
filter.gain.setValueAtTime(0, audioContext.currentTime);
return filter;
});
}
// Update audio routing based on current settings
function updateAudioRouting() {
// Disconnect nodes
if (gainNode) gainNode.disconnect();
if (noiseReductionNode) noiseReductionNode.disconnect();
if (agcNode) agcNode.disconnect();
if (compressorNode) compressorNode.disconnect();
if (phaseVocoderNode) phaseVocoderNode.disconnect();
if (formantPreservationNode) formantPreservationNode.disconnect();
if (temporalSmoothingNode) temporalSmoothingNode.disconnect();
if (dynamicEqFilters && dynamicEqFilters.length > 0) {
dynamicEqFilters.forEach(filter => filter.disconnect());
}
if (spectralShapingNode) spectralShapingNode.disconnect();
if (consonantEmphasisNode) consonantEmphasisNode.disconnect();
if (frequencyCompressionNode) frequencyCompressionNode.disconnect();
if (transientEnhancementNode) transientEnhancementNode.disconnect();
if (psychoacousticNode) psychoacousticNode.disconnect();
let currentNode = gainNode;
// 1. Noise Reduction
if (noiseReduction.checked) {
let frequency = 20000 - (noiseReductionLevel.value / 100) * 20000;
frequency = Math.max(frequency, 20);
noiseReductionNode.frequency.setValueAtTime(frequency, audioContext.currentTime);
currentNode.connect(noiseReductionNode);
currentNode = noiseReductionNode;
}
// 2. Automatic Gain Control
if (automaticGainControl.checked) {
agcNode.gain.setValueAtTime(agcTargetLevel.value, audioContext.currentTime);
currentNode.connect(agcNode);
currentNode = agcNode;
}
// 3. Dynamic Range Compression
if (dynamicCompression.checked) {
compressorNode.threshold.setValueAtTime(compressionThreshold.value, audioContext.currentTime);
compressorNode.ratio.setValueAtTime(compressionRatio.value, audioContext.currentTime);
compressorNode.attack.setValueAtTime(0.003, audioContext.currentTime);
compressorNode.release.setValueAtTime(0.25, audioContext.currentTime);
currentNode.connect(compressorNode);
currentNode = compressorNode;
}
// 4. Phase Vocoder (Simplified)
if (phaseVocoder.checked) {
let delayTime = (phaseVocoderLevel.value - 1) * 0.05;
phaseVocoderNode.delayTime.setValueAtTime(delayTime, audioContext.currentTime);
currentNode.connect(phaseVocoderNode);
currentNode = phaseVocoderNode;
}
// 5. Formant Preservation
if (formantPreservation.checked) {
formantPreservationNode.frequency.setValueAtTime(1000 * formantPreservationLevel.value, audioContext.currentTime);
currentNode.connect(formantPreservationNode);
currentNode = formantPreservationNode;
}
// 6. Temporal Smoothing
if (temporalSmoothing.checked) {
let smoothingFrequency = 20000 - (temporalSmoothingLevel.value / 100) * 20000;
smoothingFrequency = Math.max(smoothingFrequency, 20);
temporalSmoothingNode.frequency.setValueAtTime(smoothingFrequency, audioContext.currentTime);
currentNode.connect(temporalSmoothingNode);
currentNode = temporalSmoothingNode;
}
// 7. Dynamic Equalization
if (dynamicEqualization.checked) {
dynamicEqFilters.forEach(filter => {
filter.gain.setValueAtTime((dynamicEqIntensity.value - 1) * 10, audioContext.currentTime);
});
dynamicEqFilters.reduce((prevNode, currentFilter) => {
prevNode.connect(currentFilter);
return currentFilter;
}, currentNode);
currentNode = dynamicEqFilters[dynamicEqFilters.length - 1];
}
// 8. Spectral Shaping
if (spectralShaping.checked) {
spectralShapingNode.frequency.setValueAtTime(1500, audioContext.currentTime);
spectralShapingNode.gain.setValueAtTime((spectralShapingLevel.value - 1) * 10, audioContext.currentTime);
spectralShapingNode.Q.setValueAtTime(1, audioContext.currentTime);
currentNode.connect(spectralShapingNode);
currentNode = spectralShapingNode;
}
// 9. Consonant Emphasis
if (consonantEmphasis.checked) {
consonantEmphasisNode.frequency.setValueAtTime(emphasisFrequency.value, audioContext.currentTime);
consonantEmphasisNode.gain.setValueAtTime(emphasisGain.value, audioContext.currentTime);
consonantEmphasisNode.Q.setValueAtTime(1, audioContext.currentTime);
currentNode.connect(consonantEmphasisNode);
currentNode = consonantEmphasisNode;
}
// 10. Frequency Compression
if (frequencyCompression.checked) {
frequencyCompressionNode.curve = makeFrequencyCompressorCurve(frequencyCompressionLevel.value);
currentNode.connect(frequencyCompressionNode);
currentNode = frequencyCompressionNode;
}
// 11. Transient Enhancement
if (transientEnhancement.checked) {
transientEnhancementNode.threshold.setValueAtTime(-50, audioContext.currentTime);
transientEnhancementNode.ratio.setValueAtTime(20 * transientEnhancementLevel.value, audioContext.currentTime);
transientEnhancementNode.attack.setValueAtTime(0.001, audioContext.currentTime);
transientEnhancementNode.release.setValueAtTime(0.05, audioContext.currentTime);
currentNode.connect(transientEnhancementNode);
currentNode = transientEnhancementNode;
}
// 12. Psychoacoustic Modeling
if (psychoacousticModeling.checked) {
psychoacousticNode.curve = makePsychoacousticCurve(psychoacousticModelingLevel.value);
currentNode.connect(psychoacousticNode);
currentNode = psychoacousticNode;
}
// Connect to audio context destination
currentNode.connect(audioContext.destination);
}
// Functions to create curves for custom nodes
function makePsychoacousticCurve(intensity) {
let numSamples = 44100;
let curve = new Float32Array(numSamples);
for (let i = 0; i < numSamples; ++i) {
let x = (i * 2) / numSamples - 1;
curve[i] = Math.tanh(intensity * x);
}
return curve;
}
function makeFrequencyCompressorCurve(compressionLevel) {
let numSamples = 44100;
let curve = new Float32Array(numSamples);
let x;
for (let i = 0; i < numSamples; ++i) {
x = i * 2 / numSamples - 1;
curve[i] = Math.sign(x) * Math.pow(Math.abs(x), 1 / compressionLevel);
}
return curve;
}
// Initialize audio context when user interacts
function initializeAudioContext() {
if (!audioContext) {
initAudio();
}
}
// Event listener for file input
audioFileInput.addEventListener('change', function (event) {
const file = event.target.files[0];
if (file) {
const fileURL = URL.createObjectURL(file);
audioElement.src = fileURL;
audioElement.load();
initializeAudioContext();
}
});
// Event listener to resume audio context on play
audioElement.addEventListener('play', function () {
if (audioContext && audioContext.state === 'suspended') {
audioContext.resume();
}
});
// Event listener for playback speed control
speedControl.addEventListener('input', function () {
const playbackRate = parseFloat(this.value);
audioElement.playbackRate = playbackRate;
speedValue.textContent = playbackRate.toFixed(1) + 'x';
});
// Event listeners for Noise Reduction
noiseReduction.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
noiseReductionLevel.addEventListener('input', function () {
noiseReductionValue.textContent = noiseReductionLevel.value;
updateAudioRouting();
});
// Event listeners for Phase Vocoder
phaseVocoder.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
phaseVocoderLevel.addEventListener('input', function () {
phaseVocoderValue.textContent = phaseVocoderLevel.value;
updateAudioRouting();
});
// Event listeners for Formant Preservation
formantPreservation.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
formantPreservationLevel.addEventListener('input', function () {
formantPreservationValue.textContent = formantPreservationLevel.value;
updateAudioRouting();
});
// Event listeners for Dynamic Equalization
dynamicEqualization.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
dynamicEqIntensity.addEventListener('input', function () {
dynamicEqIntensityValue.textContent = dynamicEqIntensity.value;
updateAudioRouting();
});
// Event listeners for Psychoacoustic Modeling
psychoacousticModeling.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
psychoacousticModelingLevel.addEventListener('input', function () {
psychoacousticModelingValue.textContent = psychoacousticModelingLevel.value;
updateAudioRouting();
});
// Event listeners for Spectral Shaping
spectralShaping.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
spectralShapingLevel.addEventListener('input', function () {
spectralShapingValue.textContent = spectralShapingLevel.value;
updateAudioRouting();
});
// Event listeners for Transient Enhancement
transientEnhancement.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
transientEnhancementLevel.addEventListener('input', function () {
transientEnhancementValue.textContent = transientEnhancementLevel.value;
updateAudioRouting();
});
// Event listeners for Automatic Gain Control
automaticGainControl.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
agcTargetLevel.addEventListener('input', function () {
agcTargetValue.textContent = agcTargetLevel.value;
updateAudioRouting();
});
// Event listeners for Consonant Emphasis
consonantEmphasis.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
emphasisFrequency.addEventListener('input', function () {
emphasisFreqValue.textContent = emphasisFrequency.value;
updateAudioRouting();
});
emphasisGain.addEventListener('input', function () {
emphasisGainValue.textContent = emphasisGain.value;
updateAudioRouting();
});
// Event listeners for Temporal Smoothing
temporalSmoothing.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
temporalSmoothingLevel.addEventListener('input', function () {
temporalSmoothingValue.textContent = temporalSmoothingLevel.value;
updateAudioRouting();
});
// Event listeners for Frequency Compression
frequencyCompression.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
frequencyCompressionLevel.addEventListener('input', function () {
frequencyCompressionValue.textContent = frequencyCompressionLevel.value;
updateAudioRouting();
});
// Event listeners for Dynamic Range Compression
dynamicCompression.addEventListener('change', function () {
updateAudioRouting();
updateCheckboxLabels();
});
compressionThreshold.addEventListener('input', function () {
compressionThresholdValue.textContent = compressionThreshold.value;
updateAudioRouting();
});
compressionRatio.addEventListener('input', function () {
compressionRatioValue.textContent = compressionRatio.value;
updateAudioRouting();
});
// Function to update checkbox labels
function updateCheckboxLabels() {
const filters = [
{ checkbox: noiseReduction, label: 'noiseReduction' },
{ checkbox: phaseVocoder, label: 'phaseVocoder' },
{ checkbox: formantPreservation, label: 'formantPreservation' },
{ checkbox: dynamicEqualization, label: 'dynamicEqualization' },
{ checkbox: psychoacousticModeling, label: 'psychoacousticModeling' },
{ checkbox: spectralShaping, label: 'spectralShaping' },
{ checkbox: transientEnhancement, label: 'transientEnhancement' },
{ checkbox: automaticGainControl, label: 'automaticGainControl' },
{ checkbox: consonantEmphasis, label: 'consonantEmphasis' },
{ checkbox: temporalSmoothing, label: 'temporalSmoothing' },
{ checkbox: frequencyCompression, label: 'frequencyCompression' },
{ checkbox: dynamicCompression, label: 'dynamicCompression' },
];
filters.forEach(filter => {
const status = filter.checkbox.checked ? 'Enabled' : 'Disabled';
document.querySelector(`label[for="${filter.label}"] .setting-value`).textContent = `(${status})`;
});
}
// Initialize displayed values on page load
updateCheckboxLabels();
noiseReductionValue.textContent = noiseReductionLevel.value;
phaseVocoderValue.textContent = phaseVocoderLevel.value;
formantPreservationValue.textContent = formantPreservationLevel.value;
dynamicEqIntensityValue.textContent = dynamicEqIntensity.value;
psychoacousticModelingValue.textContent = psychoacousticModelingLevel.value;
spectralShapingValue.textContent = spectralShapingLevel.value;
transientEnhancementValue.textContent = transientEnhancementLevel.value;
agcTargetValue.textContent = agcTargetLevel.value;
emphasisFreqValue.textContent = emphasisFrequency.value;
emphasisGainValue.textContent = emphasisGain.value;
temporalSmoothingValue.textContent = temporalSmoothingLevel.value;
frequencyCompressionValue.textContent = frequencyCompressionLevel.value;
compressionThresholdValue.textContent = compressionThreshold.value;
compressionRatioValue.textContent = compressionRatio.value;
// Save and Load Settings
saveSettingsButton.addEventListener('click', saveSettings);
loadSettingsButton.addEventListener('click', loadSettings);
function saveSettings() {
const settings = {
playbackRate: speedControl.value,
noiseReduction: noiseReduction.checked,
noiseReductionLevel: noiseReductionLevel.value,
phaseVocoder: phaseVocoder.checked,
phaseVocoderLevel: phaseVocoderLevel.value,
formantPreservation: formantPreservation.checked,
formantPreservationLevel: formantPreservationLevel.value,
dynamicEqualization: dynamicEqualization.checked,
dynamicEqIntensity: dynamicEqIntensity.value,
psychoacousticModeling: psychoacousticModeling.checked,
psychoacousticModelingLevel: psychoacousticModelingLevel.value,
spectralShaping: spectralShaping.checked,
spectralShapingLevel: spectralShapingLevel.value,
transientEnhancement: transientEnhancement.checked,
transientEnhancementLevel: transientEnhancementLevel.value,
automaticGainControl: automaticGainControl.checked,
agcTargetLevel: agcTargetLevel.value,
consonantEmphasis: consonantEmphasis.checked,
emphasisFrequency: emphasisFrequency.value,
emphasisGain: emphasisGain.value,
temporalSmoothing: temporalSmoothing.checked,
temporalSmoothingLevel: temporalSmoothingLevel.value,
frequencyCompression: frequencyCompression.checked,
frequencyCompressionLevel: frequencyCompressionLevel.value,
dynamicCompression: dynamicCompression.checked,
compressionThreshold: compressionThreshold.value,
compressionRatio: compressionRatio.value,
};
const settingsJSON = JSON.stringify(settings, null, 2); // Pretty-print with indentation
const blob = new Blob([settingsJSON], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'audioPlayerSettings.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
alert('Settings have been saved to a file.');
}
function loadSettings() {
const input = document.createElement('input');
input.type = 'file';
input.accept = 'application/json';
input.onchange = function (event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
try {
const settingsJSON = e.target.result;
const settings = JSON.parse(settingsJSON);
// Initialize audio context and nodes
initializeAudioContext();
// Playback rate
speedControl.value = settings.playbackRate;
audioElement.playbackRate = parseFloat(settings.playbackRate);
speedValue.textContent = parseFloat(settings.playbackRate).toFixed(1) + 'x';
// Noise Reduction
noiseReduction.checked = settings.noiseReduction;
noiseReductionLevel.value = settings.noiseReductionLevel;
noiseReductionValue.textContent = settings.noiseReductionLevel;
// Phase Vocoder
phaseVocoder.checked = settings.phaseVocoder;
phaseVocoderLevel.value = settings.phaseVocoderLevel;
phaseVocoderValue.textContent = settings.phaseVocoderLevel;
// Formant Preservation
formantPreservation.checked = settings.formantPreservation;
formantPreservationLevel.value = settings.formantPreservationLevel;
formantPreservationValue.textContent = settings.formantPreservationLevel;
// Dynamic Equalization
dynamicEqualization.checked = settings.dynamicEqualization;
dynamicEqIntensity.value = settings.dynamicEqIntensity;
dynamicEqIntensityValue.textContent = settings.dynamicEqIntensity;
// Psychoacoustic Modeling
psychoacousticModeling.checked = settings.psychoacousticModeling;
psychoacousticModelingLevel.value = settings.psychoacousticModelingLevel;
psychoacousticModelingValue.textContent = settings.psychoacousticModelingLevel;
// Spectral Shaping
spectralShaping.checked = settings.spectralShaping;
spectralShapingLevel.value = settings.spectralShapingLevel;
spectralShapingValue.textContent = settings.spectralShapingLevel;
// Transient Enhancement
transientEnhancement.checked = settings.transientEnhancement;
transientEnhancementLevel.value = settings.transientEnhancementLevel;
transientEnhancementValue.textContent = settings.transientEnhancementLevel;
// Automatic Gain Control
automaticGainControl.checked = settings.automaticGainControl;
agcTargetLevel.value = settings.agcTargetLevel;
agcTargetValue.textContent = settings.agcTargetLevel;
// Consonant Emphasis
consonantEmphasis.checked = settings.consonantEmphasis;
emphasisFrequency.value = settings.emphasisFrequency;
emphasisFreqValue.textContent = settings.emphasisFrequency;
emphasisGain.value = settings.emphasisGain;
emphasisGainValue.textContent = settings.emphasisGain;
// Temporal Smoothing
temporalSmoothing.checked = settings.temporalSmoothing;
temporalSmoothingLevel.value = settings.temporalSmoothingLevel;
temporalSmoothingValue.textContent = settings.temporalSmoothingLevel;
// Frequency Compression
frequencyCompression.checked = settings.frequencyCompression;
frequencyCompressionLevel.value = settings.frequencyCompressionLevel;
frequencyCompressionValue.textContent = settings.frequencyCompressionLevel;
// Dynamic Range Compression
dynamicCompression.checked = settings.dynamicCompression;
compressionThreshold.value = settings.compressionThreshold;
compressionThresholdValue.textContent = settings.compressionThreshold;
compressionRatio.value = settings.compressionRatio;
compressionRatioValue.textContent = settings.compressionRatio;
updateAudioRouting();
updateCheckboxLabels();
alert('Settings have been loaded from the file!');
} catch (error) {
alert('Failed to load settings. The file may be corrupted.');
}
};
reader.readAsText(file);
}
};
input.click();
}