Changed around line 1
+ let currentNote = null;
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
+
+ function startTraining() {
+ document.querySelector('.trainer-container').style.display = 'block';
+ playRandomNote();
+ }
+
+ function playRandomNote() {
+ const notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
+ currentNote = notes[Math.floor(Math.random() * notes.length)];
+
+ const frequency = getNoteFrequency(currentNote);
+ const oscillator = audioContext.createOscillator();
+ const gainNode = audioContext.createGain();
+
+ oscillator.connect(gainNode);
+ gainNode.connect(audioContext.destination);
+
+ oscillator.type = 'sine';
+ oscillator.frequency.value = frequency;
+
+ gainNode.gain.setValueAtTime(0, audioContext.currentTime);
+ gainNode.gain.linearRampToValueAtTime(1, audioContext.currentTime + 0.01);
+
+ oscillator.start();
+ gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 1);
+ oscillator.stop(audioContext.currentTime + 1);
+ }
+
+ function getNoteFrequency(note) {
+ const noteToFreq = {
+ 'C': 261.63, 'C#': 277.18, 'D': 293.66, 'D#': 311.13,
+ 'E': 329.63, 'F': 349.23, 'F#': 369.99, 'G': 392.00,
+ 'G#': 415.30, 'A': 440.00, 'A#': 466.16, 'B': 493.88
+ };
+ return noteToFreq[note];
+ }
+
+ function checkAnswer(selectedNote) {
+ if (selectedNote === currentNote) {
+ updateStats(true);
+ alert('Correct!');
+ } else {
+ updateStats(false);
+ alert(`Incorrect. The note was ${currentNote}`);
+ }
+ playRandomNote();
+ }
+
+ function updateStats(correct) {
+ // Implementation for statistics tracking
+ const stats = JSON.parse(localStorage.getItem('pitchStats') || '{"correct":0,"total":0}');
+ stats.total++;
+ if (correct) stats.correct++;
+ localStorage.setItem('pitchStats', JSON.stringify(stats));
+ updateStatsDisplay();
+ }
+
+ function updateStatsDisplay() {
+ const stats = JSON.parse(localStorage.getItem('pitchStats') || '{"correct":0,"total":0}');
+ const accuracy = stats.total ? ((stats.correct / stats.total) * 100).toFixed(1) : 0;
+
+ const ctx = document.getElementById('statsChart').getContext('2d');
+ // Implementation for chart drawing
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ updateStatsDisplay();
+ });