audio

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// C0, MIDI note #12.
	C0  = Hz(16.351)
	CS0 = Hz(17.324)
	D0  = Hz(18.354)
	DS0 = Hz(19.445)
	E0  = Hz(20.601)
	F0  = Hz(21.827)
	FS0 = Hz(23.124)
	G0  = Hz(24.499)
	GS0 = Hz(25.956)
	// A0, the lowest note of a piano.
	A0  = Hz(27.5)
	AS0 = Hz(29.135)
	// B0, the lowest note of a 5 string bass.
	B0 = Hz(30.868)
	// C1, the lowest note of double bass with C extension.
	C1  = Hz(32.703)
	CS1 = Hz(34.648)
	D1  = Hz(36.708)
	DS1 = Hz(38.891)
	// E1, the lowest note of a bass.
	E1  = Hz(41.203)
	F1  = Hz(43.654)
	FS1 = Hz(46.249)
	G1  = Hz(48.999)
	GS1 = Hz(51.913)
	A1  = Hz(55.)
	AS1 = Hz(58.27)
	B1  = Hz(61.735)
	C2  = Hz(65.406)
	CS2 = Hz(69.296)
	D2  = Hz(73.416)
	DS2 = Hz(77.782)
	// E2, the lowest note of a guitar.
	E2  = Hz(82.407)
	F2  = Hz(87.307)
	FS2 = Hz(92.499)
	G2  = Hz(97.999)
	GS2 = Hz(103.826)
	A2  = Hz(110.)
	AS2 = Hz(116.541)
	B2  = Hz(123.471)
	C3  = Hz(130.813)
	CS3 = Hz(138.591)
	D3  = Hz(146.832)
	DS3 = Hz(155.563)
	E3  = Hz(164.814)
	F3  = Hz(174.614)
	FS3 = Hz(184.997)
	// G3, the lowest note of a violin.
	G3  = Hz(195.998)
	GS3 = Hz(207.652)
	A3  = Hz(220.)
	AS3 = Hz(233.082)
	B3  = Hz(246.942)
	// C4, the "middle C".
	C4  = Hz(261.626)
	CS4 = Hz(277.183)
	D4  = Hz(293.665)
	DS4 = Hz(311.127)
	E4  = Hz(329.628)
	F4  = Hz(349.228)
	FS4 = Hz(369.994)
	G4  = Hz(391.995)
	GS4 = Hz(415.305)
	// A4, the tuning reference note.
	A4  = Hz(440.)
	AS4 = Hz(466.164)
	B4  = Hz(493.883)
	C5  = Hz(523.251)
	CS5 = Hz(554.365)
	D5  = Hz(587.33)
	DS5 = Hz(622.254)
	E5  = Hz(659.255)
	F5  = Hz(698.456)
	FS5 = Hz(739.989)
	G5  = Hz(783.991)
	GS5 = Hz(830.609)
	A5  = Hz(880.)
	AS5 = Hz(932.328)
	B5  = Hz(987.767)
	C6  = Hz(1046.502)
	CS6 = Hz(1108.731)
	D6  = Hz(1174.659)
	DS6 = Hz(1244.508)
	E6  = Hz(1318.51)
	F6  = Hz(1396.913)
	FS6 = Hz(1479.978)
	G6  = Hz(1567.982)
	GS6 = Hz(1661.219)
	A6  = Hz(1760.)
	AS6 = Hz(1864.655)
	B6  = Hz(1975.533)
	C7  = Hz(2093.005)
	CS7 = Hz(2217.461)
	D7  = Hz(2349.318)
	DS7 = Hz(2489.016)
	E7  = Hz(2637.021)
	F7  = Hz(2793.826)
	FS7 = Hz(2959.955)
	G7  = Hz(3135.964)
	GS7 = Hz(3322.438)
	A7  = Hz(3520.)
	AS7 = Hz(3729.31)
	B7  = Hz(3951.066)
	// C8, the highest note of a piano.
	C8  = Hz(4186.009)
	CS8 = Hz(4434.922)
	D8  = Hz(4698.636)
	DS8 = Hz(4978.032)
	E8  = Hz(5274.042)
	F8  = Hz(5587.652)
	FS8 = Hz(5919.91)
	G8  = Hz(6271.928)
	GS8 = Hz(6644.876)
	A8  = Hz(7040.)
	AS8 = Hz(7458.62)
	B8  = Hz(7902.132)
	C9  = Hz(8372.018)
	CS9 = Hz(8869.844)
	D9  = Hz(9397.272)
	DS9 = Hz(9956.064)
	E9  = Hz(10548.084)
	F9  = Hz(11175.304)
	FS9 = Hz(11839.82)
	G9  = Hz(12543.856)
	// G#9, MIDI note #128, the top of the MIDI tuning range.
	GS9 = Hz(13289.752)
	A9  = Hz(14080.)
	AS9 = Hz(14917.24)
	// B9. For most of adults, it is already beyond the hearing range.
	B9 = Hz(15804.264)
)
View Source
const SampleRate = 44_100

