<!-- Auto-modified logic added -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Frequency-based Volume Adjustment with Predator Sounds</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 16px;
            text-align: center;
        }

        button {
            padding: 10px 20px;
            font-size: 16px;
            margin: 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <button id="playButton">SUPER Play</button>
    <button id="pauseButton" style="display:none;">Pause the ultrasound</button>

    <script>
        let isPlaying = false;
        let audioContext;

        // Ελάχιστη και μέγιστη συχνότητα
        const minFrequency = 200; // Ελάχιστη συχνότητα 200 Hz
        const maxFrequency = 3500; // Μέγιστη συχνότητα 3500 Hz

        // Μέγιστο volume για χαμηλές συχνότητες και μειωμένο για υψηλές συχνότητες
        const maxDecibel = 10; // Μέγιστο επίπεδο dB
        const lowFrequencyVolume = Math.pow(10, maxDecibel / 20); // Πλήρης ένταση για χαμηλή συχνότητα
        const highFrequencyVolume = Math.pow(10, (maxDecibel - 6) / 20); // Μειωμένη ένταση για υψηλή συχνότητα

        function playSound(frequency, volume) {
            audioContext = new (window.AudioContext || window.webkitAudioContext)();
            const oscillator = audioContext.createOscillator();
            const gainNode = audioContext.createGain();

            // Περιορισμός συχνότητας
            frequency = Math.max(minFrequency, Math.min(maxFrequency, frequency));

            oscillator.type = 'sine';
            oscillator.frequency.value = frequency;

            gainNode.gain.value = volume;

            oscillator.connect(gainNode);
            gainNode.connect(audioContext.destination);

            oscillator.start();
            setTimeout(() => {
                oscillator.stop();
                audioContext.close();
            }, 1000); // Παίζει για 1 δευτερόλεπτο
        }

        function playRandomSound() {
            const sounds = [
                { frequency: 1000, volume: lowFrequencyVolume }, // Alarm
                { frequency: 3000, volume: highFrequencyVolume }, // Hawk
                { frequency: 250, volume: lowFrequencyVolume }, // Owl
                { frequency: 1200, volume: highFrequencyVolume }, // Eagle
                { frequency: 500, volume: lowFrequencyVolume }, // Thunder
            ];

            const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
            playSound(randomSound.frequency, randomSound.volume);
        }

        async function playSoundsSequence() {
            while (isPlaying) {
                playRandomSound();
                await new Promise((resolve) => setTimeout(resolve, 2000));
            }
        }

        document.getElementById('playButton').addEventListener('click', () => {
            isPlaying = true;
            document.getElementById('playButton').style.display = 'none';
            document.getElementById('pauseButton').style.display = 'block';
            playSoundsSequence();
        });

        document.getElementById('pauseButton').addEventListener('click', () => {
            isPlaying = false;
            document.getElementById('playButton').style.display = 'block';
            document.getElementById('pauseButton').style.display = 'none';
        });
    </script>
</body>
</html>

<!-- End of auto-modifications -->