Documentation
¶
Index ¶
- Constants
- func Approximate(number float64, order, numerator, denominator *int)
- func Decrement(ptr, modulus int) int
- func Increment(ptr, modulus int) int
- func Mod0(value float64) float64
- func SrDecrement(pos *int32, modulus int)
- func SrIncrement(pos *int32, modulus int)
- type BandpassFilter
- type FirFilter
- func (ff *FirFilter) Filter(input float64, needOutput bool) float64
- func (ff *FirFilter) Init(beta, gamma, cutoff float64)
- func (ff *FirFilter) MaximallyFlat(beta, gamma float64, np *int, coefficients []float64) int
- func (ff *FirFilter) Reset()
- func (ff *FirFilter) Trim(cutoff float64, nCoefficients *int, coefficients []float64)
- type NoiseFilter
- type NoiseSource
- type RadiationFilter
- type RateConverter
- func (src *RateConverter) DataEmpty()
- func (src *RateConverter) DataFill(data float64)
- func (src *RateConverter) FlushBuffer()
- func (src *RateConverter) IZero(x float64) float64
- func (src *RateConverter) Init(sampleRate int, outputRate int, outputData *[]float64)
- func (src *RateConverter) InitBuffer()
- func (src *RateConverter) InitConversion(sampleRate int, outputRate float64)
- func (src *RateConverter) InitFilter()
- func (src *RateConverter) MaxSampleVal() float64
- func (src *RateConverter) Reset()
- type ReflectionFilter
- type Throat
- type WaveForm
- type WavetableGlottalSource
- func (wgs *WavetableGlottalSource) GetSample(frequency float64) (output float64)
- func (wgs *WavetableGlottalSource) IncrementPosition(frequency float64)
- func (wgs *WavetableGlottalSource) Init(wType WaveForm, sampleRate, tp, tnMin, tnMax float64)
- func (wgs *WavetableGlottalSource) Reset()
- func (wgs *WavetableGlottalSource) Update(amplitude float64)
Constants ¶
const ( Pulse = iota Sine )
const Beta = float64(5.658) // kaiser window parameters
kaiser window params
const BufferSize = 1024 // ring buffer size
const Factor = 377.0
const FilterLength = ZeroCrossings * LRange
const FilterLimit = FilterLength - 1
const FirBeta = .2
oversampling fir filter characteristics
const FirCutoff = .00000001
const FirGamma = .1
const FractionBits = LBits + MBits
const FractionMask uint32 = 0x0000FFFF
const FractionRange = 65536 // must be 2^FRACTION_BITS
const IZeroEpsilon = 1e-21
const InitialSeed = 0.7892347
const LBits = 8
const NBits = 16
const LMask uint32 = 0x0000FF00
const LRange = 256 // must be 2^L_BITS
const Limit = 200
const LpCutoff = float64(11.0 / 13.0) // 0.846 of nyquist
const MBits = 8
const MMask uint32 = 0x000000FF
const MRange = 256 // must be 2^M_BITS
const NMask uint32 = 0xFFFF0000
const OutputRate = 44100 // output sample rate (22.05, 44.1 KHz)
const OversamplingOscillator = true
compile with oversampling or plain oscillator
const TableLength = 512.0
glottal source oscillator table variables
const TableModulus = TableLength - 1
const ZeroCrossings = 13 // source cutoff frequency
Sample rate conversion constants
Variables ¶
This section is empty.
Functions ¶
func Approximate ¶
Approximate calculates the best rational approximation to 'number', given the maximum 'order'.
func Decrement ¶
Decrement decrements the pointer to the circular FIR filter buffer, keeping it in the range 0 -> modulus-1
func Increment ¶
Increment increments the pointer to the circular FIR filter buffer, keeping it in the range 0 -> modulus-1
func SrDecrement ¶
SrDecrement decrements the buffer position keeping it within the range 0 to (modulus - 1)
func SrIncrement ¶
SrIncrement increments the buffer position keeping it within the range 0 to (modulus - 1)
Types ¶
type BandpassFilter ¶
type BandpassFilter struct {
// contains filtered or unexported fields
}
BandPassFilter
func (*BandpassFilter) Filter ¶
func (bf *BandpassFilter) Filter(input float64) float64
BandpassFilter is a Frication bandpass filter, with variable center frequency and bandwidth
func (*BandpassFilter) Reset ¶
func (bf *BandpassFilter) Reset()
Reset sets the filter values to zero
func (*BandpassFilter) Update ¶
func (bf *BandpassFilter) Update(sampleRate, bandwidth, centerFreq float64)
Update sets the filter values based on sample rate, bandwidth and center frequency
type FirFilter ¶
func (*FirFilter) MaximallyFlat ¶
MaximallyFlat calculates coefficients for a linear phase lowpass FIR filter, with beta being the center frequency of the transition band (as a fraction of the sampling frequency), and gamme the width of the transition band
type NoiseSource ¶
type NoiseSource struct {
// contains filtered or unexported fields
}
NoiseSource
type RadiationFilter ¶
type RadiationFilter struct {
A20 float64
A21 float64
B21 float64
RadiationX float64
RadiationY float64
}
RadiationFilter is a variable, one-zero, one-pole, highpass filter, whose cutoff point is determined by the aperture coefficient.
type RateConverter ¶
type RateConverter struct {
SampleRateRatio float64
FillPtr int32
EmptyPtr int32
PadSize int32
FillSize int32
FillCounter int32
FilterIncrement uint32
PhaseIncrement uint32
TimeRegIncrement uint32
TimeReg uint32
MaxSampleValue float64
NSamples int64
H [FilterLength]float64
DeltaH [FilterLength]float64
Buffer [BufferSize]float64
OutputData *[]float64
}
RateConverter converts the sample rate
func (*RateConverter) DataEmpty ¶
func (src *RateConverter) DataEmpty()
DataEmpty converts available portion of the input signal to the new sampling rate, and outputs the samples to the sound struct.
func (*RateConverter) DataFill ¶
func (src *RateConverter) DataFill(data float64)
DataFill fills the ring buffer with a single sample, increments the counters and pointers, and empties the buffer when full
func (*RateConverter) FlushBuffer ¶
func (src *RateConverter) FlushBuffer()
FlushBuffer pads the buffer with zero samples, and flushes it by converting the remaining samples
func (*RateConverter) IZero ¶
func (src *RateConverter) IZero(x float64) float64
IZero returns the value for the modified Bessel function of the first kind, order 0, as a float
func (*RateConverter) Init ¶
func (src *RateConverter) Init(sampleRate int, outputRate int, outputData *[]float64)
Init
func (*RateConverter) InitBuffer ¶
func (src *RateConverter) InitBuffer()
InitBuffer initializes the ring buffer used for sample rate conversion
func (*RateConverter) InitConversion ¶
func (src *RateConverter) InitConversion(sampleRate int, outputRate float64)
InitConversion initializes all the sample rate conversion functions
func (*RateConverter) InitFilter ¶
func (src *RateConverter) InitFilter()
InitFilter initializes filter impulse response and impulse delta values
func (*RateConverter) Reset ¶
func (src *RateConverter) Reset()
Reset resets some values of the converter
type ReflectionFilter ¶
ReflectionFilter
func (*ReflectionFilter) Filter ¶
func (rf *ReflectionFilter) Filter(input float64) float64
Filter calculates the output based on input on current values
func (*ReflectionFilter) Init ¶
func (rf *ReflectionFilter) Init(apertureCoef float64)
Init initializes all of the filters struct fields
type Throat ¶
Throat
func (*Throat) Init ¶
Init initializes the throat lowpass filter coefficients according to the throatCutoff value, and also the throatGain, according to the throatVol value.
type WavetableGlottalSource ¶
type WavetableGlottalSource struct {
TableDiv1 int
TableDiv2 int
TnLength float64
TnDelta float64
BasicIncrement float64
CurrentPosition float64
Wavetable [TableLength]float64
FirFilter FirFilter
}
func (*WavetableGlottalSource) GetSample ¶
func (wgs *WavetableGlottalSource) GetSample(frequency float64) (output float64)
GetSample returns sample value from plain oscillator or 2x oversampling oscillator.
func (*WavetableGlottalSource) IncrementPosition ¶
func (wgs *WavetableGlottalSource) IncrementPosition(frequency float64)
IncrementPosition increments the position in the wavetable according to the specified frequency
func (*WavetableGlottalSource) Init ¶
func (wgs *WavetableGlottalSource) Init(wType WaveForm, sampleRate, tp, tnMin, tnMax float64)
Init calculates the initial glottal pulse and stores it in the wavetable, for use in the oscillator.
func (*WavetableGlottalSource) Reset ¶
func (wgs *WavetableGlottalSource) Reset()
Reset resets the current position and the Fir Filter
func (*WavetableGlottalSource) Update ¶
func (wgs *WavetableGlottalSource) Update(amplitude float64)
Update rewrites the changeable part of the glottal pulse according to the amplitude