MV_MIX16.ASM 18 KB

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