Bass 2 per-track audio filter | Intel x86 disassembly

Each line pairs a preferred virtual address (image base 0x10000000) with
the actual bytes in the named DLL. Semicolon comments are annotations.

This diff follows the executed filter path in each DLL. The original bytes
at file offset 0x650 / RVA 0x1250 begin with 55 8B EC 83 E4 F8. The patch
overwrites the first five bytes with E9 2B 0B 00 00, a jump to RVA 0x1D80.
The F8 at RVA 0x1255 is the last byte of the old AND instruction. The old
body from that byte onward is still physically present and the jump skips it.
Both call sites are shown at the bottom. ECX holds the track pointer and the
callee removes the two stack arguments (sample buffer and count).

The replacement occupies 596 bytes from RVA 0x1D80 through 0x1FD3, including
its constant pool. The PE also contains header and machine name changes.

--- Bass 2/filter.asm
+++ Bass 2 TPT/filter.asm
@@ -1,81 +1,225 @@
 ; Filter entry and reachable implementation
-10001250  55                       push   ebp
-10001251  8b ec                    mov    ebp,esp
-10001253  83 e4 f8                 and    esp,0xfffffff8
-10001256  83 ec 24                 sub    esp,0x24
-10001259  8b 51 1c                 mov    edx,DWORD PTR [ecx+0x1c]
-1000125C  8b 41 18                 mov    eax,DWORD PTR [ecx+0x18]
-1000125F  dd 41 20                 fld    QWORD PTR [ecx+0x20]
-10001262  dd 41 28                 fld    QWORD PTR [ecx+0x28]
-10001265  dd 41 08                 fld    QWORD PTR [ecx+0x8]
-10001268  89 54 24 08              mov    DWORD PTR [esp+0x8],edx
-1000126C  8b 51 14                 mov    edx,DWORD PTR [ecx+0x14]
-1000126F  89 44 24 04              mov    DWORD PTR [esp+0x4],eax
-10001273  8b 41 10                 mov    eax,DWORD PTR [ecx+0x10]
-10001276  89 54 24 20              mov    DWORD PTR [esp+0x20],edx
-1000127A  8b 51 04                 mov    edx,DWORD PTR [ecx+0x4]
-1000127D  89 44 24 1c              mov    DWORD PTR [esp+0x1c],eax
-10001281  8b 01                    mov    eax,DWORD PTR [ecx]
-10001283  56                       push   esi
-10001284  8b 75 0c                 mov    esi,DWORD PTR [ebp+0xc]
-10001287  89 54 24 14              mov    DWORD PTR [esp+0x14],edx
-1000128B  8b 55 08                 mov    edx,DWORD PTR [ebp+0x8]
-1000128E  89 44 24 10              mov    DWORD PTR [esp+0x10],eax
-          ; Sample loop. Advance the low-pass state using the previous band state.
-10001292  d9 c0                    fld    st(0)
-10001294  d8 ca                    fmul   st,st(2)
-10001296  d9 02                    fld    DWORD PTR [edx]
-10001298  dd 44 24 20              fld    QWORD PTR [esp+0x20]
-1000129C  d9 ca                    fxch   st(2)
-1000129E  de c5                    faddp  st(5),st
-100012A0  d9 c2                    fld    st(2)
-100012A2  d9 ca                    fxch   st(2)
-100012A4  d8 cc                    fmul   st,st(4)
-100012A6  d9 ca                    fxch   st(2)
-100012A8  dc 4c 24 08              fmul   QWORD PTR [esp+0x8]
-          ; Compute the next cutoff from the envelope ratio.
-100012AC  d9 c9                    fxch   st(1)
-100012AE  d8 e5                    fsub   st,st(5)
-100012B0  d9 c9                    fxch   st(1)
-100012B2  d9 cb                    fxch   st(3)
-100012B4  d9 ca                    fxch   st(2)
-100012B6  d9 c9                    fxch   st(1)
-100012B8  d9 c9                    fxch   st(1)
-          ; Subtract damping * band from input - low to get high.
-100012BA  de e9                    fsubp  st(1),st
-100012BC  d9 c2                    fld    st(2)
-100012BE  dc 5c 24 10              fcomp  QWORD PTR [esp+0x10]
-          ; Round the high-pass intermediate to double before updating band.
-100012C2  dd 5c 24 18              fstp   QWORD PTR [esp+0x18]
-100012C6  dc 4c 24 18              fmul   QWORD PTR [esp+0x18]
-100012CA  df e0                    fnstsw ax
-100012CC  f6 c4 01                 test   ah,0x1
-100012CF  de c2                    faddp  st(2),st
-100012D1  74 16                    je     0x100012e9
-          ; Cutoff fell below its base. Hold it there for the rest of this block.
-100012D3  dd d8                    fstp   st(0)
-100012D5  dd 44 24 10              fld    QWORD PTR [esp+0x10]
-100012D9  c7 44 24 08 00 00 00 00  mov    DWORD PTR [esp+0x8],0x0
-100012E1  c7 44 24 0c 00 00 f0 3f  mov    DWORD PTR [esp+0xc],0x3ff00000
-100012E9  d9 c2                    fld    st(2)
+10001250  e9 2b 0b 00 00           jmp    0x10001d80
+
+10001D80  55                       push   ebp
+10001D81  e8 12 02 00 00           call   0x10001f98
+10001D86  81 c2 42 02 00 00        add    edx,0x242
+10001D8C  89 e5                    mov    ebp,esp
+10001D8E  56                       push   esi
+10001D8F  53                       push   ebx
+10001D90  83 e4 f8                 and    esp,0xfffffff8
+10001D93  83 ec 38                 sub    esp,0x38
+10001D96  8b 5d 0c                 mov    ebx,DWORD PTR [ebp+0xc]
+10001D99  85 db                    test   ebx,ebx
+10001D9B  0f 8e d7 01 00 00        jle    0x10001f78
+          ; Read track->owner->master->sampleRate.
+10001DA1  8b 81 a0 00 00 00        mov    eax,DWORD PTR [ecx+0xa0]
+10001DA7  8b 40 10                 mov    eax,DWORD PTR [eax+0x10]
+10001DAA  db 40 08                 fild   DWORD PTR [eax+0x8]
+10001DAD  dd 82 e0 ff ff ff        fld    QWORD PTR [edx-0x20]
+10001DB3  d8 c9                    fmul   st,st(1)
+10001DB5  d9 82 d8 ff ff ff        fld    DWORD PTR [edx-0x28]
+10001DBB  db f1                    fcomi  st,st(1)
+10001DBD  db d1                    fcmovnbe st,st(1)
+10001DBF  dd d9                    fstp   st(1)
+10001DC1  dd 5c 24 08              fstp   QWORD PTR [esp+0x8]
+10001DC5  dc ba e8 ff ff ff        fdivr  QWORD PTR [edx-0x18]
+10001DCB  dd 5c 24 18              fstp   QWORD PTR [esp+0x18]
+10001DCF  dd 01                    fld    QWORD PTR [ecx]
+10001DD1  dd 41 18                 fld    QWORD PTR [ecx+0x18]
+10001DD4  dd 5c 24 10              fstp   QWORD PTR [esp+0x10]
+          ; Clamp the legacy damping control and map it to k = 1 / Q.
+10001DD8  dd 41 10                 fld    QWORD PTR [ecx+0x10]
+10001DDB  d9 ee                    fldz
+10001DDD  df f1                    fcomip st,st(1)
+10001DDF  0f 87 a3 01 00 00        ja     0x10001f88
+10001DE5  d9 e8                    fld1
+10001DE7  d9 c9                    fxch   st(1)
+10001DE9  db f1                    fcomi  st,st(1)
+10001DEB  db d1                    fcmovnbe st,st(1)
+10001DED  dd d9                    fstp   st(1)
+10001DEF  dd 82 f0 ff ff ff        fld    QWORD PTR [edx-0x10]
+10001DF5  d8 c9                    fmul   st,st(1)
+10001DF7  de c9                    fmulp  st(1),st
+10001DF9  d8 82 d4 ff ff ff        fadd   DWORD PTR [edx-0x2c]
+10001DFF  dd 1c 24                 fstp   QWORD PTR [esp]
+10001E02  dd 41 08                 fld    QWORD PTR [ecx+0x8]
+10001E05  dd 41 20                 fld    QWORD PTR [ecx+0x20]
+10001E08  dd 41 28                 fld    QWORD PTR [ecx+0x28]
+10001E0B  d9 ee                    fldz
+10001E0D  8b 45 08                 mov    eax,DWORD PTR [ebp+0x8]
+10001E10  d9 54 24 30              fst    DWORD PTR [esp+0x30]
+10001E14  dd 54 24 20              fst    QWORD PTR [esp+0x20]
+10001E18  8d 1c 98                 lea    ebx,[eax+ebx*4]
+10001E1B  d9 44 24 30              fld    DWORD PTR [esp+0x30]
+10001E1F  dd 5c 24 28              fstp   QWORD PTR [esp+0x28]
+10001E23  d9 e8                    fld1
+10001E25  d9 e0                    fchs
+10001E27  dd 5c 24 30              fstp   QWORD PTR [esp+0x30]
+10001E2B  d9 cc                    fxch   st(4)
+10001E2D  eb 23                    jmp    0x10001e52
+10001E2F  90                       nop
+10001E30  dc 4c 24 10              fmul   QWORD PTR [esp+0x10]
+10001E34  d9 cb                    fxch   st(3)
+10001E36  db f3                    fcomi  st,st(3)
+10001E38  d9 cb                    fxch   st(3)
+10001E3A  db d3                    fcmovnbe st,st(3)
+10001E3C  83 c0 04                 add    eax,0x4
+10001E3F  39 c3                    cmp    ebx,eax
+10001E41  0f 84 e9 00 00 00        je     0x10001f30
+10001E47  d9 cb                    fxch   st(3)
+10001E49  eb 07                    jmp    0x10001e52
+10001E4B  2e 8d 74 26 00           lea    esi,cs:[esi+eiz*1+0x0]
+10001E50  d9 cb                    fxch   st(3)
+          ; Clamp the instantaneous cutoff and compare it with the cached value.
+10001E52  db f3                    fcomi  st,st(3)
+10001E54  d9 c3                    fld    st(3)
+10001E56  db d1                    fcmovnbe st,st(1)
+10001E58  d9 e8                    fld1
+10001E5A  d9 c9                    fxch   st(1)
+10001E5C  db f1                    fcomi  st,st(1)
+10001E5E  db d1                    fcmovnbe st,st(1)
+10001E60  dd d9                    fstp   st(1)
+10001E62  dd 44 24 30              fld    QWORD PTR [esp+0x30]
+10001E66  d9 c9                    fxch   st(1)
+10001E68  db e9                    fucomi st,st(1)
+10001E6A  dd d9                    fstp   st(1)
+10001E6C  7a 0e                    jp     0x10001e7c
+          ; Reuse the coefficients if the cutoff is the same.
+10001E6E  74 70                    je     0x10001ee0
+10001E70  dd dd                    fstp   st(5)
+10001E72  d9 c9                    fxch   st(1)
+10001E74  d9 ca                    fxch   st(2)
+10001E76  d9 cb                    fxch   st(3)
+10001E78  d9 cc                    fxch   st(4)
+10001E7A  eb 14                    jmp    0x10001e90
+10001E7C  dd dd                    fstp   st(5)
+10001E7E  d9 c9                    fxch   st(1)
+10001E80  d9 ca                    fxch   st(2)
+10001E82  d9 cb                    fxch   st(3)
+10001E84  d9 cc                    fxch   st(4)
+10001E86  66 90                    xchg   ax,ax
+10001E88  2e 8d b4 26 00 00 00 00  lea    esi,cs:[esi+eiz*1+0x0]
+          ; Map normalized cutoff to Hz on a cubic curve.
+10001E90  d9 82 dc ff ff ff        fld    DWORD PTR [edx-0x24]
+10001E96  dd 44 24 08              fld    QWORD PTR [esp+0x8]
+10001E9A  d8 e1                    fsub   st,st(1)
+10001E9C  d8 ca                    fmul   st,st(2)
+10001E9E  d8 ca                    fmul   st,st(2)
+10001EA0  d8 ca                    fmul   st,st(2)
+10001EA2  de c1                    faddp  st(1),st
+10001EA4  dc 4c 24 18              fmul   QWORD PTR [esp+0x18]
+          ; Compute tan(pi * hz / sampleRate) for the TPT coefficients.
+10001EA8  d9 f2                    fptan
+10001EAA  dd d8                    fstp   st(0)
+10001EAC  dd 04 24                 fld    QWORD PTR [esp]
+10001EAF  d8 c1                    fadd   st,st(1)
+10001EB1  d8 c9                    fmul   st,st(1)
+10001EB3  d9 e8                    fld1
+10001EB5  dc c1                    fadd   st(1),st
+10001EB7  de f1                    fdivrp st(1),st
+10001EB9  dd 54 24 28              fst    QWORD PTR [esp+0x28]
+10001EBD  d8 c9                    fmul   st,st(1)
+10001EBF  dc c9                    fmul   st(1),st
+10001EC1  d9 c9                    fxch   st(1)
+10001EC3  dd 5c 24 20              fstp   QWORD PTR [esp+0x20]
+10001EC7  d9 c9                    fxch   st(1)
+10001EC9  dd 5c 24 30              fstp   QWORD PTR [esp+0x30]
+10001ECD  d9 cc                    fxch   st(4)
+10001ECF  d9 cb                    fxch   st(3)
+10001ED1  d9 ca                    fxch   st(2)
+10001ED3  d9 c9                    fxch   st(1)
+10001ED5  eb 0b                    jmp    0x10001ee2
+10001ED7  90                       nop
+10001ED8  2e 8d b4 26 00 00 00 00  lea    esi,cs:[esi+eiz*1+0x0]
+10001EE0  dd d8                    fstp   st(0)
+          ; Apply the two-integrator low-pass update to one sample.
+10001EE2  d9 c1                    fld    st(1)
+10001EE4  d8 28                    fsubr  DWORD PTR [eax]
+10001EE6  dd 44 24 28              fld    QWORD PTR [esp+0x28]
+10001EEA  d8 cc                    fmul   st,st(4)
+10001EEC  d9 c6                    fld    st(6)
+10001EEE  d8 ca                    fmul   st,st(2)
+10001EF0  de c1                    faddp  st(1),st
+10001EF2  d9 c6                    fld    st(6)
+10001EF4  d8 cd                    fmul   st,st(5)
+10001EF6  d8 c4                    fadd   st,st(4)
+10001EF8  d9 ca                    fxch   st(2)
+10001EFA  dc 4c 24 20              fmul   QWORD PTR [esp+0x20]
+10001EFE  de c2                    faddp  st(2),st
+10001F00  dc e4                    fsubr  st(4),st
+10001F02  de c4                    faddp  st(4),st
+10001F04  dc e2                    fsubr  st(2),st
+10001F06  dc c2                    fadd   st(2),st
           ; Write the low-pass sample back to the buffer.
