feat(go4k): Algorithm to construct small delay times tables by abusing overlapping of different delay times.

The problem of finding a string that contains all particular substrings is the "shortest superstring problem"; it is NP-hard and analogous to traveling salesman problem. We use simple greedy search instead of trying to find true optimum. But even with these algorithm, units that use exactly the same delay times will always appear only once in the delay times table.
This commit is contained in:
Veikko Sariola
2020-11-09 22:29:10 +02:00
parent c153239710
commit e36aea59a5
3 changed files with 174 additions and 6 deletions

View File

@ -82,11 +82,14 @@ func (synth *C.Synth) Render(buffer []float32, maxtime int) (int, int, error) {
func Synth(patch go4k.Patch) (*C.Synth, error) {
s := new(C.Synth)
sampleno := 0
delaytimeno := 0
totalVoices := 0
commands := make([]byte, 0)
values := make([]byte, 0)
polyphonyBitmask := 0
delayTable, delayIndices := go4k.ConstructDelayTimeTable(patch)
for i, v := range delayTable {
s.DelayTimes[i] = C.ushort(v)
}
for insid, instr := range patch {
if len(instr.Units) > 63 {
return nil, errors.New("An instrument can have a maximum of 63 units")
@ -106,11 +109,7 @@ func Synth(patch go4k.Patch) (*C.Synth, error) {
if unit.Stereo && len(unit.DelayTimes)%2 != 0 {
return nil, errors.New("Stereo delays should have even number of delaytimes")
}
values = append(values, byte(delaytimeno))
for _, v := range unit.DelayTimes {
s.DelayTimes[delaytimeno] = C.ushort(v)
delaytimeno++
}
values = append(values, byte(delayIndices[insid][unitid]))
count := len(unit.DelayTimes)
if unit.Stereo {
count /= 2