"""Original Clout mathematical references, not AI or provider-generated audio.
Run with Python 3 from any folder; WAVs are written beside this source file.
"""
from pathlib import Path
import math
import struct
import wave

RATE = 48000
ROOT = Path(__file__).resolve().parent
for name, seconds, hz, amplitude in [
    ("audio-clean-tone.wav", 2, 220, 0.4),
    ("audio-full-scale-tone.wav", 1, 1000, 1.0),
    ("audio-silence.wav", 1, 0, 0),
]:
    count = int(seconds * RATE)
    values = []
    for i in range(count):
        envelope = min(1.0, i / (RATE * 0.02), (count - 1 - i) / (RATE * 0.02))
        value = amplitude * envelope * math.sin(2 * math.pi * hz * i / RATE)
        values.append(struct.pack("<h", round(max(-1.0, min(1.0, value)) * 32767)))
    with wave.open(str(ROOT / name), "wb") as output:
        output.setnchannels(1)
        output.setsampwidth(2)
        output.setframerate(RATE)
        output.writeframes(b"".join(values))
