File size: 9,394 Bytes
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Audio Spectrum Analyzer</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
background: #1a1a1a;
color: #fff;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
padding: 20px 0;
}
.controls {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.control-panel {
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
}
.visualization {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 20px;
margin: 20px 0;
}
canvas {
width: 100%;
height: 400px;
background: #2a2a2a;
border-radius: 8px;
}
button {
background: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #45a049;
}
input[type="number"] {
width: 100%;
padding: 8px;
margin: 5px 0;
border-radius: 4px;
border: 1px solid #444;
background: #333;
color: white;
}
.device-status {
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
}
.preset-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
margin: 20px 0;
}
.preset {
background: #333;
padding: 10px;
border-radius: 4px;
cursor: pointer;
}
.preset:hover {
background: #444;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>3D Audio Spectrum Analyzer</h1>
</div>
<div class="controls">
<div class="control-panel">
<h3>Device Configuration</h3>
<button id="startAnalysis">Start Analysis</button>
<button id="stopAnalysis">Stop Analysis</button>
<button id="calibrate">Calibrate Devices</button>
<div>
<label>Device Role:</label>
<select id="deviceRole">
<option value="left">Left Channel</option>
<option value="right">Right Channel</option>
<option value="center">Center Channel</option>
</select>
</div>
</div>
<div class="control-panel">
<h3>Binaural Beat Generator</h3>
<div>
<label>Base Frequency (Hz):</label>
<input type="number" id="baseFreq" value="432" min="20" max="1000">
</div>
<div>
<label>Beat Frequency (Hz):</label>
<input type="number" id="beatFreq" value="7" min="1" max="40">
</div>
<button id="startBinaural">Generate Binaural Beat</button>
<button id="stopBinaural">Stop</button>
</div>
</div>
<div class="visualization">
<canvas id="spectrumCanvas"></canvas>
<canvas id="3dRoomCanvas"></canvas>
</div>
<div class="preset-container">
<div class="preset">
<h4>Alpha Wave</h4>
<p>8-12 Hz</p>
</div>
<div class="preset">
<h4>Theta Wave</h4>
<p>4-7 Hz</p>
</div>
<div class="preset">
<h4>Delta Wave</h4>
<p>0.5-4 Hz</p>
</div>
</div>
<div class="device-status">
<h3>Connected Devices</h3>
<div id="deviceList"></div>
</div>
</div>
<script>
class AudioAnalyzer {
constructor() {
this.audioContext = null;
this.analyser = null;
this.oscillator = null;
this.isPlaying = false;
}
async initialize() {
try {
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
this.analyser = this.audioContext.createAnalyser();
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const source = this.audioContext.createMediaStreamSource(stream);
source.connect(this.analyser);
this.setupVisualization();
} catch (error) {
console.error('Error initializing audio:', error);
}
}
generateBinauralBeat(baseFreq, beatFreq) {
if (this.isPlaying) this.stopBinauralBeat();
const leftOsc = this.audioContext.createOscillator();
const rightOsc = this.audioContext.createOscillator();
const leftGain = this.audioContext.createGain();
const rightGain = this.audioContext.createGain();
const merger = this.audioContext.createChannelMerger(2);
leftOsc.frequency.value = baseFreq;
rightOsc.frequency.value = baseFreq + beatFreq;
leftOsc.connect(leftGain);
rightOsc.connect(rightGain);
leftGain.connect(merger, 0, 0);
rightGain.connect(merger, 0, 1);
merger.connect(this.audioContext.destination);
leftOsc.start();
rightOsc.start();
this.oscillator = { left: leftOsc, right: rightOsc };
this.isPlaying = true;
}
stopBinauralBeat() {
if (this.oscillator) {
this.oscillator.left.stop();
this.oscillator.right.stop();
this.isPlaying = false;
}
}
setupVisualization() {
const canvas = document.getElementById('spectrumCanvas');
const ctx = canvas.getContext('2d');
const width = canvas.width;
const height = canvas.height;
const draw = () => {
requestAnimationFrame(draw);
const dataArray = new Uint8Array(this.analyser.frequencyBinCount);
this.analyser.getByteFrequencyData(dataArray);
ctx.fillStyle = '#2a2a2a';
ctx.fillRect(0, 0, width, height);
const barWidth = width / dataArray.length;
let x = 0;
dataArray.forEach(value => {
const barHeight = value * height / 255;
ctx.fillStyle = `hsl(${value}, 100%, 50%)`;
ctx.fillRect(x, height - barHeight, barWidth, barHeight);
x += barWidth;
});
};
draw();
}
}
// Initialize application
const analyzer = new AudioAnalyzer();
document.getElementById('startAnalysis').addEventListener('click', () => analyzer.initialize());
document.getElementById('startBinaural').addEventListener('click', () => {
const baseFreq = parseFloat(document.getElementById('baseFreq').value);
const beatFreq = parseFloat(document.getElementById('beatFreq').value);
analyzer.generateBinauralBeat(baseFreq, beatFreq);
});
document.getElementById('stopBinaural').addEventListener('click', () => analyzer.stopBinauralBeat());
// Setup room visualization
const room3d = document.getElementById('3dRoomCanvas');
const ctx3d = room3d.getContext('2d');
function draw3dRoom() {
// Basic 3D room visualization implementation would go here
// This would require a more complex 3D rendering library for proper implementation
ctx3d.fillStyle = '#2a2a2a';
ctx3d.fillRect(0, 0, room3d.width, room3d.height);
ctx3d.strokeStyle = '#4CAF50';
ctx3d.beginPath();
ctx3d.moveTo(50, 50);
ctx3d.lineTo(room3d.width - 50, 50);
ctx3d.lineTo(room3d.width - 50, room3d.height - 50);
ctx3d.lineTo(50, room3d.height - 50);
ctx3d.closePath();
ctx3d.stroke();
}
draw3dRoom();
</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> |