Python Playback API
The movie-audio playback renderer turns decoded mono, stereo, 5.1 or 7.1 PCM into either speaker-layout audio (upmix, speaker calibration, bass management) or binaural headphone audio (HRTF convolution, head tracking, room model). Pass the target, room and speaker layout in a PlaybackRendererConfig mapping. Parse saved JSON text with json.loads first. An unknown key or wrong type raises TypeError. An out-of-domain value raises SonareValueError.
PlaybackRenderer, PlaybackLoudnessMeter and HrtfSet each have close() and work as context managers, so with releases them on an exception too (Releasing Native Handles). A headphones-target renderer consumes an HrtfSet.
Renderer and configuration
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: ...Loudness meter and HRTF set
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: ...