From dfc864d131a9aa9d71df617eb5e31a200959ac1b Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Tue, 23 Mar 2021 15:07:24 +0200 Subject: [PATCH] optimize(templates): allow distort to flow into su_waveshaper (again) --- templates/amd64-386/effects.asm | 16 ---------- templates/amd64-386/patch.asm | 55 +++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/templates/amd64-386/effects.asm b/templates/amd64-386/effects.asm index bece80a..23007e6 100644 --- a/templates/amd64-386/effects.asm +++ b/templates/amd64-386/effects.asm @@ -1,19 +1,3 @@ -{{- if .HasOp "distort"}} -;------------------------------------------------------------------------------- -; DISTORT opcode: apply distortion on the signal -;------------------------------------------------------------------------------- -; Mono: x -> x*a/(1-a+(2*a-1)*abs(x)) where x is clamped first -; Stereo: l r -> l*a/(1-a+(2*a-1)*abs(l)) r*a/(1-a+(2*a-1)*abs(r)) -;------------------------------------------------------------------------------- -{{.Func "su_op_distort" "Opcode"}} -{{- if .Stereo "distort" -}} - {{.Call "su_effects_stereohelper"}} -{{- end}} - fld dword [{{.Input "distort" "drive"}}] - {{.TailCall "su_waveshaper"}} -{{end}} - - {{- if .HasOp "hold"}} ;------------------------------------------------------------------------------- ; HOLD opcode: sample and hold the signal, reducing sample rate diff --git a/templates/amd64-386/patch.asm b/templates/amd64-386/patch.asm index 9995a38..c34bf08 100644 --- a/templates/amd64-386/patch.asm +++ b/templates/amd64-386/patch.asm @@ -127,6 +127,44 @@ su_power: {{end}} +{{- if .HasOp "distort"}} +;------------------------------------------------------------------------------- +; DISTORT opcode: apply distortion on the signal +;------------------------------------------------------------------------------- +; Mono: x -> x*a/(1-a+(2*a-1)*abs(x)) where x is clamped first +; Stereo: l r -> l*a/(1-a+(2*a-1)*abs(l)) r*a/(1-a+(2*a-1)*abs(r)) +; This is placed here to be able to flow into waveshaper & also include +; wave shaper if needed by some other function; need to investigate the +; best way to do this +;------------------------------------------------------------------------------- +{{.Func "su_op_distort" "Opcode"}} +{{- if .Stereo "distort" -}} + {{.Call "su_effects_stereohelper"}} +{{- end}} + fld dword [{{.Input "distort" "drive"}}] +{{end}} + +{{- if or (.HasCall "su_waveshaper") (.HasOp "distort")}} +{{- if .HasOp "distort"}} +su_waveshaper: +{{- else}} +{{.Func "su_waveshaper"}} +{{- end}} + fld st0 ; a a x + {{.Prepare (.Float 0.5)}} + fsub dword [{{.Use (.Float 0.5)}}] ; a-.5 a x + fadd st0 ; 2*a-1 a x + fld st2 ; x 2*a-1 a x + fabs ; abs(x) 2*a-1 a x + fmulp st1 ; (2*a-1)*abs(x) a x + fld1 ; 1 (2*a-1)*abs(x) a x + faddp st1 ; 1+(2*a-1)*abs(x) a x + fsub st1 ; 1-a+(2*a-1)*abs(x) a x + fdivp st1, st0 ; a/(1-a+(2*a-1)*abs(x)) x + fmulp st1 ; x*a/(1-a+(2*a-1)*abs(x)) + ret +{{end}} + {{- if .HasCall "su_effects_stereohelper" }} ;------------------------------------------------------------------------------- ; su_effects_stereohelper: moves the workspace to next, does the filtering for @@ -145,23 +183,6 @@ su_effects_stereohelper_mono: {{end}} -{{- if .HasCall "su_waveshaper" }} -{{.Func "su_waveshaper"}} - fld st0 ; a a x - {{.Prepare (.Float 0.5)}} - fsub dword [{{.Use (.Float 0.5)}}] ; a-.5 a x - fadd st0 ; 2*a-1 a x - fld st2 ; x 2*a-1 a x - fabs ; abs(x) 2*a-1 a x - fmulp st1 ; (2*a-1)*abs(x) a x - fld1 ; 1 (2*a-1)*abs(x) a x - faddp st1 ; 1+(2*a-1)*abs(x) a x - fsub st1 ; 1-a+(2*a-1)*abs(x) a x - fdivp st1, st0 ; a/(1-a+(2*a-1)*abs(x)) x - fmulp st1 ; x*a/(1-a+(2*a-1)*abs(x)) - ret -{{end}} - {{- if .HasCall "su_clip"}} {{.Func "su_clip"}} fld1 ; 1 x a