audiocvt

package
v1.17.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audiocvt converts and mixes audio samples (SPEC §28.3): the conversion between sample types, the mixing between channel layouts, the resampler and the converter that a stream of package audio uses. It is plain Go with no OS tags and takes no device, so a test can run any of it on any host.

It is translated to Go and changed from src/audio/SDL_audiotypecvt.c, SDL_audiocvt.c, SDL_audioresample.c, SDL_audio_channel_converters.h and SDL_mixer.c of SDL 3 (zlib license, third_party/sdl/LICENSE). Samples are interleaved float32 from -1 to 1 inside the package; the layouts of channels are SDL's: mono, stereo, 2.1 (FL FR LFE), quad (FL FR BL BR), 4.1 (FL FR LFE BL BR), 5.1 (FL FR FC LFE BL BR), 6.1 (FL FR FC LFE BC SL SR) and 7.1 (FL FR FC LFE BL BR SL SR).

Flutter: no counterpart

Index

Constants

View Source
const MaxChannels = 8

MaxChannels is the most channels that a stream has (SDL's largest layout, 7.1).

Flutter: no counterpart

View Source
const ResamplerHistoryFrames = resamplerMaxPaddingFrames

ResamplerHistoryFrames is how many frames before the first one that is not used up yet are kept for the filter (SDL_GetResamplerHistoryFrames).

Flutter: no counterpart

View Source
const ResamplerPaddingFrames = resamplerMaxPaddingFrames

ResamplerPaddingFrames is how many frames the filter needs before the input and after it (SDL_GetResamplerPaddingFrames).

Flutter: no counterpart

Variables

This section is empty.

Functions

func ChannelMatrix

func ChannelMatrix(src, dst int) []float32

ChannelMatrix returns the matrix that turns src channels into dst channels (SDL's layouts), dst rows of src columns, row after row; it is nil when the counts are equal or outside 1 to MaxChannels. The caller must not change it.

Flutter: no counterpart

func Clip

func Clip(samples []float32)

Clip cuts the samples to the range from -1 to 1. A sample that is not a number becomes 0.

Flutter: no counterpart

func ConvertChannels

func ConvertChannels(dst, src []float32, srcCh, dstCh, frames int)

ConvertChannels turns frames frames of src (srcCh channels) into dst (dstCh channels). dst and src must not overlap. With equal counts it copies.

Flutter: no counterpart

func Float32ToInt16

func Float32ToInt16(dst []int16, src []float32)

Float32ToInt16 converts float32 samples to signed 16-bit ones (SDL_Convert_F32_to_S16): a sample is multiplied by 32768 and rounded to the nearest, ties to even, and what is outside the range of 16 bits is cut to it. A sample that is not a number is 0. dst must be at least as long as src.

Flutter: no counterpart

func Float32ToInt32

func Float32ToInt32(dst []int32, src []float32)

Float32ToInt32 converts float32 samples to signed 32-bit ones (SDL_Convert_F32_to_S32): a sample is multiplied by 2147483648, cut to the range of 32 bits and truncated. A sample that is not a number is 0. dst must be at least as long as src.

Flutter: no counterpart

func Int16ToFloat32

func Int16ToFloat32(dst []float32, src []int16)

Int16ToFloat32 converts signed 16-bit samples to float32 (SDL_Convert_S16_to_F32): each is divided by 32768, which is exact. dst must be at least as long as src.

Flutter: no counterpart

func Int32ToFloat32

func Int32ToFloat32(dst []float32, src []int32)

Int32ToFloat32 converts signed 32-bit samples to float32 (SDL_Convert_S32_to_F32). dst must be at least as long as src.

Flutter: no counterpart

func Mix

func Mix(dst, src []float32, gain float32)

Mix adds src multiplied by gain to dst, for the samples that both have.

Flutter: no counterpart

func Resample

func Resample(chans int, src []float32, base int, inFrames int, dst []float32, outFrames int, rate int64, offset *int64)

Resample makes outFrames frames of chans channels from inFrames input frames (SDL_ResampleAudio). src is the input with its padding: frame 0 of the input is at src[base*chans], and ResamplerPaddingFrames frames lie before it and after the last one. The offset is where in the input the first output frame is (a fixed point number, 32 bits of fraction) and is updated to the next call's. The rate comes from ResampleRate.

Flutter: no counterpart

func ResampleRate

func ResampleRate(srcRate, dstRate int) int64

ResampleRate returns the rate of the resampler for two sample rates: how far in the input one output frame goes, as a fixed point number with 32 bits of fraction, rounded up so that the input is used up (SDL_GetResampleRate). Both rates must be positive.

Flutter: no counterpart

func ResamplerInputFrames

func ResamplerInputFrames(outFrames, rate, offset int64) int64

ResamplerInputFrames returns how many input frames outFrames output frames use, given the offset the resampler is at (SDL_GetResamplerInputFrames).

Flutter: no counterpart

func ResamplerOutputFrames

func ResamplerOutputFrames(inFrames, rate int64, offset *int64) int64

ResamplerOutputFrames returns how many output frames inFrames input frames give from the offset *offset, and sets *offset to what it is afterwards (SDL_GetResamplerOutputFrames).

Flutter: no counterpart

func Scale

func Scale(samples []float32, gain float32)

Scale multiplies the samples by gain.

Flutter: no counterpart

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter queues interleaved float32 frames of one format and gives them out in another: another number of channels, another rate and, with SetSpeed, another speed. It is not safe for use from several goroutines; package audio holds a lock around it. After the first calls (which make its buffers) Read and Put do not allocate unless the queue grows.

Flutter: no counterpart

func NewConverter

func NewConverter(srcRate, srcCh, dstRate, dstCh int) *Converter

NewConverter makes a converter from srcCh channels at srcRate to dstCh channels at dstRate. The rates are positive and the channels from 1 to MaxChannels.

Flutter: no counterpart

func (*Converter) Available

func (c *Converter) Available() int

Available returns how many output frames Read can make from what is queued.

Flutter: no counterpart

func (*Converter) Clear

func (c *Converter) Clear()

Clear drops what is queued, the history and the position in the input.

Flutter: no counterpart

func (*Converter) Flush

func (c *Converter) Flush()

Flush says that no more frames come for now: the last frames are given out too, with silence after them for the filter.

Flutter: no counterpart

func (*Converter) Needed

func (c *Converter) Needed(frames int) int

Needed returns how many more frames of the source format have to be queued for Read to make frames output frames, counting the frames that the filter needs after them. A callback stream uses it to ask for just what it needs.

Flutter: no counterpart

func (*Converter) Put

func (c *Converter) Put(samples []float32)

Put queues frames; samples holds a whole number of frames of the source format. Put after Flush starts a new sound.

Flutter: no counterpart

func (*Converter) QueuedFrames

func (c *Converter) QueuedFrames() int

QueuedFrames is the number of frames of the source format that are queued.

Flutter: no counterpart

func (*Converter) Read

func (c *Converter) Read(dst []float32, frames int) int

Read converts up to frames output frames into dst (dstCh channels each) and returns how many it made, which is fewer when the queue does not have enough. dst must have room for frames frames.

Flutter: no counterpart

func (*Converter) SetSpeed

func (c *Converter) SetSpeed(ratio float64)

SetSpeed sets how fast the input is played: 2 takes twice as many frames of input for the same output, and the pitch goes up with it. The speed is cut to the range 0.01 to 100.

Flutter: no counterpart

func (*Converter) Speed

func (c *Converter) Speed() float64

Speed returns the speed that was set.

Flutter: no counterpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL