Python ダイナミクスとリペア API
マスタリングチェーンのダイナミクスとリペアの各ステージを、1 回で完結するモジュールレベル関数として呼び出せます。音声を変更せずに欠陥だけを報告する測定関数も揃っています。これらのステージを順に実行するチェーンと共通の設定キーは Python マスタリング API、ステージを推奨するアシスタントは Python マスタリング API にあります。
単発のダイナミクスとリペア
名前付きの各ステージは、単発のモジュールレベル関数としても利用できます。チェーンを組まずに 1 つのプロセッサだけを実行できます。パラメータはキーワード専用で、対応する MasteringChainConfig のキーを snake_case にしたものです。ダイナミクス系は DynamicsProcessorResult(samples と int の latency_samples)を返し、リペア系はリペア後の samples と report を持つ結果レコードを返します。
| 関数 | 戻り値 |
|---|---|
mastering_dynamics_compressor() | DynamicsProcessorResult |
mastering_dynamics_gate() | DynamicsProcessorResult |
mastering_dynamics_transient_shaper() | DynamicsProcessorResult |
mastering_repair_declick() | DeclickResult |
mastering_repair_declip() | DeclipResult |
mastering_repair_decrackle() | DecrackleResult |
mastering_repair_dehum() | DehumResult |
mastering_repair_denoise_classical() | DenoiseResult |
mastering_repair_dereverb_classical() | DereverbResult |
mastering_repair_trim_silence() | TrimSilenceResult |
sidechain_high_pass_hz と key_high_pass_hz は None でオフになります。mastering_repair_declip() の clip_threshold_db の既定は、リニア 0.98 に相当するレベルです。mastering_repair_trim_silence() では padding_samples または padding_sec のどちらか一方を渡します。
# Apply the offline feed-forward compressor.
def mastering_dynamics_compressor(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -18.0,
ratio: float = 2.0,
attack_ms: float = 10.0,
release_ms: float = 100.0,
knee_db: float = 0.0,
makeup_gain_db: float = 0.0,
auto_makeup: bool = False,
detector: CompressorDetector = 'rms',
sidechain_high_pass_hz: float | None = None,
pdr_time_ms: float = 0.0,
pdr_release_scale: float = 1.0,
) -> DynamicsProcessorResult: ...
# Apply the offline noise gate.
def mastering_dynamics_gate(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -50.0,
attack_ms: float = 2.0,
release_ms: float = 80.0,
range_db: float = -80.0,
hold_ms: float = 0.0,
close_threshold_db: float = -50.0,
key_high_pass_hz: float | None = None,
) -> DynamicsProcessorResult: ...
# Apply the offline envelope-difference transient shaper.
def mastering_dynamics_transient_shaper(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
attack_gain_db: float = 3.0,
sustain_gain_db: float = 0.0,
fast_attack_ms: float = 0.0,
fast_release_ms: float = 20.0,
slow_attack_ms: float = 15.0,
slow_release_ms: float = 200.0,
sensitivity: float = 1.0,
max_gain_db: float = 12.0,
gain_smoothing_ms: float = 0.0,
lookahead_ms: float = 0.0,
) -> DynamicsProcessorResult: ...# Offline LPC-based declicker.
def mastering_repair_declick(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.8,
neighbor_ratio: float = 4.0,
max_click_samples: int = 8,
lpc_order: int = 20,
residual_ratio: float = 8.0,
) -> DeclickResult: ...
# Offline LPC-based declipper.
def mastering_repair_declip(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
clip_threshold_db: float = _DEFAULT_CLIP_THRESHOLD_DB,
lpc_order: int = 36,
iterations: int = 2,
) -> DeclipResult: ...
# Offline crackle suppressor (median or wavelet-shrinkage).
def mastering_repair_decrackle(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.4,
mode: DecrackleMode = 'median',
levels: int = 4,
) -> DecrackleResult: ...
# Offline mains-hum remover.
def mastering_repair_dehum(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
fundamental_hz: float = 50.0,
harmonics: int = 4,
q: float = 20.0,
adaptive: bool = False,
search_range_hz: float = 2.0,
adaptation: float = 0.25,
frame_size: int = 2048,
pll_bandwidth: float = 0.01,
mode: DehumMode = 'subtract',
) -> DehumResult: ...
# Offline STFT-domain classical denoiser.
def mastering_repair_denoise_classical(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
mode: DenoiseClassicalMode = 'logMmse',
noise_estimator: DenoiseClassicalNoiseEstimator = 'quantile',
n_fft: int = 1024,
hop_length: int = 256,
dd_alpha: float = 0.98,
reduction_db: float = 26.0,
over_subtraction: float = 2.0,
spectral_floor: float = 0.05,
noise_estimation_quantile: float = 0.1,
speech_presence_gain: bool = True,
gain_smoothing: bool = True,
) -> DenoiseResult: ...
# Offline classical dereverberator (spectral subtraction + optional WPE).
def mastering_repair_dereverb_classical(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.0,
attenuation: float = 1.0,
n_fft: int = 1024,
hop_length: int = 256,
t60_sec: float = 0.4,
late_delay_ms: float = 50.0,
over_subtraction: float = 1.0,
spectral_floor: float = 0.08,
wpe_enabled: bool = False,
wpe_iterations: int = 2,
wpe_taps: int = 3,
wpe_strength: float = 0.7,
) -> DereverbResult: ...
# Offline silence trimmer (peak threshold or LUFS-gated).
def mastering_repair_trim_silence(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -60.0,
padding_samples: int | None = None,
padding_sec: float | None = None,
mode: TrimSilenceMode = 'peak',
gate_lufs: float = -60.0,
window_ms: float = 400.0,
) -> TrimSilenceResult: ...信号全体を対象とするリペアステージ(declick、declip、decrackle、dehum、dereverb)は StreamingMasteringChain では拒否されます。これらの単発ヘルパー、または master_audio* の中で実行してください。リアルタイムエンジンでは、decrackle、dehum、クラシックなデノイザー、クラシックなデリバーブがカタログ ID のインサートとしても使えます。declick と declip はオフラインのままです。
リペア系の各ヘルパーには _stereo 版があり、デノイザーとデリバーブにはチャンネルを 1 つのプログラムとして扱う _linked 版もあります。
# Declicks a stereo pair, repairing the union of both channels' runs.
def mastering_repair_declick_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.8,
neighbor_ratio: float = 4.0,
max_click_samples: int = 8,
lpc_order: int = 20,
residual_ratio: float = 8.0,
) -> DeclickStereoResult: ...
# Declips a stereo pair.
def mastering_repair_declip_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
clip_threshold_db: float = _DEFAULT_CLIP_THRESHOLD_DB,
lpc_order: int = 36,
iterations: int = 2,
link_channels: bool = False,
) -> DeclipStereoResult: ...
# Decrackles a stereo pair, each channel on its own.
def mastering_repair_decrackle_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.4,
mode: DecrackleMode = 'median',
levels: int = 4,
) -> DecrackleStereoResult: ...
# Dehums a stereo pair, sharing the tracked fundamental when tracking is on.
def mastering_repair_dehum_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
fundamental_hz: float = 50.0,
harmonics: int = 4,
q: float = 20.0,
adaptive: bool = False,
search_range_hz: float = 2.0,
adaptation: float = 0.25,
frame_size: int = 2048,
pll_bandwidth: float = 0.01,
mode: DehumMode = 'subtract',
) -> DehumStereoResult: ...
# Denoises a stereo pair with one channel-linked gain mask.
def mastering_repair_denoise_classical_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
mode: DenoiseClassicalMode = 'logMmse',
noise_estimator: DenoiseClassicalNoiseEstimator = 'quantile',
n_fft: int = 1024,
hop_length: int = 256,
dd_alpha: float = 0.98,
reduction_db: float = 26.0,
over_subtraction: float = 2.0,
spectral_floor: float = 0.05,
noise_estimation_quantile: float = 0.1,
speech_presence_gain: bool = True,
gain_smoothing: bool = True,
) -> DenoiseStereoResult: ...
# Denoises any number of channels with one channel-linked gain mask.
def mastering_repair_denoise_classical_linked(
channels: Sequence[Sequence[float] | np.ndarray] | np.ndarray,
sample_rate: int,
*,
mode: DenoiseClassicalMode = 'logMmse',
noise_estimator: DenoiseClassicalNoiseEstimator = 'quantile',
n_fft: int = 1024,
hop_length: int = 256,
dd_alpha: float = 0.98,
reduction_db: float = 26.0,
over_subtraction: float = 2.0,
spectral_floor: float = 0.05,
noise_estimation_quantile: float = 0.1,
speech_presence_gain: bool = True,
gain_smoothing: bool = True,
) -> DenoiseLinkedResult: ...
# Dereverberates a stereo pair with one channel-linked mask.
def mastering_repair_dereverb_classical_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.0,
attenuation: float = 1.0,
n_fft: int = 1024,
hop_length: int = 256,
t60_sec: float = 0.4,
late_delay_ms: float = 50.0,
over_subtraction: float = 1.0,
spectral_floor: float = 0.08,
wpe_enabled: bool = False,
wpe_iterations: int = 2,
wpe_taps: int = 3,
wpe_strength: float = 0.7,
) -> DereverbStereoResult: ...
# Dereverberates any number of channels with one channel-linked mask.
def mastering_repair_dereverb_classical_linked(
channels: Sequence[Sequence[float] | np.ndarray] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.0,
attenuation: float = 1.0,
n_fft: int = 1024,
hop_length: int = 256,
t60_sec: float = 0.4,
late_delay_ms: float = 50.0,
over_subtraction: float = 1.0,
spectral_floor: float = 0.08,
wpe_enabled: bool = False,
wpe_iterations: int = 2,
wpe_taps: int = 3,
wpe_strength: float = 0.7,
) -> DereverbLinkedResult: ...
# Trims a stereo pair to one shared range.
def mastering_repair_trim_silence_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -60.0,
padding_samples: int | None = None,
padding_sec: float | None = None,
mode: TrimSilenceMode = 'peak',
gate_lufs: float = -60.0,
window_ms: float = 400.0,
) -> TrimSilenceStereoResult: ...mastering_repair_detect_* 関数は、音声を変えずに欠陥(クリック、ノイズフロア、クリッピング、クラックル、ハム、残響、トリム範囲)を測定します。mastering_repair_detect_trim_range_stereo() は、ステレオのトリム処理が残す範囲(両チャンネルの範囲の和集合)を 1 つだけ測定します。mastering_repair_noise_band_bins() は、検出したノイズフロアを報告するバンド格子のビン境界を返します。
# Measure clicks without repairing them.
def mastering_repair_detect_clicks(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.8,
neighbor_ratio: float = 4.0,
max_click_samples: int = 8,
lpc_order: int = 20,
residual_ratio: float = 8.0,
) -> ClickDetection: ...
# Measure clipping without repairing it.
def mastering_repair_detect_clipping(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
clip_threshold_db: float = _DEFAULT_CLIP_THRESHOLD_DB,
lpc_order: int = 36,
iterations: int = 2,
) -> ClipDetection: ...
# Measure crackle without repairing it.
def mastering_repair_detect_crackle(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.4,
mode: DecrackleMode = 'median',
levels: int = 4,
) -> CrackleDetection: ...
# Measure mains hum without filtering it.
def mastering_repair_detect_hum(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
fundamental_hz: float = 50.0,
harmonics: int = 4,
q: float = 20.0,
adaptive: bool = False,
search_range_hz: float = 2.0,
adaptation: float = 0.25,
frame_size: int = 2048,
pll_bandwidth: float = 0.01,
mode: DehumMode = 'subtract',
) -> HumDetection: ...
# Measure the noise floor without denoising.
def mastering_repair_detect_noise_floor(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
mode: DenoiseClassicalMode = 'logMmse',
noise_estimator: DenoiseClassicalNoiseEstimator = 'quantile',
n_fft: int = 1024,
hop_length: int = 256,
dd_alpha: float = 0.98,
reduction_db: float = 26.0,
over_subtraction: float = 2.0,
spectral_floor: float = 0.05,
noise_estimation_quantile: float = 0.1,
speech_presence_gain: bool = True,
gain_smoothing: bool = True,
) -> NoiseDetection: ...
# Measure reverberation without dereverberating.
def mastering_repair_detect_reverb(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold: float = 0.0,
attenuation: float = 1.0,
n_fft: int = 1024,
hop_length: int = 256,
t60_sec: float = 0.4,
late_delay_ms: float = 50.0,
over_subtraction: float = 1.0,
spectral_floor: float = 0.08,
wpe_enabled: bool = False,
wpe_iterations: int = 2,
wpe_taps: int = 3,
wpe_strength: float = 0.7,
) -> ReverbDetection: ...
# Measure the range a trim pass would keep, without trimming.
def mastering_repair_detect_trim_range(
samples: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -60.0,
padding_samples: int | None = None,
padding_sec: float | None = None,
mode: TrimSilenceMode = 'peak',
gate_lufs: float = -60.0,
window_ms: float = 400.0,
) -> TrimRange: ...
# Measure the one range a stereo trim pass would cut both channels to.
def mastering_repair_detect_trim_range_stereo(
left: Sequence[float] | list[float] | np.ndarray,
right: Sequence[float] | list[float] | np.ndarray,
sample_rate: int,
*,
threshold_db: float = -60.0,
padding_samples: int | None = None,
padding_sec: float | None = None,
mode: TrimSilenceMode = 'peak',
gate_lufs: float = -60.0,
window_ms: float = 400.0,
) -> TrimRange: ...
# Bin boundaries of the grid a denoise noise floor is reported on.
def mastering_repair_noise_band_bins(sample_rate: int, n_fft: int = 1024) -> np.ndarray: ...mastering_repair_dereverb_config_for_room() は RoomEstimate から完全なデリバーブ設定を作ります。
# Point a dereverb config at a measured room.
def mastering_repair_dereverb_config_for_room(
estimate: RoomEstimate,
*,
threshold: float = 0.0,
attenuation: float = 1.0,
n_fft: int = 1024,
hop_length: int = 256,
t60_sec: float = 0.4,
late_delay_ms: float = 50.0,
over_subtraction: float = 1.0,
spectral_floor: float = 0.08,
wpe_enabled: bool = False,
wpe_iterations: int = 2,
wpe_taps: int = 3,
wpe_strength: float = 0.7,
) -> DereverbClassicalConfig: ...任意のチャンネル数の音声は 2 回の呼び出しでリペアできます。mastering_repair_analyze() はチャンネルごとの欠陥を測定し、アシスタントが実行するステージを recommended として返します(そのまま渡せます。デリバーブは推奨されません)。mastering_repair_apply(channels, sample_rate, stages=[...]) はそれを実行します。ステージはリストの順序に関わらず、declip、declick、decrackle、dehum、denoise、dereverb の固定順で実行され、重複したステージや未知の設定は拒否されます。結果には、リペア後のチャンネルと、ステージごとのレポート(チャンネルごと、またはリンクされた denoise と dereverb では 1 回)が入り、on_progress / cancel は進捗コールバックと同じ使い方です。
# Measure every channel's repair defects and recommend stages.
def mastering_repair_analyze(
channels: Sequence[Sequence[float] | np.ndarray] | np.ndarray,
sample_rate: int,
*,
prefer_streaming_safe: bool = True,
) -> MasteringRepairAnalysis: ...analysis = sonare.mastering_repair_analyze([left, right], 48000)
result = sonare.mastering_repair_apply([left, right], 48000, stages=analysis.recommended)streaming_loudness_gain() と streaming_loudness_gain_stereo() は、StreamingMasteringChain の構築に使う数値を、ラウドネスステージの入力で測定します。戻り値の StreamingLoudnessGain は loudness_static_gain_db(オフラインチェーンが適用するゲインと等しく、シーリングのクランプを含みます。無音では 0)、true_peak_dbtp、integrated_lufs を持ちます。前の 2 つをコンストラクタの loudness_static_gain_db と loudness_static_gain_peak_dbtp に渡します。詳細は ダイナミクス と リペア を参照してください。
# Measure the loudness numbers a :class:`StreamingMasteringChain` needs.
def streaming_loudness_gain(
samples: Sequence[float] | list[float],
sample_rate: int,
config: MasteringChainConfigInput | None = None,
) -> StreamingLoudnessGain: ...
# Stereo counterpart of :func:`streaming_loudness_gain`.
def streaming_loudness_gain_stereo(
left: Sequence[float] | list[float],
right: Sequence[float] | list[float],
sample_rate: int,
config: MasteringChainConfigInput | None = None,
) -> StreamingLoudnessGain: ...