# Example Training Session > A practical demonstration of the Interactive Frequency Trainer ## Quick Start Demo Copy and run these code blocks in order to experience the tool: ### 1. Initialize Audio System ```javascript // Load the training system (async () => { // Basic audio context setup const audioContext = new (window.AudioContext || window.webkitAudioContext)(); console.log('🎧 Audio system ready!'); // Test with a simple 440Hz tone (A4) const oscillator = audioContext.createOscillator(); const gainNode = audioContext.createGain(); oscillator.connect(gainNode); gainNode.connect(audioContext.destination); oscillator.frequency.value = 440; gainNode.gain.value = 0.1; oscillator.start(); oscillator.stop(audioContext.currentTime + 1); console.log('🎵 Played A4 (440Hz) test tone'); })(); ``` ### 2. Basic Frequency Generator ```javascript // Simple frequency generator function function playFrequency(freq, duration = 1, waveType = 'sine') { const audioContext = new (window.AudioContext || window.webkitAudioContext)(); const oscillator = audioContext.createOscillator(); const gainNode = audioContext.createGain(); oscillator.connect(gainNode); gainNode.connect(audioContext.destination); oscillator.type = waveType; oscillator.frequency.value = freq; gainNode.gain.value = 0.15; // Envelope to prevent clicks gainNode.gain.setValueAtTime(0, audioContext.currentTime); gainNode.gain.linearRampToValueAtTime(0.15, audioContext.currentTime + 0.1); gainNode.gain.linearRampToValueAtTime(0, audioContext.currentTime + duration - 0.1); oscillator.start(); oscillator.stop(audioContext.currentTime + duration); console.log(`🔊 Playing ${freq}Hz ${waveType} wave for ${duration}s`); } // Test different frequencies console.log('Testing different frequency ranges:'); playFrequency(100); // Bass ``` ### 3. Random Frequency Challenge ```javascript // Simple training challenge generator const frequencyRanges = { bass: [60, 250], lowMids: [250, 500], mids: [500, 2000], highMids: [2000, 4000], treble: [4000, 8000] }; function generateChallenge() { const ranges = Object.keys(frequencyRanges); const randomRange = ranges[Math.floor(Math.random() * ranges.length)]; const [min, max] = frequencyRanges[randomRange]; const frequency = Math.floor(Math.random() * (max - min) + min); return { frequency, range: randomRange }; } // Generate and play a challenge const challenge = generateChallenge(); console.log(`🎯 Challenge: Identify the frequency range`); console.log(`Hint: It's in the ${challenge.range} range`); playFrequency(challenge.frequency, 2); // Store for checking later window.currentChallenge = challenge; ``` ### 4. Check Your Guess ```javascript // Check your guess against the current challenge function checkGuess(guessedRange) { if (!window.currentChallenge) { console.log('❓ No active challenge. Run the previous code block first!'); return; } const { frequency, range } = window.currentChallenge; const correct = guessedRange === range; if (correct) { console.log(`✅ Correct! It was ${frequency}Hz in the ${range} range`); } else { console.log(`❌ Not quite. It was ${frequency}Hz in the ${range} range, not ${guessedRange}`); } // Play the frequency again for reference playFrequency(frequency, 1.5); } // Example usage: // checkGuess('bass'); // if you think it's bass // checkGuess('mids'); // if you think it's mids // checkGuess('treble'); // if you think it's treble console.log('🤔 Make your guess using: checkGuess("bass"), checkGuess("mids"), etc.'); ``` ## Advanced Examples ### Waveform Comparison ```javascript // Compare different waveforms at the same frequency const testFreq = 440; const waveforms = ['sine', 'square', 'sawtooth', 'triangle']; console.log(`🎼 Comparing waveforms at ${testFreq}Hz:`); waveforms.forEach((wave, index) => { setTimeout(() => { console.log(`▶️ Playing ${wave} wave...`); playFrequency(testFreq, 1.5, wave); }, index * 2000); // 2-second gaps between each }); ``` ### Frequency Sweep ```javascript // Create a frequency sweep function createSweep(startFreq, endFreq, duration = 3) { const audioContext = new (window.AudioContext || window.webkitAudioContext)(); const oscillator = audioContext.createOscillator(); const gainNode = audioContext.createGain(); oscillator.connect(gainNode); gainNode.connect(audioContext.destination); oscillator.type = 'sine'; oscillator.frequency.setValueAtTime(startFreq, audioContext.currentTime); oscillator.frequency.exponentialRampToValueAtTime(endFreq, audioContext.currentTime + duration); gainNode.gain.setValueAtTime(0, audioContext.currentTime); gainNode.gain.linearRampToValueAtTime(0.1, audioContext.currentTime + 0.1); gainNode.gain.linearRampToValueAtTime(0, audioContext.currentTime + duration - 0.1); oscillator.start(); oscillator.stop(audioContext.currentTime + duration); console.log(`🌊 Sweeping from ${startFreq}Hz to ${endFreq}Hz over ${duration}s`); } // Try different sweeps createSweep(100, 1000, 4); // Low to mid sweep ``` ### A/B Frequency Comparison ```javascript // Compare two close frequencies function compareFrequencies(freqA, freqB, duration = 1.5) { console.log(`🔄 A/B Test: ${freqA}Hz vs ${freqB}Hz`); // Play frequency A console.log('🅰️ Playing frequency A...'); playFrequency(freqA, duration); // Play frequency B after a pause setTimeout(() => { console.log('🅱️ Playing frequency B...'); playFrequency(freqB, duration); }, (duration + 0.5) * 1000); // Play both for comparison setTimeout(() => { console.log('🔄 Playing both for comparison...'); setTimeout(() => playFrequency(freqA, duration), 0); setTimeout(() => playFrequency(freqB, duration), (duration + 0.2) * 1000); }, (duration * 2 + 1) * 1000); } // Test your ability to distinguish close frequencies compareFrequencies(440, 445); // Very close frequencies ``` ## Training Tips 1. **Start Simple**: Begin with wide frequency ranges before narrowing down 2. **Use References**: Keep some known frequencies as reference points 3. **Take Breaks**: Ear fatigue is real - rest every 15-20 minutes 4. **Be Consistent**: Regular short sessions work better than long occasional ones 5. **Use Quality Audio**: Good headphones or monitors make a huge difference ## Common Reference Frequencies - **100 Hz**: Deep bass, fundamental of low notes - **440 Hz**: A4, standard tuning reference - **1000 Hz**: Test tone standard, good midpoint - **3000 Hz**: Vocal clarity, presence range - **10000 Hz**: High-frequency detail, "air" ## Next Steps Once you're comfortable with these examples: 1. Move to the full `Interactive Frequency Trainer.md` 2. Set up the Strudel integration following the `Setup Guide.md` 3. Customize the frequency ranges for your specific needs 4. Create your own training routines --- *Remember: Ear training is a skill that develops over time. Be patient with yourself and enjoy the process! 🎶*