Documentation ¶
Overview ¶
Package filter provides various audio filters to be applied to audios through the Filter function.
Index ¶
- Variables
- func ShortTimeFourierTransform(data []float64, fftFrameSize, sign int)
- type Data
- type Encoding
- func AssertStereo() Encoding
- func LeftPan() Encoding
- func Pan(f float64) Encoding
- func RightPan() Encoding
- func Speed(ratio float64, pitchShifter PitchShifter) Encoding
- func Volume(mult float64) Encoding
- func VolumeBalance(lMult, rMult float64) Encoding
- func VolumeLeft(mult float64) Encoding
- func VolumeRight(mult float64) Encoding
- type FFTShifter
- type Loop
- type PitchShifter
- type SampleRate
Constants ¶
This section is empty.
Variables ¶
var (
LowQualityShifter, _ = NewFFTShifter(1024, 8)
HighQualityShifter, _ = NewFFTShifter(1024, 32)
)
These are built in shifters with some common inputs
Functions ¶
func ShortTimeFourierTransform ¶
ShortTimeFourierTransform : FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse) Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the time domain data in fftBuffer[0...2*fftFrameSize-1]. The FFT array takes and returns the cosine and sine parts in an interleaved manner, ie. fftBuffer[0] = cosPart[0], fftBuffer[1] = sinPart[0], asf. fftFrameSize must be a power of 2. It expects a complex input signal (see footnote 2), ie. when working with 'common' audio signals our input signal has to be passed as {in[0],0.,in[1],0.,in[2],0.,...} asf. In that case, the transform of the frequencies of interest is in fftBuffer[0...fftFrameSize].
Types ¶
type Encoding ¶
Encoding filters are functions on any combination of the values in an audio.Encoding
func AssertStereo ¶
func AssertStereo() Encoding
AssertStereo does nothing to audio that has two channels, but will convert mono audio to two-channeled audio with the same data on both channels
func Pan ¶
Pan takes -1 <= f <= 1. An f of -1 represents a full pan to the left, a pan of 1 represents a full pan to the right.
func Speed ¶
func Speed(ratio float64, pitchShifter PitchShifter) Encoding
Speed modifies the filtered audio by a speed ratio, changing its sample rate in the process while maintaining pitch.
func Volume ¶
Volume will magnify the data by mult, increasing or reducing the volume of the output sound. For mult <= 1 this should have no unexpected behavior, although for mult ~= 1 it might not have any effect. More importantly for mult > 1, values may result in the output data clipping over integer overflows, which is presumably not desired behavior.
func VolumeBalance ¶
VolumeBalance will filter audio on two channels such that the left channel is (l+r)/2 * lMult, and the right channel is (l+r)/2 * rMult
func VolumeLeft ¶
VolumeLeft acts like volume but reduces left channel volume only
func VolumeRight ¶
VolumeRight acts like volume but reduces left channel volume only
type FFTShifter ¶
type FFTShifter struct {
// contains filtered or unexported fields
}
FFTShifter holds buffers and settings for performing a pitch shift on PCM audio
func (FFTShifter) PitchShift ¶
func (ps FFTShifter) PitchShift(shiftBy float64) Encoding
PitchShift modifies filtered audio by the input float, between 0.5 and 2.0, each end of the spectrum representing octave down and up respectively
type Loop ¶
type Loop func(*bool)
Loop functions modify a boolean, with the intention that that boolean is a loop variable
type PitchShifter ¶
A PitchShifter has an encoding function that will shift a pitch up to an octave up or down (0.5 -> octave down, 2.0 -> octave up) these are for lower-level use, and a similar type that takes in steps to shift by (and eventually pitches to set to) will follow.
func NewFFTShifter ¶
func NewFFTShifter(fftFrameSize int, oversampling int) (PitchShifter, error)
NewFFTShifter returns a pitch shifter that uses fast fourier transforms
type SampleRate ¶
type SampleRate func(*uint32)
A SampleRate is a function that takes in uint32 SampleRates
func ModSampleRate ¶
func ModSampleRate(mult float64) SampleRate
ModSampleRate might slow down or speed up a sample, but this will effect the perceived pitch of the sample. See Speed.