Owned backend API reference¶
This page documents the hand-written lifetime and extension layer in
pyalsoft.bindings. The generated AL/ALC command wrappers, typed objects,
constants, enums, and registry metadata remain in the
low-level bindings reference. See
owned backend handles for task-oriented examples and native
lifetime guidance.
This remains a low-level API: ordinary generated calls and state queries do not automatically translate the AL or ALC error state into Python exceptions. The owned methods document the places where lifetime-sensitive failures are checked and raised explicitly.
Library loading and extensions¶
Typed low-level bindings and runtime loading for OpenAL Soft.
pyalsoft.bindings.LibraryPath ¶
A string or path-like location of an OpenAL shared library.
pyalsoft.bindings.ForeignFunction ¶
A generated ctypes callable for one raw OpenAL command.
pyalsoft.bindings.OpenALLibrary ¶
A loaded OpenAL library with typed core and extension functions.
Core functions and their generated signatures are bound lazily. AL extension
functions are resolved for the current context; ALC extension functions are
resolved for the device supplied to get_function or get_alc_extension.
Resolved entry points are cached by native context or device scope.
Prefer load unless direct construction is useful.
A loaded library does not itself own devices or contexts and has no close
operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
LibraryPath | None
|
Explicit shared-library path. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
library_name |
Path or loader name used to open the native library. |
|
native_library |
Any
|
Underlying |
al |
ALCommands
|
Generated Python-value wrappers for AL commands and objects. |
alc |
ALCCommands
|
Generated Python-value wrappers for ALC commands. |
extensions |
ExtensionCapabilities
|
Generated mapping and attributes for registry extensions. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
LibraryNotFoundError
|
No usable library could be loaded. |
al
property
¶
Python-value wrappers for AL commands and typed AL objects.
Core commands are available immediately. Calling extension commands may require a current context and raises an extension-resolution error when the entry point is unavailable.
extensions
property
¶
Generated capability objects for all registry extensions.
Capabilities support mapping lookup by registry name and generated
snake-case attributes such as alc_ext_efx.
get_export ¶
get_export(name: str) -> ForeignFunction
Return a directly exported command without checking extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact C command name present in the generated registry. |
required |
Returns:
| Type | Description |
|---|---|
ForeignFunction
|
A cached |
Raises:
| Type | Description |
|---|---|
FunctionUnavailableError
|
|
clear_extension_cache ¶
Clear all cached extension entry points.
Owned devices and contexts invalidate their own scopes automatically. Applications that destroy or reconfigure raw native handles should clear this cache before a handle address can be reused.
register_system_event_callback ¶
register_system_event_callback(
callback: Callable[
[int, int, object | None, str], None
],
*,
event_types: Sequence[int] = (),
) -> CallbackRegistration
Register and retain the global ALC_SOFT_system_events callback.
Only one registration may be active for the same loaded native library;
registering another closes the previous one. The callback can run on a
background system thread and receives (event_type, device_type,
device_handle, message). It must return promptly and must not call AL or
ALC functions. Python exceptions are retained by the returned registration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[int, int, object | None, str], None]
|
Function invoked for each enabled system event. A null native
device pointer is delivered as |
required |
event_types
|
Sequence[int]
|
Registry event-type values to enable. An empty sequence installs the callback without explicitly enabling event types. |
()
|
Returns:
| Type | Description |
|---|---|
CallbackRegistration
|
Owned registration that keeps the native trampoline alive. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ExtensionUnavailableError
|
|
CallbackControlError
|
OpenAL cannot enable the requested event types. |
clear_system_event_callback ¶
Disable events and remove this native library's global callback.
Calling this without an active registration is harmless. Callback errors retained during unregistration remain available on a registration held by the caller.
Raises:
| Type | Description |
|---|---|
CallbackControlError
|
Called from the active callback or while its registration close is already in progress on this thread. |
is_al_extension_present ¶
Check an AL extension against the current context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
ASCII registry extension name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the current context reports the extension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ContextRequiredError
|
No AL context is current. |
FunctionUnavailableError
|
A required core query is unavailable. |
is_alc_extension_present ¶
Check an ALC extension for a device or the null-device scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
ASCII registry extension name. |
required |
device
|
object | None
|
Native ALC device handle. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the selected ALC scope reports the extension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FunctionUnavailableError
|
The required core query is unavailable. |
get_al_extension ¶
get_al_extension(
name: str,
*,
device: object | None = None,
check_extension: bool = True,
) -> ForeignFunction
Resolve and cache an AL extension command for the effective scope.
AL-only commands use the current context. Commands from extensions that also expose ALC entry points can instead use an explicit device, which is required by direct-context APIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact C name of an AL extension command. |
required |
device
|
object | None
|
Optional native ALC device used by dual-API extensions. |
None
|
check_extension
|
bool
|
Verify that the effective context or device reports the declaring extension before resolving the entry point. |
True
|
Returns:
| Type | Description |
|---|---|
ForeignFunction
|
A cached |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ContextRequiredError
|
Resolution requires a context or device that was not supplied. |
ExtensionUnavailableError
|
The declaring extension is not present. |
FunctionUnavailableError
|
The name, namespace, or native entry point is invalid or unavailable. |
get_alc_extension ¶
get_alc_extension(
name: str,
device: object | None = None,
*,
check_extension: bool = True,
) -> ForeignFunction
Resolve and cache an ALC extension command for a device scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact C name of an ALC extension command. |
required |
device
|
object | None
|
Native ALC device handle, or |
None
|
check_extension
|
bool
|
Verify that the effective scope reports the declaring extension before resolving the entry point. |
True
|
Returns:
| Type | Description |
|---|---|
ForeignFunction
|
A cached |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
ContextRequiredError
|
An AL-side extension check requires a current context. |
ExtensionUnavailableError
|
The declaring extension is not present. |
FunctionUnavailableError
|
The name, namespace, or native entry point is invalid or unavailable. |
get_function ¶
get_function(
name: str,
*,
device: object | None = None,
check_extension: bool = True,
) -> ForeignFunction
Return a typed core or extension function by its C command name.
Direct exports use get_export. Extension commands are routed to the
AL or ALC resolver according to generated registry metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact C command name. |
required |
device
|
object | None
|
Native ALC device handle used for device-scoped resolution. |
None
|
check_extension
|
bool
|
Verify extension availability before resolving an extension entry point. |
True
|
Returns:
| Type | Description |
|---|---|
ForeignFunction
|
A cached |
Raises:
| Type | Description |
|---|---|
ContextRequiredError
|
Resolution requires a current AL context. |
ExtensionUnavailableError
|
The command's extension is not present. |
FunctionUnavailableError
|
|
ValueError
|
A command or extension name cannot be ASCII encoded. |
pyalsoft.bindings.Extension ¶
Capabilities and runtime access for one registry extension.
Do not construct instances directly. Obtain them from
OpenALLibrary.extensions by registry name or generated snake-case
attribute. Declaration metadata is available without querying the runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
library |
Loaded library used for runtime queries and command resolution. |
|
name |
str
|
Registry extension name. |
apis |
tuple[str, ...]
|
API namespaces declared by the extension, such as |
commands |
tuple[str, ...]
|
Commands declared by all requirements of the extension. |
enums |
tuple[str, ...]
|
Enum names declared by all requirements of the extension. |
types |
tuple[str, ...]
|
C type names declared by all requirements of the extension. |
dependencies |
tuple[str, ...]
|
Non-empty registry dependency expressions. |
commands
property
¶
Command names declared by this extension, without duplicates.
types
property
¶
C type names declared by this extension, without duplicates.
dependencies
property
¶
Registry dependency expressions, without duplicates.
is_present ¶
Check whether the extension is available for a context or device.
ALC extensions use device or the null-device scope. AL extensions use
the current context. For dual-API extensions, supplying a device selects
the ALC query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
object | None
|
Native ALC device handle, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the selected runtime scope reports this extension. |
Raises:
| Type | Description |
|---|---|
ContextRequiredError
|
An AL query has no current context. |
FunctionUnavailableError
|
A required core query is unavailable. |
require ¶
Require this extension for a context or device scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
object | None
|
Native ALC device handle, or |
None
|
Raises:
| Type | Description |
|---|---|
ContextRequiredError
|
An AL query has no current context. |
ExtensionUnavailableError
|
The selected scope does not report this extension. |
FunctionUnavailableError
|
A required core query is unavailable. |
get_function ¶
get_function(
name: str, *, device: object | None = None
) -> ForeignFunction
Resolve a command declared by this extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact C command name declared by this extension. |
required |
device
|
object | None
|
Native ALC device used for device-scoped resolution. |
None
|
Returns:
| Type | Description |
|---|---|
ForeignFunction
|
Typed, cached native command callable. |
Raises:
| Type | Description |
|---|---|
KeyError
|
|
ContextRequiredError
|
Resolution requires a current AL context. |
ExtensionUnavailableError
|
This extension is not present. |
FunctionUnavailableError
|
The native entry point is unavailable. |
pyalsoft.bindings.load ¶
load(path: LibraryPath | None = None) -> OpenALLibrary
Load OpenAL and return its typed low-level binding object.
Each call creates an independent Python binding object and native-library handle. It does not cache a process-wide singleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
LibraryPath | None
|
Explicit shared-library path. |
None
|
Returns:
| Type | Description |
|---|---|
OpenALLibrary
|
Loaded low-level library with lazy command namespaces. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
LibraryNotFoundError
|
No usable library could be loaded. |
Owned devices and contexts¶
Typed low-level bindings and runtime loading for OpenAL Soft.
pyalsoft.bindings.Device ¶
An owned ALC device handle.
Do not construct instances directly. Use the more specific PlaybackDevice,
LoopbackDevice, or CaptureDevice returned by the module-level open
helpers. Closing a playback device first closes every context created through
it. Context-manager exit calls close.
Extension-backed properties raise ExtensionUnavailableError when the
device does not expose their named extension. Access requiring a native handle
raises HandleClosedError after closure. Query helpers forward directly to
generated commands; callers remain responsible for the native ALC error state.
Attributes:
| Name | Type | Description |
|---|---|---|
library |
Loaded OpenAL library that owns the command wrappers. |
|
closed |
bool
|
Whether the native device has been closed. |
handle |
object
|
Native ALC device pointer for generated raw calls. |
name |
str | None
|
Implementation-provided device specifier, when available. |
extensions |
frozenset[str]
|
Extension names reported for this device. |
version |
tuple[int, int]
|
Reported ALC major and minor version. |
handle
property
¶
The underlying ALC device pointer for raw generated calls.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device has been closed. |
hrtf_specifier_count
property
¶
The number of HRTF specifiers available to the device.
output_limiter_enabled
property
¶
Whether the output limiter is currently enabled.
clock_latency
property
¶
Atomically query device clock and latency in nanoseconds.
output_mode
property
¶
The active output mode (ALC_SOFT_output_mode).
max_ambisonic_order
property
¶
The highest loopback ambisonic order supported by the device.
context_flags
property
¶
The active context flags (ALC_EXT_debug).
require_extension ¶
Require an ALC extension on this device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registry extension name. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
|
HandleClosedError
|
This device is closed. |
ExtensionUnavailableError
|
The device does not report |
is_extension_present ¶
Return whether an ALC extension is present on this device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
ASCII registry extension name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the device reports the extension. |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device is closed. |
ValueError
|
|
get_string ¶
Query one device string through alcGetString.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
ALCContextString | int
|
ALC string selector. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Decoded implementation string, or |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device is closed. |
get_integers ¶
Query one or more device integers through alcGetIntegerv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
ALCContextInteger | int
|
ALC integer selector. |
required |
count
|
int
|
Positive number of integers to return. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Exactly |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This device is closed. |
get_integer ¶
Query one device integer through alcGetIntegerv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
ALCContextInteger | int
|
ALC integer selector. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The queried integer value. |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device is closed. |
get_integer64s ¶
Query device clock values through ALC_SOFT_device_clock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
int
|
Extension integer selector. |
required |
count
|
int
|
Positive number of 64-bit integers to return. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Exactly |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This device is closed. |
ExtensionUnavailableError
|
|
get_hrtf_specifier ¶
Return one available HRTF specifier by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Non-negative index less than |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Implementation-provided HRTF name, or |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This device is closed. |
ExtensionUnavailableError
|
|
close ¶
Close owned contexts and then the native device.
Contexts are closed in reverse creation order. Calling this again after a successful close is harmless. Exceptions raised while closing an owned context propagate and leave the device open.
Raises:
| Type | Description |
|---|---|
DeviceCloseError
|
OpenAL refuses to close the native device. |
pyalsoft.bindings.PlaybackDevice ¶
Bases: Device
An owned playback device that can create and own AL contexts.
create_context ¶
create_context(
attributes: Sequence[int] | None = None,
) -> Context
Create an owned context attached to this device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
Sequence[int] | None
|
Flat ALC attribute/value sequence terminated by the
generated wrapper. |
None
|
Returns:
| Type | Description |
|---|---|
Context
|
Open context owned by this device. |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device is closed. |
ContextCreateError
|
OpenAL cannot create the requested context. |
pyalsoft.bindings.LoopbackDevice ¶
Bases: PlaybackDevice
An ALC_SOFT_loopback device for deterministic offline rendering.
Create a context with explicit loopback format attributes, start AL sources,
then render frames into caller-owned writable storage with render_samples.
is_render_format_supported ¶
is_render_format_supported(
frequency: int,
channels: ALCRenderFormatChannelSOFT | int,
sample_type: ALCRenderFormatTypeSOFT | int,
) -> bool
Return whether a loopback render format is supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
int
|
Requested sample rate in frames per second. |
required |
channels
|
ALCRenderFormatChannelSOFT | int
|
|
required |
sample_type
|
ALCRenderFormatTypeSOFT | int
|
|
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the device accepts this exact render format. |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This device is closed. |
render_samples ¶
Render frames into caller-owned writable storage.
The caller must size buffer for samples complete frames in the
format selected when creating the active loopback context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
object
|
Writable buffer accepted by the generated command wrapper. |
required |
samples
|
int
|
Non-negative number of sample frames to render. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This device is closed. |
pyalsoft.bindings.CaptureDevice ¶
Bases: Device
An owned input device opened through the core ALC capture API.
Do not construct instances directly. Use open_capture_device. The handle
remembers the requested format for callers but does not convert captured
samples.
Attributes:
| Name | Type | Description |
|---|---|---|
library |
Loaded OpenAL library used by this device. |
|
frequency |
Capture sample rate in frames per second. |
|
format |
OpenAL sample-format value requested at open time. |
|
available_samples |
int
|
Number of complete frames currently ready to read. |
name |
str | None
|
Implementation-provided capture device specifier. |
capturing |
bool
|
Whether |
closed |
bool
|
Whether the native capture device has been closed. |
handle |
object
|
Native ALC capture-device pointer for generated raw calls. |
available_samples
property
¶
The number of capture frames currently ready to read.
start ¶
Start input capture.
Calling this while capture is already started is harmless.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This capture device is closed. |
stop ¶
Stop input capture while preserving buffered samples.
Calling this while capture is not started is harmless.
read_samples ¶
Read capture frames into caller-owned writable storage.
The caller must provide storage for samples complete frames in this
device's format and should not request more than available_samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
object
|
Writable buffer accepted by the generated command wrapper. |
required |
samples
|
int
|
Non-negative number of sample frames to read. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This capture device is closed. |
close ¶
Stop capture and close the native capture device.
Calling this again after a successful close is harmless.
Raises:
| Type | Description |
|---|---|
DeviceCloseError
|
OpenAL refuses to close the native capture device. |
pyalsoft.bindings.Context ¶
An owned AL context attached to a playback device.
Do not construct instances directly. Use PlaybackDevice.create_context.
The context owns callback registrations and retained static-buffer storage;
closing it destroys that native state and invalidates every typed AL object
bound to it. Context-manager exit calls close.
Operations that require this context temporarily activate it while holding the loaded library's context lock, then restore the previous context. Ordinary state properties forward directly to generated commands; callers remain responsible for querying and clearing the native AL error state.
Attributes:
| Name | Type | Description |
|---|---|---|
device |
Playback or loopback device that owns this context. |
|
library |
Loaded OpenAL library shared with |
|
closed |
bool
|
Whether the native context has been destroyed. |
handle |
object
|
Native ALC context pointer for generated raw calls. |
current |
bool
|
Whether this is the process-wide current context. |
listener |
Listener
|
Typed context-scoped listener singleton. |
handle
property
¶
The underlying ALC context pointer for raw generated calls.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context has been destroyed. |
current
property
¶
Whether this is the process-wide current context.
This does not inspect the ALC_EXT_thread_local_context override.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context has been destroyed. |
listener
property
¶
Return the typed listener singleton bound to this context.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context is closed. |
vendor
property
¶
The current AL implementation vendor, or None on native failure.
version
property
¶
The current AL implementation version, or None on native failure.
doppler_factor
property
writable
¶
Get or set the global Doppler scale.
OpenAL defines non-negative values and uses 1.0 by default. The low-level setter forwards the value without consuming the native AL error state.
doppler_velocity
property
writable
¶
Get or set the legacy Doppler reference velocity.
This OpenAL 1.0 control is retained for compatibility; prefer
speed_of_sound for OpenAL 1.1 behavior.
speed_of_sound
property
writable
¶
Get or set propagation speed for Doppler calculations.
Values are in world-units per second. OpenAL requires at least 0.0001 and uses 343.3 by default.
distance_model
property
writable
¶
Get or set the global distance-attenuation model.
Unknown future values are returned as integers.
default_filter_order
property
¶
The default resampler filter order for this context.
Raises:
| Type | Description |
|---|---|
ExtensionUnavailableError
|
|
HandleClosedError
|
This context or its device is closed. |
make_current ¶
Make this the process-wide current context.
The prior context is not restored automatically. Use activate for a
temporary change.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context has been destroyed. |
ContextActivationError
|
OpenAL refuses the context change. |
make_thread_current ¶
Make this current only for the calling thread.
The prior thread-local context is not restored automatically. Use
activate(thread_local=True) for a temporary change.
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context or its device is closed. |
ExtensionUnavailableError
|
|
ContextActivationError
|
OpenAL refuses the context change. |
require_extension ¶
Require an AL extension while this context is temporarily current.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registry extension name. |
required |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
The context does not report |
ContextActivationError
|
The context cannot be activated or restored. |
activate ¶
activate(
*, thread_local: bool = False
) -> Iterator[Context]
Temporarily make this context current and restore the prior context.
Activation is serialized across contexts that share this loaded library. Nested activation of the same context is supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_local
|
bool
|
Use |
False
|
Yields:
| Type | Description |
|---|---|
Context
|
This context while it is current in the requested scope. |
Raises:
| Type | Description |
|---|---|
HandleClosedError
|
This context or its device is closed. |
ExtensionUnavailableError
|
Thread-local activation was requested but the device does not expose the extension. |
ContextActivationError
|
OpenAL cannot activate or restore a context. |
source ¶
Wrap an existing integer source identifier for this context.
This does not allocate a source or verify that identifier is live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
int
|
Non-negative OpenAL source name. |
required |
Returns:
| Type | Description |
|---|---|
Source
|
Context-affine typed source. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This context is closed. |
buffer ¶
Wrap an existing integer buffer identifier for this context.
This does not allocate a buffer or verify that identifier is live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
int
|
Non-negative OpenAL buffer name. |
required |
Returns:
| Type | Description |
|---|---|
Buffer
|
Context-affine typed buffer. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This context is closed. |
effect ¶
Wrap an existing integer EFX effect identifier for this context.
This does not allocate an effect or verify that identifier is live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
int
|
Non-negative OpenAL effect name. |
required |
Returns:
| Type | Description |
|---|---|
Effect
|
Context-affine typed effect. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This context is closed. |
filter ¶
Wrap an existing integer EFX filter identifier for this context.
This does not allocate a filter or verify that identifier is live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
int
|
Non-negative OpenAL filter name. |
required |
Returns:
| Type | Description |
|---|---|
Filter
|
Context-affine typed filter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This context is closed. |
auxiliary_effect_slot ¶
Wrap an existing EFX auxiliary-slot identifier for this context.
This does not allocate a slot or verify that identifier is live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
int
|
Non-negative OpenAL auxiliary effect slot name. |
required |
Returns:
| Type | Description |
|---|---|
AuxiliaryEffectSlot
|
Context-affine typed auxiliary effect slot. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
HandleClosedError
|
This context is closed. |
register_event_callback ¶
register_event_callback(
callback: EventCallback,
*,
event_types: Sequence[int] = (),
) -> CallbackRegistration
Register and retain an AL_SOFT_events callback.
The callback receives (event_type, object_id, parameter, message).
Registering another event callback on this context closes the previous
registration. Python exceptions are retained instead of crossing the C
boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
EventCallback
|
Function invoked for enabled AL events. |
required |
event_types
|
Sequence[int]
|
Registry event-type values to enable. An empty sequence installs the callback without explicitly enabling event types. |
()
|
Returns:
| Type | Description |
|---|---|
CallbackRegistration
|
Owned registration that keeps the native trampoline alive. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
|
CallbackControlError
|
The previous callback cannot be removed safely. |
ContextActivationError
|
This context cannot be activated or restored. |
register_debug_callback ¶
register_debug_callback(
callback: DebugCallback, *, enable_output: bool = True
) -> CallbackRegistration
Register and retain an AL_EXT_debug message callback.
The callback receives (source, type, identifier, severity, message).
Registering another debug callback on this context closes the previous
registration. Python exceptions are retained by the registration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
DebugCallback
|
Function invoked for native debug messages. |
required |
enable_output
|
bool
|
Enable |
True
|
Returns:
| Type | Description |
|---|---|
CallbackRegistration
|
Owned registration that keeps the native trampoline alive. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
|
CallbackControlError
|
The previous callback cannot be removed safely. |
ContextActivationError
|
This context cannot be activated or restored. |
register_buffer_callback ¶
register_buffer_callback(
buffer: Buffer | int,
format: ALFormat | int,
frequency: int,
callback: BufferCallback,
) -> CallbackRegistration
Register a lifetime-safe AL_SOFT_callback_buffer callback.
The callback receives a writable byte view valid only for that callback invocation and returns the number of bytes written. Exceptions and invalid byte counts are retained and reported to OpenAL as zero bytes. Python callback execution is not guaranteed to satisfy hard real-time constraints.
Registering again for the same buffer closes the prior registration. Successful installation replaces retained static-buffer storage. Closing can fail while the buffer remains attached to a source; in that case the registration retains its native trampoline until cleanup can be retried or the context closes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
Buffer | int
|
Positive integer buffer name or typed buffer from this context. |
required |
format
|
ALFormat | int
|
OpenAL sample-format value produced by the callback. |
required |
frequency
|
int
|
Positive sample rate in frames per second. |
required |
callback
|
BufferCallback
|
Function that fills the temporary writable view and returns a byte count from zero through the view length. |
required |
Returns:
| Type | Description |
|---|---|
CallbackRegistration
|
Owned registration that keeps the native trampoline alive. |
Raises:
| Type | Description |
|---|---|
TypeError
|
A value has the wrong type or |
ValueError
|
The buffer belongs to another context or an integer value is outside its supported range. |
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
|
CallbackControlError
|
Native callback installation, replacement, or rollback cannot be completed safely. |
ContextActivationError
|
This context cannot be activated or restored. |
start_foldback ¶
start_foldback(
mode: ALFoldbackMode | int,
count: int,
length: int,
memory: object,
callback: FoldbackCallback,
) -> FoldbackRegistration
Start an owned AL_EXT_FOLDBACK request.
The callback receives (event_type, block_index). Starting another
request closes the prior foldback registration. The returned registration
retains both the native trampoline and the exact writable sample backing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
ALFoldbackMode | int
|
|
required |
count
|
int
|
Number of sample blocks; at least two. |
required |
length
|
int
|
Positive number of frames in each block. |
required |
memory
|
object
|
Writable |
required |
callback
|
FoldbackCallback
|
Function invoked for foldback start, block, and stop events. |
required |
Returns:
| Type | Description |
|---|---|
FoldbackRegistration
|
Owned foldback registration exposing the retained sample memory. |
Raises:
| Type | Description |
|---|---|
TypeError
|
A value has the wrong type, storage is not writable and
contiguous, or |
ValueError
|
The mode, dimensions, or storage capacity is invalid. |
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
|
CallbackControlError
|
A previous foldback request cannot close safely. |
NativeCallError
|
OpenAL reports an error before or during startup. |
ContextActivationError
|
This context cannot be activated or restored. |
set_static_buffer_data ¶
set_static_buffer_data(
buffer: Buffer | int,
format: ALFormat | int,
data: bytes | bytearray | memoryview,
frequency: int,
) -> None
Set AL_EXT_STATIC_BUFFER data and retain its native backing.
Writable bytearray and memoryview inputs are borrowed without a
copy and must not be resized while retained. Immutable or read-only input
is copied into native storage. The backing remains alive until this buffer
is updated again or the context closes. An active callback on the buffer is
closed before static storage is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
Buffer | int
|
Positive integer buffer name or typed buffer from this context. |
required |
format
|
ALFormat | int
|
OpenAL sample-format value. |
required |
data
|
bytes | bytearray | memoryview
|
Contiguous PCM bytes to retain or copy. |
required |
frequency
|
int
|
Positive sample rate in frames per second. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
A value has the wrong type or |
ValueError
|
The buffer belongs to another context or an integer value is outside its supported range. |
HandleClosedError
|
This context is closed. |
ExtensionUnavailableError
|
|
CallbackControlError
|
An existing buffer callback cannot be removed. |
NativeCallError
|
OpenAL has a pre-existing error or rejects the update. |
ContextActivationError
|
This context cannot be activated or restored. |
close ¶
Stop foldback, detach, and destroy the native context.
Closing an already closed context is harmless. Active callbacks are marked closed after native context destruction, and retained static-buffer storage is released. All typed objects bound to the context become unusable.
Raises:
| Type | Description |
|---|---|
CallbackControlError
|
Foldback or callback cleanup cannot complete. |
NativeCallError
|
OpenAL rejects an active foldback stop request. |
ContextActivationError
|
The context cannot be detached before destruction. |
pyalsoft.bindings.open_device ¶
open_device(
name: str | bytes | None = None,
*,
library: OpenALLibrary | None = None,
path: LibraryPath | None = None,
) -> PlaybackDevice
Open an owned playback device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes | None
|
Device specifier as text or encoded bytes. |
None
|
library
|
OpenALLibrary | None
|
Existing loaded library to use. |
None
|
path
|
LibraryPath | None
|
Shared-library path to load when |
None
|
Returns:
| Type | Description |
|---|---|
PlaybackDevice
|
Open playback device that owns contexts created through it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
DeviceOpenError
|
OpenAL cannot be loaded or the requested device cannot be opened. |
pyalsoft.bindings.open_loopback_device ¶
open_loopback_device(
name: str | bytes | None = None,
*,
library: OpenALLibrary | None = None,
path: LibraryPath | None = None,
) -> LoopbackDevice
Open an owned ALC_SOFT_loopback device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes | None
|
Device specifier as text or encoded bytes. |
None
|
library
|
OpenALLibrary | None
|
Existing loaded library to use. |
None
|
path
|
LibraryPath | None
|
Shared-library path to load when |
None
|
Returns:
| Type | Description |
|---|---|
LoopbackDevice
|
Open loopback device for context creation and offline rendering. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
DeviceOpenError
|
OpenAL cannot be loaded or a loopback device cannot open. |
ExtensionUnavailableError
|
|
pyalsoft.bindings.open_capture_device ¶
open_capture_device(
frequency: int,
format: ALFormat | int,
buffer_size: int,
name: str | bytes | None = None,
*,
library: OpenALLibrary | None = None,
path: LibraryPath | None = None,
) -> CaptureDevice
Open an owned core ALC capture device.
buffer_size controls the native capture ring capacity; it is measured in
sample frames, not bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
int
|
Positive capture sample rate in frames per second. |
required |
format
|
ALFormat | int
|
Core OpenAL mono or stereo sample-format value. |
required |
buffer_size
|
int
|
Positive native capture-buffer capacity in sample frames. |
required |
name
|
str | bytes | None
|
Device specifier as text or encoded bytes. |
None
|
library
|
OpenALLibrary | None
|
Existing loaded library to use. |
None
|
path
|
LibraryPath | None
|
Shared-library path to load when |
None
|
Returns:
| Type | Description |
|---|---|
CaptureDevice
|
Open capture device with explicit start, stop, and read operations. |
Raises:
| Type | Description |
|---|---|
TypeError
|
A name, path, format, frequency, or buffer size has an unsupported type. |
ValueError
|
A size is non-positive or |
DeviceOpenError
|
OpenAL cannot be loaded or the requested capture device cannot be opened. |
Callback types and registrations¶
Typed low-level bindings and runtime loading for OpenAL Soft.
pyalsoft.bindings.EventCallback ¶
An AL_SOFT_events callback receiving type, object, parameter, and message.
pyalsoft.bindings.DebugCallback ¶
An AL_EXT_debug callback receiving source, type, ID, severity, and message.
pyalsoft.bindings.SystemEventCallback ¶
An ALC system callback receiving event type, device type, handle, and message.
pyalsoft.bindings.BufferCallback ¶
A buffer callback that fills a temporary writable view and returns bytes used.
pyalsoft.bindings.FoldbackCallback ¶
A foldback callback receiving the event type and completed block index.
pyalsoft.bindings.CallbackRegistration ¶
Own a native callback and unregister it deterministically.
Native audio callbacks must never allow a Python exception to cross the C
boundary. Exceptions are retained and can be observed through errors or
re-raised in an application-controlled thread with raise_if_failed.
Do not construct instances directly. Registration helpers return them after
installing and retaining the native ctypes trampoline. Use a with
statement or call close deterministically; losing the Python reference
does not unregister the native callback.
Attributes:
| Name | Type | Description |
|---|---|---|
closed |
bool
|
Whether unregistration completed. |
errors |
tuple[BaseException, ...]
|
Snapshot of exceptions retained from callback invocations or callback-control cleanup. |
errors
property
¶
Exceptions raised by the Python callback, in arrival order.
raise_if_failed ¶
Raise and clear exceptions retained from native callback threads.
Raises:
| Type | Description |
|---|---|
BaseExceptionGroup
|
One or more retained callback exceptions. The retained list is cleared before the group is raised. |
close ¶
Unregister the callback and wait for in-flight invocations.
Calling this more than once is harmless. If native unregistration fails, the registration remains open so cleanup can be retried. A callback must never close its own registration.
Raises:
| Type | Description |
|---|---|
CallbackControlError
|
Called from this registration's callback or re-entered on the thread already closing it. |
pyalsoft.bindings.FoldbackRegistration ¶
Bases: CallbackRegistration
Own an active foldback request and its writable sample storage.
Do not construct instances directly. Context.start_foldback returns this
specialization. The public memory attribute is the exact ALfloat
backing passed to OpenAL and remains available after closure.
Attributes:
| Name | Type | Description |
|---|---|---|
memory |
Retained writable |
|
stopping |
bool
|
Whether a native stop was requested but has not completed. |
closed |
bool
|
Whether the native STOP event was received and cleanup completed. |
errors |
tuple[BaseException, ...]
|
Exceptions retained from the callback or stop preparation. |
close ¶
Request foldback stop and wait for the native STOP event.
Calling this after closure is harmless. OpenAL provides no timeout for the STOP notification, so this call waits until the native implementation delivers it and all in-flight callbacks return.
Raises:
| Type | Description |
|---|---|
CallbackControlError
|
Called from the foldback callback or re-entered on the thread already closing it. |
NativeCallError
|
OpenAL rejects the stop request. |
Exceptions¶
Typed low-level bindings and runtime loading for OpenAL Soft.
pyalsoft.bindings.OpenALError ¶
Bases: Exception
Base exception for loading or resolving OpenAL functions.
pyalsoft.bindings.LibraryNotFoundError ¶
Bases: OpenALError
Raised when no usable OpenAL shared library can be loaded.
pyalsoft.bindings.FunctionUnavailableError ¶
Bases: OpenALError
Raised when an OpenAL function has no usable entry point.
pyalsoft.bindings.ExtensionUnavailableError ¶
Bases: FunctionUnavailableError
Raised when the current implementation does not expose an extension.
pyalsoft.bindings.ContextRequiredError ¶
Bases: FunctionUnavailableError
Raised when resolving a function requires a current AL context.
pyalsoft.bindings.ContextMismatchError ¶
Bases: ValueError
Raised when typed AL objects from different contexts are combined.
pyalsoft.bindings.ALCHandleError ¶
Bases: OpenALError
Base exception for owned ALC device and context handles.
pyalsoft.bindings.DeviceOpenError ¶
Bases: ALCHandleError
Raised when an ALC device cannot be opened.
pyalsoft.bindings.DeviceCloseError ¶
Bases: ALCHandleError
Raised when an ALC device refuses to close.
pyalsoft.bindings.ContextCreateError ¶
Bases: ALCHandleError
Raised when an ALC context cannot be created.
pyalsoft.bindings.ContextActivationError ¶
Bases: ALCHandleError
Raised when an ALC context cannot be made current or restored.
pyalsoft.bindings.HandleClosedError ¶
Bases: ALCHandleError
Raised when an operation requires an open device or context.
pyalsoft.bindings.NativeCallError ¶
Bases: ALCHandleError
Raised when a lifetime-sensitive native operation reports an error.
pyalsoft.bindings.CallbackControlError ¶
Bases: NativeCallError
Raised when native callback state cannot be enabled or removed safely.