OpusFfi
in package
implements
OpusDecoderInterface
Handles the decoding of Opus audio data using FFI (Foreign Function Interface).
Tags
Table of Contents
Interfaces
- OpusDecoderInterface
- Interface for Opus Decoder implementations.
Properties
- $ffi : FFI
- $decoderHandles : array<string, mixed>
Methods
- __call() : mixed
- Magic method to redirect method calls to the FFI instance.
- __construct() : mixed
- Loads libopus via FFI and declares the decoder functions used by {@see decode()}.
- __destruct() : mixed
- Destroys every cached libopus decoder handle.
- decode() : string
- Creates a FFI instance (code in C) to decode Opus audio data.
- isAvailable() : bool
- Whether libopus can be loaded via FFI in this environment.
- new() : self
- Convenience factory equivalent to `new self()`.
- opus_decode() : int
- opus_decoder_create() : mixed
- opus_decoder_destroy() : void
- opus_packet_get_nb_frames() : int
- opus_packet_get_samples_per_frame() : int
Properties
$ffi
protected
FFI
$ffi
$decoderHandles
private
array<string, mixed>
$decoderHandles
= []
Persistent decoder handles keyed by "channels:rate".
Methods
__call()
Magic method to redirect method calls to the FFI instance.
public
__call(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
- $name : string
- $arguments : array<string|int, mixed>
__construct()
Loads libopus via FFI and declares the decoder functions used by {@see decode()}.
public
__construct() : mixed
Tags
__destruct()
Destroys every cached libopus decoder handle.
public
__destruct() : mixed
decode()
Creates a FFI instance (code in C) to decode Opus audio data.
public
decode(string|mixed $data[, int $channels = 2 ][, int $audioRate = 48000 ]) : string
By using the libopus library, this function decodes Opus-encoded audio data into PCM samples.
Parameters
- $data : string|mixed
-
The Opus-encoded audio data to decode.
- $channels : int = 2
-
Output channel count.
- $audioRate : int = 48000
-
Output sample rate in Hz.
Return values
string —The decoded PCM audio data as a string/binary.
isAvailable()
Whether libopus can be loaded via FFI in this environment.
public
static isAvailable() : bool
Return values
boolnew()
Convenience factory equivalent to `new self()`.
public
static new() : self
Return values
selfopus_decode()
public
opus_decode(mixed $st, mixed $data, int $len, mixed $pcm, int $frame_size, int $decode_fec) : int
Parameters
- $st : mixed
- $data : mixed
- $len : int
- $pcm : mixed
- $frame_size : int
- $decode_fec : int
Return values
intopus_decoder_create()
public
opus_decoder_create(int $Fs, int $channels, mixed $error) : mixed
Parameters
- $Fs : int
- $channels : int
- $error : mixed
opus_decoder_destroy()
public
opus_decoder_destroy(mixed $st) : void
Parameters
- $st : mixed
opus_packet_get_nb_frames()
public
opus_packet_get_nb_frames(mixed $packet, int $len) : int
Parameters
- $packet : mixed
- $len : int
Return values
intopus_packet_get_samples_per_frame()
public
opus_packet_get_samples_per_frame(mixed $data, int $Fs) : int
Parameters
- $data : mixed
- $Fs : int