Implement a bridge to call Sointu from Go language.

The main interface is render_samples function, which renders several samples in one call,
to limit the number of calls from Go to C. This is compiled into a library, which is then
linked and called from bridge.go.
This commit is contained in:
Veikko Sariola
2020-10-21 20:07:45 +03:00
committed by Veikko Sariola
parent af14cd310b
commit 7aac3917b7
13 changed files with 555 additions and 8 deletions

View File

@ -1,11 +1,11 @@
function(regression_test testname)
if(${ARGC} LESS 4)
set(source ${testname})
set(source ${testname}.asm)
else()
set(source ${ARGV3})
endif()
add_executable(${testname} ${source}.asm test_renderer.c)
add_executable(${testname} ${source} test_renderer.c)
# the tests include the entire ASM but we still want to rebuild when they change
file(GLOB SOINTU ${PROJECT_SOURCE_DIR}/src/*.inc
@ -143,9 +143,12 @@ 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 "" test_envelope)
regression_test(test_envelope_16bit ENVELOPE "" test_envelope.asm)
target_compile_definitions(test_envelope_16bit PUBLIC SU_USE_16BIT_OUTPUT)
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)
target_link_libraries(test_render_samples sointu)

Binary file not shown.

View File

@ -0,0 +1,45 @@
#include <stdint.h>
#include <stdlib.h>
#include "../include/sointu.h"
#if UINTPTR_MAX == 0xffffffff // are we 32-bit?
#if defined(__clang__) || defined(__GNUC__)
#define CALLCONV __attribute__ ((stdcall))
#elif defined(_WIN32)
#define CALLCONV __stdcall // on 32-bit platforms, we just use stdcall, as all know it
#endif
#else // 64-bit
#define CALLCONV // the asm will use honor honor correct x64 ABI on all 64-bit platforms
#endif
#define BPM 100
#define SAMPLE_RATE 44100
#define TOTAL_ROWS 16
#define SAMPLES_PER_ROW SAMPLE_RATE * 4 * 60 / (BPM * 16)
const int su_max_samples = SAMPLES_PER_ROW * TOTAL_ROWS;
void CALLCONV su_render(float* buffer) {
SynthState* synthState;
const unsigned char commands[] = { su_envelope_id, // MONO
su_envelope_id, // MONO
su_out_id + 1, // STEREO
su_advance_id };// MONO
const unsigned char values[] = { 64, 64, 64, 80, 128, // envelope 1
95, 64, 64, 80, 128, // envelope 2
128};
int retval;
synthState = malloc(sizeof(SynthState));
memset(synthState, 0, sizeof(SynthState));
memcpy(synthState->Commands, commands, sizeof(commands));
memcpy(synthState->Values, values, sizeof(values));
synthState->RandSeed = 1;
synthState->RowLen = INT32_MAX;
synthState->NumVoices = 1;
synthState->Synth.Voices[0].Note = 64;
retval = su_render_samples(synthState, su_max_samples / 2, buffer);
synthState->Synth.Voices[0].Release++;
buffer = buffer + su_max_samples;
retval = su_render_samples(synthState, su_max_samples / 2, buffer);
free(synthState);
return;
}