import numpy as np import pytest SAMPLE_RATE = 48000 FRAME_DURATION_MS = 20 SAMPLES_PER_FRAME = SAMPLE_RATE * FRAME_DURATION_MS // 1000 # 960 @pytest.fixture def silence(): """960 samples of silence.""" return np.zeros(SAMPLES_PER_FRAME, dtype=np.float32) @pytest.fixture def quiet_tone(): """960 samples of a quiet 440Hz sine wave at -40 dBFS.""" t = np.arange(SAMPLES_PER_FRAME, dtype=np.float32) / SAMPLE_RATE amplitude = 10 ** (-40 / 20) # ~0.01 return (amplitude * np.sin(2 * np.pi * 440 * t)).astype(np.float32) @pytest.fixture def loud_tone(): """960 samples of a loud 440Hz sine wave at -6 dBFS.""" t = np.arange(SAMPLES_PER_FRAME, dtype=np.float32) / SAMPLE_RATE amplitude = 10 ** (-6 / 20) # ~0.5 return (amplitude * np.sin(2 * np.pi * 440 * t)).astype(np.float32) @pytest.fixture def clipping_tone(): """960 samples of a sine wave that exceeds [-1, 1] range.""" t = np.arange(SAMPLES_PER_FRAME, dtype=np.float32) / SAMPLE_RATE return (1.5 * np.sin(2 * np.pi * 440 * t)).astype(np.float32)