RustyOpus.PCM (rusty_opus v0.4.0)

Copy Markdown View Source

The common, metadata-carrying PCM representation used by file APIs.

data is always interleaved little-endian IEEE-754 f32. The legacy helper functions in this module continue to operate on bare PCM binaries so raw Opus packet APIs remain source compatible.

Summary

Functions

Deinterleaves a stereo PCM binary into {left, right} mono binaries.

Number of interleaved frames in a metadata-carrying PCM value.

Builds a PCM binary from a list of float samples.

Interleaves two mono PCM binaries into one stereo PCM binary.

Constructs and validates a metadata-carrying PCM value.

Number of f32 samples in a bare PCM binary.

Decodes a PCM binary into a list of float samples.

Validates a %RustyOpus.PCM{} supplied by a caller or another decoder.

Types

t()

@type t() :: %RustyOpus.PCM{
  channels: 1 | 2,
  data: binary(),
  sample_rate: pos_integer()
}

Functions

deinterleave(pcm)

@spec deinterleave(binary()) ::
  {:ok, {binary(), binary()}} | {:error, RustyOpus.Error.t()}

Deinterleaves a stereo PCM binary into {left, right} mono binaries.

frame_count(pcm)

@spec frame_count(t()) :: non_neg_integer()

Number of interleaved frames in a metadata-carrying PCM value.

from_samples(samples)

@spec from_samples([float()]) :: binary()

Builds a PCM binary from a list of float samples.

interleave(left, right)

@spec interleave(binary(), binary()) ::
  {:ok, binary()} | {:error, RustyOpus.Error.t()}

Interleaves two mono PCM binaries into one stereo PCM binary.

new(data, sample_rate, channels)

@spec new(binary(), pos_integer(), 1 | 2) ::
  {:ok, t()} | {:error, RustyOpus.Error.t()}

Constructs and validates a metadata-carrying PCM value.

sample_count(pcm)

@spec sample_count(binary()) :: non_neg_integer()

Number of f32 samples in a bare PCM binary.

to_samples(pcm)

@spec to_samples(binary()) :: [float()]

Decodes a PCM binary into a list of float samples.

validate(arg1)

@spec validate(t()) :: :ok | {:error, RustyOpus.Error.t()}

Validates a %RustyOpus.PCM{} supplied by a caller or another decoder.