home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / tsm.zip / Replay / TSMReplay.asm < prev    next >
Assembly Source File  |  2004-10-06  |  58KB  |  1,798 lines

  1. ; ------------------------------------------------------
  2. ; TSM v1.1 Replay routine
  3. ; Written by Franck 'hitchhikr' Charlet/TRSI
  4. ; ------------------------------------------------------
  5. ; buildblock RELEASE
  6. ;     CAPT [BINDIR]\ml.exe /c /coff /I"[INCLUDEDIR]" "%2"
  7. ; buildblockend
  8. ; buildblock DEBUG
  9. ;     CAPT [BINDIR]\ml.exe /Zd /Zi /c /coff /I"[INCLUDEDIR]" "%2"
  10. ; buildblockend
  11.  
  12. ; --------------- File model
  13.                 .386
  14.                 .model    flat,stdcall
  15.                 option    casemap:none
  16.  
  17. ; --------------- Includes
  18.                 include    windows.inc
  19.                  include kernel32.inc
  20.                  include user32.inc
  21.                 include dsound.inc
  22.                  include DSoundConst.inc
  23.  
  24. ; --------------- Constants
  25. TSM_INS_WF_CUST            equ    5
  26. TSM_DSP_DELAY            equ    4
  27.  
  28. TSM_MAX_NOTES            equ    120    
  29.  
  30. ; --------------- Structures
  31. TSM_INSTRUMENT_DAT        STRUCT
  32. Operator            BYTE    ?
  33. Waveform            BYTE    ?
  34. PhaseShift            WORD    ?
  35. Attack_Volume            BYTE    ?
  36. Attack                WORD    ?
  37. Decay_Volume            BYTE    ?
  38. Decay                WORD    ?
  39. Sustain_Volume            BYTE    ?
  40. Sustain                WORD    ?
  41. Release_Volume            BYTE    ?
  42. Release                WORD    ?
  43. Attack_Volume_Delta        BYTE    ?
  44. Decay_Volume_Delta        BYTE    ?
  45. Sustain_Volume_Delta        BYTE    ?
  46. Release_Volume_Delta        BYTE    ?
  47. TSM_INSTRUMENT_DAT        ENDS
  48.  
  49. TSM_SEQUENCE_DAT        STRUCT
  50. Note                BYTE    16 dup (?)
  51. Instrument            WORD    16 dup (?)
  52. Volume                BYTE    16 dup (?)
  53. Panning                BYTE    16 dup (?)
  54. DspMask                BYTE    16 dup (?)
  55. Dsp                BYTE    16 dup (?)
  56. DspDatas1            BYTE    16 dup (?)
  57. DspDatas2            BYTE    16 dup (?)
  58. DspDatas3            BYTE    16 dup (?)
  59. Fx                BYTE    16 dup (?)
  60. FxDatas                BYTE    16 dup (?)
  61. TSM_SEQUENCE_DAT        ENDS
  62.  
  63. TSM_SONG_DAT            STRUCT
  64. Sequence            WORD    ?
  65. Transpose            BYTE    ?
  66. Volume                BYTE    ?
  67. TSM_SONG_DAT            ENDS
  68.  
  69. TSM_INSTRUMENT_VARS        STRUCT
  70. Volume                REAL4    ?
  71. Ticks                DWORD    ?
  72. RndVal1                REAL4    ?
  73. RndVal2                REAL4    ?
  74. wrpos                REAL4    ?
  75. FPos                REAL4    ?
  76. Frac_Lo_Pos            DWORD    ?
  77. Oscillator            DWORD    ?
  78. TSM_INSTRUMENT_VARS        ENDS
  79.  
  80. TSM_SEQUENCE            STRUCT
  81. Current_Sequence        DWORD    ?
  82. Current_Instrument        DWORD    ?
  83. Current_Instrument_Dat        DWORD    ?
  84. Instrument_NbrComb        DWORD    ?
  85. Freq_Lo_Speed            DWORD    ?
  86. Freq_Hi_Speed            DWORD    ?
  87. Pan                REAL4    ?
  88. Volume                REAL4    ?
  89. Position_Volume            REAL4    ?
  90. Position_Transpose        DWORD    ?
  91. Global_Volume            REAL4    ?
  92. Formant_Param1            DWORD    ?
  93. Disto_Param            REAL4    ?
  94. Disto_Abs_Input            REAL4    ?
  95. Hi_Pass_Param1            REAL4    ?
  96. Hi_Pass_Param2            REAL4    ?
  97. Hi_Pass_In1            REAL4    ?
  98. Hi_Pass_Out1            REAL4    ?
  99. Hi_Pass_In2            REAL4    ?
  100. Hi_Pass_Out2            REAL4    ?
  101. Lo_Pass_Param1            REAL4    ?
  102. Lo_Pass_Param2            REAL4    ?
  103. Lo_Pass_In1            REAL4    ?
  104. Lo_Pass_Out1            REAL4    ?
  105. Lo_Pass_In2            REAL4    ?
  106. Lo_Pass_Out2            REAL4    ?
  107. VCF_Pass_Param1            REAL4    ?
  108. VCF_Pass_Param2            REAL4    ?
  109. VCF_Pass_Out1            REAL4    ?
  110. VCF_Pass_Out2            REAL4    ?
  111. VCF_Pass_Out3            REAL4    ?
  112. VCF_Pass_Out4            REAL4    ?
  113. VCF_Pass_In1            REAL4    ?
  114. VCF_Pass_In2            REAL4    ?
  115. VCF_Pass_In3            REAL4    ?
  116. VCF_Pass_In4            REAL4    ?
  117. Delay_Cursor            DWORD    ?
  118. Delay_Value            DWORD    ?
  119. Delay_Left_FeedBack_Value    REAL4    ?
  120. Delay_Right_FeedBack_Value    REAL4    ?
  121. Delay_Left_Buffer        DWORD    ?
  122. Delay_Right_Buffer        DWORD    ?
  123. Arpeggio            DWORD    ?
  124. Vol_Side            REAL4    ?
  125. Pitch_Bend_Freq            DWORD    ?
  126. Current_Freq            DWORD    ?
  127. Pitch_Bend            DWORD    ?
  128. Vibrato                DWORD    ?
  129. Vibrato_Freq            DWORD    ?
  130. Vibrato_Tick            DWORD    ?
  131. Tone_Portamento_Speed        DWORD    ?
  132. Tone_Portamento_Note        DWORD    ?
  133. Sound_Datas            REAL4    ?
  134. Old_Vol_Side_Down        DWORD    ?
  135. Old_Vol_Side_Up            DWORD    ?
  136. Old_Pitch_Bend_Down        DWORD    ?
  137. Old_Pitch_Bend_Up        DWORD    ?
  138. Old_Vibrato            DWORD    ?
  139. Old_Arpeggio            DWORD    ?
  140. Old_Tone_Portamento_Speed    DWORD    ?
  141. Old_Tone_Portamento_Note    DWORD    ?
  142. Cur_Note            DWORD    ?
  143. Cur_Freq            DWORD    ?
  144. Cur_Instrument_Vars        TSM_INSTRUMENT_VARS 256 dup (<?>)
  145. Formant_Tmp_Mem            REAL8    10 dup (?)
  146. Source_Formant            REAL8    11 dup (?)
  147. Dest_Formant            REAL8    11 dup (?)
  148. TSM_SEQUENCE            ENDS
  149.  
  150. ; --------------- Datas section
  151.                 .data
  152.  
  153. TSM_Mixing_Buffer_Stereo    DWORD    0
  154. TSM_DSound_Context        DWORD    0
  155. TSM_Sound_Buffer_Desc        DSBUFFERDESC <>
  156. TSM_Sound_Buffer        DWORD    0
  157. TSM_Wave_Format            WAVEFORMATEX <>
  158. TSM_Buffer_Pos            DWORD    0
  159. TSM_Old_Buffer_Pos        DWORD    0
  160. TSM_Audio_Ptr1            DWORD    0
  161. TSM_Audio_Bytes1        DWORD    0
  162. TSM_Audio_Ptr2            DWORD    0
  163. TSM_Audio_Bytes2        DWORD    0
  164. TSM_Song_Position        DWORD    0
  165. TSM_Song_Restart        DWORD    0
  166. TSM_Cur_Ticks            DWORD    0
  167. TSM_Fx_Ticks            DWORD    0
  168. TSM_Speed_Tick            DWORD    0
  169. TSM_Speed_Counter        DWORD    0
  170. TSM_Tempo            DWORD    0
  171. TSM_Fx_Tempo            DWORD    0
  172. TSM_Tempo_Ticks            DWORD    0
  173. TSM_Fx_Tempo_Ticks        DWORD    0
  174. TSM_Can_Play            DWORD    0
  175. TSM_BufferSize            DWORD    0
  176. TSM_Instr_Dat_Number        DWORD    0
  177. TSM_Instr_Dat_Vars        DWORD    0
  178. TSM_Sequences_Dats        DWORD    0
  179. TSM_Cur_Play_Pos        DWORD    0
  180. TSM_Final_Signal        REAL4    0.0
  181. TSM_Module_Instruments        DWORD    0
  182. TSM_Module_Positions        DWORD    0
  183. TSM_Module_Sequences        DWORD    0
  184. TSM_Nbr_Instruments        DWORD    0
  185. TSM_Nbr_Positions        DWORD    0
  186. TSM_Length_Track        DWORD    0
  187. TSM_Nbr_Sequences        DWORD    0
  188. TSM_Synth_CallBack        DWORD    0
  189. TSM_Max_Buffer            DWORD    44100
  190. TSM_Global_Volume        REAL4    0.0
  191. TSM_Flt32767            REAL4    32767.0
  192. TSM_Flt32768            REAL4    32768.0
  193. TSM_Fltm1            REAL4    -1.0
  194. TSM_Flt025            REAL4    0.25
  195. TSM_Flt05            REAL4    0.5
  196. TSM_Fltm05            REAL4    -0.5
  197. TSM_Flt005            REAL4    0.05
  198. TSM_Flt1            REAL4    1.0
  199. TSM_Fltm005            REAL4    -0.05
  200. TSM_Flt100            REAL4    100.0
  201. TSM_Flt001            REAL4    0.01
  202. TSM_Flt00001            REAL4    0.0001
  203. TSM_Flt01            REAL4    0.1
  204. TSM_FltPI2            REAL4    6.2831853071
  205. TSM_FltPI            REAL4    3.1415926535
  206. TSM_Flt0000023            REAL4    0.000023
  207. TSM_Fltm2            REAL4    -2.0
  208. TSM_Flt116            REAL4    1.16
  209. TSM_Flt015            REAL4    0.15
  210. TSM_Flt035            REAL4    0.35
  211. TSM_Flt03            REAL4    0.3
  212. TSM_Random_Seed            DWORD     012341234h
  213. TSM_Formant_Coefficients    REAL8    3.11044e-06
  214.                 REAL8    8.943665402
  215.                 REAL8    -36.83889529
  216.                 REAL8    92.01697887
  217.                 REAL8    -154.337906
  218.                 REAL8    181.6233289
  219.                 REAL8    -151.8651235
  220.                 REAL8    89.09614114
  221.                 REAL8    -35.10298511
  222.                 REAL8    8.388101016
  223.                 REAL8    -0.923313471
  224.                 REAL8    4.36215e-06
  225.                 REAL8    8.90438318
  226.                 REAL8    -36.55179099
  227.                 REAL8    91.05750846
  228.                 REAL8    -152.422234
  229.                 REAL8    179.1170248
  230.                 REAL8    -149.6496211
  231.                 REAL8    87.78352223
  232.                 REAL8    -34.60687431
  233.                 REAL8    8.282228154
  234.                 REAL8    -0.914150747
  235.                 REAL8    3.33819e-06
  236.                 REAL8    8.893102966
  237.                 REAL8    -36.49532826
  238.                 REAL8    90.96543286
  239.                 REAL8    -152.4545478
  240.                 REAL8    179.4835618
  241.                 REAL8    -150.315433
  242.                 REAL8    88.43409371
  243.                 REAL8    -34.98612086
  244.                 REAL8    8.407803364
  245.                 REAL8    -0.932568035
  246.                 REAL8    1.13572e-06
  247.                 REAL8    8.994734087
  248.                 REAL8    -37.2084849
  249.                 REAL8    93.22900521
  250.                 REAL8    -156.6929844
  251.                 REAL8    184.596544
  252.                 REAL8    -154.3755513
  253.                 REAL8    90.49663749
  254.                 REAL8    -35.58964535
  255.                 REAL8    8.478996281
  256.                 REAL8    -0.929252233
  257.                 REAL8    4.09431e-07
  258.                 REAL8    8.997322763
  259.                 REAL8    -37.20218544
  260.                 REAL8    93.11385476
  261.                 REAL8    -156.2530937
  262.                 REAL8    183.7080141
  263.                 REAL8    -153.2631681
  264.                 REAL8    89.59539726
  265.                 REAL8    -35.12454591
  266.                 REAL8    8.338655623
  267.                 REAL8    -0.910251753
  268. TSM_Freqs_Table            DWORD    000000417h,00000455h,000000497h,0000004DDh,000000527h,000000575h,0000005C8h,000000620h,00000067Dh,0000006E0h,000000749h,0000007B8h
  269.                 DWORD    00000082Dh,000008A9h,00000092Dh,0000009B9h,000000A4Dh,000000AEAh,000000B90h,000000C40h,000000CFAh,000000DC0h,000000E91h,000000F6Fh
  270.                 DWORD    00000105Ah,00001153h,00000125Bh,000001372h,00000149Ah,0000015D4h,000001720h,000001880h,0000019F5h,000001B80h,000001D23h,000001EDEh
  271.                 DWORD    0000020B4h,000022A6h,0000024B5h,0000026E4h,000002934h,000002BA7h,000002E40h,000003100h,0000033EAh,000003700h,000003A45h,000003DBCh
  272.                 DWORD    000004168h,0000454Ch,00000496Bh,000004DC8h,000005268h,00000574Fh,000005C80h,000006200h,0000067D3h,000006E00h,00000748Ah,000007B79h
  273.                 DWORD    0000082D0h,00008A97h,0000092D5h,000009B90h,00000A4D0h,00000AE9Dh,00000B8FFh,00000C3FFh,00000CFA7h,00000DC00h,00000E915h,00000F6F1h
  274.                 DWORD    0000105A0h,0001152Fh,0000125AAh,000013721h,0000149A1h,000015D3Ah,0000171FFh,0000187FFh,000019F4Eh,00001B800h,00001D22Ah,00001EDE2h
  275.                 DWORD    000020B40h,00022A5Dh,000024B54h,000026E41h,000029341h,00002BA75h,00002E3FDh,000030FFEh,000033E9Ch,000037000h,00003A454h,00003DBC4h
  276.                 DWORD    000041681h,000454BBh,0000496A9h,00004DC82h,000052683h,0000574EAh,00005C7FAh,000061FFBh,000067D38h,00006E000h,0000748A8h,00007B789h
  277.                 DWORD    000082D01h,0008A976h,000092D52h,00009B904h,0000A4D05h,0000AE9D4h,0000B8FF5h,0000C3FF6h,0000CFA70h,0000DC000h,0000E914Fh,0000F6F11h
  278.  
  279. ; --------------- Code section
  280.                 .code
  281.  
  282. ; ------------------------------------------------------
  283. ; Name: TSM_Init()
  284. ; Desc: Init the synthetizer
  285. TSM_Init            PROC    uses ebx esi edi TSM_Module:DWORD,TSM_hWnd:HWND,TSM_CallBack_Routine:DWORD
  286.                 mov    esi,[TSM_Module]
  287.                 mov    ebx,esi
  288.                 lodsd
  289.                 cmp    eax,0024d5354h
  290.                 jne    TSM_Err_Init
  291.                 xor    eax,eax
  292.                 lodsw
  293.                 mov    [TSM_Tempo],eax
  294.                 lodsw
  295.                 mov    [TSM_Fx_Tempo],eax
  296.                 lodsw
  297.                 mov    [TSM_Song_Restart],eax
  298.                 lodsd
  299.                 add    eax,ebx
  300.                 mov    [TSM_Module_Sequences],eax
  301.                 lodsd
  302.                 add    eax,ebx
  303.                 mov    [TSM_Module_Instruments],esi
  304.                 mov    esi,eax
  305.                 lodsd
  306.                 mov    [TSM_Nbr_Positions],eax
  307.                 imul    ebx,eax,sizeof TSM_SONG_DAT
  308.                 mov    [TSM_Length_Track],ebx
  309.                 imul    eax,sizeof TSM_SONG_DAT
  310.                 shl    eax,3
  311.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, eax
  312.                 test    eax,eax
  313.                 jz    TSM_Err_Init
  314.                 mov    edi,eax
  315.                 mov    [TSM_Module_Positions],edi
  316.                 mov    ebx,8
  317. TSM_Convert_Positions:        push    edi
  318.                 push    edi
  319.                 mov    ecx,[TSM_Nbr_Positions]
  320.                 test    ecx,ecx
  321.                 jz    TSM_Err_Init
  322. TSM_Copy_Song_Datas_w:        movsw
  323.                 add    edi,(sizeof TSM_SONG_DAT) - 2
  324.                 loop    TSM_Copy_Song_Datas_w
  325.                 pop    edi
  326.                 add    edi,2
  327.                 call    TSM_Copy_Module_Datas
  328.                 inc    edi
  329.                 call    TSM_Copy_Module_Datas
  330.                 pop    edi
  331.                 add    edi,[TSM_Length_Track]
  332.                 dec    ebx
  333.                 jnz    TSM_Convert_Positions
  334.                 ; Allocate room for intruments pointers
  335.                 mov    esi,[TSM_Module_Instruments]
  336.                 lodsd
  337.                 mov    [TSM_Nbr_Instruments],eax
  338.                 push    eax
  339.                 shl    eax,3
  340.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, eax
  341.                 test    eax,eax
  342.                 jz    TSM_Err_Init
  343.                 mov    [TSM_Module_Instruments],eax
  344.                 mov    ebx,eax
  345.                 pop    ecx
  346. TSM_Create_Intruments:        push    ecx
  347.                 ; Allocate slots
  348.                 movzx    eax,byte ptr [esi]
  349.                 imul    eax,sizeof TSM_INSTRUMENT_DAT
  350.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, eax
  351.                 mov    edi,eax
  352.                 test    eax,eax
  353.                 jz    TSM_Err_Init
  354.                 movzx    ecx,byte ptr [esi]
  355.                 mov    [ebx],eax            ; Address
  356.                 add    ebx,4
  357.                 mov    [ebx],ecx            ; Number of combinators
  358.                 add    ebx,4
  359.                 inc    esi
  360. TSM_Create_Instruments_Datas:    push    ecx
  361.                 push    edi
  362.                 mov    ecx,16                ; Copy datas
  363.                 rep    movsb
  364.                 pop    edi
  365.                 ; Calc the deltas
  366.                 mov    al,[edi + TSM_INSTRUMENT_DAT.Attack_Volume]
  367.                 mov    [edi + TSM_INSTRUMENT_DAT.Attack_Volume_Delta],al
  368.                 mov    al,[edi + TSM_INSTRUMENT_DAT.Decay_Volume]
  369.                 sub    al,[edi + TSM_INSTRUMENT_DAT.Attack_Volume]
  370.                 mov    [edi + TSM_INSTRUMENT_DAT.Decay_Volume_Delta],al
  371.                 mov    al,[edi + TSM_INSTRUMENT_DAT.Sustain_Volume]
  372.                 sub    al,[edi + TSM_INSTRUMENT_DAT.Decay_Volume]
  373.                 mov    [edi + TSM_INSTRUMENT_DAT.Sustain_Volume_Delta],al
  374.                 mov    al,[edi + TSM_INSTRUMENT_DAT.Release_Volume]
  375.                 sub    al,[edi + TSM_INSTRUMENT_DAT.Sustain_Volume]
  376.                 mov    [edi + TSM_INSTRUMENT_DAT.Release_Volume_Delta],al
  377.                 add    edi, sizeof TSM_INSTRUMENT_DAT
  378.                 pop    ecx
  379.                 loop    TSM_Create_Instruments_Datas
  380.                 pop    ecx
  381.                 loop    TSM_Create_Intruments
  382.                 
  383.                 ; Set the sequences pointer
  384.                 mov    esi,[TSM_Module_Sequences]
  385.                 lodsd
  386.                 mov    [TSM_Nbr_Sequences],eax
  387.                 mov    [TSM_Module_Sequences],esi
  388.                 invoke    DirectSoundCreate, NULL, addr TSM_DSound_Context, NULL
  389.                 test    eax,eax
  390.                 jnz    TSM_Err_Init
  391.                 DSINVOKE SetCooperativeLevel, [TSM_DSound_Context], [TSM_hWnd], DSSCL_EXCLUSIVE
  392.                 test    eax,eax
  393.                 jnz    TSM_Err_Init
  394.                 mov    [TSM_Sound_Buffer_Desc.dwSize], sizeof DSBUFFERDESC
  395.                 mov    [TSM_Sound_Buffer_Desc.dwFlags], DSBCAPS_STICKYFOCUS
  396.                 ; 44100 hz
  397.                 mov    eax,[TSM_Max_Buffer]
  398.                 mov    [TSM_Sound_Buffer_Desc.dwBufferBytes],eax
  399.                 mov    [TSM_Wave_Format.wFormatTag], WAVE_FORMAT_PCM
  400.                 ; Stereo
  401.                 mov    [TSM_Wave_Format.nChannels], 2
  402.                 mov    [TSM_Wave_Format.nSamplesPerSec], 44100
  403.                 mov    [TSM_Wave_Format.nAvgBytesPerSec], (44100 * ((16 * 2) shr 3))
  404.                 mov    [TSM_Wave_Format.nBlockAlign], ((16 * 2) shr 3)
  405.                 ; 16 bits
  406.                 mov    [TSM_Wave_Format.wBitsPerSample], 16
  407.                 mov    [TSM_Sound_Buffer_Desc.lpwfxFormat], offset TSM_Wave_Format
  408.                 DSINVOKE CreateSoundBuffer, [TSM_DSound_Context], addr TSM_Sound_Buffer_Desc, addr TSM_Sound_Buffer, NULL
  409.                 test    eax,eax
  410.                 jnz    TSM_Err_Init
  411.                 DSBINVOKE Play, [TSM_Sound_Buffer], 0, 0, DSBPLAY_LOOPING
  412.                 test    eax,eax
  413.                 jnz    TSM_Err_Init
  414.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, ((44100 * 2) + 4) * 4
  415.                 test    eax,eax
  416.                 jz    TSM_Err_Init
  417.                 mov    [TSM_Mixing_Buffer_Stereo],eax
  418.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, (sizeof TSM_SEQUENCE) * 8
  419.                 test    eax,eax
  420.                 jz    TSM_Err_Init
  421.                 mov    [TSM_Sequences_Dats],eax
  422.                 mov    dword ptr [TSM_Global_Volume],03f800000h
  423.                 mov    dword ptr [TSM_Speed_Counter],3
  424.                 mov    dword ptr [TSM_Cur_Play_Pos],15
  425.                 mov    edi,[TSM_Sequences_Dats]
  426.                 mov    ebx,8
  427. TSM_Alloc_Delay_Buffers:    invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, (44100 * 4)
  428.                 test    eax,eax
  429.                 jz    TSM_Err_Init
  430.                 mov    [edi + TSM_SEQUENCE.Delay_Left_Buffer],eax
  431.                 invoke    GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, (44100 * 4)
  432.                 test    eax,eax
  433.                 jz    TSM_Err_Init
  434.                 mov    [edi + TSM_SEQUENCE.Delay_Right_Buffer],eax
  435.                 ; Set default position volume to 1.0
  436.                 mov    [edi + TSM_SEQUENCE.Position_Volume],03f800000h
  437.                 add    edi,sizeof TSM_SEQUENCE
  438.                 dec    ebx
  439.                 jnz    TSM_Alloc_Delay_Buffers
  440.                 push    dword ptr [TSM_Tempo]
  441.                 call    TSM_Get_Mix_Buffer_Len
  442.                 mov    [TSM_Tempo_Ticks],eax
  443.                 push    dword ptr [TSM_Fx_Tempo]
  444.                 call    TSM_Get_Mix_Buffer_Len
  445.                 mov    [TSM_Fx_Tempo_Ticks],eax
  446.                 inc    dword ptr [TSM_Can_Play]
  447.                 mov    eax,[TSM_CallBack_Routine]
  448.                 mov    [TSM_Synth_CallBack],eax
  449. TSM_Err_Init:            mov    eax,[TSM_Can_Play]
  450.                 ret
  451. TSM_Init            ENDP
  452.  
  453. TSM_Copy_Module_Datas:        push    edi
  454.                 mov    ecx,[TSM_Nbr_Positions]
  455. TSM_Copy_Module_Datas_b:    movsb
  456.                 add    edi,(sizeof TSM_SONG_DAT) - 1
  457.                 loop    TSM_Copy_Module_Datas_b
  458.                 pop    edi
  459.                 ret
  460.  
  461. ; ------------------------------------------------------
  462. ; Name: TSM_Stop()
  463. ; Desc: Stop the synthetizer
  464. TSM_Stop            PROC    uses edi
  465.                 dec    dword ptr [TSM_Can_Play]
  466.                 mov    eax,[TSM_Sound_Buffer]
  467.                 test    eax,eax
  468.                 jz    TSM_Release_SoundBuffer
  469.                 DSBINVOKE Stop,[TSM_Sound_Buffer]
  470.                 DSBINVOKE Release,[TSM_Sound_Buffer]
  471. TSM_Release_SoundBuffer:    mov    eax,[TSM_DSound_Context]
  472.                 test    eax,eax
  473.                 jz    TSM_Release_DSContext
  474.                 DSINVOKE Release, [TSM_DSound_Context]
  475. TSM_Release_DSContext:        mov    eax,[TSM_Mixing_Buffer_Stereo]
  476.                 test    eax,eax
  477.                 jz    TSM_Free_Mixing_Buffer_Stereo
  478.                 invoke    GlobalFree,eax
  479. TSM_Free_Mixing_Buffer_Stereo:    mov    edi,[TSM_Sequences_Dats]
  480.                 test    edi,edi
  481.                 jz    TSM_No_Sequences_Dats
  482.                 mov    ebx,8
  483. TSM_Free_Delay_Buffers:        mov    eax,[edi + TSM_SEQUENCE.Delay_Left_Buffer]
  484.                 test    eax,eax
  485.                 jz    TSM_Free_Delay_Left_Buffer
  486.                 invoke    GlobalFree,eax
  487. TSM_Free_Delay_Left_Buffer:    mov    eax,[edi + TSM_SEQUENCE.Delay_Right_Buffer]
  488.                 test    eax,eax
  489.                 jz    TSM_Free_Delay_Right_Buffer
  490.                 invoke    GlobalFree,eax
  491. TSM_Free_Delay_Right_Buffer:    add    edi,sizeof TSM_SEQUENCE
  492.                 dec    ebx
  493.                 jnz    TSM_Free_Delay_Buffers
  494. TSM_No_Sequences_Dats:        mov    eax,[TSM_Sequences_Dats]
  495.                 test    eax,eax
  496.                 jz    TSM_Free_Sequences_Dats
  497.                 invoke    GlobalFree,eax
  498. TSM_Free_Sequences_Dats:    mov    eax,[TSM_Module_Positions]
  499.                 test    eax,eax
  500.                 jz    TSM_Free_Module_Positions
  501.                 invoke    GlobalFree,eax
  502. TSM_Free_Module_Positions:    ret
  503. TSM_Stop            ENDP
  504.  
  505. ; ------------------------------------------------------
  506. ; Name: TSM_Play()
  507. ; Desc: Replay routine
  508. TSM_Play            PROC    uses ebx esi edi
  509.                 local    TSM_Bytes_To_Lock:dword
  510.                 cmp    dword ptr [TSM_Can_Play],0
  511.                 jne    TSM_Proceed_Play
  512.                 ret
  513. TSM_Proceed_Play:        DSBINVOKE GetCurrentPosition, [TSM_Sound_Buffer], addr TSM_Buffer_Pos, NULL
  514.                 mov    eax,[TSM_Buffer_Pos]
  515.                 sub    eax,[TSM_Old_Buffer_Pos]
  516.                 jns    TSM_Reset_Buffer_Pos
  517.                 add    eax,[TSM_Max_Buffer]
  518. TSM_Reset_Buffer_Pos:        mov    [TSM_Bytes_To_Lock],eax
  519.                 DSBINVOKE mLock, [TSM_Sound_Buffer], [TSM_Old_Buffer_Pos], [TSM_Bytes_To_Lock], addr TSM_Audio_Ptr1, addr TSM_Audio_Bytes1, addr TSM_Audio_Ptr2, addr TSM_Audio_Bytes2, 0
  520.                 mov    eax,[TSM_Buffer_Pos]
  521.                 mov    [TSM_Old_Buffer_Pos],eax
  522.                 mov    edx,[TSM_Audio_Bytes1]
  523.                 mov    eax,[TSM_Audio_Ptr1]
  524.                 call    TSM_Process_Sound_Dat
  525.                 mov    edx,[TSM_Audio_Bytes2]
  526.                 mov    eax,[TSM_Audio_Ptr2]
  527.                 call    TSM_Process_Sound_Dat
  528.                 DSBINVOKE Unlock, [TSM_Sound_Buffer], [TSM_Audio_Ptr1], [TSM_Audio_Bytes1], [TSM_Audio_Ptr2], [TSM_Audio_Bytes2]
  529.                 ret
  530. TSM_Play            ENDP
  531.  
  532. ; ------------------------------------------------------
  533. ; Name: TSM_Process_Sound_Dat()
  534. ; Desc: Inner part of the replay
  535. TSM_Process_Sound_Dat:        push    ebp
  536.                 push    eax
  537.                 mov    [TSM_BufferSize],edx
  538.                 shr    edx,2
  539.                 mov    edi,[TSM_Mixing_Buffer_Stereo]
  540. TSM_Mix_Loop:            test    edx,edx
  541.                 jz    TSM_End_Mix_Loop
  542.                 push    edx
  543.                 mov    ebp,[TSM_Sequences_Dats]
  544.                 mov    dword ptr [TSM_Speed_Tick],0
  545.                 dec    dword ptr [TSM_Fx_Ticks]
  546.                 jns    TSM_Speed_Limit
  547.                 push    dword ptr [TSM_Fx_Tempo_Ticks]
  548.                 pop    dword ptr [TSM_Fx_Ticks]
  549.                 inc    dword ptr [TSM_Speed_Tick]
  550.                 inc    dword ptr [TSM_Speed_Counter]
  551.                 cmp    dword ptr [TSM_Speed_Counter],3
  552.                 jl    TSM_Speed_Limit
  553.                 mov    dword ptr [TSM_Speed_Counter],0
  554. TSM_Speed_Limit:        dec    dword ptr [TSM_Cur_Ticks]
  555.                 jns    TSM_Update_Channels
  556.                 push    dword ptr [TSM_Tempo_Ticks]
  557.                 pop    dword ptr [TSM_Cur_Ticks]
  558.                 ; Goto next position
  559.                 inc    dword ptr [TSM_Cur_Play_Pos]
  560.                 cmp    dword ptr [TSM_Cur_Play_Pos],16
  561.                 jne    TSM_Reset_Sequence_Pos
  562.                 mov    dword ptr [TSM_Cur_Play_Pos],0
  563.                 ; Fill the sequences datas
  564.                 lea    ebx,[ebp]
  565.                 xor    esi,esi
  566.                 mov    ecx,8
  567. TSM_Set_Sequences:        push    ecx
  568.                 mov    eax,[TSM_Module_Positions]
  569.                 mov    edx,[TSM_Length_Track]
  570.                 imul    edx,esi
  571.                 add    eax,edx            ; Start address of the track
  572.                 imul    edx,[TSM_Song_Position],sizeof TSM_SONG_DAT
  573.                 add    eax,edx
  574.                 movzx    edx,byte ptr [eax + TSM_SONG_DAT.Volume]
  575.                 push    edx            ; Push volume
  576.                 movzx    edx,byte ptr [eax + TSM_SONG_DAT.Transpose]
  577.                 mov    cl,dl
  578.                 and    dl,07fh
  579.                 and    cl,080h
  580.                 jz    TSM_Negative_Transpose
  581.                 neg    edx
  582. TSM_Negative_Transpose:        push    edx            ; Push transpose
  583.                 movzx    eax,word ptr [eax + TSM_SONG_DAT.Sequence]
  584.                 test    eax,eax
  585.                 jz    TSM_No_Sequence
  586.                 dec    eax
  587.                 cmp    [TSM_Nbr_Sequences],eax
  588.                 ja    TSM_Wrong_Sequence
  589.                 xor    eax,eax
  590.                 jmp    TSM_No_Sequence
  591. TSM_Wrong_Sequence:        imul    eax,sizeof TSM_SEQUENCE_DAT
  592.                 add    eax,[TSM_Module_Sequences]
  593. TSM_No_Sequence:        mov    [ebx + TSM_SEQUENCE.Current_Sequence],eax
  594.                 ; Set transpose for this sequence
  595.                 pop    dword ptr [ebx + TSM_SEQUENCE.Position_Transpose]
  596.                 ; Set global volume for this sequence
  597.                 pop    eax
  598.                 test    eax,eax
  599.                 jz    TSM_No_New_Global_Volume
  600.                 dec    eax
  601.                 push    eax
  602.                 fild    dword ptr [esp]
  603.                 fmul    dword ptr [TSM_Flt001]
  604.                 pop    eax
  605.                 fstp    dword ptr [ebx + TSM_SEQUENCE.Position_Volume]
  606. TSM_No_New_Global_Volume:    add    ebx,sizeof TSM_SEQUENCE
  607.                 inc    esi
  608.                 pop    ecx
  609.                 dec    ecx
  610.                 jnz    TSM_Set_Sequences
  611.                 mov    eax,[TSM_Nbr_Positions]    
  612.                 inc    dword ptr [TSM_Song_Position]
  613.                 cmp    [TSM_Song_Position],eax
  614.                 jl    TSM_Reset_Song_Position
  615.                 xor    ebx,ebx
  616.                 test    eax,eax
  617.                 jz    TSM_Max_Restart
  618.                 mov    ebx,[TSM_Song_Restart]
  619.                 dec    ebx
  620.                 dec    eax
  621.                 cmp    ebx,eax
  622.                 jb    TSM_Max_Restart
  623.                 mov    ebx,eax
  624. TSM_Max_Restart:        mov    [TSM_Song_Position],ebx
  625. TSM_Reset_Song_Position:    ; Set the default pans of the sequences
  626.                 lea    eax,[ebp]
  627.                 mov    ecx,8
  628. TSM_Reset_Pan:            ; (Default pan)
  629.                 fld    dword ptr [TSM_Flt05]
  630.                 fstp    dword ptr [eax + TSM_SEQUENCE.Pan]
  631.                 add    eax,sizeof TSM_SEQUENCE
  632.                 loop    TSM_Reset_Pan
  633. TSM_Reset_Sequence_Pos:        mov    ecx,8
  634. TSM_Set_Song_Datas:        push    ecx
  635.                 push    edi
  636.                 mov    dword ptr [ebp + TSM_SEQUENCE.Vol_Side],0
  637.                 mov    dword ptr [ebp + TSM_SEQUENCE.Arpeggio],0
  638.                 mov    dword ptr [ebp + TSM_SEQUENCE.Pitch_Bend],0
  639.                 mov    dword ptr [ebp + TSM_SEQUENCE.Vibrato],0
  640.                 mov    dword ptr [ebp + TSM_SEQUENCE.Vibrato_Freq],0
  641.                 mov    dword ptr [ebp + TSM_SEQUENCE.Tone_Portamento_Speed],0
  642.                 mov    dword ptr [ebp + TSM_SEQUENCE.Tone_Portamento_Note],0
  643.                 ; Set the effects
  644.                 mov    edi,[ebp + TSM_SEQUENCE.Current_Sequence]
  645.                 test    edi,edi
  646.                 jz    TSM_No_New_Panning
  647.                 mov    esi,[TSM_Cur_Play_Pos]
  648.                 movzx    ebx,byte ptr [edi + esi + TSM_SEQUENCE_DAT.Fx]
  649.                 movzx    eax,byte ptr [edi + esi + TSM_SEQUENCE_DAT.FxDatas]
  650.                 ; Arpeggio
  651.                 dec    ebx
  652.                 js    TSM_Fx_NoFx
  653.                 jnz    TSM_Fx_Arpeggio
  654.                 test    eax,eax
  655.                 jnz    TSM_Fx_Old_Arpeggio
  656.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Arpeggio]
  657. TSM_Fx_Old_Arpeggio:        mov    [ebp + TSM_SEQUENCE.Arpeggio],eax
  658.                 mov    [ebp + TSM_SEQUENCE.Old_Arpeggio],eax
  659. TSM_Fx_Arpeggio:        ; Pitch bend up
  660.                 dec    ebx
  661.                 jnz    TSM_Fx_Pitch_Bend_Up
  662.                 test    eax,eax
  663.                 jnz    TSM_Fx_Old_Pitch_Bend_Up
  664.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Pitch_Bend_Up]
  665. TSM_Fx_Old_Pitch_Bend_Up:    mov    [ebp + TSM_SEQUENCE.Pitch_Bend],eax
  666.                 mov    [ebp + TSM_SEQUENCE.Old_Pitch_Bend_Up],eax
  667. TSM_Fx_Pitch_Bend_Up:        ; Pitch bend down
  668.                 dec    ebx
  669.                 jnz    TSM_Fx_Pitch_Bend_Down
  670.                 neg    eax
  671.                 test    eax,eax
  672.                 jnz    TSM_Fx_Old_Pitch_Bend_Down
  673.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Pitch_Bend_Down]
  674. TSM_Fx_Old_Pitch_Bend_Down:    mov    [ebp + TSM_SEQUENCE.Pitch_Bend],eax
  675.                 mov    [ebp + TSM_SEQUENCE.Old_Pitch_Bend_Down],eax
  676. TSM_Fx_Pitch_Bend_Down:        ; Vibrato
  677.                 dec    ebx
  678.                 jnz    TSM_Fx_Vibrato
  679.                 test    eax,eax
  680.                 jnz    TSM_Fx_Old_Vibrato
  681.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Vibrato]
  682. TSM_Fx_Old_Vibrato:        mov    [ebp + TSM_SEQUENCE.Vibrato],eax
  683.                 mov    [ebp + TSM_SEQUENCE.Old_Vibrato],eax
  684. TSM_Fx_Vibrato:            ; Volume slide up
  685.                 dec    ebx
  686.                 jnz    TSM_Fx_Vol_Slide_Up
  687.                 test    eax,eax
  688.                 jnz    TSM_Fx_Old_Vol_Slide_Up
  689.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Vol_Side_Up]
  690. TSM_Fx_Old_Vol_Slide_Up:    push    eax
  691.                 fild    dword ptr [esp]
  692.                 pop    eax
  693.                 fmul    dword ptr [TSM_Flt001]
  694.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Vol_Side]
  695.                 mov    [ebp + TSM_SEQUENCE.Old_Vol_Side_Up],eax
  696. TSM_Fx_Vol_Slide_Up:        ; Volume slide down
  697.                 dec    ebx
  698.                 jnz    TSM_Fx_Vol_Slide_Down
  699.                 test    eax,eax
  700.                 jnz    TSM_Fx_Old_Vol_Slide_Down
  701.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Vol_Side_Down]
  702. TSM_Fx_Old_Vol_Slide_Down:    push    eax
  703.                 fild    dword ptr [esp]
  704.                 pop    eax
  705.                 fmul    dword ptr [TSM_Flt001]
  706.                 fchs
  707.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Vol_Side]
  708.                 mov    [ebp + TSM_SEQUENCE.Old_Vol_Side_Down],eax
  709. TSM_Fx_Vol_Slide_Down:        ; Modify tempo
  710.                 dec    ebx
  711.                 jnz    TSM_Fx_Set_Tempo
  712.                 mov    [TSM_Tempo],eax
  713.                 push    eax
  714.                 call    TSM_Get_Mix_Buffer_Len
  715.                 mov    [TSM_Tempo_Ticks],eax
  716. TSM_Fx_Set_Tempo:        ; Modify misc. FX tempo
  717.                 dec    ebx
  718.                 jnz    TSM_Fx_Set_Misc_Tempo
  719.                 mov    [TSM_Fx_Tempo],eax
  720.                 push    eax
  721.                 call    TSM_Get_Mix_Buffer_Len
  722.                 mov    [TSM_Fx_Tempo_Ticks],eax
  723. TSM_Fx_Set_Misc_Tempo:        ; Modify global volume
  724.                 dec    ebx
  725.                 jnz    TSM_Fx_Set_Global_Volume
  726.                 push    eax
  727.                 fild    dword ptr [esp]
  728.                 pop    eax
  729.                 fmul    dword ptr [TSM_Flt001]
  730.                 call    TSM_Clamp_Value
  731.                 fstp    dword ptr [TSM_Global_Volume]
  732. TSM_Fx_Set_Global_Volume:    ; Tone portamento
  733.                 dec    ebx
  734.                 jnz    Fx_Tone_Portamento
  735.                 movzx    edx,byte ptr [edi + esi + TSM_SEQUENCE_DAT.Note]
  736.                 test    eax,eax
  737.                 jnz    TSM_Fx_Old_Tone_Portamento_Spd
  738.                 mov    eax,[ebp + TSM_SEQUENCE.Old_Tone_Portamento_Speed]
  739. TSM_Fx_Old_Tone_Portamento_Spd:    dec    edx
  740.                 jns    TSM_Fx_Old_Tone_Portamento_Nt
  741.                 mov    edx,[ebp + TSM_SEQUENCE.Old_Tone_Portamento_Note]
  742. TSM_Fx_Old_Tone_Portamento_Nt:    mov    [ebp + TSM_SEQUENCE.Tone_Portamento_Speed],eax
  743.                 mov    [ebp + TSM_SEQUENCE.Old_Tone_Portamento_Speed],eax
  744.                 mov    [ebp + TSM_SEQUENCE.Tone_Portamento_Note],edx
  745.                 mov    [ebp + TSM_SEQUENCE.Old_Tone_Portamento_Note],edx
  746. Fx_Tone_Portamento:        ; External program control
  747.                 dec    ebx
  748.                 jnz    TSM_Fx_NoFx
  749.                 push    esi
  750.                 push    edi
  751.                 mov    ebx,[TSM_Synth_CallBack]
  752.                 test    ebx,ebx
  753.                 jz    No_Synchro
  754.                 push    eax
  755.                 call    ebx
  756. No_Synchro:            pop    edi
  757.                 pop    esi
  758. TSM_Fx_NoFx:            ; Set the instrument
  759.                 movzx    eax,word ptr [edi + TSM_SEQUENCE_DAT.Instrument + esi * 2]
  760.                 dec    eax
  761.                 js    TSM_No_New_Instrument
  762.                 cmp    [TSM_Nbr_Instruments],eax
  763.                 jg    TSM_Return_Instrument
  764.                 xor    eax,eax
  765.                 jmp    TSM_Wrong_Instrument
  766. TSM_Return_Instrument:        shl    eax,3
  767.                 add    eax,[TSM_Module_Instruments]
  768. TSM_Wrong_Instrument:        mov    [ebp + TSM_SEQUENCE.Current_Instrument],eax
  769.                 push    0
  770.                 push    dword ptr [ebp + TSM_SEQUENCE.Current_Instrument]
  771.                 call    TSM_Get_Instrument_Dat
  772.                 mov    [ebp + TSM_SEQUENCE.Current_Instrument_Dat],eax
  773.                 test    eax,eax
  774.                 jz    TSM_No_New_Instrument
  775.                 mov    eax,[ebp + TSM_SEQUENCE.Current_Instrument]
  776.                 test    eax,eax
  777.                 jz    TSM_Return_Comb
  778.                 mov    eax,[eax + 4]
  779. TSM_Return_Comb:        mov    [ebp + TSM_SEQUENCE.Instrument_NbrComb],eax
  780.                 fld1
  781.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Volume]
  782. TSM_No_New_Instrument:        ; Set the note
  783.                 mov    esi,[TSM_Cur_Play_Pos]
  784.                 cmp    dword ptr [ebp + TSM_SEQUENCE.Tone_Portamento_Speed],0
  785.                 jne    TSM_No_New_Note
  786.                 movzx    ebx,byte ptr [edi + esi + TSM_SEQUENCE_DAT.Note]
  787.                 dec    ebx
  788.                 js    TSM_No_New_Note
  789.                 add    ebx,[ebp + TSM_SEQUENCE.Position_Transpose]
  790.                 mov    [ebp + TSM_SEQUENCE.Cur_Note],ebx
  791.                 mov    [ebp + TSM_SEQUENCE.Cur_Freq],ebx
  792.                 mov    dword ptr [ebp + TSM_SEQUENCE.Pitch_Bend_Freq],0
  793.                 mov    eax,[ebp + TSM_SEQUENCE.Current_Instrument]
  794.                 test    eax,eax
  795.                 jz    TSM_No_New_Note
  796.                 mov    ecx,[ebp + TSM_SEQUENCE.Instrument_NbrComb]
  797.                 lea    eax,[ebp + TSM_SEQUENCE.Cur_Instrument_Vars]
  798. TSM_Clear_Instrument_Dats:    xor    edx,edx
  799.                 mov    [eax + TSM_INSTRUMENT_VARS.Volume],edx
  800.                 mov    [eax + TSM_INSTRUMENT_VARS.Ticks],edx
  801.                 mov    [eax + TSM_INSTRUMENT_VARS.RndVal1],edx
  802.                 mov    [eax + TSM_INSTRUMENT_VARS.RndVal2],edx
  803.                 mov    [eax + TSM_INSTRUMENT_VARS.wrpos],edx
  804.                 mov    [eax + TSM_INSTRUMENT_VARS.FPos],edx
  805.                 mov    [eax + TSM_INSTRUMENT_VARS.Oscillator],edx
  806.                 mov    [eax + TSM_INSTRUMENT_VARS.Frac_Lo_Pos],edx
  807.                 add    eax,sizeof TSM_INSTRUMENT_VARS
  808.                 loop    TSM_Clear_Instrument_Dats
  809. TSM_No_New_Note:        ; Set the volume
  810.                 movzx    ebx,byte ptr [edi + esi + TSM_SEQUENCE_DAT.Volume]
  811.                 dec    ebx
  812.                 js    TSM_No_New_Volume
  813.                 push    ebx
  814.                 fild    dword ptr [esp]
  815.                 pop    ebx
  816.                 fmul    dword ptr [TSM_Flt001]
  817.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Volume]
  818. TSM_No_New_Volume:        ; Set the panning
  819.                 movzx    ebx,byte ptr [edi + esi + TSM_SEQUENCE_DAT.Panning]
  820.                 dec    ebx
  821.                 js    TSM_No_New_Panning
  822.                 push    ebx
  823.                 fild    dword ptr [esp]
  824.                 pop    ebx
  825.                 fmul    dword ptr [TSM_Flt001]
  826.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Pan]
  827. TSM_No_New_Panning:        pop    edi
  828.                 pop    ecx
  829.                 add    ebp,sizeof TSM_SEQUENCE
  830.                 dec    ecx
  831.                 jnz    TSM_Set_Song_Datas
  832. TSM_Update_Channels:        ; -------------------------------------------------
  833.                 ; Process in-between effects
  834.                 mov    ebp,[TSM_Sequences_Dats]
  835.                 mov    ecx,8
  836. TSM_Set_Song_Fx:        push    ecx
  837.                 cmp    dword ptr [ebp + TSM_SEQUENCE.Pitch_Bend],0
  838.                 je    TSM_No_PitchBend
  839.                 cmp    dword ptr [TSM_Speed_Tick],0
  840.                 je    TSM_No_PitchBend
  841.                 mov    eax,[ebp + TSM_SEQUENCE.Pitch_Bend_Freq]
  842.                 add    eax,[ebp + TSM_SEQUENCE.Pitch_Bend]
  843.                 mov    [ebp + TSM_SEQUENCE.Pitch_Bend_Freq],eax
  844. TSM_No_PitchBend:        cmp    dword ptr [ebp + TSM_SEQUENCE.Vibrato],0
  845.                 je    TSM_No_Vibrato
  846.                 cmp    dword ptr [TSM_Speed_Tick],0
  847.                 je    TSM_No_Vibrato
  848.                 mov    eax,[ebp + TSM_SEQUENCE.Vibrato]
  849.                 mov    ebx,eax
  850.                 shr    ebx,4
  851.                 and    eax,0fh
  852.                 push    eax
  853.                 fild    dword ptr [esp]
  854.                 fadd    st(0),st(0)
  855.                 fadd    st(0),st(0)
  856.                 fadd    st(0),st(0)
  857.                 fadd    st(0),st(0)
  858.                 pop    eax
  859.                 push    dword ptr [ebp + TSM_SEQUENCE.Vibrato_Tick]
  860.                 fild    dword ptr [esp]
  861.                 fmul    dword ptr [TSM_Flt005]
  862.                 fsin
  863.                 fmulp    st(1),st(0)
  864.                 fistp    dword ptr [esp]
  865.                 pop    eax
  866.                 mov    [ebp + TSM_SEQUENCE.Vibrato_Freq],eax
  867.                 add    [ebp + TSM_SEQUENCE.Vibrato_Tick],ebx
  868. TSM_No_Vibrato:            cmp    dword ptr [ebp + TSM_SEQUENCE.Arpeggio],0
  869.                 je    TSM_No_Arpeggio
  870.                 mov    eax,[TSM_Speed_Counter]
  871.                 xor    edx,edx
  872.                 mov    ebx,3
  873.                 div    ebx
  874.                 dec    edx
  875.                 jz    TSM_Do_Arpeggio1
  876.                 dec    edx
  877.                 jz    TSM_Do_Arpeggio2
  878.                 xor    edx,edx
  879.                 jmp    TSM_Do_Arpeggio
  880. TSM_Do_Arpeggio1:        mov    edx,[ebp + TSM_SEQUENCE.Arpeggio]
  881.                 shr    edx,4
  882.                 jmp    TSM_Do_Arpeggio
  883. TSM_Do_Arpeggio2:        mov    edx,[ebp + TSM_SEQUENCE.Arpeggio]
  884.                 and    edx,0fh
  885. TSM_Do_Arpeggio:        add    edx,[ebp + TSM_SEQUENCE.Cur_Note]
  886.                 mov    [ebp + TSM_SEQUENCE.Cur_Freq],edx
  887. TSM_No_Arpeggio:        cmp    dword ptr [ebp + TSM_SEQUENCE.Tone_Portamento_Speed],0
  888.                 je    TSM_No_TonePortamento
  889.                 cmp    dword ptr [TSM_Speed_Tick],0
  890.                 je    TSM_No_TonePortamento
  891.                 mov    ebx,[ebp + TSM_SEQUENCE.Pitch_Bend_Freq]
  892.                 mov    ecx,[ebp + TSM_SEQUENCE.Tone_Portamento_Speed]
  893.                 mov    edx,[ebp + TSM_SEQUENCE.Tone_Portamento_Note]
  894.                 mov    eax,[TSM_Freqs_Table + edx * 4]
  895.                 cmp    eax,[ebp + TSM_SEQUENCE.Current_Freq]
  896.                 je    TSM_Portamento_Stop
  897.                 ja    TSM_Portamento_Up
  898.                 sub    ebx,ecx
  899.                 cmp    eax,ebx
  900.                 ja    TSM_Portamento_Stop
  901.                 jmp    TSM_Set_Portamento_Freq
  902. TSM_Portamento_Up:        add    ebx,ecx
  903.                 cmp    eax,ebx
  904.                 jb    TSM_Portamento_Stop
  905.                 jmp    TSM_Set_Portamento_Freq
  906. TSM_Portamento_Stop:        mov    [ebp + TSM_SEQUENCE.Cur_Freq],edx
  907.                 xor    ebx,ebx
  908. TSM_Set_Portamento_Freq:    mov    [ebp + TSM_SEQUENCE.Pitch_Bend_Freq],ebx
  909. TSM_No_TonePortamento:        pop    ecx
  910.                 add    ebp,sizeof TSM_SEQUENCE
  911.                 dec    ecx
  912.                 jnz    TSM_Set_Song_Fx
  913.                 ; -------------------------
  914.                 ; Handle waves combinations
  915.                 mov    ebp,[TSM_Sequences_Dats]
  916.                 mov    ecx,8
  917. TSM_Set_Song_Instruments:    push    ecx
  918.                 push    edi
  919.                 lea    eax,[ebp + TSM_SEQUENCE.Cur_Instrument_Vars]
  920.                 mov    [TSM_Instr_Dat_Vars],eax
  921.                 mov    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas],0
  922.                 mov    dword ptr [TSM_Instr_Dat_Number], 0
  923.                 mov    ebx,[ebp + TSM_SEQUENCE.Current_Instrument_Dat]
  924.                 ; Load number of combinators
  925.                 mov    ecx,[ebp + TSM_SEQUENCE.Instrument_NbrComb]
  926. TSM_Load_Instrument:        test    ebx,ebx
  927.                 jz    TSM_No_Instrument
  928.                 push    ecx
  929.                 mov    edi,[TSM_Instr_Dat_Vars]
  930.                 mov    ecx,[ebp + TSM_SEQUENCE.Cur_Freq]
  931.                 mov    dword ptr [ebp + TSM_SEQUENCE.Freq_Hi_Speed],0
  932.                 mov    dword ptr [ebp + TSM_SEQUENCE.Freq_Lo_Speed],0
  933.                 test    ecx,ecx
  934.                 js    TSM_No_Freq
  935.                 cmp    ecx,TSM_MAX_NOTES
  936.                 jge    TSM_No_Freq
  937.                 mov    eax,[TSM_Freqs_Table + ecx * 4]
  938.                 add    eax,[ebp + TSM_SEQUENCE.Vibrato_Freq]
  939.                 add    eax,[ebp + TSM_SEQUENCE.Pitch_Bend_Freq]
  940.                 movzx    edx,byte ptr [ebx + TSM_INSTRUMENT_DAT.Waveform]
  941.                 cmp    dl,TSM_INS_WF_CUST
  942.                 je    TSM_Custom_Value
  943.                 movsx    edx,word ptr [ebx + TSM_INSTRUMENT_DAT.PhaseShift]
  944.                 add    eax,edx
  945. TSM_Custom_Value:        cmp    eax,0417h
  946.                 jg    TSM_Min_Frequency
  947.                 mov    eax,0417h
  948. TSM_Min_Frequency:        cmp    eax,0F6F11h
  949.                 jl    TSM_Max_Frequency
  950.                 mov    eax,0F6F11h
  951. TSM_Max_Frequency:        mov    [ebp + TSM_SEQUENCE.Current_Freq],eax
  952.                 xor    edx,edx
  953.                 div    dword ptr [TSM_Max_Buffer]
  954.                 mov    [ebp + TSM_SEQUENCE.Freq_Hi_Speed],eax
  955.                 xor    eax,eax
  956.                 div    dword ptr [TSM_Max_Buffer]
  957.                 mov    [ebp + TSM_SEQUENCE.Freq_Lo_Speed],eax
  958. TSM_No_Freq:            mov    edx,[edi + TSM_INSTRUMENT_VARS.Frac_Lo_Pos]
  959.                 mov    esi,[edi + TSM_INSTRUMENT_VARS.Oscillator]
  960.                 add    edx,[ebp + TSM_SEQUENCE.Freq_Lo_Speed]
  961.                 adc    esi,[ebp + TSM_SEQUENCE.Freq_Hi_Speed]
  962.                 mov    [edi + TSM_INSTRUMENT_VARS.Frac_Lo_Pos],edx
  963.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  964.                 mov    [edi + TSM_INSTRUMENT_VARS.Oscillator],esi
  965.                 fild    dword ptr [edi + TSM_INSTRUMENT_VARS.Oscillator]
  966.                 fmul    dword ptr [TSM_Flt01]
  967.                 movzx    edx,byte ptr [ebx + TSM_INSTRUMENT_DAT.Waveform]
  968.                 dec    dl
  969.                 jnz    TSM_Set_Ins_Sin
  970.                 fsin
  971. TSM_Set_Ins_Sin:        dec    dl
  972.                 jnz    TSM_Set_Ins_Sqr
  973.                 fsin
  974.                 fld    st(0)
  975.                 push    eax
  976.                 fistp    dword ptr [esp]
  977.                 fild    dword ptr [esp]
  978.                 fxch    st(1)
  979.                 cmp    dword ptr [esp],0
  980.                 jne    TSM_Sqr_Zero
  981.                 ftst
  982.                 fstsw    ax
  983.                 sahf
  984.                 fstp    st(0)
  985.                 fstp    st(0)
  986.                 fld1
  987.                 ja    TSM_Sqr_Neg
  988.                 fchs
  989. TSM_Sqr_Neg:            fld    st(0)
  990. TSM_Sqr_Zero:            fstp    st(0)
  991.                 pop    eax
  992. TSM_Set_Ins_Sqr:        dec    dl
  993.                 jnz    TSM_Set_Ins_Saw
  994.                 fld    dword ptr [TSM_FltPI2]
  995.                 fxch    st(1)
  996. TSM_FModf_Saw:            fprem
  997.                 fstsw    ax
  998.                 sahf
  999.                 jp    TSM_FModf_Saw
  1000.                 fstp    st(1)
  1001.                 fdiv    dword ptr [TSM_FltPI]
  1002.                 fsub    dword ptr [TSM_Flt1]
  1003. TSM_Set_Ins_Saw:        dec    dl
  1004.                 jnz    TSM_Set_Ins_Rnd
  1005.                 fstp    dword ptr [edi + TSM_INSTRUMENT_VARS.FPos]
  1006.                 cmp    dword ptr [edi + TSM_INSTRUMENT_VARS.wrpos],0
  1007.                 jne    TSM_Reset_Noise
  1008.                 call    TSM_Wave_WhiteNoise
  1009.                 fstp    dword ptr [edi + TSM_INSTRUMENT_VARS.RndVal1]
  1010.                 call    TSM_Wave_WhiteNoise
  1011.                 fstp    dword ptr [edi + TSM_INSTRUMENT_VARS.RndVal2]
  1012.                 mov    eax,[edi + TSM_INSTRUMENT_VARS.FPos]
  1013.                 mov    [edi + TSM_INSTRUMENT_VARS.wrpos],eax
  1014. TSM_Reset_Noise:        fld    dword ptr [edi + TSM_INSTRUMENT_VARS.wrpos]
  1015.                 fadd    dword ptr [TSM_FltPI2]
  1016.                 fcom    dword ptr [edi + TSM_INSTRUMENT_VARS.FPos]
  1017.                 fnstsw    ax
  1018.                 sahf
  1019.                 jae    TSM_Done_Rnd
  1020.                 fstp    dword ptr [edi + TSM_INSTRUMENT_VARS.wrpos]
  1021.                 mov    eax,[edi + TSM_INSTRUMENT_VARS.RndVal2]
  1022.                 mov    [edi + TSM_INSTRUMENT_VARS.RndVal1],eax
  1023.                 call    TSM_Wave_WhiteNoise
  1024.                 fstp    dword ptr [edi + TSM_INSTRUMENT_VARS.RndVal2]
  1025.                 jmp    TSM_Reset_Noise
  1026. TSM_Done_Rnd:            fstp    st(0)
  1027.                 fld    dword ptr [edi + TSM_INSTRUMENT_VARS.FPos]
  1028.                 fsub    dword ptr [edi + TSM_INSTRUMENT_VARS.wrpos]
  1029.                 fmul    dword ptr [edi + TSM_INSTRUMENT_VARS.RndVal2]
  1030.                 fld    dword ptr [TSM_FltPI2]
  1031.                 fadd    dword ptr [edi + TSM_INSTRUMENT_VARS.wrpos]
  1032.                 fsub    dword ptr [edi + TSM_INSTRUMENT_VARS.FPos]
  1033.                 fmul    dword ptr [edi + TSM_INSTRUMENT_VARS.RndVal1]
  1034.                 faddp    st(1),st(0)
  1035.                 fmul    dword ptr [TSM_Flt05]
  1036. TSM_Set_Ins_Rnd:        dec    dl
  1037.                 jnz    TSM_Set_Ins_Tri
  1038.                 fld    dword ptr [TSM_FltPI2]
  1039.                 fxch    st(1)
  1040. TSM_FModf_Tri:            fprem
  1041.                 fstsw    ax
  1042.                 sahf
  1043.                 jp    TSM_FModf_Tri
  1044.                 fstp    st(1)
  1045.                 fcom    dword ptr [TSM_FltPI]
  1046.                 fnstsw    ax
  1047.                 sahf
  1048.                 fld1
  1049.                 ja    TSM_Tri_Desc
  1050.                 fchs
  1051. TSM_Tri_Desc:            fxch    st(1)
  1052.                 fcom    dword ptr [TSM_FltPI2]
  1053.                 fnstsw    ax
  1054.                 sahf
  1055.                 jb    TSM_Tri_Ramp
  1056.                 fsub    dword ptr [TSM_FltPI2]
  1057.                 fld    dword ptr [TSM_FltPI2]
  1058.                 fsubrp    st(1),st(0)
  1059. TSM_Tri_Ramp:            fdiv    dword ptr [TSM_FltPI2]
  1060.                 fmulp    st(1),st(0)
  1061.                 fadd    dword ptr [TSM_Flt025]
  1062.                 fcom    dword ptr [TSM_Flt05]
  1063.                 fnstsw    ax
  1064.                 sahf
  1065.                 jb    TSM_Tri_Invert
  1066.                 fsub    dword ptr [TSM_Flt1]
  1067. TSM_Tri_Invert:            fadd    st(0),st(0)
  1068.                 fadd    st(0),st(0)
  1069. TSM_Set_Ins_Tri:        dec    dl
  1070.                 jnz    TSM_Set_Ins_Cust
  1071.                 fstp    st(0)
  1072.                 movzx    eax,byte ptr [ebx + TSM_INSTRUMENT_DAT.PhaseShift]
  1073.                 push    eax
  1074.                 fild    dword ptr [esp]
  1075.                 pop    eax
  1076.                 cmp    word ptr [ebx + TSM_INSTRUMENT_DAT.PhaseShift],0
  1077.                 jg    TSM_Negative_Shift
  1078.                 fchs
  1079. TSM_Negative_Shift:        fmul    dword ptr [TSM_Flt001]
  1080. TSM_Set_Ins_Cust:        push    ebp
  1081.                 mov    ebp,[TSM_Instr_Dat_Vars]
  1082.                 ; Handle ADSR
  1083.                 push    edi
  1084.                 movzx    edi,byte ptr [ebx + TSM_INSTRUMENT_DAT.Attack_Volume]
  1085.                 movzx    ecx,word ptr [ebx + TSM_INSTRUMENT_DAT.Attack]
  1086.                 xor    edx,edx
  1087.                 movsx    eax,byte ptr [ebx + TSM_INSTRUMENT_DAT.Attack_Volume_Delta]
  1088.                 mov    esi,ecx
  1089.                 test    ecx,ecx
  1090.                 jz    TSM_Load_Decay
  1091.                 add    edx,ecx
  1092.                 cmp    [ebp + TSM_INSTRUMENT_VARS.Ticks],edx
  1093.                 jb    TSM_Load_Decay
  1094.                 movzx    edi,byte ptr [ebx + TSM_INSTRUMENT_DAT.Decay_Volume]
  1095.                 movzx    esi,word ptr [ebx + TSM_INSTRUMENT_DAT.Decay]
  1096.                 movsx    eax,byte ptr [ebx + TSM_INSTRUMENT_DAT.Decay_Volume_Delta]
  1097. TSM_Load_Decay:            movzx    ecx,word ptr [ebx + TSM_INSTRUMENT_DAT.Decay]
  1098.                 test    ecx,ecx
  1099.                 jz    TSM_Load_Sustain
  1100.                 add    edx,ecx
  1101.                 cmp    [ebp + TSM_INSTRUMENT_VARS.Ticks],edx
  1102.                 jb    TSM_Load_Sustain
  1103.                 movzx    edi,byte ptr [ebx + TSM_INSTRUMENT_DAT.Sustain_Volume]
  1104.                 movzx    esi,word ptr [ebx + TSM_INSTRUMENT_DAT.Sustain]
  1105.                 movsx    eax,byte ptr [ebx + TSM_INSTRUMENT_DAT.Sustain_Volume_Delta]
  1106. TSM_Load_Sustain:        movzx    ecx,word ptr [ebx + TSM_INSTRUMENT_DAT.Sustain]
  1107.                 test    ecx,ecx
  1108.                 jz    TSM_Load_Release
  1109.                 add    edx,ecx
  1110.                 cmp    dword ptr [ebp + TSM_INSTRUMENT_VARS.Ticks],edx
  1111.                 jb    TSM_Load_Release
  1112.                 movzx    edi,byte ptr [ebx + TSM_INSTRUMENT_DAT.Release_Volume]
  1113.                 movzx    esi,word ptr [ebx + TSM_INSTRUMENT_DAT.Release]
  1114.                 movsx    eax,byte ptr [ebx + TSM_INSTRUMENT_DAT.Release_Volume_Delta]
  1115. TSM_Load_Release:        test    esi,esi
  1116.                 jz    TSM_Done_Ramping
  1117.                 test    eax,eax
  1118.                 jz    TSM_Done_Ramping
  1119.                 push    eax
  1120.                 jg    TSM_Vol_Ramp_Up
  1121.                 ; Ramping down
  1122.                 push    edi                ; Dest volume
  1123.                 fild    dword ptr [esp]
  1124.                 pop    edi
  1125.                 fmul    dword ptr [TSM_Flt001]
  1126.                 fcomp    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1127.                 fnstsw    ax
  1128.                 sahf
  1129.                 jb    TSM_Volume_Max
  1130.                 jmp    TSM_Volume_Equal
  1131.                 ; Ramping up
  1132. TSM_Vol_Ramp_Up:        push    edi
  1133.                 fild    dword ptr [esp]
  1134.                 pop    edi
  1135.                 fmul    dword ptr [TSM_Flt001]
  1136.                 fcomp    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1137.                 fnstsw    ax
  1138.                 sahf
  1139.                 jz    TSM_Volume_Equal
  1140.                 ja    TSM_Volume_Max
  1141. TSM_Volume_Equal:        ; Set the Dest volume
  1142.                 mov    [esp],edi
  1143.                 fild    dword ptr [esp]
  1144.                 pop    edi
  1145.                 fmul    dword ptr [TSM_Flt001]
  1146.                 fstp    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1147.                 jmp    TSM_Done_Ramping
  1148. TSM_Volume_Max:            fild    dword ptr [esp]            ; Delta volume
  1149.                 pop    eax
  1150.                 push    esi
  1151.                 fild    dword ptr [esp]            ; Ramping time
  1152.                 pop    esi
  1153.                 fdivp    st(1),st(0)
  1154.                 fmul    dword ptr [TSM_Flt001]
  1155.                 fadd    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1156.                 call    TSM_Clamp_Value
  1157.                 fstp    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1158. TSM_Done_Ramping:        ; Set the volume of the sample according to the ADSR
  1159.                 fmul    dword ptr [ebp + TSM_INSTRUMENT_VARS.Volume]
  1160.                 pop    edi
  1161.                 ; Handle operators
  1162.                 mov    dl,[ebx + TSM_INSTRUMENT_DAT.Operator]
  1163.                 dec    dl
  1164.                 jnz    TSM_Set_Ins_Op_Add
  1165.                 faddp    st(1),st(0)
  1166. TSM_Set_Ins_Op_Add:        dec    dl
  1167.                 jnz    TSM_Set_Ins_Op_Sub
  1168.                 fsubp    st(1),st(0)
  1169. TSM_Set_Ins_Op_Sub:        dec    dl
  1170.                 jnz    TSM_Set_Ins_Op_Mul
  1171.                 fmulp    st(1),st(0)
  1172. TSM_Set_Ins_Op_Mul:        dec    dl
  1173.                 jnz    TSM_Set_Ins_Op_Div
  1174.                 fdivp    st(1),st(0)
  1175. TSM_Set_Ins_Op_Div:        inc    dword ptr [ebp + TSM_INSTRUMENT_VARS.Ticks]
  1176.                 pop    ebp
  1177.                 ; Store oscillator value now
  1178.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1179.                 ; Next instrument's datas
  1180.                 inc    dword ptr [TSM_Instr_Dat_Number]
  1181.                 push    dword ptr [TSM_Instr_Dat_Number]
  1182.                 ; Next datas of the instrument of the sequence
  1183.                 push    dword ptr [ebp + TSM_SEQUENCE.Current_Instrument]
  1184.                 call    TSM_Get_Instrument_Dat
  1185.                 mov    ebx,eax
  1186.                 add    [TSM_Instr_Dat_Vars],sizeof TSM_INSTRUMENT_VARS
  1187.                 pop    ecx
  1188.                 dec    ecx
  1189.                 jnz    TSM_Load_Instrument
  1190. TSM_No_Instrument:        pop    edi
  1191.                 ; Set channel volume
  1192.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1193.                 fld    dword ptr [ebp + TSM_SEQUENCE.Volume]
  1194.                 cmp    dword ptr [TSM_Speed_Tick],0
  1195.                 je    TSM_No_Vol_Slide
  1196.                 fadd    dword ptr [ebp + TSM_SEQUENCE.Vol_Side]
  1197.                 call    TSM_Clamp_Value
  1198.                 fst    dword ptr [ebp + TSM_SEQUENCE.Volume]
  1199. TSM_No_Vol_Slide:        fmulp    st(1),st(0)
  1200.                 ; Set song position volume
  1201.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Position_Volume]
  1202.                 fmul    dword ptr [TSM_Global_Volume]
  1203.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1204.                 ; Reset DSP effects parameters
  1205.                 mov    edx,[ebp + TSM_SEQUENCE.Current_Sequence]
  1206.                 test    edx,edx
  1207.                 jz    TSM_No_DSP_Params
  1208.                 mov    esi,[TSM_Cur_Play_Pos]
  1209.                 mov    bl,[edx + esi + TSM_SEQUENCE_DAT.DspMask]
  1210.                 test    bl,1
  1211.                 jz    TSM_Switch_Lo_Pass_Off
  1212.                 mov    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param1],0
  1213.                 mov    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param2],0
  1214. TSM_Switch_Lo_Pass_Off:        test    bl,2
  1215.                 jz    TSM_Switch_Hi_Pass_Off
  1216.                 mov    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param1],0
  1217.                 mov    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param2],0
  1218. TSM_Switch_Hi_Pass_Off:        test    bl,4
  1219.                 jz    TSM_Switch_VCF_Pass_Off
  1220.                 mov    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param1],0
  1221.                 mov    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param2],0
  1222. TSM_Switch_VCF_Pass_Off:    test    bl,8
  1223.                 jz    TSM_Switch_Delay_Off
  1224.                 push    0
  1225.                 push    0
  1226.                 push    0
  1227.                 push    ebp
  1228.                 call    TSM_Set_Delay
  1229.                 mov    dword ptr [ebp + TSM_SEQUENCE.Delay_Cursor],0
  1230. TSM_Switch_Delay_Off:        test    bl,16
  1231.                 jz    TSM_Switch_Disto_Off
  1232.                 mov    dword ptr [ebp + TSM_SEQUENCE.Disto_Param],0
  1233. TSM_Switch_Disto_Off:        test    bl,32
  1234.                 jz    TSM_Switch_Formant_Off
  1235.                 mov    dword ptr [ebp + TSM_SEQUENCE.Formant_Param1],0
  1236. TSM_Switch_Formant_Off:        ; Process DSP effects
  1237.                 mov    bl,byte ptr [edx + esi + TSM_SEQUENCE_DAT.Dsp]
  1238.                 dec    bl
  1239.                 js    TSM_No_DSP_Params
  1240.                 jnz    TSM_No_Lo_Pass_Filter
  1241.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas3]
  1242.                 mov    ah,[edx + esi + TSM_SEQUENCE_DAT.DspDatas2]
  1243.                 push    eax
  1244.                 fild    dword ptr [esp]
  1245.                 pop    eax
  1246.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param2]
  1247.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas1]
  1248.                 push    eax
  1249.                 fild    dword ptr [esp]
  1250.                 pop    eax
  1251.                 fmul    dword ptr [TSM_Flt01]
  1252.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param1]
  1253. TSM_No_Lo_Pass_Filter:        dec    bl
  1254.                 jnz    TSM_No_Hi_Pass_Filter
  1255.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas3]
  1256.                 mov    ah,[edx + esi + TSM_SEQUENCE_DAT.DspDatas2]
  1257.                 push    eax
  1258.                 fild    dword ptr [esp]
  1259.                 pop    eax
  1260.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param2]
  1261.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas1]
  1262.                 push    eax
  1263.                 fild    dword ptr [esp]
  1264.                 pop    eax
  1265.                 fmul    dword ptr [TSM_Flt01]
  1266.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param1]
  1267. TSM_No_Hi_Pass_Filter:        dec    bl
  1268.                 jnz    TSM_No_VCF_Pass_Filter
  1269.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas3]
  1270.                 mov    ah,[edx + esi + TSM_SEQUENCE_DAT.DspDatas2]
  1271.                 push    eax
  1272.                 fild    dword ptr [esp]
  1273.                 pop    eax
  1274.                 fmul    dword ptr [TSM_Flt00001]
  1275.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param2]
  1276.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas1]
  1277.                 push    eax
  1278.                 fild    dword ptr [esp]
  1279.                 pop    eax
  1280.                 fmul    dword ptr [TSM_Flt001]
  1281.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param1]
  1282. TSM_No_VCF_Pass_Filter:        dec    bl
  1283.                 dec    bl
  1284.                 jnz    TSM_No_Disto_Filter
  1285.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas3]
  1286.                 mov    ah,[edx + esi + TSM_SEQUENCE_DAT.DspDatas2]
  1287.                 push    eax
  1288.                 fild    dword ptr [esp]
  1289.                 pop    eax
  1290.                 fmul    dword ptr [TSM_Flt01]
  1291.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Disto_Param]
  1292. TSM_No_Disto_Filter:        dec    bl
  1293.                 jnz    TSM_No_DSP_Params
  1294.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas1]
  1295.                 cmp    eax,5
  1296.                 jb    TSM_Max_Formant_Filter
  1297.                 mov    eax,5
  1298. TSM_Max_Formant_Filter:        mov    [ebp + TSM_SEQUENCE.Formant_Param1],eax
  1299. TSM_No_DSP_Params:        cmp    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param1],0
  1300.                 je    TSM_No_Process_Lo_Pass
  1301.                 cmp    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param2],0
  1302.                 je    TSM_No_Process_Lo_Pass
  1303.                 fldpi
  1304.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param2]
  1305.                 fmul    dword ptr [TSM_Flt0000023]
  1306.                 fptan
  1307.                 fstp    st(0)
  1308.                 mov    edx,[ebp + TSM_SEQUENCE.Lo_Pass_In1]
  1309.                 mov    ecx,[ebp + TSM_SEQUENCE.Lo_Pass_Out1]
  1310.                 fld1
  1311.                 fld    st(0)
  1312.                 fdivrp    st(2),st(0)
  1313.                 fld    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Param1]
  1314.                 fmul    st(0),st(2)
  1315.                 fxch    st(2)
  1316.                 fmul    st(0),st(0)
  1317.                 fld    st(1)
  1318.                 fadd    st(0),st(3)
  1319.                 fadd    st(0),st(1)
  1320.                 fdivr    st(0),st(2)
  1321.                 fld    st(0)
  1322.                 fadd    st(0),st(0)
  1323.                 fld    st(3)
  1324.                 fsub    st(0),st(3)
  1325.                 fadd    st(0),st(0)
  1326.                 fmul    st(0),st(2)
  1327.                 fxch    st(4)
  1328.                 fsubrp    st(5),st(0)
  1329.                 fxch    st(2)
  1330.                 faddp    st(4),st(0)
  1331.                 fmul    st(3),st(0)
  1332.                 fld    st(0)
  1333.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1334.                 fxch    st(2)
  1335.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_In1]
  1336.                 faddp    st(2),st(0)
  1337.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_In2]
  1338.                 faddp    st(1),st(0)
  1339.                 fld    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Out1]
  1340.                 fchs
  1341.                 fmulp    st(2),st(0)
  1342.                 faddp    st(1),st(0)
  1343.                 fld    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Out2]
  1344.                 fchs
  1345.                 fmulp    st(2),st(0)
  1346.                 faddp    st(1),st(0)
  1347.                 mov    [ebp + TSM_SEQUENCE.Lo_Pass_In2],edx
  1348.                 fld    st(0)
  1349.                 mov    [ebp + TSM_SEQUENCE.Lo_Pass_Out2],ecx
  1350.                 push    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1351.                 pop    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_In1]
  1352.                 fxch    st(1)
  1353.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Lo_Pass_Out1]
  1354.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1355. TSM_No_Process_Lo_Pass:        cmp    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param1],0
  1356.                 je    TSM_No_Process_Hi_Pass
  1357.                 cmp    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param2],0
  1358.                 je    TSM_No_Process_Hi_Pass
  1359.                 fldpi
  1360.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param2]
  1361.                 fmul    dword ptr [TSM_Flt0000023]
  1362.                 fptan
  1363.                 fstp    st(0)
  1364.                 fld    st(0)
  1365.                 fmul    st(0),st(0)
  1366.                 fld1
  1367.                 fld    st(0)
  1368.                 fadd    st(0),st(2)
  1369.                 fld    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Param1]
  1370.                 fmulp    st(4),st(0)
  1371.                 fld    st(0)
  1372.                 fadd    st(0),st(4)
  1373.                 fdivp    st(2),st(0)
  1374.                 fxch    st(2)
  1375.                 fadd    dword ptr [TSM_Fltm1]
  1376.                 fld    dword ptr [TSM_Fltm2]
  1377.                 fmul    st(0),st(2)
  1378.                 fxch    st(1)
  1379.                 fadd    st(0),st(0)
  1380.                 fmul    st(0),st(2)
  1381.                 fxch    st(4)
  1382.                 fsubp    st(3),st(0)
  1383.                 fxch    st(1)
  1384.                 fmul    st(2),st(0)
  1385.                 mov    edx,[ebp + TSM_SEQUENCE.Hi_Pass_In1]
  1386.                 mov    ecx,[ebp + TSM_SEQUENCE.Hi_Pass_Out1]
  1387.                 fld    st(0)
  1388.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1389.                 fxch    st(2)
  1390.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_In1]
  1391.                 faddp    st(2),st(0)
  1392.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_In2]
  1393.                 faddp    st(1),st(0)
  1394.                 fld    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Out1]
  1395.                 fchs
  1396.                 fmulp    st(3),st(0)
  1397.                 faddp    st(2),st(0)
  1398.                 fld    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Out2]
  1399.                 fchs
  1400.                 fmulp    st(1),st(0)
  1401.                 faddp    st(1),st(0)
  1402.                 mov    [ebp + TSM_SEQUENCE.Hi_Pass_In2],edx
  1403.                 fld    st(0)
  1404.                 mov    [ebp + TSM_SEQUENCE.Hi_Pass_Out2],ecx
  1405.                 push    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1406.                 pop    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_In1]
  1407.                 fxch    st(1)
  1408.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Hi_Pass_Out1]
  1409.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1410. TSM_No_Process_Hi_Pass:        cmp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param1],0
  1411.                 je    TSM_No_Process_VCF_Pass
  1412.                 cmp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param2],0
  1413.                 je    TSM_No_Process_VCF_Pass
  1414.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param2]
  1415.                 fmul    dword ptr [TSM_Flt116]
  1416.                 fld1
  1417.                 fld    st(1)
  1418.                 fmul    st(0),st(0)
  1419.                 fld    dword ptr [TSM_Flt015]
  1420.                 fmul    st(0),st(3)
  1421.                 fmul    st(0),st(3)
  1422.                 fsubr    st(0),st(2)
  1423.                 fmul    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Param1]
  1424.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out4]
  1425.                 fld    st(0)
  1426.                 fchs
  1427.                 fmulp    st(2),st(0)
  1428.                 fxch    st(1)
  1429.                 fadd    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1430.                 fxch    st(3)
  1431.                 fsubrp    st(4),st(0)
  1432.                 fld    dword ptr [TSM_Flt035]
  1433.                 fmul    st(0),st(2)
  1434.                 fmulp    st(2),st(0)
  1435.                 fxch    st(1)
  1436.                 fmulp    st(2),st(0)
  1437.                 fld    st(2)
  1438.                 fld    dword ptr [TSM_Flt03]
  1439.                 fld    st(0)
  1440.                 fld    st(5)
  1441.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In1]
  1442.                 fmulp    st(2),st(0)
  1443.                 fxch    st(1)
  1444.                 fadd    st(0),st(5)
  1445.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out1]
  1446.                 fmulp    st(4),st(0)
  1447.                 faddp    st(3),st(0)
  1448.                 fxch    st(2) 
  1449.                 fst    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out1]
  1450.                 fld    st(1)
  1451.                 fxch    st(5)
  1452.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In1]
  1453.                 fld    st(5)
  1454.                 fxch    st(4)
  1455.                 fmulp    st(6),st(0)
  1456.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In2]
  1457.                 fmulp    st(5),st(0)
  1458.                 fadd    st(4),st(0)
  1459.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out2]
  1460.                 fmulp    st(3),st(0)
  1461.                 fxch    st(2)
  1462.                 faddp    st(4),st(0)
  1463.                 fxch    st(3)
  1464.                 fst    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out2]
  1465.                 fld    st(3)
  1466.                 fxch    st(2)
  1467.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In2]
  1468.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In3]
  1469.                 fmulp    st(2),st(0)
  1470.                 fadd    st(1),st(0)
  1471.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out3]
  1472.                 fmulp    st(3),st(0)
  1473.                 fxch    st(2)
  1474.                 faddp    st(1),st(0)
  1475.                 fst    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out3]
  1476.                 fxch    st(1)
  1477.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In3]
  1478.                 fld    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In4]
  1479.                 fmulp    st(2),st(0)
  1480.                 fadd    st(1),st(0)
  1481.                 fxch    st(2)
  1482.                 faddp    st(1),st(0)
  1483.                 fst    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_Out4]
  1484.                 fxch    st(1)
  1485.                 fstp    dword ptr [ebp + TSM_SEQUENCE.VCF_Pass_In4]
  1486.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1487. TSM_No_Process_VCF_Pass:    cmp    dword ptr [ebp + TSM_SEQUENCE.Disto_Param],0
  1488.                 je    TSM_No_Process_Disto
  1489.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1490.                 fabs
  1491.                 fst    qword ptr [ebp + TSM_SEQUENCE.Disto_Abs_Input]
  1492.                 fld1
  1493.                 fld    dword ptr [ebp + TSM_SEQUENCE.Disto_Param]
  1494.                 fld    st(0)
  1495.                 fadd    qword ptr [ebp + TSM_SEQUENCE.Disto_Abs_Input]
  1496.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1497.                 fmul    st(1),st(0)
  1498.                 fmul    st(0),st(0)
  1499.                 fadd    st(0),st(3)
  1500.                 fld    dword ptr [TSM_Fltm1]
  1501.                 faddp    st(3),st(0)
  1502.                 fxch    st(4)
  1503.                 fmulp    st(2),st(0)
  1504.                 fxch    st(1)
  1505.                 faddp    st(3),st(0)
  1506.                 fxch    st(1)
  1507.                 fdivrp    st(2),st(0)
  1508.                 fmulp    st(1),st(0)
  1509.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1510. TSM_No_Process_Disto:        mov    eax,[ebp + TSM_SEQUENCE.Formant_Param1]
  1511.                 test    eax,eax
  1512.                 jz    TSM_No_Process_Filters
  1513.                 dec    eax
  1514.                 imul    eax,eax,(11 * 8)
  1515.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 5)]
  1516.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 6)]
  1517.                 fld    qword ptr [eax + TSM_Formant_Coefficients]
  1518.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1519.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 1)]
  1520.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem]
  1521.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 2)]
  1522.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 1)]
  1523.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 3)]
  1524.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 2)]
  1525.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 4)]
  1526.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 3)]
  1527.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 7)]
  1528.                 fxch    st(6)
  1529.                 fst    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 7)]
  1530.                 fxch    st(7)
  1531.                 fst    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 6)]
  1532.                 fxch    st(4)
  1533.                 faddp    st(5),st(0)
  1534.                 fxch    st(2)
  1535.                 faddp    st(4),st(0)
  1536.                 faddp    st(3),st(0)
  1537.                 faddp    st(2),st(0)
  1538.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 5)]
  1539.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 4)]
  1540.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 6)]
  1541.                 fmulp    st(2),st(0)
  1542.                 faddp    st(1),st(0)
  1543.                 faddp    st(1),st(0)
  1544.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 7)]
  1545.                 fmulp    st(3),st(0)
  1546.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 8)]
  1547.                 fmul    st(0),st(2)
  1548.                 faddp    st(3),st(0)
  1549.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 9)]
  1550.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 8)]
  1551.                 fld    qword ptr [eax + TSM_Formant_Coefficients + (8 * 10)]
  1552.                 fmul    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 9)]
  1553.                 fxch    st(1)
  1554.                 fmul    st(2),st(0)
  1555.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 9)]
  1556.                 fxch    st(3)
  1557.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 8)]
  1558.                 faddp    st(2),st(0)
  1559.                 fxch    st(1)
  1560.                 faddp    st(2),st(0)
  1561.                 faddp    st(1),st(0)
  1562.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 4)]
  1563.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 5)]
  1564.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 3)]
  1565.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 4)]
  1566.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 2)]
  1567.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 3)]
  1568.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 1)]
  1569.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 2)]
  1570.                 fld    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem]
  1571.                 fstp    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem + (8 * 1)]
  1572.                 fst    qword ptr [ebp + TSM_SEQUENCE.Formant_Tmp_Mem]
  1573.                 fstp    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1574. TSM_No_Process_Filters:        pop    ecx
  1575.                 add    ebp,sizeof TSM_SEQUENCE
  1576.                 dec    ecx
  1577.                 jnz    TSM_Set_Song_Instruments
  1578.                 ; ----------------------------------
  1579.                 ; Split stereo signal now
  1580.                 xor    edx,edx
  1581.                 mov    ebp,[TSM_Sequences_Dats]
  1582.                 mov    ecx,8
  1583. TSM_Process_Effects:        push    edx
  1584.                 push    ecx
  1585.                 fld1
  1586.                 fsub    dword ptr [ebp + TSM_SEQUENCE.Pan]
  1587.                 fsqrt
  1588.                 fmul    dword ptr [ebp+TSM_SEQUENCE.Sound_Datas]
  1589.                 ; Store left signal
  1590.                 test    edx,edx
  1591.                 jz    TSM_Set_Left_Channel
  1592.                 fadd    dword ptr [edi]
  1593. TSM_Set_Left_Channel:        fstp    dword ptr [edi]
  1594.                 fld    dword ptr [ebp + TSM_SEQUENCE.Pan]
  1595.                 fsqrt
  1596.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1597.                 ; Store right signal
  1598.                 test    edx,edx
  1599.                 jz    TSM_Set_Right_Channel
  1600.                 fadd    dword ptr [edi + 4]
  1601. TSM_Set_Right_Channel:        fstp    dword ptr [edi + 4]
  1602.                 ; ----------------------------------
  1603.                 ; Process delay if necessary
  1604.                 mov    edx,[ebp + TSM_SEQUENCE.Current_Sequence]
  1605.                 test    edx,edx
  1606.                 jz    TSM_No_Delay_Dsp
  1607.                 mov    esi,[TSM_Cur_Play_Pos]
  1608.                 mov    bl,byte ptr [edx + esi + TSM_SEQUENCE_DAT.Dsp]
  1609.                 cmp    bl,TSM_DSP_DELAY
  1610.                 jne    TSM_No_Delay_Dsp
  1611.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas3]
  1612.                 push    eax
  1613.                 fild    dword ptr [esp]
  1614.                 fmul    dword ptr [TSM_Flt001]
  1615.                 fstp    dword ptr [esp]
  1616.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas2]
  1617.                 push    eax
  1618.                 fild    dword ptr [esp]
  1619.                 fmul    dword ptr [TSM_Flt001]
  1620.                 fstp    dword ptr [esp]
  1621.                 movzx    eax,byte ptr [edx + esi + TSM_SEQUENCE_DAT.DspDatas1]
  1622.                 push    eax
  1623.                 fild    dword ptr [esp]
  1624.                 fmul    dword ptr [TSM_Flt001]
  1625.                 fstp    dword ptr [esp]
  1626.                 push    ebp
  1627.                 call    TSM_Set_Delay
  1628. TSM_No_Delay_Dsp:        mov    eax,[ebp + TSM_SEQUENCE.Delay_Value]
  1629.                 test    eax,eax
  1630.                 jz    TSM_No_Delay
  1631.                 mov    eax,[ebp + TSM_SEQUENCE.Delay_Cursor]
  1632.                 mov    ebx,[ebp + TSM_SEQUENCE.Delay_Left_Buffer]
  1633.                 mov    ecx,edi
  1634.                 fld    dword ptr [ebx + eax * 4]
  1635.                 fadd    dword ptr [ecx]
  1636.                 fstp    dword ptr [ecx]
  1637.                 add    ecx,4
  1638.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1639.                 fadd    dword ptr [ebx + eax * 4]
  1640.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Delay_Left_FeedBack_Value]
  1641.                 fstp    dword ptr [ebx + eax * 4]
  1642.                 mov    eax,[ebp + TSM_SEQUENCE.Delay_Cursor]
  1643.                 mov    ebx,[ebp + TSM_SEQUENCE.Delay_Right_Buffer]
  1644.                 fld    dword ptr [ebx + eax * 4]
  1645.                 fadd    dword ptr [ecx]
  1646.                 fstp    dword ptr [ecx]
  1647.                 fld    dword ptr [ebp + TSM_SEQUENCE.Sound_Datas]
  1648.                 fadd    dword ptr [ebx + eax * 4]
  1649.                 fmul    dword ptr [ebp + TSM_SEQUENCE.Delay_Right_FeedBack_Value]
  1650.                 fstp    dword ptr [ebx + eax * 4]
  1651.                 inc    dword ptr [ebp + TSM_SEQUENCE.Delay_Cursor]
  1652.                 mov    eax,[ebp + TSM_SEQUENCE.Delay_Value]
  1653.                 cmp    [ebp + TSM_SEQUENCE.Delay_Cursor],eax
  1654.                 jl    TSM_No_Delay
  1655.                 mov    dword ptr [ebp + TSM_SEQUENCE.Delay_Cursor],0
  1656. TSM_No_Delay:            pop    ecx
  1657.                 pop    edx
  1658.                 mov    edx,1
  1659.                 add    ebp,sizeof TSM_SEQUENCE
  1660.                 dec    ecx
  1661.                 jnz    TSM_Process_Effects
  1662.                 add    edi,8
  1663.                 pop    edx
  1664.                 dec    edx
  1665.                 jmp    TSM_Mix_Loop
  1666. TSM_End_Mix_Loop:        pop    edi
  1667.                 ; ----------------------------------
  1668.                 ; Final mixing and conversion into 16 bits output
  1669.                 mov    edx,[TSM_BufferSize]
  1670.                 shr    edx,1
  1671.                 mov    esi,[TSM_Mixing_Buffer_Stereo]
  1672. TSM_Final_Mix_Loop:        test    edx,edx
  1673.                 jz    TSM_End_Final_Mix_Loop
  1674.                 lodsd
  1675.                 mov    [TSM_Final_Signal],eax
  1676.                 ; Clip sample
  1677.                 fld    dword ptr [TSM_Final_Signal]
  1678.                 fld1
  1679.                 fcom    st(1)
  1680.                 fnstsw    ax
  1681.                 sahf
  1682.                 jae    TSM_Min_Value
  1683.                 fst    dword ptr [TSM_Final_Signal]
  1684. TSM_Min_Value:            fstp    st(0)
  1685.                 fstp    st(0)
  1686.                 fld    dword ptr [TSM_Final_Signal]
  1687.                 fld    dword ptr [TSM_Fltm1]
  1688.                 fcom    st(1)
  1689.                 fnstsw    ax
  1690.                 sahf
  1691.                 jbe    TSM_Max_Value
  1692.                 fst    dword ptr [TSM_Final_Signal]
  1693. TSM_Max_Value:            fstp    st(0)
  1694.                 fstp    st(0)
  1695.                 fld    dword ptr [TSM_Final_Signal]
  1696.                 fmul    dword ptr [TSM_Flt32767]        ; Sign the sample
  1697.                 fistp    dword ptr [TSM_Final_Signal]
  1698.                 fstp    st(0)
  1699.                 mov    eax,[TSM_Final_Signal]
  1700.                 stosw
  1701.                 dec    edx
  1702.                 jmp    TSM_Final_Mix_Loop
  1703. TSM_End_Final_Mix_Loop:        pop    ebp
  1704.                 ret
  1705.  
  1706. ; ------------------------------------------------------
  1707. ; Name: TSM_Get_Instrument_Dat()
  1708. ; Desc: Retrieve the address of an instrument
  1709. TSM_Get_Instrument_Dat        PROC    TSM_Cur_Instrument:DWORD,TSM_Instr_Number:DWORD
  1710.                 mov    eax,[TSM_Cur_Instrument]
  1711.                 test    eax,eax
  1712.                 jz    TSM_Return_Dat
  1713.                 push    ebx
  1714.                 mov    ebx,[eax + 4]
  1715.                 cmp    [TSM_Instr_Number],ebx
  1716.                 jl    TSM_Max_Comb
  1717.                 pop    ebx
  1718.                 xor    eax,eax
  1719.                 ret
  1720. TSM_Max_Comb:            imul    ebx,[TSM_Instr_Number],sizeof TSM_INSTRUMENT_DAT
  1721.                 mov    eax,[eax]
  1722.                 add    eax,ebx            ; Offset to instrument's datas
  1723.                 pop    ebx
  1724. TSM_Return_Dat:            ret
  1725. TSM_Get_Instrument_Dat        ENDP
  1726.  
  1727. ; ------------------------------------------------------
  1728. ; Name: TSM_Wave_WhiteNoise()
  1729. ; Desc: Produce a whitenoise
  1730. TSM_Wave_WhiteNoise:        mov    eax,[TSM_Random_Seed]
  1731.                 inc    eax
  1732.                 imul    eax,01df5d45h
  1733.                 mov    [TSM_Random_Seed],eax
  1734.                 and    eax,0ffffh
  1735.                 sub    eax,08000h
  1736.                 push    eax
  1737.                 fild    dword ptr [esp]
  1738.                 pop    eax
  1739.                 fdiv    dword ptr [TSM_Flt32768]
  1740.                 ret
  1741.  
  1742. ; ------------------------------------------------------
  1743. ; Name: TSM_Get_Mix_Buffer_Len()
  1744. ; Desc: Convert a given BPM into ticks
  1745. TSM_Get_Mix_Buffer_Len        PROC    TSM_BPM:DWORD
  1746.                 push    ebx
  1747.                 push    edx
  1748.                 mov    eax,44100
  1749.                 mov    ebx,10
  1750.                 imul    eax,ebx
  1751.                 xor    edx,edx
  1752.                 mov    ebx,[TSM_BPM]
  1753.                 test    ebx,ebx
  1754.                 jz    TSM_ZeroBPM
  1755.                 idiv    ebx
  1756. TSM_ZeroBPM:            shr    eax,2
  1757.                 pop    edx
  1758.                 pop    ebx
  1759.                 ret
  1760. TSM_Get_Mix_Buffer_Len        ENDP
  1761.  
  1762. ; ------------------------------------------------------
  1763. ; Name: TSM_Set_Delay()
  1764. ; Desc: Set the delay effect values
  1765. TSM_Set_Delay            PROC    TSM_Sequence:DWORD,TSM_Delay_Distance:REAL4,TSM_Delay_Feedback:REAL4,TSM_Delay_Pan:REAL4
  1766.                 mov    eax,[TSM_Sequence]
  1767.                 fld    dword ptr [TSM_Delay_Distance]
  1768.                 fimul    dword ptr [TSM_Max_Buffer]
  1769.                 fistp    dword ptr [eax + TSM_SEQUENCE.Delay_Value]
  1770.                 fld1
  1771.                 fsub    dword ptr [TSM_Delay_Pan]
  1772.                 fsqrt
  1773.                 fmul    dword ptr [TSM_Delay_Feedback]
  1774.                 fstp    dword ptr [eax + TSM_SEQUENCE.Delay_Left_FeedBack_Value]
  1775.                 fld    dword ptr [TSM_Delay_Pan]
  1776.                 fsqrt
  1777.                 fmul    dword ptr [TSM_Delay_Feedback]
  1778.                 fstp    dword ptr [eax + TSM_SEQUENCE.Delay_Right_FeedBack_Value]
  1779.                 ret
  1780. TSM_Set_Delay            ENDP
  1781.  
  1782. ; ------------------------------------------------------
  1783. ; Name: TSM_Clamp_Value()
  1784. ; Desc: Clamp the a value between [0..1] 
  1785. TSM_Clamp_Value:        fcom    dword ptr [TSM_Flt1]
  1786.                 fnstsw    ax
  1787.                 sahf
  1788.                 jb    TSM_Clamp_Volume_Max
  1789.                 fstp    st(0)
  1790.                 fld1
  1791. TSM_Clamp_Volume_Max:        ftst
  1792.                 fnstsw    ax
  1793.                 sahf
  1794.                 ja    TSM_Clamp_Volume_Min
  1795.                 fsub    st(0),st(0)
  1796. TSM_Clamp_Volume_Min:        ret
  1797.  
  1798. end