filter

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package filter provides various audio filters to be applied to audios through the Filter function.

Index

Constants

This section is empty.

Variables

View Source
var (
	LowQualityShifter, _  = NewFFTShifter(1024, 8)
	HighQualityShifter, _ = NewFFTShifter(1024, 32)
)

These are built in shifters with some common inputs

Functions

func ShortTimeFourierTransform

func ShortTimeFourierTransform(data []float64, fftFrameSize, sign int)

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 Data

type Data func(*[]byte)

Data filters are functions on []byte types

func (Data) Apply

func (df Data) Apply(a klang.Audio) (klang.Audio, error)

Apply checks that the given audio supports Data, filters if it can, then returns

type Encoding

type Encoding func(supports.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 LeftPan

func LeftPan() Encoding

LeftPan filters audio to only play on the left speaker

func Pan

func Pan(f float64) Encoding

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 RightPan

func RightPan() Encoding

RightPan filters audio to only play on the right speaker

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

func Volume(mult float64) Encoding

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

func VolumeBalance(lMult, rMult float64) Encoding

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

func VolumeLeft(mult float64) Encoding

VolumeLeft acts like volume but reduces left channel volume only

func VolumeRight

func VolumeRight(mult float64) Encoding

VolumeRight acts like volume but reduces left channel volume only

func (Encoding) Apply

func (enc Encoding) Apply(a klang.Audio) (klang.Audio, error)

Apply checks that the given audio supports Encoding, filters if it can, then returns

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

func LoopOff

func LoopOff() Loop

LoopOff sets the loop to not happen

func LoopOn

func LoopOn() Loop

LoopOn sets the loop to happen

func (Loop) Apply

func (lf Loop) Apply(a klang.Audio) (klang.Audio, error)

Apply checks that the given audio supports Loop, filters if it can, then returns

type PitchShifter

type PitchShifter interface {
	PitchShift(float64) Encoding
}

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.

func (SampleRate) Apply

func (srf SampleRate) Apply(a klang.Audio) (klang.Audio, error)

Apply checks that the given audio supports SampleRate, filters if it can, then returns

Directories

Path Synopsis
Package supports holds interface types for filter supports.
Package supports holds interface types for filter supports.

Jump to

Keyboard shortcuts

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