mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-03 09:08:18 -04:00
Delays and samples are not implemented yet and thus the tests are skipped, as these require parsing the delay and sample tables also. Various macronames were changed to be more sensible and consistent i.e. ATTAC was changed to ATTACK. GatesLow and GatesHigh was removed for the time being and the tracker will just have to know they are the SHAPE and COLOR parameters. SU_SPEED was changed to take a parameter so the parser picks it up.
58 lines
1.0 KiB
Go
58 lines
1.0 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
|
|
}
|
|
|
|
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
|
|
}
|