diff --git a/src/opcodes/effects.asm b/src/opcodes/effects.asm index 0142b73..6337ed6 100644 --- a/src/opcodes/effects.asm +++ b/src/opcodes/effects.asm @@ -431,13 +431,16 @@ su_op_delay_loop: SECT_TEXT(sucompr) EXPORT MANGLE_FUNC(su_op_compressor,0) + fdiv dword [INP+su_compres_ports.invgain]; l/g, we'll call this pre inverse gained signal x from now on fld st0 ; x x fmul st0, st0 ; x^2 x %ifdef INCLUDE_STEREO_COMPRES jnc su_op_compressor_mono - fld st2 ; r l^2 l r - fmul st0, st0 ; r^2 l^2 l r - faddp st1, st0 ; r^2+l^2 l r + fld st2 ; r x^2 l/g r + fdiv dword [INP+su_compres_ports.invgain]; r/g, we'll call this pre inverse gained signal y from now on + fst st3 ; y x^2 l/g r/g + fmul st0, st0 ; y^2 x^2 l/g r/g + faddp st1, st0 ; y^2+x^2 l/g r/g call su_op_compressor_mono ; So, for stereo, we square both left & right and add them up fld st0 ; and return the computed gain two times, ready for MULP STEREO ret diff --git a/src/opcodes/effects.inc b/src/opcodes/effects.inc index ba1d898..df799da 100644 --- a/src/opcodes/effects.inc +++ b/src/opcodes/effects.inc @@ -347,15 +347,16 @@ endstruc %assign COMPRES_ID CUR_ID %assign CUR_ID CUR_ID + 2 %xdefine OPCODES OPCODES MANGLE_FUNC(su_op_compressor,0), - %xdefine NUMPARAMS NUMPARAMS 4, + %xdefine NUMPARAMS NUMPARAMS 5, %endif %endmacro -%macro SU_COMPRES 5 +%macro SU_COMPRES 6 db %2 db %3 db %4 db %5 + db %6 USE_COMPRES %xdefine CMDS CMDS COMPRES_ID + %1, %if %1 == STEREO @@ -365,12 +366,14 @@ endstruc %define ATTAC(val) val %define RELEASE(val) val +%define INVGAIN(val) val %define THRESHOLD(val) val %define RATIO(val) val struc su_compres_ports .attack resd 1 .release resd 1 + .invgain resd 1 .threshold resd 1 .ratio resd 1 endstruc diff --git a/tests/expected_output/test_compressor.raw b/tests/expected_output/test_compressor.raw index a9fe6ce..cdab4d0 100644 Binary files a/tests/expected_output/test_compressor.raw and b/tests/expected_output/test_compressor.raw differ diff --git a/tests/expected_output/test_compressor_stereo.raw b/tests/expected_output/test_compressor_stereo.raw index 797a6f3..847462a 100644 Binary files a/tests/expected_output/test_compressor_stereo.raw and b/tests/expected_output/test_compressor_stereo.raw differ diff --git a/tests/test_compressor.asm b/tests/test_compressor.asm index 6e5895f..7df4cbc 100644 --- a/tests/test_compressor.asm +++ b/tests/test_compressor.asm @@ -33,7 +33,7 @@ BEGIN_PATCH END_INSTRUMENT BEGIN_INSTRUMENT VOICES(1) ; Global compressor effect SU_RECEIVE STEREO - SU_COMPRES MONO,ATTAC(32),RELEASE(80),THRESHOLD(32),RATIO(64) + SU_COMPRES MONO,ATTAC(32),RELEASE(64),INVGAIN(32),THRESHOLD(64),RATIO(96) SU_MULP MONO SU_OUT STEREO, GAIN(128) END_INSTRUMENT diff --git a/tests/test_compressor_stereo.asm b/tests/test_compressor_stereo.asm index 472bb6c..2d6a390 100644 --- a/tests/test_compressor_stereo.asm +++ b/tests/test_compressor_stereo.asm @@ -33,7 +33,7 @@ BEGIN_PATCH END_INSTRUMENT BEGIN_INSTRUMENT VOICES(1) ; Global compressor effect SU_RECEIVE STEREO - SU_COMPRES STEREO,ATTAC(32),RELEASE(80),THRESHOLD(32),RATIO(64) + SU_COMPRES STEREO,ATTAC(32),RELEASE(64),INVGAIN(32),THRESHOLD(64),RATIO(96) SU_MULP STEREO SU_OUT STEREO, GAIN(128) END_INSTRUMENT