refactor(templates,tests): make sync an extern instead of parameter to render

This is to be able to use CreateThread with su_render_song; let's worry about multicore rendering sometime in the future.
This commit is contained in:
vsariola 2021-03-16 23:38:45 +02:00
parent 8ef6de7ffd
commit 38c0cea40f
3 changed files with 20 additions and 24 deletions

View File

@ -7,6 +7,15 @@ su_synth_obj:
resb su_synthworkspace.size
resb {{.Song.Patch.NumDelayLines}}*su_delayline_wrk.size
{{- if or .RowSync (.HasOp "sync")}}
{{- if or (and (eq .OS "windows") (not .Amd64)) (eq .OS "darwin")}}
extern _syncBuf
{{- else}}
extern syncBuf
{{- end}}
{{- end}}
;-------------------------------------------------------------------------------
; su_render_song function: the entry point for the synth
;-------------------------------------------------------------------------------
@ -14,27 +23,26 @@ su_synth_obj:
; the output buffer. Renders the compile time hard-coded song to the buffer.
; Stack: output_ptr
;-------------------------------------------------------------------------------
{{- if or .RowSync (.HasOp "sync")}}
{{.ExportFunc "su_render_song" "OutputBufPtr" "SyncBufPtr"}}
{{- else}}
{{.ExportFunc "su_render_song" "OutputBufPtr"}}
{{- end}}
{{- if .Amd64}}
{{- if eq .OS "windows"}}
{{- .PushRegs "rcx" "OutputBufPtr" "rdi" "NonVolatileRsi" "rsi" "NonVolatile" "rbx" "NonVolatileRbx" "rbp" "NonVolatileRbp" | indent 4}} ; rcx = ptr to buf. rdi,rsi,rbx,rbp nonvolatile
{{- if or .RowSync (.HasOp "sync")}}
{{- .PushRegs "rdx" "SyncBufPtr" | indent 4}}
{{- end}}
{{- else}} ; SystemV amd64 ABI, linux mac or hopefully something similar
{{- .PushRegs "rdi" "OutputBufPtr" "rbx" "NonVolatileRbx" "rbp" "NonVolatileRbp" | indent 4}}
{{- if or .RowSync (.HasOp "sync")}}
{{- .PushRegs "rsi" "SyncBufPtr" | indent 4}}
{{- end}}
{{- end}}
{{- else}}
{{- .PushRegs | indent 4}}
{{- end}}
{{- $prologsize := len .Stacklocs}}
{{- if or .RowSync (.HasOp "sync")}}
{{- if or (and (eq .OS "windows") (not .Amd64)) (eq .OS "darwin")}}
{{- .Prepare "_syncBuf"}}
{{.Push (.Use "_syncBuf") "SyncBufPtr"}}
{{- else}}
{{- .Prepare "syncBuf"}}
{{.Push (.Use "syncBuf") "SyncBufPtr"}}
{{- end}}
{{- end}}
xor eax, eax
{{- if ne .VoiceTrackBitmask 0}}
{{.Push (.VoiceTrackBitmask | printf "%v") "VoiceTrackBitmask"}}
@ -78,9 +86,6 @@ su_render_sampleloop: ; loop through every sample in the row
{{$.Pop $.AX}}
{{- end}}
{{- if .Amd64}}
{{- if or .RowSync (.HasOp "sync")}}
{{.Pop .AX}} ; pop the sync buf ptr away
{{- end}}
{{- if eq .OS "windows"}}
; Windows64 ABI, rdi rsi rbx rbp non-volatile
{{- .PopRegs "rcx" "rdi" "rsi" "rbx" "rbp" | indent 4}}
@ -91,12 +96,8 @@ su_render_sampleloop: ; loop through every sample in the row
ret
{{- else}}
{{- .PopRegs | indent 4}}
{{- if or .RowSync (.HasOp "sync")}}
ret 8
{{- else}}
ret 4
{{- end}}
{{- end}}
;-------------------------------------------------------------------------------
; su_update_voices function: polyphonic & chord implementation

View File

@ -49,11 +49,10 @@ extern "C" {
#endif
{{- if or .RowSync (.HasOp "sync")}}
void SU_CALLCONV su_render_song(SUsample *buffer,float *syncBuffer);
#define SU_SYNC
{{- else}}
void SU_CALLCONV su_render_song(SUsample *buffer);
{{- end}}
void SU_CALLCONV su_render_song(SUsample *buffer);
{{- if gt (.SampleOffsets | len) 0}}
void SU_CALLCONV su_load_gmdls();
#define SU_LOAD_GMDLS

View File

@ -41,11 +41,7 @@ int main(int argc, char* argv[]) {
su_load_gmdls();
#endif
#ifdef SU_SYNC
su_render_song(buf, syncBuf);
#else
su_render_song(buf);
#endif
#if defined (_WIN32)
CreateDirectory(actual_output_folder, NULL);