optimize(templates): allow distort to flow into su_waveshaper (again)

This commit is contained in:
vsariola
2021-03-23 15:07:24 +02:00
parent 8e55132ddd
commit dfc864d131
2 changed files with 38 additions and 33 deletions

View File

@ -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

View File

@ -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