sointu/go4k/go4k.go
Veikko Sariola bcbb5aaf19 feat: Delays and samples are now working through the bridge.
One should call bridge.Init() once during the initialization of the program to load the static sample table. On linux, bridge.Init() does nothing.
2020-11-08 16:03:10 +02:00

59 lines
1.1 KiB
Go

package go4k
import (
"errors"
"math"
)
// Unit is e.g. a filter, oscillator, envelope and its parameters
type Unit struct {
Type string
Stereo bool
Parameters map[string]int
DelayTimes []int
}
const (
Sine = iota
Trisaw = iota
Pulse = iota
Gate = iota
Sample = iota
)
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
type Instrument struct {
NumVoices int
Units []Unit
}
// Patch is simply a list of instruments used in a song
type Patch []Instrument
func (p Patch) TotalVoices() int {
ret := 0
for _, i := range p {
ret += i.NumVoices
}
return ret
}
type Track struct {
NumVoices int
Sequence []byte
}
type Synth interface {
Render(buffer []float32, maxtime int) (int, int, error)
Trigger(voice int, note byte)
Release(voice int)
}
func Render(synth Synth, buffer []float32) error {
s, _, err := synth.Render(buffer, math.MaxInt32)
if s != len(buffer)/2 {
return errors.New("synth.Render should have filled the whole buffer")
}
return err
}