trm

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pulse = iota
	Sine
)
View Source
const Beta = float64(5.658) // kaiser window parameters

kaiser window params

View Source
const BufferSize = 1024 // ring buffer size
View Source
const Factor = 377.0
View Source
const FilterLength = ZeroCrossings * LRange
View Source
const FilterLimit = FilterLength - 1
View Source
const FirBeta = .2

oversampling fir filter characteristics

View Source
const FirCutoff = .00000001
View Source
const FirGamma = .1
View Source
const FractionBits = LBits + MBits
View Source
const FractionMask uint32 = 0x0000FFFF
View Source
const FractionRange = 65536 // must be 2^FRACTION_BITS
View Source
const IZeroEpsilon = 1e-21
View Source
const InitialSeed = 0.7892347
View Source
const LBits = 8

const NBits = 16

View Source
const LMask uint32 = 0x0000FF00
View Source
const LRange = 256 // must be 2^L_BITS
View Source
const Limit = 200
View Source
const LpCutoff = float64(11.0 / 13.0) // 0.846 of nyquist
View Source
const MBits = 8
View Source
const MMask uint32 = 0x000000FF
View Source
const MRange = 256 // must be 2^M_BITS
View Source
const NMask uint32 = 0xFFFF0000
View Source
const OutputRate = 44100 // output sample rate (22.05, 44.1 KHz)
View Source
const OversamplingOscillator = true

compile with oversampling or plain oscillator

View Source
const TableLength = 512.0

glottal source oscillator table variables

View Source
const TableModulus = TableLength - 1
View Source
const ZeroCrossings = 13 // source cutoff frequency

Sample rate conversion constants

Variables

This section is empty.

Functions

func Approximate

func Approximate(number float64, order, numerator, denominator *int)

Approximate calculates the best rational approximation to 'number', given the maximum 'order'.

func Decrement

func Decrement(ptr, modulus int) int

Decrement decrements the pointer to the circular FIR filter buffer, keeping it in the range 0 -> modulus-1

func Increment

func Increment(ptr, modulus int) int

Increment increments the pointer to the circular FIR filter buffer, keeping it in the range 0 -> modulus-1

func Mod0

func Mod0(value float64) float64

Mod0 returns the modulus of 'value', keeping it in the range 0 -> TableModulus

func SrDecrement

func SrDecrement(pos *int32, modulus int)

SrDecrement decrements the buffer position keeping it within the range 0 to (modulus - 1)

func SrIncrement

func SrIncrement(pos *int32, modulus int)

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

type FirFilter struct {
	Ptr   int
	NTaps int
	Data  []float64
	Coef  []float64
}

func (*FirFilter) Filter

func (ff *FirFilter) Filter(input float64, needOutput bool) float64

Filter

func (*FirFilter) Init

func (ff *FirFilter) Init(beta, gamma, cutoff float64)

Init

func (*FirFilter) MaximallyFlat

func (ff *FirFilter) MaximallyFlat(beta, gamma float64, np *int, coefficients []float64) int

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

func (*FirFilter) Reset

func (ff *FirFilter) Reset()

Reset resets the data and sets the pointer to first element

func (*FirFilter) Trim

func (ff *FirFilter) Trim(cutoff float64, nCoefficients *int, coefficients []float64)

Trim trims the higher order coefficients of the FIR filter which fall below the cutoff value

type NoiseFilter

type NoiseFilter struct {
	NoiseX float64
}

NoiseFilter

func (*NoiseFilter) Filter

func (nf *NoiseFilter) Filter(input float64) float64

Filter

func (*NoiseFilter) Reset

func (nf *NoiseFilter) Reset()

Reset

type NoiseSource

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

NoiseSource

func (*NoiseSource) GetSample

func (ns *NoiseSource) GetSample() float64

GetSample

func (*NoiseSource) Init

func (ns *NoiseSource) Init()

Init

func (*NoiseSource) Reset

func (ns *NoiseSource) Reset()

Reset

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.

func (*RadiationFilter) Filter

func (rf *RadiationFilter) Filter(input float64) float64

Filter

func (*RadiationFilter) Init

func (rf *RadiationFilter) Init(apertureCoef float64)

Init

func (*RadiationFilter) Reset

func (rf *RadiationFilter) Reset()

Reset

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) MaxSampleVal

func (src *RateConverter) MaxSampleVal() float64

MaxSampleVal

func (*RateConverter) Reset

func (src *RateConverter) Reset()

Reset resets some values of the converter

type ReflectionFilter

type ReflectionFilter struct {
	A10         float64
	B11         float64
	ReflectionY float64
}

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

func (*ReflectionFilter) Reset

func (rf *ReflectionFilter) Reset()

Reset set ReflectionY to 0

type Throat

type Throat struct {
	Gain float64

	Y float64
	// contains filtered or unexported fields
}

Throat

func (*Throat) Init

func (thr *Throat) Init(sampleRate, cutoff, gain float64)

Init initializes the throat lowpass filter coefficients according to the throatCutoff value, and also the throatGain, according to the throatVol value.

func (*Throat) Process

func (thr *Throat) Process(input float64) float64

Process simulates the radiation of sound through the walls of the throat. Note that this form of the filter uses addition instead of subtraction for the econd term, since tb1 has reversed sign.

func (*Throat) Reset

func (thr *Throat) Reset()

Reset sets Y to 0

type WaveForm

type WaveForm int32

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

Jump to

Keyboard shortcuts

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