lupy.meter

class lupy.meter.Meter(block_size: int, num_channels: NumChannelsT, sampler_class: type[Sampler] = <class 'lupy.sampling.Sampler'>, tp_sampler_class: type[TruePeakSampler] = <class 'lupy.sampling.TruePeakSampler'>, sample_rate: int = 48000, true_peak_gate_duration: Fraction = Fraction(2, 5), true_peak_enabled: bool = True, momentary_enabled: bool = True, short_term_enabled: bool = True, lra_enabled: bool = True)[source]

Bases: Generic[NumChannelsT]

Parameters:

Important

If short_term_enabled is False, lra_enabled must also be False. This is because Loudness Range calculation depends on Short-Term Loudness values.

Raises:

ValueError – If short_term_enabled is False and lra_enabled is True

block_size: int

The number of input samples per call to write()

num_channels: NumChannelsT

Number of audio channels

sample_rate: int

The sample rate of the audio data

sampler: Sampler[NumChannelsT]

The Sampler instance to buffer input data

true_peak_sampler: TruePeakSampler[NumChannelsT]

Sample buffer to hold un-filtered samples for true_peak_processor

processor: BlockProcessor[NumChannelsT]

The BlockProcessor to perform the calulations

true_peak_processor: TruePeakProcessor[NumChannelsT]

The TruePeakProcessor

property true_peak_enabled: bool

Whether True Peak processing is enabled (read-only)

property momentary_enabled: bool

Whether Momentary Loudness processing is enabled (read-only)

property short_term_enabled: bool

Whether Short-Term Loudness processing is enabled (read-only)

property lra_enabled: bool

Whether Loudness Range processing is enabled (read-only)

property paused: bool

True if processing is currently paused

can_write() bool[source]

Whether there is enough room on the internal buffer for at least one call to write()

can_process() bool[source]

Whether there are enough samples in the internal buffer for at least one call to process()

write(samples: ndarray[tuple[int, int], dtype[float64]] | ndarray[tuple[int, int], dtype[float32]], process: bool = True, process_all: bool = True) None[source]

Store input data into the internal buffer

The input data must be of shape (num_channels, block_size)

write_all(samples: ndarray[tuple[int, int], dtype[float32] | dtype[float64]]) None[source]

Write an arbitrary number of samples and process them

If the number of samples is not a multiple of block_size, the samples will be truncated to the nearest multiple.

process(process_all: bool = True) None[source]

Process the samples for at least one gating block

Parameters:

process_all (bool) – If True (the default), the read() method of the sampler will be called and the data passed to the process_block() method on the processor repeatedly until there are no gating block samples available. Otherwise, only one call to each will be performed.

reset() None[source]

Reset all values for processor and clear any buffered input samples

set_paused(paused: bool) None[source]

Pause or unpause processing

When paused, the current state of the processor is preserved and any input provided to the write() method will be discarded.

property integrated_lkfs: floating

The current Integrated Loudness

property lra: float

The current Loudness Range

If lra_enabled is False, this will always return 0.0.

property block_data: MeterArray

A structured array of measurement values with dtype MeterDtype

property current_measurement: CurrentMeasurement[NumChannelsT]

The current measurement values as a CurrentMeasurement instance

This is a snapshot of the most recent measurement values for each metric as of the last processed gating block.

It provides the latest values for:

If no gating blocks have been processed yet, the values returned will correspond to their initial silence states.

property momentary_lkfs: ndarray[tuple[int], dtype[float64]]

Momentary Loudness for each 100ms block, averaged over 400ms (not gated)

If momentary_enabled is False, this will return an array of zeroes.

property short_term_lkfs: ndarray[tuple[int], dtype[float64]]

Short-Term Loudness for each 100ms block, averaged over 3 seconds (not gated)

If short_term_enabled is False, this will return an array of zeroes.

property t: ndarray[tuple[int], dtype[float64]]

The measurement time for each element in short_term_lkfs and momentary_lkfs

property true_peak_array: TruePeakArray[NumChannelsT]

A structured array of True Peak measurement values with dtype TruePeakDtype

property true_peak_max: floating

Maximum True Peak value detected

If true_peak_enabled is False, this will always return -inf.

property true_peak_current: ndarray[tuple[NumChannelsT], dtype[float64]]

True Peak values per channel from the last processing period

If true_peak_enabled is False, this will always return an array of -inf values.