File size: 10,739 Bytes
d1bc016
 
 
 
 
797cfe7
d1bc016
797cfe7
 
 
 
 
 
 
 
d1bc016
 
 
 
797cfe7
d1bc016
 
 
797cfe7
 
 
d1bc016
 
797cfe7
 
 
 
d1bc016
797cfe7
d1bc016
 
797cfe7
 
 
 
 
 
 
d1bc016
 
797cfe7
d1bc016
797cfe7
d1bc016
 
 
797cfe7
d1bc016
 
 
797cfe7
 
 
 
 
 
 
d1bc016
 
 
 
797cfe7
 
d1bc016
 
 
797cfe7
 
 
 
 
 
 
 
d1bc016
 
797cfe7
 
d1bc016
797cfe7
 
 
 
 
 
 
 
 
 
 
d1bc016
 
797cfe7
 
d1bc016
 
797cfe7
 
 
 
 
 
 
 
d1bc016
 
797cfe7
 
d1bc016
 
 
 
797cfe7
 
 
 
d1bc016
 
797cfe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1bc016
797cfe7
d1bc016
 
 
797cfe7
 
d1bc016
 
 
797cfe7
d1bc016
 
797cfe7
 
d1bc016
 
 
 
797cfe7
 
d1bc016
797cfe7
 
 
d1bc016
797cfe7
d1bc016
 
 
 
797cfe7
 
 
 
 
 
 
 
 
 
d1bc016
797cfe7
d1bc016
797cfe7
d1bc016
797cfe7
 
 
d1bc016
 
797cfe7
 
d1bc016
 
797cfe7
d1bc016
 
797cfe7
 
 
 
 
 
 
 
d1bc016
797cfe7
d1bc016
 
 
797cfe7
d1bc016
 
 
797cfe7
 
 
 
 
 
 
d1bc016
 
 
 
 
 
797cfe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1bc016
 
 
797cfe7
d1bc016
797cfe7
d1bc016
 
 
 
797cfe7
d1bc016
 
 
797cfe7
d1bc016
 
 
797cfe7
 
 
 
 
d1bc016
 
 
797cfe7
 
 
d1bc016
 
 
797cfe7
 
 
 
 
d1bc016
 
797cfe7
 
d1bc016
797cfe7
 
d1bc016
 
 
797cfe7
d1bc016
797cfe7
 
 
d1bc016
797cfe7
d1bc016
 
797cfe7
 
 
 
 
 
 
 
 
d1bc016
 
 
 
 
797cfe7
 
 
 
 
 
 
 
d1bc016
 
797cfe7
 
d1bc016
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi-Device Audio Analysis System</title>
    <style>
        :root {
            --primary: #2196F3;
            --secondary: #4CAF50;
            --bg-dark: #1a1a1a;
            --bg-light: #2a2a2a;
            --text: #ffffff;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        body {
            background: var(--bg-dark);
            color: var(--text);
            min-height: 100vh;
        }

        .app-container {
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 20px;
            padding: 20px;
            height: 100vh;
        }

        .sidebar {
            background: var(--bg-light);
            border-radius: 12px;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .main-content {
            display: grid;
            grid-template-rows: auto 1fr;
            gap: 20px;
        }

        .visualization-container {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 20px;
        }

        .canvas-container {
            background: var(--bg-light);
            border-radius: 12px;
            padding: 20px;
            position: relative;
        }

        canvas {
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.2);
            border-radius: 8px;
        }

        .control-panel {
            background: var(--bg-light);
            border-radius: 12px;
            padding: 20px;
        }

        .btn {
            background: var(--primary);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 6px;
            cursor: pointer;
            transition: opacity 0.2s;
            width: 100%;
            margin-bottom: 10px;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .btn.secondary {
            background: var(--secondary);
        }

        .input-group {
            margin-bottom: 15px;
        }

        .input-group label {
            display: block;
            margin-bottom: 5px;
            color: #888;
        }

        input[type="number"],
        select {
            width: 100%;
            padding: 8px;
            background: rgba(255,255,255,0.1);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: 4px;
            color: white;
        }

        .device-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .device-item {
            background: rgba(255,255,255,0.1);
            padding: 10px;
            border-radius: 4px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .status-indicator {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: var(--secondary);
        }

        #frequencyDisplay {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(0,0,0,0.7);
            padding: 5px 10px;
            border-radius: 4px;
        }

        .preset-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
            gap: 10px;
        }

        .preset-item {
            background: rgba(255,255,255,0.1);
            padding: 10px;
            border-radius: 4px;
            cursor: pointer;
            transition: background 0.2s;
        }

        .preset-item:hover {
            background: rgba(255,255,255,0.2);
        }
    </style>
