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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AUDIOFORM: by webXOS</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/jszip@3.7.1/dist/jszip.min.js"></script>
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
10
+ <style>
11
+ * {
12
+ margin: 0;
13
+ padding: 0;
14
+ box-sizing: border-box;
15
+ font-family: 'Courier New', monospace;
16
+ }
17
+
18
+ body {
19
+ background: #0a0a12;
20
+ color: #00ff9d;
21
+ overflow: hidden;
22
+ height: 100vh;
23
+ position: relative;
24
+ }
25
+
26
+ /* Loading Screen */
27
+ #loading-screen {
28
+ position: fixed;
29
+ top: 0;
30
+ left: 0;
31
+ width: 100%;
32
+ height: 100%;
33
+ background: #000000;
34
+ display: flex;
35
+ flex-direction: column;
36
+ justify-content: center;
37
+ align-items: center;
38
+ z-index: 1000;
39
+ transition: opacity 1s;
40
+ }
41
+
42
+ .loading-title {
43
+ font-size: 3rem;
44
+ color: #00ff9d;
45
+ text-shadow: 0 0 10px #00ff9d;
46
+ margin-bottom: 2rem;
47
+ letter-spacing: 5px;
48
+ }
49
+
50
+ .loading-bar {
51
+ width: 300px;
52
+ height: 4px;
53
+ background: #111;
54
+ border-radius: 2px;
55
+ overflow: hidden;
56
+ margin-top: 20px;
57
+ }
58
+
59
+ .loading-progress {
60
+ height: 100%;
61
+ background: #00ff9d;
62
+ width: 0%;
63
+ transition: width 0.3s;
64
+ }
65
+
66
+ /* Main UI */
67
+ #ui-container {
68
+ position: absolute;
69
+ top: 0;
70
+ left: 0;
71
+ width: 100%;
72
+ height: 100%;
73
+ pointer-events: none;
74
+ z-index: 10;
75
+ }
76
+
77
+ .ui-section {
78
+ position: absolute;
79
+ background: rgba(5, 5, 15, 0.85);
80
+ border: 1px solid #00ff9d;
81
+ border-radius: 5px;
82
+ padding: 15px;
83
+ box-shadow: 0 0 15px rgba(0, 255, 157, 0.3);
84
+ pointer-events: all;
85
+ }
86
+
87
+ /* Control Panel */
88
+ #control-panel {
89
+ top: 20px;
90
+ left: 20px;
91
+ width: 320px;
92
+ }
93
+
94
+ /* Visualization Panel */
95
+ #viz-panel {
96
+ bottom: 20px;
97
+ left: 20px;
98
+ width: 320px;
99
+ }
100
+
101
+ /* Export Panel */
102
+ #export-panel {
103
+ top: 20px;
104
+ right: 20px;
105
+ width: 320px;
106
+ }
107
+
108
+ /* Title */
109
+ #title {
110
+ position: absolute;
111
+ top: 20px;
112
+ left: 50%;
113
+ transform: translateX(-50%);
114
+ font-size: 2.2rem;
115
+ color: #00ff9d;
116
+ text-shadow: 0 0 10px #00ff9d;
117
+ letter-spacing: 3px;
118
+ text-align: center;
119
+ background: rgba(5, 5, 15, 0.7);
120
+ padding: 10px 30px;
121
+ border-radius: 5px;
122
+ border: 1px solid #00ff9d;
123
+ box-shadow: 0 0 15px rgba(0, 255, 157, 0.3);
124
+ z-index: 11;
125
+ }
126
+
127
+ /* Fullscreen Button */
128
+ #fullscreen-btn {
129
+ position: absolute;
130
+ bottom: 20px;
131
+ right: 20px;
132
+ width: 50px;
133
+ height: 50px;
134
+ background: rgba(5, 5, 15, 0.85);
135
+ border: 1px solid #00ff9d;
136
+ border-radius: 50%;
137
+ color: #00ff9d;
138
+ font-size: 24px;
139
+ cursor: pointer;
140
+ display: flex;
141
+ justify-content: center;
142
+ align-items: center;
143
+ z-index: 11;
144
+ pointer-events: all;
145
+ transition: all 0.3s;
146
+ }
147
+
148
+ #fullscreen-btn:hover {
149
+ background: rgba(0, 255, 157, 0.2);
150
+ box-shadow: 0 0 15px #00ff9d;
151
+ }
152
+
153
+ /* UI Elements */
154
+ h2 {
155
+ color: #00ff9d;
156
+ margin-bottom: 15px;
157
+ border-bottom: 1px solid #00ff9d;
158
+ padding-bottom: 5px;
159
+ font-size: 1.3rem;
160
+ }
161
+
162
+ .btn {
163
+ background: #001a0f;
164
+ color: #00ff9d;
165
+ border: 1px solid #00ff9d;
166
+ padding: 10px 15px;
167
+ border-radius: 3px;
168
+ cursor: pointer;
169
+ margin: 5px 0;
170
+ width: 100%;
171
+ font-weight: bold;
172
+ transition: all 0.3s;
173
+ }
174
+
175
+ .btn:hover {
176
+ background: #003320;
177
+ box-shadow: 0 0 10px #00ff9d;
178
+ }
179
+
180
+ .btn:active {
181
+ background: #00ff9d;
182
+ color: #000;
183
+ }
184
+
185
+ .btn-red {
186
+ background: #1a0000;
187
+ border-color: #ff0033;
188
+ color: #ff0033;
189
+ }
190
+
191
+ .btn-red:hover {
192
+ background: #330000;
193
+ box-shadow: 0 0 10px #ff0033;
194
+ }
195
+
196
+ .file-input {
197
+ width: 100%;
198
+ margin: 10px 0;
199
+ padding: 8px;
200
+ background: #000;
201
+ color: #00ff9d;
202
+ border: 1px solid #00ff9d;
203
+ border-radius: 3px;
204
+ }
205
+
206
+ .slider-container {
207
+ margin: 15px 0;
208
+ }
209
+
210
+ .slider-label {
211
+ display: flex;
212
+ justify-content: space-between;
213
+ margin-bottom: 5px;
214
+ }
215
+
216
+ .slider {
217
+ width: 100%;
218
+ -webkit-appearance: none;
219
+ height: 6px;
220
+ background: #001a0f;
221
+ border-radius: 3px;
222
+ outline: none;
223
+ }
224
+
225
+ .slider::-webkit-slider-thumb {
226
+ -webkit-appearance: none;
227
+ width: 18px;
228
+ height: 18px;
229
+ background: #00ff9d;
230
+ border-radius: 50%;
231
+ cursor: pointer;
232
+ }
233
+
234
+ .toggle {
235
+ display: flex;
236
+ align-items: center;
237
+ margin: 10px 0;
238
+ }
239
+
240
+ .toggle input {
241
+ display: none;
242
+ }
243
+
244
+ .toggle-slider {
245
+ width: 50px;
246
+ height: 24px;
247
+ background: #001a0f;
248
+ border-radius: 12px;
249
+ margin-right: 10px;
250
+ position: relative;
251
+ cursor: pointer;
252
+ border: 1px solid #00ff9d;
253
+ }
254
+
255
+ .toggle-slider:after {
256
+ content: '';
257
+ position: absolute;
258
+ width: 20px;
259
+ height: 20px;
260
+ background: #00ff9d;
261
+ border-radius: 50%;
262
+ top: 1px;
263
+ left: 1px;
264
+ transition: 0.3s;
265
+ }
266
+
267
+ .toggle input:checked + .toggle-slider:after {
268
+ transform: translateX(26px);
269
+ }
270
+
271
+ .info-text {
272
+ font-size: 0.85rem;
273
+ color: #00cc7a;
274
+ margin-top: 10px;
275
+ line-height: 1.4;
276
+ }
277
+
278
+ /* Canvas */
279
+ #canvas-container {
280
+ width: 100%;
281
+ height: 100%;
282
+ }
283
+
284
+ canvas {
285
+ display: block;
286
+ }
287
+
288
+ /* Metrics Display */
289
+ .metrics {
290
+ background: rgba(0, 0, 0, 0.7);
291
+ padding: 10px;
292
+ border-radius: 3px;
293
+ margin-top: 15px;
294
+ border: 1px solid #ff0033;
295
+ }
296
+
297
+ .metric-row {
298
+ display: flex;
299
+ justify-content: space-between;
300
+ margin: 5px 0;
301
+ font-size: 0.9rem;
302
+ }
303
+
304
+ .metric-value {
305
+ color: #ff0033;
306
+ }
307
+ </style>
308
+ </head>
309
+ <body>
310
+ <!-- Loading Screen -->
311
+ <div id="loading-screen">
312
+ <div class="loading-title">AUDIOFORM</div>
313
+ <div>Initializing 3D Audio Visualization System...</div>
314
+ <div class="loading-bar">
315
+ <div class="loading-progress" id="loading-progress"></div>
316
+ </div>
317
+ </div>
318
+
319
+ <!-- Main UI -->
320
+ <div id="ui-container">
321
+ <div id="title">AUDIOFORM by webXOS</div>
322
+
323
+ <div class="ui-section" id="control-panel">
324
+ <h2>Audio Input</h2>
325
+ <input type="file" id="audio-upload" accept=".wav" class="file-input">
326
+ <button id="load-sample" class="btn">Load Sample Audio</button>
327
+
328
+ <h2>Synthetic Noise Generator</h2>
329
+ <div class="toggle">
330
+ <input type="checkbox" id="noise-toggle">
331
+ <label for="noise-toggle" class="toggle-slider"></label>
332
+ <label for="noise-toggle">Enable 8-bit Tone Generation</label>
333
+ </div>
334
+
335
+ <div class="slider-container">
336
+ <div class="slider-label">
337
+ <span>Tone Frequency</span>
338
+ <span id="freq-value">440 Hz</span>
339
+ </div>
340
+ <input type="range" min="50" max="2000" value="440" class="slider" id="freq-slider">
341
+ </div>
342
+
343
+ <div class="slider-container">
344
+ <div class="slider-label">
345
+ <span>Time Scaling</span>
346
+ <span id="time-value">1.0x</span>
347
+ </div>
348
+ <input type="range" min="0.1" max="5" step="0.1" value="1" class="slider" id="time-slider">
349
+ </div>
350
+
351
+ <button id="generate-noise" class="btn">Generate Synthetic Audio</button>
352
+
353
+ <div class="info-text">
354
+ Synthetic mode generates 8-bit tones with timelapse time-scaling for dataset creation.
355
+ </div>
356
+ </div>
357
+
358
+ <div class="ui-section" id="viz-panel">
359
+ <h2>Visualization Controls</h2>
360
+
361
+ <div class="slider-container">
362
+ <div class="slider-label">
363
+ <span>Waveform Scale</span>
364
+ <span id="scale-value">1.0</span>
365
+ </div>
366
+ <input type="range" min="0.1" max="3" step="0.1" value="1" class="slider" id="scale-slider">
367
+ </div>
368
+
369
+ <div class="slider-container">
370
+ <div class="slider-label">
371
+ <span>Rotation Speed</span>
372
+ <span id="rotation-value">0.5</span>
373
+ </div>
374
+ <input type="range" min="0" max="2" step="0.1" value="0.5" class="slider" id="rotation-slider">
375
+ </div>
376
+
377
+ <div class="toggle">
378
+ <input type="checkbox" id="auto-rotate" checked>
379
+ <label for="auto-rotate" class="toggle-slider"></label>
380
+ <label for="auto-rotate">Auto-Rotate Visualization</label>
381
+ </div>
382
+
383
+ <button id="capture-frame" class="btn">Capture Current Frame</button>
384
+
385
+ <div class="metrics">
386
+ <div class="metric-row">
387
+ <span>Frames Captured:</span>
388
+ <span class="metric-value" id="frame-count">0</span>
389
+ </div>
390
+ <div class="metric-row">
391
+ <span>Audio Duration:</span>
392
+ <span class="metric-value" id="audio-duration">0.0s</span>
393
+ </div>
394
+ <div class="metric-row">
395
+ <span>Current Time:</span>
396
+ <span class="metric-value" id="current-time">0.0s</span>
397
+ </div>
398
+ </div>
399
+ </div>
400
+
401
+ <div class="ui-section" id="export-panel">
402
+ <h2>Dataset Export</h2>
403
+
404
+ <input type="text" id="dataset-name" placeholder="Dataset Name" class="file-input" value="audioform_dataset">
405
+
406
+ <div class="slider-container">
407
+ <div class="slider-label">
408
+ <span>Frames to Capture</span>
409
+ <span id="capture-count-value">10</span>
410
+ </div>
411
+ <input type="range" min="5" max="100" value="10" class="slider" id="capture-count-slider">
412
+ </div>
413
+
414
+ <button id="start-capture" class="btn">Start Timelapse Capture</button>
415
+ <button id="export-dataset" class="btn">Export Dataset (.zip)</button>
416
+ <button id="reset-captures" class="btn btn-red">Reset All Captures</button>
417
+
418
+ <div class="info-text">
419
+ Exports Hugging Face formatted .zip with README.md, images, and classification CSV.
420
+ </div>
421
+ </div>
422
+
423
+ <div id="fullscreen-btn">⛶</div>
424
+ </div>
425
+
426
+ <!-- Three.js Canvas Container -->
427
+ <div id="canvas-container"></div>
428
+
429
+ <script>
430
+ // Main Application
431
+ document.addEventListener('DOMContentLoaded', function() {
432
+ // Simulate loading progress
433
+ let progress = 0;
434
+ const progressInterval = setInterval(() => {
435
+ progress += Math.random() * 15;
436
+ if (progress >= 100) {
437
+ progress = 100;
438
+ clearInterval(progressInterval);
439
+ setTimeout(() => {
440
+ document.getElementById('loading-screen').style.opacity = '0';
441
+ setTimeout(() => {
442
+ document.getElementById('loading-screen').style.display = 'none';
443
+ }, 1000);
444
+ }, 500);
445
+ }
446
+ document.getElementById('loading-progress').style.width = `${progress}%`;
447
+ }, 150);
448
+
449
+ // Global variables
450
+ let scene, camera, renderer, audioContext, audioSource, analyser;
451
+ let waveformGeometry, waveformMaterial, waveformMesh;
452
+ let capturedFrames = [];
453
+ let isPlaying = false;
454
+ let isNoiseMode = false;
455
+ let currentAudioBuffer = null;
456
+ let startTime = 0;
457
+ let rotationSpeed = 0.5;
458
+ let autoRotate = true;
459
+ let timeScale = 1.0;
460
+ let noiseFrequency = 440;
461
+ let frameCaptureCount = 0;
462
+
463
+ // Initialize Three.js scene
464
+ function initThreeJS() {
465
+ // Create scene
466
+ scene = new THREE.Scene();
467
+ scene.background = new THREE.Color(0x000000);
468
+
469
+ // Create camera
470
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
471
+ camera.position.z = 15;
472
+ camera.position.y = 5;
473
+
474
+ // Create renderer
475
+ renderer = new THREE.WebGLRenderer({ antialias: true });
476
+ renderer.setSize(window.innerWidth, window.innerHeight);
477
+ renderer.setPixelRatio(window.devicePixelRatio);
478
+ document.getElementById('canvas-container').appendChild(renderer.domElement);
479
+
480
+ // Add lights
481
+ const ambientLight = new THREE.AmbientLight(0x222222);
482
+ scene.add(ambientLight);
483
+
484
+ const directionalLight = new THREE.DirectionalLight(0x00ff9d, 1);
485
+ directionalLight.position.set(10, 10, 5);
486
+ scene.add(directionalLight);
487
+
488
+ const redLight = new THREE.DirectionalLight(0xff0033, 0.5);
489
+ redLight.position.set(-10, 5, -5);
490
+ scene.add(redLight);
491
+
492
+ // Create initial waveform visualization
493
+ createWaveformVisualization();
494
+
495
+ // Add grid helper
496
+ const gridHelper = new THREE.GridHelper(30, 30, 0x00aa00, 0x003300);
497
+ gridHelper.position.y = -5;
498
+ scene.add(gridHelper);
499
+
500
+ // Add axes helper
501
+ const axesHelper = new THREE.AxesHelper(10);
502
+ scene.add(axesHelper);
503
+
504
+ // Handle window resize
505
+ window.addEventListener('resize', onWindowResize);
506
+ }
507
+
508
+ // Create waveform visualization
509
+ function createWaveformVisualization() {
510
+ // Create geometry for waveform visualization
511
+ const geometry = new THREE.BufferGeometry();
512
+ const pointCount = 512;
513
+ const positions = new Float32Array(pointCount * 3);
514
+
515
+ // Initialize with flat line
516
+ for (let i = 0; i < pointCount; i++) {
517
+ positions[i * 3] = (i - pointCount / 2) * 0.05;
518
+ positions[i * 3 + 1] = 0;
519
+ positions[i * 3 + 2] = 0;
520
+ }
521
+
522
+ geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
523
+
524
+ // Create material with neon green color
525
+ const material = new THREE.LineBasicMaterial({
526
+ color: 0x00ff9d,
527
+ linewidth: 2
528
+ });
529
+
530
+ // Create mesh and add to scene
531
+ waveformMesh = new THREE.Line(geometry, material);
532
+ scene.add(waveformMesh);
533
+
534
+ // Also create a particle system for additional visualization
535
+ const particleGeometry = new THREE.BufferGeometry();
536
+ const particlePositions = new Float32Array(pointCount * 3);
537
+ const particleColors = new Float32Array(pointCount * 3);
538
+
539
+ for (let i = 0; i < pointCount; i++) {
540
+ particlePositions[i * 3] = (i - pointCount / 2) * 0.05;
541
+ particlePositions[i * 3 + 1] = 0;
542
+ particlePositions[i * 3 + 2] = 0;
543
+
544
+ // Green color for particles
545
+ particleColors[i * 3] = 0.0; // R
546
+ particleColors[i * 3 + 1] = 1.0; // G
547
+ particleColors[i * 3 + 2] = 0.0; // B
548
+ }
549
+
550
+ particleGeometry.setAttribute('position', new THREE.BufferAttribute(particlePositions, 3));
551
+ particleGeometry.setAttribute('color', new THREE.BufferAttribute(particleColors, 3));
552
+
553
+ const particleMaterial = new THREE.PointsMaterial({
554
+ size: 0.05,
555
+ vertexColors: true,
556
+ transparent: true
557
+ });
558
+
559
+ const particles = new THREE.Points(particleGeometry, particleMaterial);
560
+ waveformMesh.add(particles);
561
+
562
+ waveformGeometry = geometry;
563
+ }
564
+
565
+ // Update waveform visualization based on audio data
566
+ function updateWaveform(dataArray) {
567
+ if (!waveformGeometry) return;
568
+
569
+ const positions = waveformGeometry.attributes.position.array;
570
+ const pointCount = positions.length / 3;
571
+
572
+ for (let i = 0; i < pointCount; i++) {
573
+ // Get audio data value (normalized)
574
+ const value = dataArray[i] / 128.0;
575
+
576
+ // Update Y position based on audio data
577
+ positions[i * 3 + 1] = value * 5;
578
+
579
+ // Add some Z variation for 3D effect
580
+ positions[i * 3 + 2] = Math.sin(i * 0.05 + Date.now() * 0.001) * value;
581
+ }
582
+
583
+ waveformGeometry.attributes.position.needsUpdate = true;
584
+ }
585
+
586
+ // Initialize audio context
587
+ function initAudio() {
588
+ audioContext = new (window.AudioContext || window.webkitAudioContext)();
589
+ analyser = audioContext.createAnalyser();
590
+ analyser.fftSize = 512;
591
+ analyser.smoothingTimeConstant = 0.8;
592
+ }
593
+
594
+ // Load and play audio file
595
+ function loadAudioFile(file) {
596
+ if (!audioContext) initAudio();
597
+
598
+ const reader = new FileReader();
599
+ reader.onload = function(e) {
600
+ audioContext.decodeAudioData(e.target.result, function(buffer) {
601
+ playAudioBuffer(buffer);
602
+ }, function(e) {
603
+ console.error("Error decoding audio data", e);
604
+ });
605
+ };
606
+ reader.readAsArrayBuffer(file);
607
+ }
608
+
609
+ // Play audio buffer
610
+ function playAudioBuffer(buffer) {
611
+ stopAudio();
612
+
613
+ currentAudioBuffer = buffer;
614
+ audioSource = audioContext.createBufferSource();
615
+ audioSource.buffer = buffer;
616
+ audioSource.connect(analyser);
617
+ analyser.connect(audioContext.destination);
618
+
619
+ // Set playback rate based on time scaling
620
+ audioSource.playbackRate.value = timeScale;
621
+
622
+ audioSource.start(0);
623
+ isPlaying = true;
624
+ startTime = audioContext.currentTime;
625
+
626
+ // Update duration display
627
+ document.getElementById('audio-duration').textContent = `${buffer.duration.toFixed(2)}s`;
628
+
629
+ // Start animation loop
630
+ animate();
631
+ }
632
+
633
+ // Generate synthetic 8-bit tone
634
+ function generateSyntheticNoise() {
635
+ if (!audioContext) initAudio();
636
+
637
+ stopAudio();
638
+
639
+ // Create oscillator for 8-bit tone
640
+ const oscillator = audioContext.createOscillator();
641
+ oscillator.type = 'square'; // Square wave for 8-bit sound
642
+ oscillator.frequency.setValueAtTime(noiseFrequency, audioContext.currentTime);
643
+
644
+ // Create gain node for volume control
645
+ const gainNode = audioContext.createGain();
646
+ gainNode.gain.setValueAtTime(0.1, audioContext.currentTime);
647
+
648
+ // Connect nodes
649
+ oscillator.connect(gainNode);
650
+ gainNode.connect(analyser);
651
+ analyser.connect(audioContext.destination);
652
+
653
+ // Create buffer source for continuous playback
654
+ const bufferLength = 2; // 2 seconds buffer
655
+ const buffer = audioContext.createBuffer(1, audioContext.sampleRate * bufferLength, audioContext.sampleRate);
656
+ const channelData = buffer.getChannelData(0);
657
+
658
+ // Fill buffer with 8-bit style square wave
659
+ for (let i = 0; i < channelData.length; i++) {
660
+ const time = i / audioContext.sampleRate;
661
+ const frequency = noiseFrequency;
662
+ // Square wave calculation
663
+ channelData[i] = Math.sign(Math.sin(2 * Math.PI * frequency * time));
664
+ // Add some noise for "8-bit" character
665
+ channelData[i] += (Math.random() - 0.5) * 0.1;
666
+ // Clamp to prevent distortion
667
+ channelData[i] = Math.max(-0.8, Math.min(0.8, channelData[i]));
668
+ }
669
+
670
+ // Play the buffer
671
+ audioSource = audioContext.createBufferSource();
672
+ audioSource.buffer = buffer;
673
+ audioSource.loop = true;
674
+ audioSource.playbackRate.value = timeScale;
675
+ audioSource.connect(analyser);
676
+ analyser.connect(audioContext.destination);
677
+
678
+ audioSource.start(0);
679
+ isPlaying = true;
680
+ startTime = audioContext.currentTime;
681
+
682
+ // Update duration display for synthetic audio
683
+ document.getElementById('audio-duration').textContent = `∞ (synthetic)`;
684
+
685
+ // Start animation loop
686
+ animate();
687
+ }
688
+
689
+ // Stop audio playback
690
+ function stopAudio() {
691
+ if (audioSource) {
692
+ audioSource.stop();
693
+ audioSource.disconnect();
694
+ isPlaying = false;
695
+ }
696
+ }
697
+
698
+ // Capture current frame as image
699
+ function captureFrame() {
700
+ // Render the current frame to a data URL
701
+ renderer.render(scene, camera);
702
+ const dataURL = renderer.domElement.toDataURL('image/png');
703
+
704
+ // Create frame object
705
+ const frame = {
706
+ id: frameCaptureCount,
707
+ timestamp: audioContext ? (audioContext.currentTime - startTime).toFixed(3) : '0.000',
708
+ dataURL: dataURL,
709
+ frequency: isNoiseMode ? noiseFrequency : 0,
710
+ timeScale: timeScale,
711
+ date: new Date().toISOString()
712
+ };
713
+
714
+ capturedFrames.push(frame);
715
+ frameCaptureCount++;
716
+
717
+ // Update UI
718
+ document.getElementById('frame-count').textContent = frameCaptureCount;
719
+
720
+ // Add visual feedback
721
+ waveformMesh.material.color.setHex(0xff0033);
722
+ setTimeout(() => {
723
+ waveformMesh.material.color.setHex(0x00ff9d);
724
+ }, 100);
725
+
726
+ return frame;
727
+ }
728
+
729
+ // Start timelapse capture
730
+ function startTimelapseCapture() {
731
+ const totalFrames = parseInt(document.getElementById('capture-count-slider').value);
732
+ const interval = 0.5; // Capture every 0.5 seconds
733
+
734
+ let framesCaptured = 0;
735
+
736
+ const captureInterval = setInterval(() => {
737
+ if (framesCaptured >= totalFrames) {
738
+ clearInterval(captureInterval);
739
+ alert(`Timelapse capture complete! Captured ${totalFrames} frames.`);
740
+ return;
741
+ }
742
+
743
+ captureFrame();
744
+ framesCaptured++;
745
+ }, interval * 1000);
746
+ }
747
+
748
+ // Export dataset as Hugging Face formatted zip
749
+ async function exportDataset() {
750
+ if (capturedFrames.length === 0) {
751
+ alert('No frames captured yet! Capture some frames before exporting.');
752
+ return;
753
+ }
754
+
755
+ const datasetName = document.getElementById('dataset-name').value || 'audioform_dataset';
756
+ const zip = new JSZip();
757
+
758
+ // Create dataset folder structure
759
+ const datasetFolder = zip.folder(datasetName);
760
+ const imagesFolder = datasetFolder.folder('images');
761
+
762
+ // Create metadata CSV with REQUIRED file_name column for Hugging Face compatibility
763
+ let csvContent = 'file_name,frame_id,timestamp,frequency,time_scale,capture_date\n';
764
+
765
+ // Add images to zip and build CSV simultaneously
766
+ capturedFrames.forEach((frame, index) => {
767
+ // Convert dataURL to blob
768
+ const data = frame.dataURL.split(',')[1];
769
+ const blob = b64toBlob(data, 'image/png');
770
+
771
+ // Add image to zip
772
+ const imageName = `frame_${String(index).padStart(4, '0')}.png`;
773
+ imagesFolder.file(imageName, blob);
774
+
775
+ // Add to CSV with file_name column (required by Hugging Face ImageFolder)
776
+ csvContent += `images/${imageName},${frame.id},${frame.timestamp},${frame.frequency},${frame.timeScale},${frame.date}\n`;
777
+ });
778
+
779
+ datasetFolder.file('metadata.csv', csvContent);
780
+
781
+ // Create README.md
782
+ const readmeContent = `# ${datasetName}
783
+
784
+ ## Dataset Description
785
+
786
+ This dataset was generated using AUDIOFORM, a 3D audio visualization system.
787
+
788
+ - **Total Frames**: ${capturedFrames.length}
789
+ - **Generation Date**: ${new Date().toISOString().split('T')[0]}
790
+ - **Audio Type**: ${isNoiseMode ? 'Synthetic 8-bit Tone' : 'Uploaded WAV File'}
791
+ - **Time Scaling**: ${timeScale}x
792
+
793
+ ## Dataset Structure
794
+
795
+ - \`images/\`: Contains all captured frames in PNG format
796
+ - \`metadata.csv\`: Contains classification data for each frame
797
+
798
+ ## Metadata Columns
799
+
800
+ - \`file_name\`: Relative path to the image file (e.g., images/frame_0001.png) - **REQUIRED for Hugging Face**
801
+ - \`frame_id\`: Unique identifier for each frame
802
+ - \`timestamp\`: Time in seconds when frame was captured
803
+ - \`frequency\`: Audio frequency at capture time (Hz)
804
+ - \`time_scale\`: Playback speed multiplier
805
+ - \`capture_date\`: ISO date string of capture
806
+
807
+ ## Intended Use
808
+
809
+ This dataset is intended for training machine learning models on audio visualization patterns, waveform classification, or generative AI tasks.
810
+
811
+ ## Generation Details
812
+
813
+ Generated with AUDIOFORM v1.0 - A Three.js based audio visualization dataset generator.
814
+ `;
815
+
816
+ datasetFolder.file('README.md', readmeContent);
817
+
818
+ // Generate and download zip file
819
+ const zipBlob = await zip.generateAsync({type: 'blob'});
820
+ saveAs(zipBlob, `${datasetName}.zip`);
821
+
822
+ alert(`Dataset exported successfully as ${datasetName}.zip\n\nThe dataset includes the required 'file_name' column for Hugging Face compatibility.`);
823
+ }
824
+
825
+ // Helper function to convert base64 to blob
826
+ function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
827
+ const byteCharacters = atob(b64Data);
828
+ const byteArrays = [];
829
+
830
+ for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
831
+ const slice = byteCharacters.slice(offset, offset + sliceSize);
832
+
833
+ const byteNumbers = new Array(slice.length);
834
+ for (let i = 0; i < slice.length; i++) {
835
+ byteNumbers[i] = slice.charCodeAt(i);
836
+ }
837
+
838
+ const byteArray = new Uint8Array(byteNumbers);
839
+ byteArrays.push(byteArray);
840
+ }
841
+
842
+ const blob = new Blob(byteArrays, {type: contentType});
843
+ return blob;
844
+ }
845
+
846
+ // Reset all captured frames
847
+ function resetCaptures() {
848
+ if (capturedFrames.length > 0 && !confirm('Are you sure you want to reset all captured frames?')) {
849
+ return;
850
+ }
851
+
852
+ capturedFrames = [];
853
+ frameCaptureCount = 0;
854
+ document.getElementById('frame-count').textContent = '0';
855
+ }
856
+
857
+ // Animation loop
858
+ function animate() {
859
+ requestAnimationFrame(animate);
860
+
861
+ // Update audio visualization if playing
862
+ if (isPlaying && analyser) {
863
+ const dataArray = new Uint8Array(analyser.frequencyBinCount);
864
+ analyser.getByteFrequencyData(dataArray);
865
+ updateWaveform(dataArray);
866
+
867
+ // Update current time display
868
+ if (audioContext) {
869
+ const currentTime = audioContext.currentTime - startTime;
870
+ document.getElementById('current-time').textContent = `${currentTime.toFixed(2)}s`;
871
+ }
872
+ }
873
+
874
+ // Auto-rotate visualization
875
+ if (autoRotate && waveformMesh) {
876
+ waveformMesh.rotation.y += 0.005 * rotationSpeed;
877
+ waveformMesh.rotation.x += 0.002 * rotationSpeed;
878
+ }
879
+
880
+ // Render scene
881
+ renderer.render(scene, camera);
882
+ }
883
+
884
+ // Handle window resize
885
+ function onWindowResize() {
886
+ camera.aspect = window.innerWidth / window.innerHeight;
887
+ camera.updateProjectionMatrix();
888
+ renderer.setSize(window.innerWidth, window.innerHeight);
889
+ }
890
+
891
+ // Toggle fullscreen mode
892
+ function toggleFullscreen() {
893
+ if (!document.fullscreenElement) {
894
+ document.documentElement.requestFullscreen().catch(err => {
895
+ console.error(`Error attempting to enable fullscreen: ${err.message}`);
896
+ });
897
+ } else {
898
+ if (document.exitFullscreen) {
899
+ document.exitFullscreen();
900
+ }
901
+ }
902
+ }
903
+
904
+ // Load sample audio
905
+ function loadSampleAudio() {
906
+ // Create a simple 8-bit style sample audio
907
+ if (!audioContext) initAudio();
908
+
909
+ // Create a buffer with multiple frequencies
910
+ const buffer = audioContext.createBuffer(1, audioContext.sampleRate * 3, audioContext.sampleRate);
911
+ const channelData = buffer.getChannelData(0);
912
+
913
+ // Generate a sample with varying frequencies
914
+ for (let i = 0; i < channelData.length; i++) {
915
+ const time = i / audioContext.sampleRate;
916
+
917
+ // Vary frequency over time
918
+ const freq = 200 + Math.sin(time * 2) * 100;
919
+
920
+ // Square wave
921
+ channelData[i] = Math.sign(Math.sin(2 * Math.PI * freq * time));
922
+
923
+ // Add some noise
924
+ channelData[i] += (Math.random() - 0.5) * 0.05;
925
+
926
+ // Clamp
927
+ channelData[i] = Math.max(-0.8, Math.min(0.8, channelData[i]));
928
+ }
929
+
930
+ playAudioBuffer(buffer);
931
+ }
932
+
933
+ // Setup event listeners
934
+ function setupEventListeners() {
935
+ // File upload
936
+ document.getElementById('audio-upload').addEventListener('change', function(e) {
937
+ if (e.target.files.length > 0) {
938
+ loadAudioFile(e.target.files[0]);
939
+ isNoiseMode = false;
940
+ }
941
+ });
942
+
943
+ // Sample audio button
944
+ document.getElementById('load-sample').addEventListener('click', loadSampleAudio);
945
+
946
+ // Noise generator toggle
947
+ document.getElementById('noise-toggle').addEventListener('change', function(e) {
948
+ isNoiseMode = e.target.checked;
949
+ });
950
+
951
+ // Generate synthetic noise
952
+ document.getElementById('generate-noise').addEventListener('click', generateSyntheticNoise);
953
+
954
+ // Frequency slider
955
+ const freqSlider = document.getElementById('freq-slider');
956
+ const freqValue = document.getElementById('freq-value');
957
+ freqSlider.addEventListener('input', function() {
958
+ noiseFrequency = parseInt(this.value);
959
+ freqValue.textContent = `${noiseFrequency} Hz`;
960
+
961
+ // Regenerate noise if currently playing in noise mode
962
+ if (isPlaying && isNoiseMode) {
963
+ generateSyntheticNoise();
964
+ }
965
+ });
966
+
967
+ // Time scaling slider
968
+ const timeSlider = document.getElementById('time-slider');
969
+ const timeValue = document.getElementById('time-value');
970
+ timeSlider.addEventListener('input', function() {
971
+ timeScale = parseFloat(this.value);
972
+ timeValue.textContent = `${timeScale.toFixed(1)}x`;
973
+
974
+ // Update playback rate if audio is playing
975
+ if (audioSource && isPlaying) {
976
+ audioSource.playbackRate.value = timeScale;
977
+ }
978
+ });
979
+
980
+ // Waveform scale slider
981
+ const scaleSlider = document.getElementById('scale-slider');
982
+ const scaleValue = document.getElementById('scale-value');
983
+ scaleSlider.addEventListener('input', function() {
984
+ const scale = parseFloat(this.value);
985
+ scaleValue.textContent = scale.toFixed(1);
986
+
987
+ if (waveformMesh) {
988
+ waveformMesh.scale.y = scale;
989
+ }
990
+ });
991
+
992
+ // Rotation speed slider
993
+ const rotationSlider = document.getElementById('rotation-slider');
994
+ const rotationValue = document.getElementById('rotation-value');
995
+ rotationSlider.addEventListener('input', function() {
996
+ rotationSpeed = parseFloat(this.value);
997
+ rotationValue.textContent = rotationSpeed.toFixed(1);
998
+ });
999
+
1000
+ // Auto-rotate toggle
1001
+ document.getElementById('auto-rotate').addEventListener('change', function(e) {
1002
+ autoRotate = e.target.checked;
1003
+ });
1004
+
1005
+ // Capture frame button
1006
+ document.getElementById('capture-frame').addEventListener('click', captureFrame);
1007
+
1008
+ // Capture count slider
1009
+ const captureCountSlider = document.getElementById('capture-count-slider');
1010
+ const captureCountValue = document.getElementById('capture-count-value');
1011
+ captureCountSlider.addEventListener('input', function() {
1012
+ captureCountValue.textContent = this.value;
1013
+ });
1014
+
1015
+ // Start timelapse capture
1016
+ document.getElementById('start-capture').addEventListener('click', startTimelapseCapture);
1017
+
1018
+ // Export dataset
1019
+ document.getElementById('export-dataset').addEventListener('click', exportDataset);
1020
+
1021
+ // Reset captures
1022
+ document.getElementById('reset-captures').addEventListener('click', resetCaptures);
1023
+
1024
+ // Fullscreen button
1025
+ document.getElementById('fullscreen-btn').addEventListener('click', toggleFullscreen);
1026
+
1027
+ // Handle fullscreen change
1028
+ document.addEventListener('fullscreenchange', function() {
1029
+ const fullscreenBtn = document.getElementById('fullscreen-btn');
1030
+ if (document.fullscreenElement) {
1031
+ fullscreenBtn.textContent = '⛶';
1032
+ } else {
1033
+ fullscreenBtn.textContent = '⛶';
1034
+ }
1035
+ });
1036
+ }
1037
+
1038
+ // Initialize everything
1039
+ initThreeJS();
1040
+ initAudio();
1041
+ setupEventListeners();
1042
+
1043
+ // Start animation loop
1044
+ animate();
1045
+
1046
+ // Show a welcome message
1047
+ setTimeout(() => {
1048
+ console.log('AUDIOFORM initialized. Ready to generate audio visualization datasets.');
1049
+ }, 1000);
1050
+ });
1051
+ </script>
1052
+ </body>
1053
+ </html>