Variables

View Source
var Out = Node{0}

Functions

This section is empty.

Types

type AllForOne

type AllForOne struct{ Node }

An audio node created by Node.AddAllForOne.

type Clip

type Clip struct{ Node }

An audio node created by Node.AddClip.

func (Clip) ModulateBoth

func (n Clip) ModulateBoth(m Modulator)

Modulate the low cut amplitude and adjust the high amplitude to keep the gap.

In other words, the difference between low and high cut points will stay the same.

func (Clip) ModulateHigh

func (n Clip) ModulateHigh(m Modulator)

Modulate the high cut amplitude.

func (Clip) ModulateLow

func (n Clip) ModulateLow(m Modulator)

Modulate the low cut amplitude.

type Concat

type Concat struct{ Node }

An audio node created by Node.AddConcat.

type Empty

type Empty struct{ Node }

An audio node created by Node.AddEmpty.

type File added in v0.7.0

type File struct{ Node }

An audio node created by Node.AddFile.

type Gain

type Gain struct{ Node }

An audio node created by Node.AddGain.

func (Gain) Modulate

func (n Gain) Modulate(m Modulator)

Modulate the gain level.

type HighPass

type HighPass struct{ Node }

An audio node created by Node.AddHighPass.

func (HighPass) ModulateFreq

func (n HighPass) ModulateFreq(m Modulator)

Modulate the cut-off frequency.

type HoldModulator

type HoldModulator struct {
	Before float32
	After  float32
	Time   Samples
}

Hold envelope.

It looks like this: `⎽│⎺` or `⎺│⎽`.

The value before `time` is `before` and the value after `time` is `after`. Equivalent to [`LinearModulator`] with `start_at` being equal to `end_at`.

func (HoldModulator) Modulate

func (m HoldModulator) Modulate(nodeID uint32, param uint32)

type Hz

type Hz float32

Frequency in Hz.

func MIDI

func MIDI(note uint8) Hz

type LinearModulator

type LinearModulator struct {
	Start   float32
	End     float32
	StartAt Samples
	EndAt   Samples
}

Linear (ramp up or down) envelope.

It looks like this: `⎽╱⎺` or `⎺╲⎽`.

The value before `start_at` is `start`, the value after `end_at` is `end`, and the value between `start_at` and `end_at` changes linearly from `start` to `end`.

func (LinearModulator) Modulate

func (m LinearModulator) Modulate(nodeID uint32, param uint32)

type Loop

type Loop struct{ Node }

An audio node created by Node.AddLoop.

type LowPass

type LowPass struct{ Node }

An audio node created by Node.AddLowPass.

func (LowPass) ModulateFreq

func (n LowPass) ModulateFreq(m Modulator)

Modulate the cut-off frequency.

type Mix

type Mix struct{ Node }

An audio node created by Node.AddMix.

type Modulator

type Modulator interface {
	Modulate(nodeID uint32, param uint32)
}

type Mute

type Mute struct{ Node }

An audio node created by Node.AddMute.

func (Mute) Modulate

func (n Mute) Modulate(m Modulator)

Modulate the muted state.

Below 0.5 is muted, above is unmuted.

type Node

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

func (Node) AddAllForOne

func (n Node) AddAllForOne() AllForOne

Add mixer node that stops if any of the sources stops.

func (Node) AddClip

func (n Node) AddClip(low float32, high float32) Clip

Add node clamping the input amplitude. Can be used for hard distortion.

func (Node) AddConcat

func (n Node) AddConcat() Concat

Add a node that plays the inputs one after the other, in the order as they added.

func (Node) AddEmpty

func (n Node) AddEmpty() Empty

Add always stopped source.

func (Node) AddFile added in v0.7.0

func (n Node) AddFile(path string) File

Add source playing audio from a file.

func (Node) AddGain

func (n Node) AddGain(lvl float32) Gain

Add gain control node.

func (Node) AddHighPass

func (n Node) AddHighPass(freq float32, q float32) HighPass

Add highpass filter node.

func (Node) AddLoop

func (n Node) AddLoop() Loop

Add a loop node that resets the input if it stops.

func (Node) AddLowPass

func (n Node) AddLowPass(freq float32, q float32) LowPass

