MV_MIX.ASM 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. IDEAL
  2. p386
  3. MODEL flat
  4. dataseg
  5. CODESEG
  6. MASM
  7. ALIGN 4
  8. EXTRN _MV_HarshClipTable:DWORD
  9. EXTRN _MV_MixDestination:DWORD
  10. EXTRN _MV_MixPosition:DWORD
  11. EXTRN _MV_LeftVolume:DWORD
  12. EXTRN _MV_RightVolume:DWORD
  13. EXTRN _MV_SampleSize:DWORD
  14. EXTRN _MV_RightChannelOffset:DWORD
  15. ;================
  16. ;
  17. ; MV_Mix8BitMono
  18. ;
  19. ;================
  20. ; eax - position
  21. ; edx - rate
  22. ; ebx - start
  23. ; ecx - number of samples to mix
  24. PROC MV_Mix8BitMono_
  25. PUBLIC MV_Mix8BitMono_
  26. ; Two at once
  27. pushad
  28. mov ebp, eax
  29. mov esi, ebx ; Source pointer
  30. ; Sample size
  31. mov ebx, _MV_SampleSize
  32. mov eax,OFFSET apatch7+2 ; convice tasm to modify code...
  33. mov [eax],bl
  34. mov eax,OFFSET apatch8+2 ; convice tasm to modify code...
  35. mov [eax],bl
  36. mov eax,OFFSET apatch9+3 ; convice tasm to modify code...
  37. mov [eax],bl
  38. ; Volume table ptr
  39. mov ebx, _MV_LeftVolume ; Since we're mono, use left volume
  40. mov eax,OFFSET apatch1+4 ; convice tasm to modify code...
  41. mov [eax],ebx
  42. mov eax,OFFSET apatch2+4 ; convice tasm to modify code...
  43. mov [eax],ebx
  44. ; Harsh Clip table ptr
  45. mov ebx, _MV_HarshClipTable
  46. add ebx, 128
  47. mov eax,OFFSET apatch3+2 ; convice tasm to modify code...
  48. mov [eax],ebx
  49. mov eax,OFFSET apatch4+2 ; convice tasm to modify code...
  50. mov [eax],ebx
  51. ; Rate scale ptr
  52. mov eax,OFFSET apatch5+2 ; convice tasm to modify code...
  53. mov [eax],edx
  54. mov eax,OFFSET apatch6+2 ; convice tasm to modify code...
  55. mov [eax],edx
  56. mov edi, _MV_MixDestination ; Get the position to write to
  57. ; Number of samples to mix
  58. shr ecx, 1 ; double sample count
  59. cmp ecx, 0
  60. je short exit8m
  61. ; eax - scratch
  62. ; ebx - scratch
  63. ; edx - scratch
  64. ; ecx - count
  65. ; edi - destination
  66. ; esi - source
  67. ; ebp - frac pointer
  68. ; apatch1 - volume table
  69. ; apatch2 - volume table
  70. ; apatch3 - harsh clip table
  71. ; apatch4 - harsh clip table
  72. ; apatch5 - sample rate
  73. ; apatch6 - sample rate
  74. mov eax,ebp ; begin calculating first sample
  75. add ebp,edx ; advance frac pointer
  76. shr eax,16 ; finish calculation for first sample
  77. mov ebx,ebp ; begin calculating second sample
  78. add ebp,edx ; advance frac pointer
  79. shr ebx,16 ; finish calculation for second sample
  80. movzx eax, byte ptr [esi+eax] ; get first sample
  81. movzx ebx, byte ptr [esi+ebx] ; get second sample
  82. ALIGN 4
  83. mix8Mloop:
  84. movzx edx, byte ptr [edi] ; get current sample from destination
  85. apatch1:
  86. movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample
  87. apatch2:
  88. movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample
  89. add eax, edx ; mix first sample
  90. apatch9:
  91. movzx edx, byte ptr [edi + 1] ; get current sample from destination
  92. apatch3:
  93. mov eax, [eax + 12345678h] ; harsh clip new sample
  94. add ebx, edx ; mix second sample
  95. mov [edi], al ; write new sample to destination
  96. mov edx, ebp ; begin calculating third sample
  97. apatch4:
  98. mov ebx, [ebx + 12345678h] ; harsh clip new sample
  99. apatch5:
  100. add ebp,12345678h ; advance frac pointer
  101. shr edx, 16 ; finish calculation for third sample
  102. mov eax, ebp ; begin calculating fourth sample
  103. apatch7:
  104. add edi, 1 ; move destination to second sample
  105. shr eax, 16 ; finish calculation for fourth sample
  106. mov [edi], bl ; write new sample to destination
  107. apatch6:
  108. add ebp,12345678h ; advance frac pointer
  109. movzx ebx, byte ptr [esi+eax] ; get fourth sample
  110. movzx eax, byte ptr [esi+edx] ; get third sample
  111. apatch8:
  112. add edi, 2 ; move destination to third sample
  113. dec ecx ; decrement count
  114. jnz mix8Mloop ; loop
  115. mov _MV_MixDestination, edi ; Store the current write position
  116. mov _MV_MixPosition, ebp ; return position
  117. exit8m:
  118. popad
  119. ret
  120. ENDP MV_Mix8BitMono_
  121. ;================
  122. ;
  123. ; MV_Mix8BitStereo
  124. ;
  125. ;================
  126. ; eax - position
  127. ; edx - rate
  128. ; ebx - start
  129. ; ecx - number of samples to mix
  130. PROC MV_Mix8BitStereo_
  131. PUBLIC MV_Mix8BitStereo_
  132. pushad
  133. mov ebp, eax
  134. mov esi, ebx ; Source pointer
  135. ; Sample size
  136. mov ebx, _MV_SampleSize
  137. mov eax,OFFSET bpatch8+2 ; convice tasm to modify code...
  138. mov [eax],bl
  139. ; Right channel offset
  140. mov ebx, _MV_RightChannelOffset
  141. mov eax,OFFSET bpatch6+3 ; convice tasm to modify code...
  142. mov [eax],ebx
  143. mov eax,OFFSET bpatch7+2 ; convice tasm to modify code...
  144. mov [eax],ebx
  145. ; Volume table ptr
  146. mov ebx, _MV_LeftVolume
  147. mov eax,OFFSET bpatch1+4 ; convice tasm to modify code...
  148. mov [eax],ebx
  149. mov ebx, _MV_RightVolume
  150. mov eax,OFFSET bpatch2+4 ; convice tasm to modify code...
  151. mov [eax],ebx
  152. ; Rate scale ptr
  153. mov eax,OFFSET bpatch3+2 ; convice tasm to modify code...
  154. mov [eax],edx
  155. ; Harsh Clip table ptr
  156. mov ebx, _MV_HarshClipTable
  157. add ebx,128
  158. mov eax,OFFSET bpatch4+2 ; convice tasm to modify code...
  159. mov [eax],ebx
  160. mov eax,OFFSET bpatch5+2 ; convice tasm to modify code...
  161. mov [eax],ebx
  162. mov edi, _MV_MixDestination ; Get the position to write to
  163. ; Number of samples to mix
  164. cmp ecx, 0
  165. je short exit8S
  166. ; eax - scratch
  167. ; ebx - scratch
  168. ; edx - scratch
  169. ; ecx - count
  170. ; edi - destination
  171. ; esi - source
  172. ; ebp - frac pointer
  173. ; bpatch1 - left volume table
  174. ; bpatch2 - right volume table
  175. ; bpatch3 - sample rate
  176. ; bpatch4 - harsh clip table
  177. ; bpatch5 - harsh clip table
  178. mov eax,ebp ; begin calculating first sample
  179. shr eax,16 ; finish calculation for first sample
  180. movzx ebx, byte ptr [esi+eax] ; get first sample
  181. ALIGN 4
  182. mix8Sloop:
  183. bpatch1:
  184. movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample
  185. movzx edx, byte ptr [edi] ; get current sample from destination
  186. bpatch2:
  187. movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample
  188. add eax, edx ; mix left sample
  189. bpatch3:
  190. add ebp,12345678h ; advance frac pointer
  191. bpatch6:
  192. movzx edx, byte ptr [edi+12345678h] ; get current sample from destination
  193. bpatch4:
  194. mov eax, [eax + 12345678h] ; harsh clip left sample
  195. add ebx, edx ; mix right sample
  196. mov [edi], al ; write left sample to destination
  197. bpatch5:
  198. mov ebx, [ebx + 12345678h] ; harsh clip right sample
  199. mov edx, ebp ; begin calculating second sample
  200. bpatch7:
  201. mov [edi+12345678h], bl ; write right sample to destination
  202. shr edx, 16 ; finish calculation for second sample
  203. bpatch8:
  204. add edi, 2 ; move destination to second sample
  205. movzx ebx, byte ptr [esi+edx] ; get second sample
  206. dec ecx ; decrement count
  207. jnz mix8Sloop ; loop
  208. mov _MV_MixDestination, edi ; Store the current write position
  209. mov _MV_MixPosition, ebp ; return position
  210. EXIT8S:
  211. popad
  212. ret
  213. ENDP MV_Mix8BitStereo_
  214. ;================
  215. ;
  216. ; MV_Mix16BitMono
  217. ;
  218. ;================
  219. ; eax - position
  220. ; edx - rate
  221. ; ebx - start
  222. ; ecx - number of samples to mix
  223. PROC MV_Mix16BitMono_
  224. PUBLIC MV_Mix16BitMono_
  225. ; Two at once
  226. pushad
  227. mov ebp, eax
  228. mov esi, ebx ; Source pointer
  229. ; Sample size
  230. mov ebx, _MV_SampleSize
  231. mov eax,OFFSET cpatch5+3 ; convice tasm to modify code...
  232. mov [eax],bl
  233. mov eax,OFFSET cpatch6+3 ; convice tasm to modify code...
  234. mov [eax],bl
  235. mov eax,OFFSET cpatch7+2 ; convice tasm to modify code...
  236. add bl,bl
  237. mov [eax],bl
  238. ; Volume table ptr
  239. mov ebx, _MV_LeftVolume
  240. mov eax,OFFSET cpatch1+4 ; convice tasm to modify code...
  241. mov [eax],ebx
  242. mov eax,OFFSET cpatch2+4 ; convice tasm to modify code...
  243. mov [eax],ebx
  244. ; Rate scale ptr
  245. mov eax,OFFSET cpatch3+2 ; convice tasm to modify code...
  246. mov [eax],edx
  247. mov eax,OFFSET cpatch4+2 ; convice tasm to modify code...
  248. mov [eax],edx
  249. mov edi, _MV_MixDestination ; Get the position to write to
  250. ; Number of samples to mix
  251. shr ecx, 1 ; double sample count
  252. cmp ecx, 0
  253. je exit16M
  254. ; eax - scratch
  255. ; ebx - scratch
  256. ; edx - scratch
  257. ; ecx - count
  258. ; edi - destination
  259. ; esi - source
  260. ; ebp - frac pointer
  261. ; cpatch1 - volume table
  262. ; cpatch2 - volume table
  263. ; cpatch3 - sample rate
  264. ; cpatch4 - sample rate
  265. mov eax,ebp ; begin calculating first sample
  266. add ebp,edx ; advance frac pointer
  267. shr eax,16 ; finish calculation for first sample
  268. mov ebx,ebp ; begin calculating second sample
  269. add ebp,edx ; advance frac pointer
  270. shr ebx,16 ; finish calculation for second sample
  271. movzx eax, byte ptr [esi+eax] ; get first sample
  272. movzx ebx, byte ptr [esi+ebx] ; get second sample
  273. ALIGN 4
  274. mix16Mloop:
  275. movsx edx, word ptr [edi] ; get current sample from destination
  276. cpatch1:
  277. movsx eax, word ptr [2*eax+12345678h] ; volume translate first sample
  278. cpatch2:
  279. movsx ebx, word ptr [2*ebx+12345678h] ; volume translate second sample
  280. add eax, edx ; mix first sample
  281. cpatch5:
  282. movsx edx, word ptr [edi + 2] ; get current sample from destination
  283. cmp eax, -32768 ; Harsh clip sample
  284. jge short m16skip1
  285. mov eax, -32768
  286. jmp short m16skip2
  287. m16skip1:
  288. cmp eax, 32767
  289. jle short m16skip2
  290. mov eax, 32767
  291. m16skip2:
  292. add ebx, edx ; mix second sample
  293. mov [edi], ax ; write new sample to destination
  294. mov edx, ebp ; begin calculating third sample
  295. cmp ebx, -32768 ; Harsh clip sample
  296. jge short m16skip3
  297. mov ebx, -32768
  298. jmp short m16skip4
  299. m16skip3:
  300. cmp ebx, 32767
  301. jle short m16skip4
  302. mov ebx, 32767
  303. m16skip4:
  304. cpatch3:
  305. add ebp,12345678h ; advance frac pointer
  306. shr edx, 16 ; finish calculation for third sample
  307. mov eax, ebp ; begin calculating fourth sample
  308. cpatch6:
  309. mov [edi + 2], bx ; write new sample to destination
  310. shr eax, 16 ; finish calculation for fourth sample
  311. cpatch4:
  312. add ebp,12345678h ; advance frac pointer
  313. movzx ebx, byte ptr [esi+eax] ; get fourth sample
  314. cpatch7:
  315. add edi, 4 ; move destination to third sample
  316. movzx eax, byte ptr [esi+edx] ; get third sample
  317. dec ecx ; decrement count
  318. jnz mix16Mloop ; loop
  319. mov _MV_MixDestination, edi ; Store the current write position
  320. mov _MV_MixPosition, ebp ; return position
  321. EXIT16M:
  322. popad
  323. ret
  324. ENDP MV_Mix16BitMono_
  325. ;================
  326. ;
  327. ; MV_Mix16BitStereo
  328. ;
  329. ;================
  330. ; eax - position
  331. ; edx - rate
  332. ; ebx - start
  333. ; ecx - number of samples to mix
  334. PROC MV_Mix16BitStereo_
  335. PUBLIC MV_Mix16BitStereo_
  336. pushad
  337. mov ebp, eax
  338. mov esi, ebx ; Source pointer
  339. ; Sample size
  340. mov ebx, _MV_SampleSize
  341. mov eax,OFFSET dpatch6+2 ; convice tasm to modify code...
  342. mov [eax],bl
  343. ; Right channel offset
  344. mov ebx, _MV_RightChannelOffset
  345. mov eax,OFFSET dpatch4+3 ; convice tasm to modify code...
  346. mov [eax],ebx
  347. mov eax,OFFSET dpatch5+3 ; convice tasm to modify code...
  348. mov [eax],ebx
  349. ; Volume table ptr
  350. mov ebx, _MV_LeftVolume
  351. mov eax,OFFSET dpatch1+4 ; convice tasm to modify code...
  352. mov [eax],ebx
  353. mov ebx, _MV_RightVolume
  354. mov eax,OFFSET dpatch2+4 ; convice tasm to modify code...
  355. mov [eax],ebx
  356. ; Rate scale ptr
  357. mov eax,OFFSET dpatch3+2 ; convice tasm to modify code...
  358. mov [eax],edx
  359. mov edi, _MV_MixDestination ; Get the position to write to
  360. ; Number of samples to mix
  361. cmp ecx, 0
  362. je exit16S
  363. ; eax - scratch
  364. ; ebx - scratch
  365. ; edx - scratch
  366. ; ecx - count
  367. ; edi - destination
  368. ; esi - source
  369. ; ebp - frac pointer
  370. ; dpatch1 - left volume table
  371. ; dpatch2 - right volume table
  372. ; dpatch3 - sample rate
  373. mov eax,ebp ; begin calculating first sample
  374. shr eax,16 ; finish calculation for first sample
  375. movzx ebx, byte ptr [esi+eax] ; get first sample
  376. ALIGN 4
  377. mix16Sloop:
  378. dpatch1:
  379. movsx eax, word ptr [2*ebx+12345678h] ; volume translate left sample
  380. movsx edx, word ptr [edi] ; get current sample from destination
  381. dpatch2:
  382. movsx ebx, word ptr [2*ebx+12345678h] ; volume translate right sample
  383. add eax, edx ; mix left sample
  384. dpatch3:
  385. add ebp,12345678h ; advance frac pointer
  386. dpatch4:
  387. movsx edx, word ptr [edi+12345678h] ; get current sample from destination
  388. cmp eax, -32768 ; Harsh clip sample
  389. jge short s16skip1
  390. mov eax, -32768
  391. jmp short s16skip2
  392. s16skip1:
  393. cmp eax, 32767
  394. jle short s16skip2
  395. mov eax, 32767
  396. s16skip2:
  397. add ebx, edx ; mix right sample
  398. mov [edi], ax ; write left sample to destination
  399. cmp ebx, -32768 ; Harsh clip sample
  400. jge short s16skip3
  401. mov ebx, -32768
  402. jmp short s16skip4
  403. s16skip3:
  404. cmp ebx, 32767
  405. jle short s16skip4
  406. mov ebx, 32767
  407. s16skip4:
  408. mov edx, ebp ; begin calculating second sample
  409. dpatch5:
  410. mov [edi+12345678h], bx ; write right sample to destination
  411. shr edx, 16 ; finish calculation for second sample
  412. dpatch6:
  413. add edi, 4 ; move destination to second sample
  414. movzx ebx, byte ptr [esi+edx] ; get second sample
  415. dec ecx ; decrement count
  416. jnz mix16Sloop ; loop
  417. mov _MV_MixDestination, edi ; Store the current write position
  418. mov _MV_MixPosition, ebp ; return position
  419. exit16S:
  420. popad
  421. ret
  422. ENDP MV_Mix16BitStereo_
  423. ENDS
  424. END