Documentation
¶
Overview ¶
Package resample converts interleaved S16LE PCM audio between sample rates, preserving the channel count. It reconciles service sample rates (for example 24 kHz TTS audio) with the 48 kHz the WebRTC/Opus output path needs.
A Resampler is stateful: it carries filter state across calls so a continuous stream resamples cleanly across chunk boundaries. Create one per audio stream with New; it is not safe for concurrent use, and Close must be called when finished.
Two builds are selected by the `libsoxr` build tag, both exposing the same New/Process/Close API:
- Default (pure Go, see resample_purego.go): a no-cgo converter from github.com/gojargo/go-resample. It cross-compiles and links into static binaries with no native dependency.
- `-tags libsoxr` (see resample_soxr.go): links libsoxr (the SoX Resampler) via cgo for its high-quality polyphase conversion. Requires libsoxr at build and run time (libsoxr-dev to build, libsoxr0 to run).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resampler ¶
type Resampler struct {
// contains filtered or unexported fields
}
Resampler converts a stream of interleaved S16LE PCM from one sample rate to another using the pure-Go github.com/gojargo/go-resample converter (no cgo). This is the default build; `-tags libsoxr` swaps in libsoxr (see resample_soxr.go). Create one per audio stream with New; it is not safe for concurrent use. Close is a no-op kept for API parity with the libsoxr build.
func New ¶
New returns a Resampler from inRate to outRate for the given channel count. When inRate equals outRate the Resampler passes audio through unchanged and allocates no converter.
func (*Resampler) Close ¶
func (r *Resampler) Close()
Close releases converter resources. The pure-Go converter holds none, so this is a no-op; it is safe to call more than once and exists for API parity with the libsoxr build.
func (*Resampler) Process ¶
Process resamples one buffer of interleaved S16LE PCM and returns the resampled audio. When the input and output rates match it returns the input unchanged; otherwise the returned slice is freshly allocated and owned by the caller. Because the converter has filter delay, the first calls of a stream emit slightly fewer frames than the rate ratio implies, which later calls make up.