Documentation
¶
Overview ¶
Package resample converts interleaved S16LE PCM audio between sample rates using libsoxr (the SoX Resampler), a high-quality polyphase resampler. It reconciles service sample rates (for example 24 kHz TTS audio) with the 48 kHz the WebRTC/Opus output path needs; the channel count is preserved.
A Resampler is stateful: libsoxr 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 to release the native resampler.
This package uses cgo and requires libsoxr at build and run time. On Debian/Ubuntu install libsoxr-dev to build and libsoxr0 to run; the container image jargo ships in bundles both.
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. Create one per audio stream with New; it is not safe for concurrent use. Call Close when finished to free the native resampler.
func New ¶
New returns a Resampler from inRate to outRate for the given channel count. It returns an error if libsoxr cannot create the resampler. When inRate equals outRate the Resampler passes audio through unchanged and holds no native resources.
func (*Resampler) Close ¶
func (r *Resampler) Close()
Close releases the native resampler. It is safe to call more than once and on a passthrough Resampler.
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 libsoxr has filter delay, the first calls of a stream emit slightly fewer frames than the rate ratio implies, which later calls make up.