Source code for jdxi_editor.audio.audio_snapshot

"""
The latest analysis, handed to the window as one immutable value.
"""

from dataclasses import dataclass

import numpy as np

#: Meter floor and ceiling, in dB
[docs] DB_FLOOR = -60.0
[docs] DB_CEIL = 0.0
#: Display rate, and the FFT the spectrum analyser consumes
[docs] REFRESH_HZ = 30
[docs] FFT_SIZE = 4096
[docs] BAND_COUNT = 31
#: Columns stored for the oscilloscope. The widget scales them to its width.
[docs] WAVEFORM_COLUMNS = 480
[docs] SAMPLE_RATE = 48_000
[docs] BLOCK_SIZE = 1024
[docs] def clip_db(value: float) -> float: """ Clamp a level onto the meter scale. :param value: float decibels :return: float in DB_FLOOR..DB_CEIL """ return float(min(DB_CEIL, max(DB_FLOOR, value)))
@dataclass(frozen=True)
[docs] class AudioSnapshot: """ One published frame of analysis. Levels are decibels on the meter scale. ``spectrum`` has :data:`BAND_COUNT` bands. Each waveform is ``(columns, 2)`` of min and max per column, so a transient is not averaged away. :param rms_left: float block RMS, left, dB :param rms_right: float block RMS, right, dB :param peak_left: float peak meter, left, dB :param peak_right: float peak meter, right, dB :param peak_hold_left: float held peak, left, dB :param peak_hold_right: float held peak, right, dB :param vu_left: float VU, left, dB :param vu_right: float VU, right, dB :param spectrum: np.ndarray band levels, dB :param waveform_left: np.ndarray decimated min/max :param waveform_right: np.ndarray decimated min/max :param sample_rate: int Hz :param timebase_ms: int oscilloscope window """
[docs] rms_left: float
[docs] rms_right: float
[docs] peak_left: float
[docs] peak_right: float
[docs] peak_hold_left: float
[docs] peak_hold_right: float
[docs] vu_left: float
[docs] vu_right: float
[docs] spectrum: np.ndarray
[docs] waveform_left: np.ndarray
[docs] waveform_right: np.ndarray
[docs] sample_rate: int
[docs] timebase_ms: int