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.
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package go4k_test
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"io/ioutil"
|
|
"path"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/vsariola/sointu/go4k"
|
|
"github.com/vsariola/sointu/go4k/bridge"
|
|
// TODO: test the song using a mocks instead
|
|
)
|
|
|
|
const BPM = 100
|
|
const SAMPLE_RATE = 44100
|
|
const TOTAL_ROWS = 16
|
|
const SAMPLES_PER_ROW = SAMPLE_RATE * 4 * 60 / (BPM * 16)
|
|
|
|
const su_max_samples = SAMPLES_PER_ROW * TOTAL_ROWS
|
|
|
|
// const bufsize = su_max_samples * 2
|
|
|
|
func TestPlayer(t *testing.T) {
|
|
patch := go4k.Patch{go4k.Instrument{1, []go4k.Unit{
|
|
go4k.Unit{"envelope", false, map[string]int{"attack": 32, "decay": 32, "sustain": 64, "release": 64, "gain": 128}},
|
|
go4k.Unit{"oscillator", false, map[string]int{"transpose": 64, "detune": 64, "phase": 0, "color": 96, "shape": 64, "gain": 128, "type": go4k.Sine, "lfo": 0, "unison": 1}},
|
|
go4k.Unit{"mulp", false, map[string]int{}},
|
|
go4k.Unit{"envelope", false, map[string]int{"attack": 32, "decay": 32, "sustain": 64, "release": 64, "gain": 128}},
|
|
go4k.Unit{"oscillator", false, map[string]int{"transpose": 72, "detune": 64, "phase": 64, "color": 64, "shape": 96, "gain": 128, "type": go4k.Sine, "lfo": 0, "unison": 1}},
|
|
go4k.Unit{"mulp", false, map[string]int{}},
|
|
go4k.Unit{"out", true, map[string]int{"gain": 128}},
|
|
}}}
|
|
patterns := [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}}
|
|
tracks := []go4k.Track{go4k.Track{1, []byte{0}}}
|
|
song := go4k.Song{100, patterns, tracks, 0, patch}
|
|
synth, err := bridge.Synth(patch)
|
|
if err != nil {
|
|
t.Fatalf("Compiling patch failed: %v", err)
|
|
}
|
|
buffer, err := go4k.Play(synth, song)
|
|
if err != nil {
|
|
t.Fatalf("Render failed: %v", err)
|
|
}
|
|
_, filename, _, _ := runtime.Caller(0)
|
|
expectedb, err := ioutil.ReadFile(path.Join(path.Dir(filename), "..", "tests", "expected_output", "test_oscillat_sine.raw"))
|
|
if err != nil {
|
|
t.Fatalf("cannot read expected: %v", err)
|
|
}
|
|
var createdbuf bytes.Buffer
|
|
err = binary.Write(&createdbuf, binary.LittleEndian, buffer)
|
|
if err != nil {
|
|
t.Fatalf("error converting buffer: %v", err)
|
|
}
|
|
createdb := createdbuf.Bytes()
|
|
if len(createdb) != len(expectedb) {
|
|
t.Fatalf("buffer length mismatch, got %v, expected %v", len(createdb), len(expectedb))
|
|
}
|
|
for i, v := range createdb {
|
|
if expectedb[i] != v {
|
|
t.Fatalf("byte mismatch @ %v, got %v, expected %v", i, v, expectedb[i])
|
|
}
|
|
}
|
|
}
|