Python Mastering Types
The records returned by the mastering, mastering-assistant and mixing-assistant calls. Chain, preset and processor calls are on Python Mastering API, standalone dynamics and repair on Python Dynamics and Repair API, the assistant, profile and delivery preview calls on Python Mastering API, and mixing_assistant_suggest on Python Mixer API.
All of these are frozen dataclasses except StreamingPlatform (a TypedDict) and MixAssistantTrack (a NamedTuple); samples, left and right are float32 arrays.
Offline mastering results
mastering() and the preset calls return a MasteringResult (mono) or MasteringStereoResult. The configurable chain returns MasteringChainResult or MasteringChainStereoResult, which add the stage list, the measured output true peak and loudness range, per-stage gain reduction and an optional report.
applied_gain_dbsums the static gains only; limiter gain reduction is reported separately instage_gain_reductions.output_true_peak_dbtpis measured at the oversample factor of the peak-limiting stage the chain applied (4x by default), andoutput_loudness_range_luis the EBU R128 loudness range in LU.- Each
stage_gain_reductionsentry is zero or negative, in dB.
# Mastering loudness/true-peak processing result.
@dataclass(frozen=True, slots=True, eq=False)
class MasteringResult:
samples: npt.NDArray[np.float32]
sample_rate: int
input_lufs: float
output_lufs: float
applied_gain_db: float
latency_samples: int = 0
loudness_target_limited: bool = False
non_finite_substitution_count: int = 0
declip_unreconstructed_runs: int | None = None
quantize_clipped_samples: int | None = None
# Stereo mastering processing result.
@dataclass(frozen=True, slots=True, eq=False)
class MasteringStereoResult:
left: npt.NDArray[np.float32]
right: npt.NDArray[np.float32]
sample_rate: int
input_lufs: float
output_lufs: float
applied_gain_db: float
latency_samples: int = 0
loudness_target_limited: bool = False
non_finite_substitution_count: int = 0
declip_unreconstructed_runs: int | None = None
quantize_clipped_samples: int | None = None
# Result of running a configurable mastering chain on mono audio.
@dataclass(frozen=True, slots=True, eq=False)
class MasteringChainResult:
samples: npt.NDArray[np.float32]
sample_rate: int
input_lufs: float
output_lufs: float
applied_gain_db: float
stages: list[str]
output_true_peak_dbtp: float = 0.0
output_loudness_range_lu: float | None = None
loudness_target_limited: bool = False
stage_gain_reductions: list[StageGainReduction] = field(default_factory=list)
report: MasteringReport | None = None
non_finite_substitution_count: int = 0
loudness_gain_db: float | None = None
declip_unreconstructed_runs: int | None = None
# Result of running a configurable mastering chain on stereo audio.
@dataclass(frozen=True, slots=True, eq=False)
class MasteringChainStereoResult:
left: npt.NDArray[np.float32]
right: npt.NDArray[np.float32]
sample_rate: int
input_lufs: float
output_lufs: float
applied_gain_db: float
stages: list[str]
output_true_peak_dbtp: float = 0.0
output_loudness_range_lu: float | None = None
loudness_target_limited: bool = False
stage_gain_reductions: list[StageGainReduction] = field(default_factory=list)
report: MasteringReport | None = None
non_finite_substitution_count: int = 0
loudness_gain_db: float | None = None
declip_unreconstructed_runs: int | None = None
# Gain reduction reported by a single dynamics/maximizer chain stage.
@dataclass(frozen=True, slots=True)
class StageGainReduction:
stage: str
gain_reduction_db: floatReport
MasteringChainResult.report explains how the chain changed the program. before and after are MasteringLoudnessSummary measurements; band_energy_delta_db is the change in spectral energy over 32 logarithmic bands.
# Compact explanation of how an offline mastering chain changed a program.
@dataclass(frozen=True, slots=True, eq=False)
class MasteringReport:
before: MasteringLoudnessSummary
after: MasteringLoudnessSummary
applied_gain_db: float
max_gain_reduction_db: float
loudness_target_limited: bool
band_energy_delta_db: npt.NDArray[np.float32] = field(default_factory=_empty_float32)
loudness_gain_db: float | None = None
# Existing EBU R128 measurements captured before or after mastering.
@dataclass(frozen=True, slots=True)
class MasteringLoudnessSummary:
integrated_lufs: float
max_momentary_lufs: float | None
max_short_term_lufs: float | None
true_peak_dbtp: float
loudness_range_lu: float | NoneStage and streaming helpers
The standalone dynamics processors return a DynamicsProcessorResult; latency_samples is the processor's latency in samples. streaming_loudness_gain() and its stereo form return a StreamingLoudnessGain: pass loudness_static_gain_db and true_peak_dbtp to a StreamingMasteringChain as loudness_static_gain_db and loudness_static_gain_peak_dbtp (see Python Dynamics and Repair API).
# Result of a mastering dynamics processor.
@dataclass(frozen=True, slots=True, eq=False)
class DynamicsProcessorResult:
samples: npt.NDArray[np.float32]
latency_samples: int
# The loudness numbers a :class:`StreamingMasteringChain` is built with.
@dataclass(frozen=True, slots=True)
class StreamingLoudnessGain:
loudness_static_gain_db: float | None
true_peak_dbtp: float
integrated_lufs: floatReference matching
mastering_ab_match_loudness() returns the source with one static gain applied so its loudness matches the reference. The stereo form applies one shared gain to both channels and does not apply a ceiling. reference_lufs and source_lufs are None for a silent or below-gate take.
# Result of :func:`mastering_ab_match_loudness`: the matched take and the match.
@dataclass(frozen=True, slots=True, eq=False)
class LoudnessMatchResult:
samples: npt.NDArray[np.float32]
sample_rate: int
reference_lufs: float
source_lufs: float
applied_gain_db: float
matched_true_peak_dbtp: float
# Result of :func:`mastering_ab_match_loudness_stereo`; see :class:`LoudnessMatchResult`.
@dataclass(frozen=True, slots=True, eq=False)
class LoudnessMatchStereoResult:
left: npt.NDArray[np.float32]
right: npt.NDArray[np.float32]
sample_rate: int
reference_lufs: float
source_lufs: float
applied_gain_db: float
matched_true_peak_dbtp: floatPair analyses
mastering_analyze_pair() returns one of these records according to the analysis name: match.referenceLoudness, match.tonalBalance and match.tonalBalanceLogBands, match.matchEqCurve, or match.estimateReferenceDelaySamples. In MatchEqCurveResult, gain_db[i] is the correction at frequencies[i]. Each MatchTonalBalanceBand spans low_hz to high_hz, with the source and reference levels and their deviation in dB.
# Result of the ``match.referenceLoudness`` pair analysis.
@dataclass(frozen=True, slots=True)
class MatchReferenceLoudnessResult:
source_lufs: float
reference_lufs: float
gain_to_match_db: float | None
# Result of the ``match.tonalBalance`` and ``match.tonalBalanceLogBands`` analyses.
@dataclass(frozen=True, slots=True)
class MatchTonalBalanceResult:
bands: list[MatchTonalBalanceBand]
# One band of the ``match.tonalBalance`` and ``match.tonalBalanceLogBands`` analyses.
@dataclass(frozen=True, slots=True)
class MatchTonalBalanceBand:
low_hz: float
high_hz: float
source_db: float | None
reference_db: float | None
deviation_db: float | None
# Result of the ``match.matchEqCurve`` pair analysis: ``gain_db[i]`` at ``frequencies[i]``.
@dataclass(frozen=True, slots=True, eq=False)
class MatchEqCurveResult:
frequencies: npt.NDArray[np.float32]
gain_db: npt.NDArray[np.float32]
# Result of the ``match.estimateReferenceDelaySamples`` pair analysis.
@dataclass(frozen=True, slots=True)
class MatchEstimateReferenceDelaySamplesResult:
delay_samples: intMono compatibility
mastering_analyze_stereo() returns these for stereo.monoCompatCheck and stereo.monoCompatCheckLogBands. correlation is in [-1, 1], and width is None for a fully out-of-phase pair.
# Result of the ``stereo.monoCompatCheck`` analysis.
@dataclass(frozen=True, slots=True)
class StereoMonoCompatCheckResult:
correlation: float | None
width: float | None
mono_peak: float
side_rms: float
likely_mono_compatible: bool
# One band of the ``stereo.monoCompatCheckLogBands`` analysis.
@dataclass(frozen=True, slots=True)
class StereoMonoCompatBand:
low_hz: float
high_hz: float
correlation: float | None
side_rms: float
# Result of the ``stereo.monoCompatCheckLogBands`` analysis.
@dataclass(frozen=True, slots=True)
class StereoMonoCompatCheckLogBandsResult:
bands: list[StereoMonoCompatBand]Assistant and profile
mastering_audio_profile() returns a MasteringAudioProfile, grouped into loudness, spectral and dynamics blocks plus optional defects. mastering_assistant_suggest() returns a MasteringAssistantResult: the suggested chain_config (a flat MasteringChainConfig mapping), the explanation lines that give the reasoning, and a flat MasteringAssistantProfile of the measurements it summarised from. The stereo forms return the same records. integrated_lufs is None for a silent or below-gate take.
# What :func:`mastering_audio_profile` and its stereo form return.
@dataclass(frozen=True, slots=True)
class MasteringAudioProfile:
duration_sec: float
bpm: float | None
bpm_confidence: float
loudness: MasteringAudioProfileLoudness
spectral: MasteringAudioProfileSpectral
dynamics: MasteringAudioProfileDynamics
defects: AudioDefects | None
# Loudness group of :class:`MasteringAudioProfile`.
@dataclass(frozen=True, slots=True)
class MasteringAudioProfileLoudness:
integrated_lufs: float
loudness_range_lu: float | None
true_peak_dbtp: float
crest_factor_db: float | None
# Spectral group of :class:`MasteringAudioProfile`.
@dataclass(frozen=True, slots=True)
class MasteringAudioProfileSpectral:
sub_rms_db: float | None
low_rms_db: float | None
low_mid_rms_db: float | None
mid_rms_db: float | None
high_mid_rms_db: float | None
high_rms_db: float | None
air_rms_db: float | None
centroid_hz: float | None
flatness: float | None
rolloff_hz: float | None
# Dynamics group of :class:`MasteringAudioProfile`.
@dataclass(frozen=True, slots=True)
class MasteringAudioProfileDynamics:
short_term_lufs_std: float | None
attack_per_second: float
sustain_ratio: float | None
# Measurements the assistant summarises its suggestion from (flat).
@dataclass(frozen=True, slots=True)
class MasteringAssistantProfile:
duration_sec: float
bpm: float | None
bpm_confidence: float
integrated_lufs: float
loudness_range_lu: float | None
true_peak_dbtp: float
crest_factor_db: float | None
spectral_centroid_hz: float | None
spectral_flatness: float | None
attack_per_second: float
sustain_ratio: float | None
# What :func:`mastering_assistant_suggest` and its stereo form return.
@dataclass(frozen=True, slots=True)
class MasteringAssistantResult:
chain_config: MasteringChainConfig
explanation: list[str]
profile: MasteringAssistantProfileStreaming preview
mastering_streaming_preview() and its stereo form return a MasteringStreamingPreviewResult with one entry per delivery target. Passing platforms= takes StreamingPlatform mappings; omitting it uses the built-in Spotify, Apple Music and YouTube set. normalization_gain_db is the gain that lands the take on the platform's target (0 when the loudness is None), and ceiling_risk is true when that gain would push the true peak above the platform's ceiling.
# One delivery target a streaming preview or the assistant measures against.
class StreamingPlatform(TypedDict):
name: str
target_lufs: float
ceiling_dbtp: float
# One delivery target in a :class:`MasteringStreamingPreviewResult`.
@dataclass(frozen=True, slots=True)
class MasteringStreamingPreviewPlatform:
name: str
integrated_lufs: float
true_peak_dbtp: float
normalization_gain_db: float | None
ceiling_risk: bool
# What :func:`mastering_streaming_preview` and its stereo form return.
@dataclass(frozen=True, slots=True)
class MasteringStreamingPreviewResult:
platforms: list[MasteringStreamingPreviewPlatform]Mixing assistant records
mixing_assistant_suggest(tracks, *, sample_rate, ...) takes a list of MixAssistantTrack (a track at another sample rate is resampled onto the call's rate) and returns a MixAssistantResult. A degenerate track is not an error: it appears in tracks with usable false and an exclusion_reason. source is a MixSourceClass and band_occupancy is keyed by MixAnalysisBand ("sub", "low", "lowMid", "mid", "highMid", "high", "air"). The workflow is on Mixing Assistant.
# One track handed to the mixing assistant.
class MixAssistantTrack(NamedTuple):
id: str
channels: Sequence[Sequence[float] | np.ndarray]
name: str | None = None
sample_rate: int | None = None
# What :func:`mixing_assistant_suggest` returns.
@dataclass(frozen=True, slots=True)
class MixAssistantResult:
scene: dict[str, Any]
tracks: list[MixAssistantTrackProfile]
mix: MixAssistantMixProfile
explanation: list[str]
# Per-track measurements and the class the track was resolved to.
@dataclass(frozen=True, slots=True)
class MixAssistantTrackProfile:
strip_id: str
name: str | None
source: MixSourceClass
source_confidence: float
usable: bool
exclusion_reason: str | None
num_channels: int
duration_sec: float
integrated_lufs: float | None
true_peak_dbtp: float | None
crest_factor_db: float | None
spectral_centroid_hz: float | None
spectral_flatness: float | None
attack_per_second: float
sustain_ratio: float | None
band_occupancy: dict[MixAnalysisBand, float]Cross-track measurements
MixAssistantResult.mix holds the findings that involve more than one track.
# Cross-track measurements the decisions were made from.
@dataclass(frozen=True, slots=True)
class MixAssistantMixProfile:
track_count: int
band_dominance: list[MixBandDominance]
alignment: list[MixTrackAlignment]
crowded_bands: list[MixCrowdedBand]
mono_risks: list[MixMonoRisk]
# One informative masker/maskee band pair.
@dataclass(frozen=True, slots=True)
class MixBandDominance:
masker: str
maskee: str
band: MixAnalysisBand
ratio: float
valid_frames: int
# A related track pair and the time/polarity relationship measured between them.
@dataclass(frozen=True, slots=True)
class MixTrackAlignment:
reference: str
target: str
lag_samples: int
correlation: float
polarity_opposed: bool
# A band carrying more simultaneous sources than the image comfortably holds.
@dataclass(frozen=True, slots=True)
class MixCrowdedBand:
band: MixAnalysisBand
crowding: float
# A track whose stereo image is likely to collapse in mono.
@dataclass(frozen=True, slots=True)
class MixMonoRisk:
strip_id: str
correlation: float
width: float
wide_low_end: bool