from __future__ import annotations

import numpy as np

from engine.processor import AudioEngine


def test_rms_envelope_stays_finite_for_near_silence():
    engine = AudioEngine()
    engine.sample_rate = 44100
    x = np.zeros(44100, dtype=np.float32)
    x[::997] = np.float32(1e-20)
    env = engine._calculate_rms_envelope(x, 441)
    assert np.all(np.isfinite(env))
    assert np.all(env >= 0.0)
