feat(asm&go4k): Preprocess asm code using go text/template

The preprocessing is done sointu-cli and (almost) nothing is done by the NASM preprocessor anymore (some .strucs are still there.
Now, sointu-cli loads the .yml song, defines bunch of macros (go functions / variables) and passes the struct to text/template parses.
This a lot more powerful way to generate .asm code than trying to fight with the nasm preprocessor.

At the moment, tests pass but the repository is a bit of monster, as the library is still compiled using the old approach. Go should
generate the library also from the templates.
This commit is contained in:
Veikko Sariola
2020-12-14 15:44:16 +02:00
parent 92c8b70fd2
commit 2ad61ff6b2
19 changed files with 2934 additions and 212 deletions

View File

@ -1,33 +1,30 @@
function(regression_test testname)
function(regression_test testname)
if(${ARGC} LESS 4)
set(source ${testname}.yml)
set(asmfile ${testname}.asm)
set (headerfile ${CMAKE_CURRENT_BINARY_DIR}/${testname}.h)
add_custom_command(
PRE_BUILD
OUTPUT ${headerfile}
COMMAND go run ${PROJECT_SOURCE_DIR}/go4k/cmd/sointu-cli/main.go -c -w -d ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${source}
DEPENDS ${source}
)
add_custom_command(
PRE_BUILD
if(DEFINED CMAKE_C_SIZEOF_DATA_PTR AND CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
set(arch "-arch=amd64")
elseif(DEFINED CMAKE_CXX_SIZEOF_DATA_PTR AND CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
set(arch "-arch=amd64")
else()
set(arch "-arch=386")
endif()
add_custom_command(
OUTPUT ${asmfile}
COMMAND go run ${PROJECT_SOURCE_DIR}/go4k/cmd/sointu-cli/main.go -a -w -d ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${source}
DEPENDS ${source}
COMMAND ${sointuexe} -a -c -w ${arch} -d ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${source}
DEPENDS ${source} ${sointuexe}
)
add_executable(${testname} test_renderer.c ${headerfile} ${asmfile})
add_executable(${testname} test_renderer.c ${asmfile})
target_compile_definitions(${testname} PUBLIC TEST_HEADER=<${testname}.h>)
else()
set(source ${ARGV3})
add_executable(${testname} ${source} test_renderer.c)
endif()
# the tests include the entire ASM but we still want to rebuild when they change
file(GLOB SOINTU ${PROJECT_SOURCE_DIR}/include/sointu/*.inc
${PROJECT_SOURCE_DIR}/include/sointu/win32/*.inc
${PROJECT_SOURCE_DIR}/include/sointu/win64/*.inc)
set_source_files_properties(${source}.asm PROPERTIES OBJECT_DEPENDS "${SOINTU}")
set_source_files_properties(${FOURKLANG} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()
add_test(${testname} ${testname})
target_link_libraries(${testname} ${HEADERLIB})
@ -39,11 +36,11 @@ function(regression_test testname)
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${rawinput} ${rawoutput}
)
target_include_directories(${testname} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(${testname} PUBLIC TEST_NAME="${testname}")
add_dependencies(${testname} ${testname}_rawcopy)
target_include_directories(${testname} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(${testname} PUBLIC TEST_NAME="${testname}")
if(ARGC GREATER 1)
if (ARGV1)
message("${testname} requires ${ARGV1}")
@ -59,6 +56,27 @@ function(regression_test testname)
endif()
endfunction(regression_test)
if(WIN32)
set(sointuexe ${CMAKE_CURRENT_BINARY_DIR}/sointu-cli.exe)
else()
set(sointuexe ${CMAKE_CURRENT_BINARY_DIR}/sointu-cli)
endif()
# the tests include the entire ASM but we still want to rebuild when they change
file(GLOB templates ${PROJECT_SOURCE_DIR}/templates/*.asm)
file(GLOB go4k "${PROJECT_SOURCE_DIR}/go4k/*.go" "${PROJECT_SOURCE_DIR}/go4k/cmd/sointu-cli/*.go")
message("templates=${templates}")
message("go4k=${go4k}")
# Build sointu-cli only once because go run has everytime quite a bit of delay when
# starting
add_custom_command(
OUTPUT ${sointuexe}
COMMAND go build -o ${sointuexe} ${PROJECT_SOURCE_DIR}/go4k/cmd/sointu-cli/main.go
DEPENDS "${templates}" "${go4k}"
)
regression_test(test_envelope "" ENVELOPE)
regression_test(test_envelope_stereo ENVELOPE)
regression_test(test_loadval "" LOADVAL)

View File

@ -24,6 +24,6 @@ patch:
- type: oscillator
parameters: {color: 128, detune: 64, gain: 128, lfo: 1, phase: 64, shape: 64, stereo: 0, transpose: 50, type: 0, unison: 0}
- type: send
parameters: {amount: 65, port: 5, sendpop: 1, stereo: 0, unit: 3, voice: 0}
parameters: {amount: 65, port: 4, sendpop: 1, stereo: 0, unit: 3, voice: 0}
delaytimes: [1000]
sampleoffsets: []

View File

@ -1,16 +1,17 @@
#include <stdio.h>
#if defined (_WIN32)
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#if defined (_WIN32)
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <stdio.h>
#include TEST_HEADER
SUsample buf[SU_BUFFER_LENGTH];
@ -20,7 +21,6 @@ int main(int argc, char* argv[]) {
FILE* f;
char filename[256];
int n;
int retval;
char test_name[] = TEST_NAME;
char expected_output_folder[] = "expected_output/";
char actual_output_folder[] = "actual_output/";
@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
max_diff = 0.0f;
for (n = 0; n < SU_BUFFER_LENGTH; n++) {
diff = fabs((float)(buf[n] - filebuf[n])/SU_SAMPLE_RANGE);
diff = (float)fabs((float)(buf[n] - filebuf[n])/SU_SAMPLE_RANGE);
if (diff > 1e-3f || isnan(diff)) {
printf("Sointu rendered different wave than expected\n");
goto fail;