Add lowpass filter node.

func (Node) AddMix

func (n Node) AddMix() Mix

Add node simply mixing all inputs.

func (Node) AddMute

func (n Node) AddMute() Mute

Add node that can be muted using modulation.

func (Node) AddNoise

func (n Node) AddNoise(seed int) Noise

Add white noise source (amplitude on each tick is random).

func (Node) AddPan

func (n Node) AddPan(lvl float32) Pan

Add node panning the audio to the left (0.), right (1.), or something in between.

func (Node) AddPause

func (n Node) AddPause() Pause

Add node that can be paused using modulation.

func (Node) AddSawtooth

func (n Node) AddSawtooth(freq Hz, phase float32) Sawtooth

Add sawtooth wave oscillator source (`╱│`).

func (Node) AddSine

func (n Node) AddSine(freq Hz, phase float32) Sine

Add sine wave oscillator source (`∿`).

func (Node) AddSquare

func (n Node) AddSquare(freq Hz, phase float32) Square

Add square wave oscillator source (`⎍`).

func (Node) AddSwap

func (n Node) AddSwap() Swap

Add node swapping left and right channels of the stereo input.

func (Node) AddTakeLeft

func (n Node) AddTakeLeft() TakeLeft

Add node converting stereo to mono by taking the left channel.

func (Node) AddTakeRight

func (n Node) AddTakeRight() TakeRight

Add node converting stereo to mono by taking the right channel.

func (Node) AddTrackPosition

func (n Node) AddTrackPosition() TrackPosition

Add node tracking the elapsed playback time.

func (Node) AddTriangle

func (n Node) AddTriangle(freq Hz, phase float32) Triangle

Add triangle wave oscillator source (`╱╲`).

func (Node) AddZero

func (n Node) AddZero() Zero

Add silent source producing zeros.

func (Node) Clear

func (n Node) Clear()

Remove all child nodes.

After it is called, you should make sure to discard all references to the old child nodes.

func (Node) Reset

func (n Node) Reset()

Reset the node state to how it was when it was just added.

func (Node) ResetAll

func (n Node) ResetAll()

Reset the node and all child nodes to the state to how it was when they were just added.

type Noise

type Noise struct{ Node }

An audio node created by Node.AddNoise.

type Pan

type Pan struct{ Node }

An audio node created by Node.AddPan.

func (Pan) Modulate

func (n Pan) Modulate(m Modulator)

Modulate the pan value (from 0. to 1.: 0. is only left, 1. is only right).

type Pause

type Pause struct{ Node }

An audio node created by Node.AddPause.

func (Pause) Modulate

func (n Pause) Modulate(m Modulator)

Modulate the paused state.

Below 0.5 is paused, above is playing.

type Samples

type Samples uint32

Time in number of samples.

func Duration

func Duration(t time.Duration) Samples

Time from time.Duration.

func MS

func MS(s uint32) Samples

Time in milliseconds.

func Seconds

func Seconds(s uint32) Samples

Time in seconds.

type Sawtooth

type Sawtooth struct{ Node }

An audio node created by Node.AddSawtooth.

func (Sawtooth) Modulate

func (n Sawtooth) Modulate(m Modulator)

Modulate oscillation frequency.

type Sine

type Sine struct{ Node }

An audio node created by Node.AddSine.

func (Sine) Modulate

func (n Sine) Modulate(m Modulator)

Modulate oscillation frequency.

type SineModulator

type SineModulator struct {
	Freq Hz
	Low  float32
	High float32
}

Sine wave low-frequency oscillator.

It looks like this: `∿`.

`low` is the lowest produced value, `high` is the highest.

func (SineModulator) Modulate

func (m SineModulator) Modulate(nodeID uint32, param uint32)

type Square

type Square struct{ Node }

An audio node created by Node.AddSquare.

func (Square) Modulate

func (n Square) Modulate(m Modulator)

Modulate oscillation frequency.

type Swap

type Swap struct{ Node }

An audio node created by Node.AddSwap.

type TakeLeft

type TakeLeft struct{ Node }

An audio node created by Node.AddTakeLeft.

type TakeRight

type TakeRight struct{ Node }

An audio node created by Node.AddTakeRight.

type TrackPosition

type TrackPosition struct{ Node }

An audio node created by Node.AddTrackPosition.

type Triangle

type Triangle struct{ Node }

An audio node created by Node.AddTriangle.

func (Triangle) Modulate

func (n Triangle) Modulate(m Modulator)

Modulate oscillation frequency.

type Zero

type Zero struct{ Node }

An audio node created by Node.AddZero.

Jump to

Keyboard shortcuts

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