ExCubecl.Audio (ExCubecl v0.4.0)

Copy Markdown View Source

Audio-specific GPU operations: mix, overlay, resample, channel conversion.

All operations run on GPU-resident sample buffers (f32 planar PCM).

Examples

result = ExCubecl.Audio.mix([track_a, track_b], gains: [0.7, 0.5])
result = ExCubecl.Audio.overlay(bg, fg, duck_level: -12)
resampled = ExCubecl.Audio.resample(samples, from: 44100, to: 48000)
mono = ExCubecl.Audio.channels(samples, :stereo, :mono)

Summary

Functions

Converts between channel layouts (e.g. stereo → mono, mono → stereo).

Mixes multiple audio streams by summing with per-channel gain.

Overlays foreground audio over background, optionally ducking the background.

Resamples audio to a different sample rate using GPU-accelerated linear interpolation.

Types

samples()

@type samples() :: ExCubecl.AudioSamples.t()

Functions

channels(samples, from_layout, to_layout)

@spec channels(samples(), atom(), atom()) :: {:ok, samples()} | {:error, term()}

Converts between channel layouts (e.g. stereo → mono, mono → stereo).

Examples

mono = ExCubecl.Audio.channels(samples, :stereo, :mono)

mix(tracks, opts \\ [])

@spec mix(
  [samples()],
  keyword()
) :: {:ok, samples()} | {:error, term()}

Mixes multiple audio streams by summing with per-channel gain.

Options

  • :gains — list of gain values (0.0–1.0+) corresponding to each track

overlay(bg, fg, opts \\ [])

@spec overlay(samples(), samples(), keyword()) :: {:ok, samples()} | {:error, term()}

Overlays foreground audio over background, optionally ducking the background.

Options

  • :duck_level — dB reduction for background during foreground (default -12)

resample(samples, opts)

@spec resample(
  samples(),
  keyword()
) :: {:ok, samples()} | {:error, term()}

Resamples audio to a different sample rate using GPU-accelerated linear interpolation.

Options

  • :from — source sample rate (Hz)
  • :to — target sample rate (Hz)