diff --git a/src/opcodes/effects.asm b/src/opcodes/effects.asm index 6bb017e..0c27b72 100644 --- a/src/opcodes/effects.asm +++ b/src/opcodes/effects.asm @@ -78,6 +78,27 @@ su_op_hold_holding: %endif ; HOLD_ID > -1 +;------------------------------------------------------------------------------- +; CRUSH Tick +;------------------------------------------------------------------------------- +%if CRUSH_ID > -1 + +SECT_TEXT(sucrush) + +EXPORT MANGLE_FUNC(su_op_crush,0) +%ifdef INCLUDE_STEREO_CRUSH + jnc su_op_crush_mono + call su_stereo_filterhelper + %define INCLUDE_STEREO_FILTERHELPER +su_op_crush_mono: +%endif + fdiv dword [edx+su_crush_ports.resolution] + frndint + fmul dword [edx+su_crush_ports.resolution] + ret + +%endif ; CRUSH_ID > -1 + ;------------------------------------------------------------------------------- ; GAIN Tick ;------------------------------------------------------------------------------- diff --git a/src/opcodes/effects.inc b/src/opcodes/effects.inc index 2bd70ba..784f51e 100644 --- a/src/opcodes/effects.inc +++ b/src/opcodes/effects.inc @@ -156,6 +156,36 @@ struc su_hold_wrk .holdval resd 1 endstruc +;------------------------------------------------------------------------------- +; CRUSH effect related defines +;------------------------------------------------------------------------------- +%assign CRUSH_ID -1 + +%macro USE_CRUSH 0 + %if CRUSH_ID == -1 + %assign CRUSH_ID CUR_ID + %assign CUR_ID CUR_ID + 2 + %xdefine OPCODES OPCODES MANGLE_FUNC(su_op_crush,0), + %xdefine NUMPARAMS NUMPARAMS 1, + %endif +%endmacro + +%macro SU_CRUSH 2 + db %2 + USE_CRUSH + %xdefine CMDS CMDS CRUSH_ID + %1, + %if %1 == STEREO + %define INCLUDE_STEREO_CRUSH + %endif +%endmacro + +%define RESOLUTION(val) val + +struc su_crush_ports + .resolution resd 1 + .params +endstruc + ;------------------------------------------------------------------------------- ; GAIN effect related defines ;------------------------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 033cf0e..c68bc81 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -97,6 +97,9 @@ regression_test(test_hold_stereo HOLD) regression_test(test_clip "VCO_SINE;ENVELOPE;FOP_MULP;INVGAIN" CLIP) regression_test(test_clip_stereo CLIP) +regression_test(test_crush "VCO_SINE;ENVELOPE;FOP_MULP;INVGAIN" CRUSH) +regression_test(test_crush_stereo CRUSH) + regression_test(test_filter_band "VCO_SINE;ENVELOPE;FOP_MULP") regression_test(test_filter_low "VCO_SINE;ENVELOPE;FOP_MULP") regression_test(test_filter_high "VCO_SINE;ENVELOPE;FOP_MULP") diff --git a/tests/expected_output/test_crush.raw b/tests/expected_output/test_crush.raw new file mode 100644 index 0000000..0e08f81 Binary files /dev/null and b/tests/expected_output/test_crush.raw differ diff --git a/tests/expected_output/test_crush_stereo.raw b/tests/expected_output/test_crush_stereo.raw new file mode 100644 index 0000000..0d93cbb Binary files /dev/null and b/tests/expected_output/test_crush_stereo.raw differ diff --git a/tests/test_crush.asm b/tests/test_crush.asm new file mode 100644 index 0000000..467bc4b --- /dev/null +++ b/tests/test_crush.asm @@ -0,0 +1,28 @@ +%define BPM 100 +%define USE_SECTIONS + +%include "../src/sointu.inc" + +SU_BEGIN_PATTERNS + PATTERN 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0, +SU_END_PATTERNS + +SU_BEGIN_TRACKS + TRACK VOICES(1),0 +SU_END_TRACKS + +SU_BEGIN_PATCH + SU_BEGIN_INSTRUMENT VOICES(1) ; Instrument0 + SU_ENVELOPE MONO, ATTAC(32),DECAY(32),SUSTAIN(128),RELEASE(64),GAIN(128) + SU_OSCILLAT MONO, TRANSPOSE(64),DETUNE(64),PHASE(0),COLOR(96),SHAPE(64),GAIN(128), FLAGS(SINE) + SU_MULP MONO + SU_CRUSH MONO, RESOLUTION(3) + SU_ENVELOPE MONO, ATTAC(32),DECAY(32),SUSTAIN(128),RELEASE(64),GAIN(128) + SU_OSCILLAT MONO, TRANSPOSE(72),DETUNE(64),PHASE(64),COLOR(64),SHAPE(96),GAIN(128), FLAGS(SINE) + SU_MULP MONO + SU_CRUSH MONO, RESOLUTION(64) + SU_OUT STEREO, GAIN(128) + SU_END_INSTRUMENT +SU_END_PATCH + +%include "../src/sointu.asm" diff --git a/tests/test_crush_stereo.asm b/tests/test_crush_stereo.asm new file mode 100644 index 0000000..a2ee630 --- /dev/null +++ b/tests/test_crush_stereo.asm @@ -0,0 +1,27 @@ +%define BPM 100 +%define USE_SECTIONS + +%include "../src/sointu.inc" + +SU_BEGIN_PATTERNS + PATTERN 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0, +SU_END_PATTERNS + +SU_BEGIN_TRACKS + TRACK VOICES(1),0 +SU_END_TRACKS + +SU_BEGIN_PATCH + SU_BEGIN_INSTRUMENT VOICES(1) ; Instrument0 + SU_ENVELOPE MONO, ATTAC(32),DECAY(32),SUSTAIN(128),RELEASE(64),GAIN(128) + SU_OSCILLAT MONO, TRANSPOSE(64),DETUNE(64),PHASE(0),COLOR(96),SHAPE(64),GAIN(128), FLAGS(SINE) + SU_MULP MONO + SU_ENVELOPE MONO, ATTAC(32),DECAY(32),SUSTAIN(128),RELEASE(64),GAIN(128) + SU_OSCILLAT MONO, TRANSPOSE(72),DETUNE(64),PHASE(64),COLOR(64),SHAPE(96),GAIN(128), FLAGS(SINE) + SU_MULP MONO + SU_CRUSH STEREO, RESOLUTION(32) + SU_OUT STEREO, GAIN(128) + SU_END_INSTRUMENT +SU_END_PATCH + +%include "../src/sointu.asm"