feat(sointu): remove 16-bit output toggle from song; make it compile time option

This commit is contained in:
vsariola 2021-01-05 18:08:13 +02:00
parent 30379c981d
commit 588488ce54
98 changed files with 48 additions and 140 deletions

View File

@ -40,7 +40,7 @@ func TestOscillatSine(t *testing.T) {
sointu.Unit{Type: "out", Parameters: map[string]int{"stereo": 1, "gain": 128}},
}}}}
tracks := []sointu.Track{{NumVoices: 1, Sequence: []byte{0}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}}}}
song := sointu.Song{BPM: 100, Tracks: tracks, Patch: patch, Output16Bit: false}
song := sointu.Song{BPM: 100, Tracks: tracks, Patch: patch}
synth, err := bridge.Synth(patch)
if err != nil {
t.Fatalf("Compiling patch failed: %v", err)
@ -132,12 +132,7 @@ func TestAllRegressionTests(t *testing.T) {
log.Fatal(err)
}
}
if song.Output16Bit {
int16Buffer := convertToInt16Buffer(buffer)
compareToRawInt16(t, int16Buffer, testname+".raw")
} else {
compareToRawFloat32(t, buffer, testname+".raw")
}
})
}
}

View File

@ -37,9 +37,10 @@ func main() {
jsonOut := flag.Bool("j", false, "Output the song as .json file instead of compiling.")
yamlOut := flag.Bool("y", false, "Output the song as .yml file instead of compiling.")
tmplDir := flag.String("t", "", "When compiling, use the templates in this directory instead of the standard templates.")
directory := flag.String("o", "", "Directory where to output all files. The directory and its parents are created if needed. By default, everything is placed in the same directory where the original song file is.")
outPath := flag.String("o", "", "Directory or filename where to write compiled code. Extension is ignored. Directory and its parents are created if needed. By default, everything is placed in the same directory where the original song file is.")
extensionsOut := flag.String("e", "", "Output only the compiled files with these comma separated extensions. For example: h,asm")
targetArch := flag.String("arch", runtime.GOARCH, "Target architecture. Defaults to OS architecture. Possible values: 386, amd64")
output16bit := flag.Bool("i", false, "Compiled song should output 16-bit integers, instead of floats.")
targetOs := flag.String("os", runtime.GOOS, "Target OS. Defaults to current OS. Possible values: windows, darwin, linux. Anything else is assumed linuxy.")
flag.Usage = printUsage
flag.Parse()
@ -52,9 +53,9 @@ func main() {
if compile || *library {
var err error
if *tmplDir != "" {
comp, err = compiler.NewFromTemplates(*targetOs, *targetArch, *tmplDir)
comp, err = compiler.NewFromTemplates(*targetOs, *targetArch, *output16bit, *tmplDir)
} else {
comp, err = compiler.New(*targetOs, *targetArch)
comp, err = compiler.New(*targetOs, *targetArch, *output16bit)
}
if err != nil {
fmt.Fprintf(os.Stderr, `error creating compiler: %v`, err)
@ -67,8 +68,19 @@ func main() {
return nil
}
dir, name := filepath.Split(filename)
if *directory != "" {
dir = *directory
if *outPath != "" {
// check if it's an already existing directory and the user just forgot trailing slash
if info, err := os.Stat(*outPath); err == nil && info.IsDir() {
dir = *outPath
} else {
outdir, outname := filepath.Split(*outPath)
if outdir != "" {
dir = outdir
}
if outname != "" {
name = outname
}
}
}
name = strings.TrimSuffix(name, filepath.Ext(name)) + extension
f := filepath.Join(dir, name)

View File

@ -16,10 +16,11 @@ type Compiler struct {
Template *template.Template
OS string
Arch string
Output16Bit bool
}
// New returns a new compiler using the default .asm templates
func New(os string, arch string) (*Compiler, error) {
func New(os string, arch string, output16Bit bool) (*Compiler, error) {
_, myname, _, _ := runtime.Caller(0)
var subdir string
if arch == "386" || arch == "amd64" {
@ -30,17 +31,17 @@ func New(os string, arch string) (*Compiler, error) {
return nil, fmt.Errorf("compiler.New failed, because only amd64, 386 and wasm archs are supported (targeted architecture was %v)", arch)
}
templateDir := filepath.Join(path.Dir(myname), "..", "templates", subdir)
compiler, err := NewFromTemplates(os, arch, templateDir)
compiler, err := NewFromTemplates(os, arch, output16Bit, templateDir)
return compiler, err
}
func NewFromTemplates(os string, arch string, templateDirectory string) (*Compiler, error) {
func NewFromTemplates(os string, arch string, output16Bit bool, templateDirectory string) (*Compiler, error) {
globPtrn := filepath.Join(templateDirectory, "*.*")
tmpl, err := template.New("base").Funcs(sprig.TxtFuncMap()).ParseGlob(globPtrn)
if err != nil {
return nil, fmt.Errorf(`could not create template based on directory "%v": %v`, templateDirectory, err)
}
return &Compiler{Template: tmpl, OS: os, Arch: arch}, nil
return &Compiler{Template: tmpl, OS: os, Arch: arch, Output16Bit: output16Bit}, nil
}
func (com *Compiler) Library() (map[string]string, error) {

View File

@ -213,7 +213,6 @@ var UnitTypes = map[string]([]UnitParameter){
type Song struct {
BPM int
Output16Bit bool
Tracks []Track
Patch Patch
}

View File

@ -1,4 +1,4 @@
{{- if not .Song.Output16Bit }}
{{- if not .Output16Bit }}
{{- if not .Clip }}
mov {{.DI}}, [{{.Stack "OutputBufPtr"}}] ; edi containts ptr
mov {{.SI}}, {{.PTRWORD}} su_synth_obj + su_synthworkspace.left

View File

@ -23,7 +23,7 @@
#define SU_CALLCONV
#endif
{{- if .Song.Output16Bit}}
{{- if .Output16Bit}}
typedef short SUsample;
#define SU_SAMPLE_RANGE 32767.0
{{- else}}

View File

@ -1,4 +1,4 @@
{{- if not .Song.Output16Bit }}
{{- if not .Output16Bit }}
(i64.store (global.get $outputBufPtr) (i64.load (i32.const 4128))) ;; load the sample from left & right channels as one 64bit int and store it in the address pointed by outputBufPtr
(global.set $outputBufPtr (i32.add (global.get $outputBufPtr) (i32.const 8))) ;; advance outputbufptr
{{- else }}

View File

@ -111,8 +111,8 @@
;; TODO: only export start and length with certain compiler options; in demo use, they can be hard coded
;; in the intro
(global $outputStart (export "s") i32 (i32.const 8388608)) ;; TODO: do not hard code, layout memory somehow intelligently
(global $outputLength (export "l") i32 (i32.const {{if .Song.Output16Bit}}{{mul .EncodedSong.TotalRows .Song.SamplesPerRow 4}}{{else}}{{mul .EncodedSong.TotalRows .Song.SamplesPerRow 8}}{{end}}))
(global $output16bit (export "t") i32 (i32.const {{if .Song.Output16Bit}}1{{else}}0{{end}}))
(global $outputLength (export "l") i32 (i32.const {{if .Output16Bit}}{{mul .EncodedSong.TotalRows .Song.SamplesPerRow 4}}{{else}}{{mul .EncodedSong.TotalRows .Song.SamplesPerRow 8}}{{end}}))
(global $output16bit (export "t") i32 (i32.const {{if .Output16Bit}}1{{else}}0{{end}}))
;;------------------------------------------------------------------------------
@ -155,7 +155,7 @@
(start $render) ;; we run render automagically when the module is instantiated
(func $render (param)
{{- if .Song.Output16Bit }} (local $channel i32) {{- end }}
{{- if .Output16Bit }} (local $channel i32) {{- end }}
loop $pattern_loop
(global.set $row (i32.const 0))
loop $row_loop

View File

@ -1,13 +1,18 @@
function(regression_test testname)
if(${ARGC} LESS 6)
if(${ARGC} LESS 4)
set(source ${testname}.yml)
else()
set(source ${ARGV3}.yml)
endif()
set(asmfile ${testname}.asm)
set (headerfile ${CMAKE_CURRENT_BINARY_DIR}/${testname}.h)
add_custom_command(
OUTPUT ${asmfile}
COMMAND ${compilecmd} -arch=${arch} -o ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${source}
COMMAND ${compilecmd} ${ARGV4} -arch=${arch} -o ${CMAKE_CURRENT_BINARY_DIR}/${asmfile} ${CMAKE_CURRENT_SOURCE_DIR}/${source}
DEPENDS ${source} ${x86templates} sointu-compiler
)
@ -19,14 +24,14 @@ function(regression_test testname)
set(watfile ${CMAKE_CURRENT_BINARY_DIR}/${testname}.wat)
set(wasmtarget wasm_${testname})
add_custom_target(${wasmtarget} ALL
COMMAND ${compilecmd} -arch=wasm -o ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${source} && ${WAT2WASM} --enable-bulk-memory -o ${wasmfile} ${watfile}
COMMAND ${compilecmd} -arch=wasm -o ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/${source} && ${WAT2WASM} --enable-bulk-memory -o ${wasmfile} ${watfile}
SOURCES "${source}" "${wasmtemplates}"
DEPENDS sointu-compiler
)
add_test(${wasmtarget} ${NODE} ${CMAKE_CURRENT_SOURCE_DIR}/wasm_test_renderer.es6 ${wasmfile} ${CMAKE_CURRENT_SOURCE_DIR}/expected_output/${testname}.raw)
endif()
else()
set(source ${ARGV3})
set(source ${ARGV5})
add_executable(${testname} ${source} test_renderer.c)
endif()
@ -155,13 +160,13 @@ regression_test(test_delay_drymod "ENVELOPE;FOP_MULP;PANNING;VCO_SINE;SEND")
regression_test(test_delay_flanger "ENVELOPE;FOP_MULP;PANNING;VCO_SINE;SEND")
regression_test(test_envelope_mod "VCO_SINE;ENVELOPE;SEND")
regression_test(test_envelope_16bit ENVELOPE)
regression_test(test_envelope_16bit ENVELOPE "" test_envelope "-i")
regression_test(test_polyphony "ENVELOPE;VCO_SINE")
regression_test(test_chords "ENVELOPE;VCO_SINE")
regression_test(test_speed "ENVELOPE;VCO_SINE")
regression_test(test_render_samples ENVELOPE "" test_render_samples.c)
regression_test(test_render_samples ENVELOPE "" "" "" test_render_samples.c)
target_link_libraries(test_render_samples ${STATICLIB})
target_compile_definitions(test_render_samples PUBLIC TEST_HEADER="test_render_samples.h")

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,16 +0,0 @@
bpm: 100
output16bit: true
tracks:
- numvoices: 1
sequence: [0]
patterns: [[64, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]
patch:
instruments:
- numvoices: 1
units:
- type: envelope
parameters: {attack: 64, decay: 64, gain: 128, release: 80, stereo: 0, sustain: 64}
- type: envelope
parameters: {attack: 95, decay: 64, gain: 128, release: 80, stereo: 0, sustain: 64}
- type: out
parameters: {gain: 128, stereo: 1}

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [1, 0, 2, 0, 3, 0, 4, 0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [1, 0, 2, 0, 3, 0, 4, 0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 2
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0, 0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]

View File

@ -1,5 +1,4 @@
bpm: 100
output16bit: false
tracks:
- numvoices: 1
sequence: [0]