Skip to content

Python 再生 API ​

映画音声の再生レンダラーは、デコード済みのモノラル、ステレオ、5.1、7.1 の PCM を、スピーカーレイアウトの音声(アップミックス、スピーカー較正、バスマネジメント)か、バイノーラルのヘッドホン音声(HRTF 畳み込み、ヘッドトラッキング、ルームモデル)に変換します。ターゲット、ルーム、スピーカーごとのレイアウトは PlaybackRendererConfig のマッピングで渡します。保存した JSON テキストは json.loads で読み取ってから渡します。未定義のキーや型の違いには TypeError、範囲外の値には SonareValueError を送出します。

PlaybackRenderer、PlaybackLoudnessMeter、HrtfSet はいずれも close() を持ち、コンテキストマネージャとして使えるので、with なら例外時にも解放されます(ネイティブハンドルの解放)。ヘッドホンターゲットのレンダラーは HrtfSet を使います。

レンダラーと設定 ​

python
PlaybackRendererConfig = dict[str, Any]

# Renders decoded movie audio to speakers or binaural headphones.
class PlaybackRenderer:
    # Create a renderer at ``sample_rate``.
    def __init__(
        self,
        config: PlaybackRendererConfig,
        *,
        sample_rate: int,
        hrtf: HrtfSet | None = None,
        max_block_size: int | None = None,
    ) -> None: ...
    # Release the underlying C handle.
    def close(self) -> None: ...
    # Return the object itself for ``with`` use.
    def __enter__(self) -> PlaybackRenderer: ...
    # Close the object on leaving the ``with`` block; never suppresses exceptions.
    def __exit__(self, exc_type: object, exc: object, tb: object) -> None: ...
    # Clear DSP state (filters, FIFOs, DRC, convolution history, pending drains).
    def reset(self) -> None: ...
    # Apply a complete configuration.
    def set_config(self, config: PlaybackRendererConfig) -> None: ...
    # The current complete configuration document.
    def config(self) -> PlaybackRendererConfig: ...
    # Publish the listener head orientation; ignored by a speakers target.
    def set_head_orientation(
        self,
        yaw_deg: float,
        pitch_deg: float = 0.0,
        roll_deg: float = 0.0,
    ) -> None: ...
    # The largest frame count one ``process_*`` call accepts.
    @property
    def max_block_size(self) -> int: ...
    # Channel count of the active input layout.
    @property
    def num_input_channels(self) -> int: ...
    # Channel count of the output target; fixed for the renderer's lifetime.
    @property
    def num_output_channels(self) -> int: ...
    # Renderer latency in frames (headphones: near ear).
    @property
    def latency_samples(self) -> int: ...
    # Non-finite input samples replaced with 0 since creation.
    @property
    def non_finite_discard_count(self) -> int: ...
    # Inactive stages, per-stage latency, clamps, active input layout and counters.
    def diagnostics(self) -> dict[str, Any]: ...
    # Render one planar block; returns a ``(num_output_channels, frames)`` array.
    def process_planar(self, planes: Sequence[Sequence[float]] | np.ndarray) -> np.ndarray: ...
    # Render one planar block of silence; returns a ``(num_output_channels, frames)`` array.
    def process_silence(self, frames: int) -> np.ndarray: ...
    # Render one interleaved block; returns an interleaved ``float32`` array.
    def process_interleaved(
        self,
        samples: Sequence[float] | list[float] | np.ndarray,
        num_input_channels: int,
    ) -> np.ndarray: ...
    # Render a whole interleaved buffer offline; returns an interleaved ``float32`` array.
    def render_offline(
        self,
        samples: Sequence[float] | list[float] | np.ndarray,
        num_input_channels: int,
    ) -> np.ndarray: ...

# Render a whole interleaved buffer offline, time-aligned with the input.
def render_playback(
    samples: Sequence[float] | list[float] | np.ndarray,
    *,
    num_channels: int,
    sample_rate: int,
    config: PlaybackRendererConfig,
    hrtf: HrtfSet | None = None,
) -> np.ndarray: ...

ラウドネスメーターと HRTF セット ​

python
# Integrated-loudness meter for multichannel program material (1/2/6/8 ch).
class PlaybackLoudnessMeter:
    def __init__(self, *, num_channels: int, sample_rate: int) -> None: ...
    # Release the underlying C handle.
    def close(self) -> None: ...
    # Return the object itself for ``with`` use.
    def __enter__(self) -> PlaybackLoudnessMeter: ...
    # Close the object on leaving the ``with`` block; never suppresses exceptions.
    def __exit__(self, exc_type: object, exc: object, tb: object) -> None: ...
    # Feed interleaved frames of any length.
    def push_interleaved(self, samples: Sequence[float] | list[float] | np.ndarray) -> None: ...
    # Integrated loudness of everything pushed so far, in LUFS.
    @property
    def integrated_lufs(self) -> float | None: ...

# Opaque SHRF v1 HRTF set consumed by a headphones-target :class:`PlaybackRenderer`.
class HrtfSet:
    def __init__(self, handle: ctypes.c_void_p, lib: ctypes.CDLL) -> None: ...
    # Build the embedded default set (SADIE II KU100, native builds only).
    @classmethod
    def default(cls) -> HrtfSet: ...
    # Parse SHRF v1 bytes; malformed data raises :class:`SonareError` with `InvalidFormat`.
    @classmethod
    def from_bytes(cls, data: bytes) -> HrtfSet: ...
    # Release the underlying C handle.
    def close(self) -> None: ...
    # Return the object itself for ``with`` use.
    def __enter__(self) -> HrtfSet: ...
    # Close the object on leaving the ``with`` block; never suppresses exceptions.
    def __exit__(self, exc_type: object, exc: object, tb: object) -> None: ...