123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- .386
- .MODEL flat
- .data
- .code
- SEGMENT text USE32
- ALIGN 16
- EXTRN _MV_HarshClipTable:DWORD
- EXTRN _MV_MixDestination:DWORD
- EXTRN _MV_MixPosition:DWORD
- EXTRN _MV_LeftVolume:DWORD
- EXTRN _MV_RightVolume:DWORD
- ;================
- ;
- ; MV_Mix8BitMonoFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- MixBufferSize equ 256
- PROC MV_Mix8BitMonoFast_
- PUBLIC MV_Mix8BitMonoFast_
- ; Two at once
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume ; Since we're mono, use left volume
- mov eax,OFFSET apatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET apatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Harsh Clip table ptr
- mov ebx, _MV_HarshClipTable
- add ebx, 128
- mov eax,OFFSET apatch3+2 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET apatch4+2 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET apatch5+2 ; convice tasm to modify code...
- mov [eax],edx
- mov eax,OFFSET apatch6+2 ; convice tasm to modify code...
- mov [eax],edx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- shr ecx, 1 ; double sample count
- cmp ecx, 0
- je short exit8m
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; apatch1 - volume table
- ; apatch2 - volume table
- ; apatch3 - harsh clip table
- ; apatch4 - harsh clip table
- ; apatch5 - sample rate
- ; apatch6 - sample rate
- mov eax,ebp ; begin calculating first sample
- add ebp,edx ; advance frac pointer
- shr eax,16 ; finish calculation for first sample
- mov ebx,ebp ; begin calculating second sample
- add ebp,edx ; advance frac pointer
- shr ebx,16 ; finish calculation for second sample
- movzx eax, byte ptr [esi+eax] ; get first sample
- movzx ebx, byte ptr [esi+ebx] ; get second sample
- ALIGN 16
- mix8Mloop:
- movzx edx, byte ptr [edi] ; get current sample from destination
- apatch1:
- movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample
- apatch2:
- movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample
- add eax, edx ; mix first sample
- movzx edx, byte ptr [edi + 1] ; get current sample from destination
- apatch3:
- mov eax, [eax + 12345678h] ; harsh clip new sample
- add ebx, edx ; mix second sample
- mov [edi], al ; write new sample to destination
- mov edx, ebp ; begin calculating third sample
- apatch4:
- mov ebx, [ebx + 12345678h] ; harsh clip new sample
- apatch5:
- add ebp,12345678h ; advance frac pointer
- shr edx, 16 ; finish calculation for third sample
- mov eax, ebp ; begin calculating fourth sample
- inc edi ; move destination to second sample
- shr eax, 16 ; finish calculation for fourth sample
- mov [edi], bl ; write new sample to destination
- apatch6:
- add ebp,12345678h ; advance frac pointer
- movzx ebx, byte ptr [esi+eax] ; get fourth sample
- movzx eax, byte ptr [esi+edx] ; get third sample
- inc edi ; move destination to third sample
- dec ecx ; decrement count
- jnz mix8Mloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- exit8m:
- popad
- ret
- ENDP MV_Mix8BitMonoFast_
- ;================
- ;
- ; MV_Mix8BitStereoFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- PROC MV_Mix8BitStereoFast_
- PUBLIC MV_Mix8BitStereoFast_
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume
- mov eax,OFFSET bpatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov ebx, _MV_RightVolume
- mov eax,OFFSET bpatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET bpatch3+2 ; convice tasm to modify code...
- mov [eax],edx
- ; Harsh Clip table ptr
- mov ebx, _MV_HarshClipTable
- add ebx,128
- mov eax,OFFSET bpatch4+2 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET bpatch5+2 ; convice tasm to modify code...
- mov [eax],ebx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- cmp ecx, 0
- je short exit8S
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; bpatch1 - left volume table
- ; bpatch2 - right volume table
- ; bpatch3 - sample rate
- ; bpatch4 - harsh clip table
- ; bpatch5 - harsh clip table
- mov eax,ebp ; begin calculating first sample
- shr eax,16 ; finish calculation for first sample
- movzx ebx, byte ptr [esi+eax] ; get first sample
- ALIGN 16
- mix8Sloop:
- bpatch1:
- movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample
- movzx edx, byte ptr [edi] ; get current sample from destination
- bpatch2:
- movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample
- add eax, edx ; mix left sample
- bpatch3:
- add ebp,12345678h ; advance frac pointer
- movzx edx, byte ptr [edi+1] ; get current sample from destination
- bpatch4:
- mov eax, [eax + 12345678h] ; harsh clip left sample
- add ebx, edx ; mix right sample
- mov [edi], al ; write left sample to destination
- bpatch5:
- mov ebx, [ebx + 12345678h] ; harsh clip right sample
- inc edi ; move destination to second sample
- mov edx, ebp ; begin calculating second sample
- mov [edi], bl ; write right sample to destination
- shr edx, 16 ; finish calculation for second sample
- inc edi ; move destination to second sample
- movzx ebx, byte ptr [esi+edx] ; get second sample
- dec ecx ; decrement count
- jnz mix8Sloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- EXIT8S:
- popad
- ret
- ENDP MV_Mix8BitStereoFast_
- ;================
- ;
- ; MV_Mix8Bit1ChannelFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- PROC MV_Mix8Bit1ChannelFast_
- PUBLIC MV_Mix8Bit1ChannelFast_
- ; Two at once
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume
- mov eax,OFFSET epatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET epatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Harsh Clip table ptr
- mov ebx, _MV_HarshClipTable
- add ebx,128
- mov eax,OFFSET epatch3+2 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET epatch4+2 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET epatch5+2 ; convice tasm to modify code...
- mov [eax],edx
- mov eax,OFFSET epatch6+2 ; convice tasm to modify code...
- mov [eax],edx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- shr ecx, 1 ; double sample count
- cmp ecx, 0
- je exit81C
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; apatch1 - volume table
- ; apatch2 - volume table
- ; apatch3 - harsh clip table
- ; apatch4 - harsh clip table
- ; apatch5 - sample rate
- ; apatch6 - sample rate
- mov eax,ebp ; begin calculating first sample
- add ebp,edx ; advance frac pointer
- shr eax,16 ; finish calculation for first sample
- mov ebx,ebp ; begin calculating second sample
- add ebp,edx ; advance frac pointer
- shr ebx,16 ; finish calculation for second sample
- movzx eax, byte ptr [esi+eax] ; get first sample
- movzx ebx, byte ptr [esi+ebx] ; get second sample
- ALIGN 16
- mix81Cloop:
- movzx edx, byte ptr [edi] ; get current sample from destination
- epatch1:
- movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample
- epatch2:
- movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample
- add eax, edx ; mix first sample
- movzx edx, byte ptr [edi + 2] ; get current sample from destination
- epatch3:
- mov eax, [eax + 12345678h] ; harsh clip new sample
- add ebx, edx ; mix second sample
- mov [edi], al ; write new sample to destination
- mov edx, ebp ; begin calculating third sample
- epatch4:
- mov ebx, [ebx + 12345678h] ; harsh clip new sample
- epatch5:
- add ebp,12345678h ; advance frac pointer
- shr edx, 16 ; finish calculation for third sample
- mov eax, ebp ; begin calculating fourth sample
- add edi, 2 ; move destination to second sample
- shr eax, 16 ; finish calculation for fourth sample
- mov [edi], bl ; write new sample to destination
- epatch6:
- add ebp,12345678h ; advance frac pointer
- movzx ebx, byte ptr [esi+eax] ; get fourth sample
- movzx eax, byte ptr [esi+edx] ; get third sample
- add edi, 2 ; move destination to third sample
- dec ecx ; decrement count
- jnz mix81Cloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- EXIT81C:
- popad
- ret
- ENDP MV_Mix8Bit1ChannelFast_
- ;================
- ;
- ; MV_Mix16BitMonoFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- MixBufferSize equ 256
- PROC MV_Mix16BitMonoFast_
- PUBLIC MV_Mix16BitMonoFast_
- ; Two at once
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume
- mov eax,OFFSET cpatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET cpatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET cpatch3+2 ; convice tasm to modify code...
- mov [eax],edx
- mov eax,OFFSET cpatch4+2 ; convice tasm to modify code...
- mov [eax],edx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- shr ecx, 1 ; double sample count
- cmp ecx, 0
- je exit16M
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; cpatch1 - volume table
- ; cpatch2 - volume table
- ; cpatch3 - sample rate
- ; cpatch4 - sample rate
- mov eax,ebp ; begin calculating first sample
- add ebp,edx ; advance frac pointer
- shr eax,16 ; finish calculation for first sample
- mov ebx,ebp ; begin calculating second sample
- add ebp,edx ; advance frac pointer
- shr ebx,16 ; finish calculation for second sample
- movzx eax, byte ptr [esi+eax] ; get first sample
- movzx ebx, byte ptr [esi+ebx] ; get second sample
- ALIGN 16
- mix16Mloop:
- movsx edx, word ptr [edi] ; get current sample from destination
- cpatch1:
- movsx eax, word ptr [2*eax+12345678h] ; volume translate first sample
- cpatch2:
- movsx ebx, word ptr [2*ebx+12345678h] ; volume translate second sample
- add eax, edx ; mix first sample
- movsx edx, word ptr [edi + 2] ; get current sample from destination
- cmp eax, -32768 ; Harsh clip sample
- jge short m16skip1
- mov eax, -32768
- jmp short m16skip2
- m16skip1:
- cmp eax, 32767
- jle short m16skip2
- mov eax, 32767
- m16skip2:
- add ebx, edx ; mix second sample
- mov [edi], ax ; write new sample to destination
- mov edx, ebp ; begin calculating third sample
- cmp ebx, -32768 ; Harsh clip sample
- jge short m16skip3
- mov ebx, -32768
- jmp short m16skip4
- m16skip3:
- cmp ebx, 32767
- jle short m16skip4
- mov ebx, 32767
- m16skip4:
- cpatch3:
- add ebp,12345678h ; advance frac pointer
- shr edx, 16 ; finish calculation for third sample
- mov eax, ebp ; begin calculating fourth sample
- mov [edi + 2], bx ; write new sample to destination
- shr eax, 16 ; finish calculation for fourth sample
- cpatch4:
- add ebp,12345678h ; advance frac pointer
- movzx ebx, byte ptr [esi+eax] ; get fourth sample
- add edi, 4 ; move destination to third sample
- movzx eax, byte ptr [esi+edx] ; get third sample
- dec ecx ; decrement count
- jnz mix16Mloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- EXIT16M:
- popad
- ret
- ENDP MV_Mix16BitMonoFast_
- ;================
- ;
- ; MV_Mix16BitStereoFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- PROC MV_Mix16BitStereoFast_
- PUBLIC MV_Mix16BitStereoFast_
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume
- mov eax,OFFSET dpatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov ebx, _MV_RightVolume
- mov eax,OFFSET dpatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET dpatch3+2 ; convice tasm to modify code...
- mov [eax],edx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- cmp ecx, 0
- je exit16S
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; dpatch1 - left volume table
- ; dpatch2 - right volume table
- ; dpatch3 - sample rate
- mov eax,ebp ; begin calculating first sample
- shr eax,16 ; finish calculation for first sample
- movzx ebx, byte ptr [esi+eax] ; get first sample
- ALIGN 16
- mix16Sloop:
- dpatch1:
- movsx eax, word ptr [2*ebx+12345678h] ; volume translate left sample
- movsx edx, word ptr [edi] ; get current sample from destination
- dpatch2:
- movsx ebx, word ptr [2*ebx+12345678h] ; volume translate right sample
- add eax, edx ; mix left sample
- dpatch3:
- add ebp,12345678h ; advance frac pointer
- movsx edx, word ptr [edi+2] ; get current sample from destination
- cmp eax, -32768 ; Harsh clip sample
- jge short s16skip1
- mov eax, -32768
- jmp short s16skip2
- s16skip1:
- cmp eax, 32767
- jle short s16skip2
- mov eax, 32767
- s16skip2:
- add ebx, edx ; mix right sample
- mov [edi], ax ; write left sample to destination
- cmp ebx, -32768 ; Harsh clip sample
- jge short s16skip3
- mov ebx, -32768
- jmp short s16skip4
- s16skip3:
- cmp ebx, 32767
- jle short s16skip4
- mov ebx, 32767
- s16skip4:
- mov edx, ebp ; begin calculating second sample
- mov [edi+2], bx ; write right sample to destination
- shr edx, 16 ; finish calculation for second sample
- add edi, 4 ; move destination to second sample
- movzx ebx, byte ptr [esi+edx] ; get second sample
- dec ecx ; decrement count
- jnz mix16Sloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- exit16S:
- popad
- ret
- ENDP MV_Mix16BitStereoFast_
- ;================
- ;
- ; MV_Mix16Bit1ChannelFast
- ;
- ;================
- ; eax - position
- ; edx - rate
- ; ebx - start
- ; ecx - number of samples to mix
- MixBufferSize equ 256
- PROC MV_Mix16Bit1ChannelFast_
- PUBLIC MV_Mix16Bit1ChannelFast_
- ; Two at once
- pushad
- mov ebp, eax
- mov esi, ebx ; Source pointer
- ; Volume table ptr
- mov ebx, _MV_LeftVolume
- mov eax,OFFSET fpatch1+4 ; convice tasm to modify code...
- mov [eax],ebx
- mov eax,OFFSET fpatch2+4 ; convice tasm to modify code...
- mov [eax],ebx
- ; Rate scale ptr
- mov eax,OFFSET fpatch3+2 ; convice tasm to modify code...
- mov [eax],edx
- mov eax,OFFSET fpatch4+2 ; convice tasm to modify code...
- mov [eax],edx
- mov edi, _MV_MixDestination ; Get the position to write to
- ; Number of samples to mix
- shr ecx, 1 ; double sample count
- cmp ecx, 0
- je exit161C
- ; eax - scratch
- ; ebx - scratch
- ; edx - scratch
- ; ecx - count
- ; edi - destination
- ; esi - source
- ; ebp - frac pointer
- ; cpatch1 - volume table
- ; cpatch2 - volume table
- ; cpatch3 - sample rate
- ; cpatch4 - sample rate
- mov eax,ebp ; begin calculating first sample
- add ebp,edx ; advance frac pointer
- shr eax,16 ; finish calculation for first sample
- mov ebx,ebp ; begin calculating second sample
- add ebp,edx ; advance frac pointer
- shr ebx,16 ; finish calculation for second sample
- movzx eax, byte ptr [esi+eax] ; get first sample
- movzx ebx, byte ptr [esi+ebx] ; get second sample
- ALIGN 16
- mix161Cloop:
- movsx edx, word ptr [edi] ; get current sample from destination
- fpatch1:
- movsx eax, word ptr [2*eax+12345678h] ; volume translate first sample
- fpatch2:
- movsx ebx, word ptr [2*ebx+12345678h] ; volume translate second sample
- add eax, edx ; mix first sample
- movsx edx, word ptr [edi + 4] ; get current sample from destination
- cmp eax, -32768 ; Harsh clip sample
- jge short m16c1skip1
- mov eax, -32768
- jmp short m16c1skip2
- m16c1skip1:
- cmp eax, 32767
- jle short m16c1skip2
- mov eax, 32767
- m16c1skip2:
- add ebx, edx ; mix second sample
- mov [edi], ax ; write new sample to destination
- mov edx, ebp ; begin calculating third sample
- cmp ebx, -32768 ; Harsh clip sample
- jge short m16c1skip3
- mov ebx, -32768
- jmp short m16c1skip4
- m16c1skip3:
- cmp ebx, 32767
- jle short m16c1skip4
- mov ebx, 32767
- m16c1skip4:
- fpatch3:
- add ebp,12345678h ; advance frac pointer
- shr edx, 16 ; finish calculation for third sample
- mov eax, ebp ; begin calculating fourth sample
- mov [edi + 4], bx ; write new sample to destination
- shr eax, 16 ; finish calculation for fourth sample
- fpatch4:
- add ebp,12345678h ; advance frac pointer
- movzx ebx, byte ptr [esi+eax] ; get fourth sample
- add edi, 8 ; move destination to third sample
- movzx eax, byte ptr [esi+edx] ; get third sample
- dec ecx ; decrement count
- jnz mix161Cloop ; loop
- mov _MV_MixDestination, edi ; Store the current write position
- mov _MV_MixPosition, ebp ; return position
- exit161C:
- popad
- ret
- ENDP MV_Mix16Bit1ChannelFast_
- ENDS
- END
|