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
- func ChannelMatrix(src, dst int) []float32
- func Clip(samples []float32)
- func ConvertChannels(dst, src []float32, srcCh, dstCh, frames int)
- func Float32ToInt16(dst []int16, src []float32)
- func Float32ToInt32(dst []int32, src []float32)
- func Int16ToFloat32(dst []float32, src []int16)
- func Int32ToFloat32(dst []float32, src []int32)
- func Mix(dst, src []float32, gain float32)
- func Resample(chans int, src []float32, base int, inFrames int, dst []float32, outFrames int, ...)
- func ResampleRate(srcRate, dstRate int) int64
- func ResamplerInputFrames(outFrames, rate, offset int64) int64
- func ResamplerOutputFrames(inFrames, rate int64, offset *int64) int64
- func Scale(samples []float32, gain float32)
- type Converter
- func (c *Converter) Available() int
- func (c *Converter) Clear()
- func (c *Converter) Flush()
- func (c *Converter) Needed(frames int) int
- func (c *Converter) Put(samples []float32)
- func (c *Converter) QueuedFrames() int
- func (c *Converter) Read(dst []float32, frames int) int
- func (c *Converter) SetSpeed(ratio float64)
- func (c *Converter) Speed() float64
Constants ¶
const MaxChannels = 8
MaxChannels is the most channels that a stream has (SDL's largest layout, 7.1).
Flutter: no counterpart
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ResamplerInputFrames returns how many input frames outFrames output frames use, given the offset the resampler is at (SDL_GetResamplerInputFrames).
Flutter: no counterpart
func ResamplerOutputFrames ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
QueuedFrames is the number of frames of the source format that are queued.
Flutter: no counterpart
func (*Converter) Read ¶
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