</head>
<body>
    <div class="app-container">
        <aside class="sidebar">
            <div class="control-panel">
                <h3>Device Settings</h3>
                <div class="input-group">
                    <label>Device Role</label>
                    <select id="deviceRole">
                        <option value="primary">Primary</option>
                        <option value="left">Left Channel</option>
                        <option value="right">Right Channel</option>
                    </select>
                </div>
                <button class="btn" id="startCapture">Start Capture</button>
                <button class="btn secondary" id="calibrate">Calibrate</button>
            </div>

            <div class="device-list">
                <h3>Connected Devices</h3>
                <div class="device-item">
                    <span>This Device</span>
                    <div class="status-indicator"></div>
                </div>
            </div>
        </aside>

        <main class="main-content">
            <div class="control-panel">
                <h2>Binaural Beat Generator</h2>
                <div class="input-group">
                    <label>Base Frequency (Hz)</label>
                    <input type="number" id="baseFreq" value="432" min="20" max="1000">
                </div>
                <div class="input-group">
                    <label>Beat Frequency (Hz)</label>
                    <input type="number" id="beatFreq" value="7" min="1" max="40">
                </div>
                <button class="btn" id="generateBeat">Generate Beat</button>
            </div>

            <div class="visualization-container">
                <div class="canvas-container">
                    <canvas id="spectrumAnalyzer"></canvas>
                    <div id="frequencyDisplay">0 Hz</div>
                </div>
                <div class="canvas-container">
                    <canvas id="roomAnalysis"></canvas>
                </div>
            </div>
        </main>
    </div>

    <script>
        class AudioSystem {
            constructor() {
                this.audioContext = null;
                this.analyser = null;
                this.gainNode = null;
                this.oscillators = {};
                this.isCapturing = false;
                this.isGenerating = false;
                
                this.initialize();
                this.setupEventListeners();
            }

            async initialize() {
                try {
                    this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
                    this.analyser = this.audioContext.createAnalyser();
                    this.gainNode = this.audioContext.createGain();
                    
                    this.analyser.fftSize = 2048;
                    this.gainNode.connect(this.audioContext.destination);
                    this.analyser.connect(this.gainNode);
                    
                    await this.setupSpectrumVisualizer();
                } catch (error) {
                    console.error('Audio initialization failed:', error);
                }
            }

            async startCapture() {
                if (this.isCapturing) return;
                
                try {
                    const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
                    const source = this.audioContext.createMediaStreamSource(stream);
                    source.connect(this.analyser);
                    this.isCapturing = true;
                } catch (error) {
                    console.error('Capture failed:', error);
                }
            }

            generateBinauralBeat(baseFreq, beatFreq) {
                if (this.isGenerating) this.stopBinauralBeat();

                const leftOsc = this.audioContext.createOscillator();
                const rightOsc = this.audioContext.createOscillator();
                
                leftOsc.frequency.value = baseFreq;
                rightOsc.frequency.value = baseFreq + beatFreq;

                const merger = this.audioContext.createChannelMerger(2);
                
                leftOsc.connect(merger, 0, 0);
                rightOsc.connect(merger, 0, 1);
                merger.connect(this.gainNode);

                leftOsc.start();
                rightOsc.start();

                this.oscillators = { left: leftOsc, right: rightOsc };
                this.isGenerating = true;
            }

            stopBinauralBeat() {
                if (!this.isGenerating) return;

                Object.values(this.oscillators).forEach(osc => osc.stop());
                this.oscillators = {};
                this.isGenerating = false;
            }

            async setupSpectrumVisualizer() {
                const canvas = document.getElementById('spectrumAnalyzer');
                const ctx = canvas.getContext('2d');
                const bufferLength = this.analyser.frequencyBinCount;
                const dataArray = new Uint8Array(bufferLength);

                const draw = () => {
                    requestAnimationFrame(draw);
                    
                    this.analyser.getByteFrequencyData(dataArray);
                    
                    ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
                    ctx.fillRect(0, 0, canvas.width, canvas.height);

                    const barWidth = canvas.width / bufferLength;
                    let x = 0;

                    for(let i = 0; i < bufferLength; i++) {
                        const barHeight = (dataArray[i] / 255) * canvas.height;
                        
                        const hue = i / bufferLength * 360;
                        ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
                        
                        ctx.fillRect(x, canvas.height - barHeight, barWidth, barHeight);
                        x += barWidth + 1;
                    }
                };

                draw();
            }

            setupEventListeners() {
                document.getElementById('startCapture').onclick = () => this.startCapture();
                document.getElementById('generateBeat').onclick = () => {
                    const baseFreq = parseFloat(document.getElementById('baseFreq').value);
                    const beatFreq = parseFloat(document.getElementById('beatFreq').value);
                    this.generateBinauralBeat(baseFreq, beatFreq);
                };
            }
        }

        // Initialize the system
        const audioSystem = new AudioSystem();
    </script>
</body>
</html><script async data-explicit-opt-in="true" data-cookie-opt-in="true" src="https://vercel.live/_next-live/feedback/feedback.js"></script>