From cf86a951f51dca3af223cf296c00f68df62c1d21 Mon Sep 17 00:00:00 2001 From: Veikko Sariola Date: Tue, 26 May 2020 16:30:57 +0300 Subject: [PATCH] Move all constants into the end of sointu.asm, littering them around started getting messy. --- src/opcodes/effects.asm | 19 ++------------- src/opcodes/flowcontrol.asm | 15 +----------- src/opcodes/sources.asm | 28 ++++------------------ src/player.asm | 13 +---------- src/sointu.asm | 46 ++++++++++++++++++++++++++----------- src/sointu.inc | 1 - src/win32/gmdls_win32.asm | 3 --- src/win64/gmdls_win64.asm | 3 --- 8 files changed, 41 insertions(+), 87 deletions(-) diff --git a/src/opcodes/effects.asm b/src/opcodes/effects.asm index 4df9f60..0142b73 100644 --- a/src/opcodes/effects.asm +++ b/src/opcodes/effects.asm @@ -376,6 +376,7 @@ su_op_delay_loop: fld dword [WRK+su_unit.ports+su_delay_ports.delaymod] do fmul dword [,c_32767,] ; scale it up, as the modulations would be too small otherwise faddp st1, st0 + %define USE_C_32767 %endif fistp dword [_SP-4] ; dr*y p*p*x, dword [_SP-4] = integer amount of delay (samples) mov edi, esi ; edi = esi = current time @@ -413,23 +414,7 @@ su_op_delay_loop: fst dword [_CX+su_delayline_wrk.dcout] ; o'=s+c*o-i ret -;------------------------------------------------------------------------------- -; Delay data -;------------------------------------------------------------------------------- -SECT_DATA(suconst) - -%ifndef C_DC_CONST - c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) - %define C_DC_CONST -%endif - -%ifdef INCLUDE_DELAY_MODULATION - %ifndef C_32767 - c_32767 dd 32767.0 - %define C_32767 - %endif -%endif - +%define USE_C_DC_CONST %endif ; DELAY_ID > -1 diff --git a/src/opcodes/flowcontrol.asm b/src/opcodes/flowcontrol.asm index 227b414..d793206 100644 --- a/src/opcodes/flowcontrol.asm +++ b/src/opcodes/flowcontrol.asm @@ -66,19 +66,6 @@ EXPORT MANGLE_FUNC(su_op_speed,0) fstp dword [WRK+su_speed_wrk.remainder] ; save the remainder for future ret -SECT_DATA(suconst) - c_bpmscale dd 2.666666666666 ; 64/24, 24 values will be double speed, so you can go from ~ 1/2.5 speed to 2.5x speed - -%endif - -;------------------------------------------------------------------------------- -; Constants -;------------------------------------------------------------------------------- -%ifdef SU_USE_DLL_DC_FILTER -%ifndef C_DC_CONST -SECT_DATA(suconst) -c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) -%define C_DC_CONST -%endif +%define USE_C_BPMSCALE %endif diff --git a/src/opcodes/sources.asm b/src/opcodes/sources.asm index 859434b..cbc12af 100644 --- a/src/opcodes/sources.asm +++ b/src/opcodes/sources.asm @@ -212,14 +212,6 @@ su_op_oscillat_gain: ret %define SU_INCLUDE_WAVESHAPER -SECT_DATA(suconst) - -%ifndef C_FREQ_NORMALIZE - c_freq_normalize dd 0.000092696138 ; // 220.0/(2^(69/12)) / 44100.0 - %define C_FREQ_NORMALIZE -%endif - c_lfo_normalize dd 0.000038 - %endif ; PULSE @@ -306,17 +298,8 @@ go4kVCO_gate_bit: ; stack: 0/1, let's call it x ret ; g'=cg+(1-c)x ; This is a low-pass to smooth the gate transitions -SECT_DATA(suconst) - -%ifndef C_16 - c_16 dd 16.0 - %define C_16 -%endif - -%ifndef C_DC_CONST - c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) - %define C_DC_CONST -%endif +%define USE_C_16 +%define USE_C_DC_CONST %endif @@ -348,11 +331,8 @@ su_oscillat_sample_not_looping: pop_registers _AX,_DX,_CX,_BX ret -SECT_DATA(suconst) - %ifndef C_32767 - c_32767 dd 32767.0 - %define C_32767 - %endif +%define USE_C_32767 +%define USE_C_SAMPLEFREQ_SCALING %endif diff --git a/src/player.asm b/src/player.asm index 48c837b..f279b27 100644 --- a/src/player.asm +++ b/src/player.asm @@ -29,18 +29,6 @@ su_synth_obj resb su_synth.size resb NUM_DELAY_LINES*su_delayline_wrk.size %endif -;------------------------------------------------------------------------------- -; Constants -;------------------------------------------------------------------------------- -SECT_DATA(suconst) - -%ifdef SU_USE_16BIT_OUTPUT - %ifndef C_32767 - c_32767 dd 32767.0 - %define C_32767 - %endif -%endif - ;------------------------------------------------------------------------------- ; output_sound macro: used by the render function to write sound to buffer ;------------------------------------------------------------------------------- @@ -91,6 +79,7 @@ SECT_DATA(suconst) add _SI,2 loop %%loop mov [_SP+su_stack.bufferptr - su_stack.output_sound], _SI ; save esi back to stack + %define USE_C_32767 %endif %endmacro diff --git a/src/sointu.asm b/src/sointu.asm index 6f5464f..dc64508 100644 --- a/src/sointu.asm +++ b/src/sointu.asm @@ -155,19 +155,6 @@ SECT_DATA(suparcnt) su_opcode_numparams db NUMPARAMS -;------------------------------------------------------------------------------- -; Constants used by the common functions -;------------------------------------------------------------------------------- -SECT_DATA(suconst) - -c_i128 dd 0.0078125 -c_RandDiv dd 65536*32768 -c_0_5 dd 0.5 -c_24 dd 24 -c_i12 dd 0x3DAAAAAA -EXPORT MANGLE_DATA(LFO_NORMALIZE) - dd DEF_LFO_NORMALIZE - ;------------------------------------------------------------------------------- ; su_run_vm function: runs the entire virtual machine once, creating 1 sample ;------------------------------------------------------------------------------- @@ -274,3 +261,36 @@ EXPORT MANGLE_FUNC(su_power,0) %ifidn __OUTPUT_FORMAT__,win32 %include "win32/gmdls_win32.asm" %endif + +;------------------------------------------------------------------------------- +; Constants +;------------------------------------------------------------------------------- +SECT_DATA(suconst) + +c_24 dd 24 +c_i128 dd 0.0078125 +c_RandDiv dd 65536*32768 +c_0_5 dd 0.5 +c_i12 dd 0x3DAAAAAA +c_lfo_normalize dd 0.000038 +c_freq_normalize dd 0.000092696138 ; // 220.0/(2^(69/12)) / 44100.0 + +%ifdef USE_C_DC_CONST + c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) +%endif + +%ifdef USE_C_32767 + c_32767 dd 32767.0 +%endif + +%ifdef USE_C_BPMSCALE + c_bpmscale dd 2.666666666666 ; 64/24, 24 values will be double speed, so you can go from ~ 1/2.5 speed to 2.5x speed +%endif + +%ifdef USE_C_16 + c_16 dd 16.0 +%endif + +%ifdef USE_C_SAMPLEFREQ_SCALING + c_samplefreq_scaling dd 84.28074964676522 ; o = 0.000092696138, n = 72, f = 44100*o*2**(n/12), scaling = 22050/f <- so note 72 plays at the "normal rate" +%endif diff --git a/src/sointu.inc b/src/sointu.inc index 3f76d28..65d2f07 100644 --- a/src/sointu.inc +++ b/src/sointu.inc @@ -104,7 +104,6 @@ %define TOTAL_ROWS (MAX_PATTERNS*PATTERN_SIZE) %define SAMPLES_PER_ROW (SAMPLE_RATE*4*60/(BPM*16)) -%define DEF_LFO_NORMALIZE 0.000038 %define MAX_SAMPLES (SAMPLES_PER_ROW*TOTAL_ROWS) %macro SU_BEGIN_PATCH 0 diff --git a/src/win32/gmdls_win32.asm b/src/win32/gmdls_win32.asm index 50b7c99..b43850f 100644 --- a/src/win32/gmdls_win32.asm +++ b/src/win32/gmdls_win32.asm @@ -33,9 +33,6 @@ su_gmdls_path1: su_gmdls_path2: db 'drivers/etc/gm.dls',0 -SECT_DATA(suconst) - c_samplefreq_scaling dd 84.28074964676522 ; o = 0.000092696138, n = 72, f = 44100*o*2**(n/12), scaling = 22050/f <- so note 72 plays at the "normal rate" - SECT_BSS(susamtbl) EXPORT MANGLE_DATA(su_sample_table) resb SAMPLE_TABLE_SIZE ; size of gmdls. diff --git a/src/win64/gmdls_win64.asm b/src/win64/gmdls_win64.asm index 724287d..43fd208 100644 --- a/src/win64/gmdls_win64.asm +++ b/src/win64/gmdls_win64.asm @@ -35,9 +35,6 @@ su_gmdls_path1: su_gmdls_path2: db 'drivers/etc/gm.dls',0 -SECT_DATA(suconst) - c_samplefreq_scaling dd 84.28074964676522 ; o = 0.000092696138, n = 72, f = 44100*o*2**(n/12), scaling = 22050/f <- so note 72 plays at the "normal rate" - SECT_BSS(susamtbl) EXPORT MANGLE_DATA(su_sample_table) resb SAMPLE_TABLE_SIZE ; size of gmdls.