synth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoteC    uint8 = 0
	NoteCisz uint8 = 1
	NoteDesz uint8 = 1
	NoteD    uint8 = 2
	NoteDisz uint8 = 3
	NoteEsz  uint8 = 3
	NoteE    uint8 = 4
	NoteF    uint8 = 5
	NoteFisz uint8 = 6
	NoteGesz uint8 = 6
	NoteG    uint8 = 7
	NoteGisz uint8 = 8
	NoteAsz  uint8 = 8
	NoteA    uint8 = 9
	NoteAisz uint8 = 10
	NoteB    uint8 = 10
	NoteH    uint8 = 11
)

Variables

This section is empty.

Functions

func GenerateFreqTableBasedOn

func GenerateFreqTableBasedOn(freqOfA4 float64)

GenerateFreqTableBasedOn generates a 12 note LUT based on an arbitrary frequency in Hz used as the A note of the 4th octave. Can't use the LUT before this. This value changed a lot throughout history. Also, some instruments are tuned differently - currently only 1 LUT is supported. Use GetFreqOf to get the frequency of a note.

func GetFreqOf

func GetFreqOf(octave uint8, note uint8) float64

GetFreqOf returns the frequency of a note from the pre set LUT. Use GenerateFreqTableBasedOn to generate it.

Types

type OscGeneratorType

type OscGeneratorType uint
const (
	OscTypeWave OscGeneratorType = iota
	OscTypePulse
	OscTypeNoise
)

type Oscillator

type Oscillator struct {
	Wave  *generator.FunctionGenerator
	Pulse *generator.Generator //TODO
	Noise *generator.NoiseGenerator

	Frequency    float64
	FrequencyMod generator.Generator // modulates Frequency

	Volume    float64
	VolumeMod generator.Generator // modulates Volume

	Envelope    *modulator.ADSR
	UseEnvelope bool // turn on the envelope
	// contains filtered or unexported fields
}

TODO: extract delay, so GetNextSample don't need to modify the object

func NewOscillator

func NewOscillator(sampleRate uint) *Oscillator

NewOscillator creates a new oscillator which has a function generator, an optional envelope, a starting volume and frequency value with modulation options. The sample rate is in Hz and can't be changed later.

func (*Oscillator) GetNextSample

func (osc *Oscillator) GetNextSample() float64

GetNextSample returns the next sample using the set oscillator state.

func (Oscillator) GetSampleRate

func (osc Oscillator) GetSampleRate() uint

GetSampleRate returns the sample rate with which the oscillator was created.

func (*Oscillator) Reset

func (osc *Oscillator) Reset()

Reset resets ALL the oscillator values to their default.

func (*Oscillator) SetDelay

func (osc *Oscillator) SetDelay(durationMS uint)

SetDelay sets a delay in milliseconds for the oscillator start.

func (*Oscillator) SwitchGeneratorType

func (osc *Oscillator) SwitchGeneratorType(oscType OscGeneratorType)

SwitchGeneratorType will instantly switch to another type of function generator. Won't change any values for them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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