-100012EB  d9 1a                    fstp   DWORD PTR [edx]
-100012ED  83 c2 04                 add    edx,0x4
-100012F0  4e                       dec    esi
-100012F1  75 9f                    jne    0x10001292
-          ; Persist cutoff, band, high and low.
-100012F3  dd 59 08                 fstp   QWORD PTR [ecx+0x8]
-100012F6  8b 44 24 18              mov    eax,DWORD PTR [esp+0x18]
-100012FA  8b 54 24 1c              mov    edx,DWORD PTR [esp+0x1c]
-100012FE  dd 59 28                 fstp   QWORD PTR [ecx+0x28]
-10001301  89 41 30                 mov    DWORD PTR [ecx+0x30],eax
-10001304  89 51 34                 mov    DWORD PTR [ecx+0x34],edx
-10001307  dd 59 20                 fstp   QWORD PTR [ecx+0x20]
-1000130A  5e                       pop    esi
-1000130B  8b e5                    mov    esp,ebp
-1000130D  5d                       pop    ebp
-1000130E  c2 08 00                 ret    0x8
+10001F08  d9 18                    fstp   DWORD PTR [eax]
+10001F0A  d9 cb                    fxch   st(3)
+10001F0C  db f3                    fcomi  st,st(3)
+10001F0E  0f 87 1c ff ff ff        ja     0x10001e30
+10001F14  dd d8                    fstp   st(0)
+10001F16  d9 c2                    fld    st(2)
+10001F18  83 c0 04                 add    eax,0x4
+10001F1B  39 c3                    cmp    ebx,eax
+10001F1D  0f 85 2d ff ff ff        jne    0x10001e50
+10001F23  dd dc                    fstp   st(4)
+10001F25  dd da                    fstp   st(2)
+10001F27  d9 ca                    fxch   st(2)
+10001F29  eb 0b                    jmp    0x10001f36
+10001F2B  2e 8d 74 26 00           lea    esi,cs:[esi+eiz*1+0x0]
+10001F30  dd dc                    fstp   st(4)
+10001F32  dd da                    fstp   st(2)
+10001F34  d9 ca                    fxch   st(2)
+          ; Persist cutoff and clear tiny integrator states.
+10001F36  dd 59 08                 fstp   QWORD PTR [ecx+0x8]
+10001F39  d9 c1                    fld    st(1)
+10001F3B  d9 e1                    fabs
+10001F3D  dd 82 f8 ff ff ff        fld    QWORD PTR [edx-0x8]
+10001F43  dd 54 24 30              fst    QWORD PTR [esp+0x30]
+10001F47  df f1                    fcomip st,st(1)
+10001F49  dd d8                    fstp   st(0)
+10001F4B  76 0b                    jbe    0x10001f58
+10001F4D  dd d9                    fstp   st(1)
+10001F4F  d9 ee                    fldz
+10001F51  eb 07                    jmp    0x10001f5a
+10001F53  2e 8d 74 26 00           lea    esi,cs:[esi+eiz*1+0x0]
+10001F58  d9 c9                    fxch   st(1)
+10001F5A  dd 59 20                 fstp   QWORD PTR [ecx+0x20]
+10001F5D  d9 c0                    fld    st(0)
+10001F5F  d9 e1                    fabs
+10001F61  dd 82 f8 ff ff ff        fld    QWORD PTR [edx-0x8]
+10001F67  dd 54 24 30              fst    QWORD PTR [esp+0x30]
+10001F6B  df f1                    fcomip st,st(1)
+10001F6D  dd d8                    fstp   st(0)
+10001F6F  76 04                    jbe    0x10001f75
+10001F71  dd d8                    fstp   st(0)
+10001F73  d9 ee                    fldz
+10001F75  dd 59 28                 fstp   QWORD PTR [ecx+0x28]
+10001F78  8d 65 f8                 lea    esp,[ebp-0x8]
+10001F7B  5b                       pop    ebx
+10001F7C  5e                       pop    esi
+10001F7D  5d                       pop    ebp
+10001F7E  c2 08 00                 ret    0x8
+10001F81  8d b4 26 00 00 00 00     lea    esi,[esi+eiz*1+0x0]
+10001F88  dd d8                    fstp   st(0)
+10001F8A  d9 82 d4 ff ff ff        fld    DWORD PTR [edx-0x2c]
+10001F90  dd 1c 24                 fstp   QWORD PTR [esp]
+10001F93  e9 6a fe ff ff           jmp    0x10001e02
+          ; Position-independent constant access. Return the call site in EDX.
+10001F98  8b 14 24                 mov    edx,DWORD PTR [esp]
+10001F9B  c3                       ret
+
+; Embedded constants and position-independent addressing table
+10001F9C  00 00 00 3e              float    0.125
+10001FA0  00 a0 8c 46              float    18000.0
+10001FA4  00 00 c8 41              float    25.0
+10001FA8  cd cc cc cc cc cc dc 3f  double   0.45
+10001FB0  18 2d 44 54 fb 21 09 40  double   3.141592653589793
+10001FB8  cd 3b 7f 66 9e a0 f4 3f  double   1.2892135623730951
+10001FC0  a7 8e a8 99 c2 57 f3 3a  double   1e-24
+10001FC8  00 00 00 00              dword    0
+10001FCC  00 00 00 00              dword    0
+10001FD0  00 00 00 00              dword    0
 
 ; Calls from Work() for the first active track and subsequent tracks
 10001AAA  e8 a1 f7 ff ff           call   0x10001250
 10001ACD  e8 7e f7 ff ff           call   0x10001250
