Documentation ¶
Overview ¶
Package synth provides functions and types to support waveform synthesis.
Index ¶
- Variables
- type Option
- type Pitch
- type PitchDetector
- type Source
- func (s Source) MultiWave(waveFns []Waveform, opts ...Option) pcm.Reader
- func (s Source) Noise(opts ...Option) pcm.Reader
- func (s Source) NoiseWave(idx int) float64
- func (s Source) Phase(i int) float64
- func (s Source) PlayLength() time.Duration
- func (s Source) Pulse(pulse float64) func(opts ...Option) pcm.Reader
- func (s Source) Saw(opts ...Option) pcm.Reader
- func (s Source) SawWave(idx int) float64
- func (s Source) Sin(opts ...Option) pcm.Reader
- func (s Source) SinWave(idx int) float64
- func (s Source) Square(opts ...Option) pcm.Reader
- func (s Source) Triangle(opts ...Option) pcm.Reader
- func (s Source) TriangleWave(idx int) float64
- func (s Source) Update(opts ...Option) Source
- func (s Source) Wave(waveFn Waveform, opts ...Option) pcm.Reader
- type Step
- type Wave
- type Waveform
Constants ¶
This section is empty.
Variables ¶
var ( // Int16 is a default source for building 16-bit audio Int16 = Source{ Format: pcm.Format{ SampleRate: 44100, Channels: 2, Bits: 16, }, Pitch: A4, Volume: .25, Seconds: 1, } )
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option types modify waveform sources before they generate a waveform
func Detune ¶
Detune detunes between -1.0 and 1.0, 1.0 representing a half step up. Q: What is detuning? A: It's taking the pitch of the audio and adjusting it less than a single tone up or down. If you detune too far, you've just made the next pitch, but if you detune a little, you get a resonant sound.
type Pitch ¶
type Pitch uint16
A Pitch is a frequency value which represents how fast a wave should oscillate to produce a specific tone.
const ( // 0 is reserved as representing a 'rest' for the purpose of composition Rest Pitch = 0 C0 Pitch = 16 C0s Pitch = 17 D0b Pitch = 17 D0 Pitch = 18 D0s Pitch = 20 E0b Pitch = 20 E0 Pitch = 21 F0 Pitch = 22 F0s Pitch = 23 G0b Pitch = 23 G0 Pitch = 25 G0s Pitch = 26 A0b Pitch = 26 A0 Pitch = 28 A0s Pitch = 29 B0b Pitch = 29 B0 Pitch = 31 C1 Pitch = 33 C1s Pitch = 35 D1b Pitch = 35 D1 Pitch = 37 D1s Pitch = 39 E1b Pitch = 39 E1 Pitch = 41 F1 Pitch = 44 F1s Pitch = 46 G1b Pitch = 46 G1 Pitch = 49 G1s Pitch = 52 A1b Pitch = 52 A1 Pitch = 55 A1s Pitch = 58 B1b Pitch = 58 B1 Pitch = 62 C2 Pitch = 65 C2s Pitch = 69 D2b Pitch = 69 D2 Pitch = 73 D2s Pitch = 78 E2b Pitch = 78 E2 Pitch = 82 F2 Pitch = 87 F2s Pitch = 93 G2b Pitch = 93 G2 Pitch = 98 G2s Pitch = 104 A2b Pitch = 104 A2 Pitch = 110 A2s Pitch = 117 B2b Pitch = 117 B2 Pitch = 124 C3 Pitch = 131 C3s Pitch = 139 D3b Pitch = 139 D3 Pitch = 147 D3s Pitch = 156 E3b Pitch = 156 E3 Pitch = 165 F3 Pitch = 175 F3s Pitch = 185 G3b Pitch = 185 G3 Pitch = 196 G3s Pitch = 208 A3b Pitch = 208 A3 Pitch = 220 A3s Pitch = 233 B3b Pitch = 233 B3 Pitch = 247 C4 Pitch = 262 C4s Pitch = 278 D4b Pitch = 278 D4 Pitch = 294 D4s Pitch = 311 E4b Pitch = 311 E4 Pitch = 330 F4 Pitch = 349 F4s Pitch = 370 G4b Pitch = 370 G4 Pitch = 392 G4s Pitch = 415 A4b Pitch = 415 A4 Pitch = 440 A4s Pitch = 466 B4b Pitch = 466 B4 Pitch = 494 C5 Pitch = 523 C5s Pitch = 554 D5b Pitch = 554 D5 Pitch = 587 D5s Pitch = 622 E5b Pitch = 622 E5 Pitch = 659 F5 Pitch = 699 F5s Pitch = 740 G5b Pitch = 740 G5 Pitch = 784 G5s Pitch = 831 A5b Pitch = 831 A5 Pitch = 880 A5s Pitch = 932 B5b Pitch = 932 B5 Pitch = 988 C6 Pitch = 1047 C6s Pitch = 1109 D6b Pitch = 1109 D6 Pitch = 1175 D6s Pitch = 1245 E6b Pitch = 1245 E6 Pitch = 1319 F6 Pitch = 1397 F6s Pitch = 1475 G6b Pitch = 1475 G6 Pitch = 1568 G6s Pitch = 1661 A6b Pitch = 1661 A6 Pitch = 1760 A6s Pitch = 1865 B6b Pitch = 1865 B6 Pitch = 1976 C7 Pitch = 2093 C7s Pitch = 2218 D7b Pitch = 2218 D7 Pitch = 2349 D7s Pitch = 2489 E7b Pitch = 2489 E7 Pitch = 2637 F7 Pitch = 2794 F7s Pitch = 2960 G7b Pitch = 2960 G7 Pitch = 3136 G7s Pitch = 3322 A7b Pitch = 3322 A7 Pitch = 3520 A7s Pitch = 3729 B7b Pitch = 3729 B7 Pitch = 3951 C8 Pitch = 4186 C8s Pitch = 4435 D8b Pitch = 4435 D8 Pitch = 4699 D8s Pitch = 4978 E8b Pitch = 4978 E8 Pitch = 5274 F8 Pitch = 5588 F8s Pitch = 5920 G8b Pitch = 5920 G8 Pitch = 6272 G8s Pitch = 6645 A8b Pitch = 6645 A8 Pitch = 7040 A8s Pitch = 7459 B8b Pitch = 7459 B8 Pitch = 7902 )
Pitch frequencies, taken from http://peabody.sapp.org/class/st2/lab/notehz/ These span octave 0 through octave 8, with sharps suffixed 's' and flats suffixed 'b'
func (Pitch) IsAccidental ¶
IsAccidental reports true if this pitch is represented with a single sharp or a flat, usually.
type PitchDetector ¶
type PitchDetector struct { pcm.Reader // DetectedPitches and DetectedRawPitches store the calculated pitch values as this reader parses data. The length // of these slices will be equal to this reader's format's channel count. Consumers should not modify these slices. DetectedPitches []Pitch DetectedRawPitches []float64 // contains filtered or unexported fields }
func NewPitchDetector ¶
func NewPitchDetector(r pcm.Reader) *PitchDetector
type Source ¶
type Source struct { pcm.Format Pitch Pitch // Volume, between 0.0 -> 1.0 Volume float64 Seconds float64 }
A Source stores necessary information for generating waveform data
func (Source) MultiWave ¶
MultiWave converts a series of waveform functions into a combined reader, outputting the average of all of the source waveforms at any given index
func (Source) Phase ¶
Phase is shorthand for phase(s.Pitch, i, s.SampleRate). Some sources might have custom phase functions in the future, however.
func (Source) PlayLength ¶
PlayLength returns the time it will take before audio generated from this source will stop.
func (Source) Pulse ¶
Pulse acts like Square when given a pulse of 2, when given any lesser pulse the time up and down will change so that 1/pulse time the wave will be up.
__ __ || || ____||____||____
func (Source) TriangleWave ¶
type Step ¶
type Step int
A Step is an index offset on a pitch to raise or lower it to a relative new pitch