| 1 |
#include "pa_x86_plain_converters.h" |
| 2 |
|
| 3 |
#include "pa_converters.h" |
| 4 |
#include "pa_dither.h" |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static const short fpuControlWord_ = 0x033F; |
| 81 |
static const double int32Scaler_ = 0x7FFFFFFF; |
| 82 |
static const double ditheredInt32Scaler_ = 0x7FFFFFFE; |
| 83 |
static const double int24Scaler_ = 0x7FFFFF; |
| 84 |
static const double ditheredInt24Scaler_ = 0x7FFFFE; |
| 85 |
static const double int16Scaler_ = 0x7FFF; |
| 86 |
static const double ditheredInt16Scaler_ = 0x7FFE; |
| 87 |
|
| 88 |
#define PA_DITHER_BITS_ (15) |
| 89 |
|
| 90 |
#define PA_FLOAT_DITHER_SCALE_ (1.0 / ((1<<PA_DITHER_BITS_)-1)) |
| 91 |
static const float const_float_dither_scale_ = PA_FLOAT_DITHER_SCALE_; |
| 92 |
#define PA_DITHER_SHIFT_ ((32 - PA_DITHER_BITS_) + 1) |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static void Float32_To_Int32( |
| 97 |
void *destinationBuffer, signed int destinationStride, |
| 98 |
void *sourceBuffer, signed int sourceStride, |
| 99 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 100 |
{ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
short savedFpuControlWord; |
| 118 |
|
| 119 |
(void) ditherGenerator; |
| 120 |
|
| 121 |
|
| 122 |
__asm{ |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
mov esi, sourceBuffer |
| 131 |
|
| 132 |
mov edx, 4 |
| 133 |
mov eax, sourceStride |
| 134 |
imul eax, edx |
| 135 |
|
| 136 |
mov ecx, count |
| 137 |
imul ecx, eax |
| 138 |
add ecx, esi |
| 139 |
|
| 140 |
mov edi, destinationBuffer |
| 141 |
|
| 142 |
mov ebx, destinationStride |
| 143 |
imul ebx, edx |
| 144 |
|
| 145 |
fwait |
| 146 |
fstcw savedFpuControlWord |
| 147 |
fldcw fpuControlWord_ |
| 148 |
|
| 149 |
fld int32Scaler_ |
| 150 |
|
| 151 |
Float32_To_Int32_loop: |
| 152 |
|
| 153 |
|
| 154 |
fld dword ptr [esi] |
| 155 |
add esi, eax |
| 156 |
|
| 157 |
fmul st(0), st(1) |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
fistp dword ptr [edi] |
| 165 |
|
| 166 |
add edi, ebx |
| 167 |
|
| 168 |
|
| 169 |
cmp esi, ecx |
| 170 |
jne Float32_To_Int32_loop |
| 171 |
|
| 172 |
ffree st(0) |
| 173 |
fincstp |
| 174 |
|
| 175 |
fwait |
| 176 |
fnclex |
| 177 |
fldcw savedFpuControlWord |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
static void Float32_To_Int32_Clip( |
| 184 |
void *destinationBuffer, signed int destinationStride, |
| 185 |
void *sourceBuffer, signed int sourceStride, |
| 186 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 187 |
{ |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
short savedFpuControlWord; |
| 206 |
|
| 207 |
(void) ditherGenerator; |
| 208 |
|
| 209 |
__asm{ |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
mov esi, sourceBuffer |
| 218 |
|
| 219 |
mov edx, 4 |
| 220 |
mov eax, sourceStride |
| 221 |
imul eax, edx |
| 222 |
|
| 223 |
mov ecx, count |
| 224 |
imul ecx, eax |
| 225 |
add ecx, esi |
| 226 |
|
| 227 |
mov edi, destinationBuffer |
| 228 |
|
| 229 |
mov ebx, destinationStride |
| 230 |
imul ebx, edx |
| 231 |
|
| 232 |
fwait |
| 233 |
fstcw savedFpuControlWord |
| 234 |
fldcw fpuControlWord_ |
| 235 |
|
| 236 |
fld int32Scaler_ |
| 237 |
|
| 238 |
Float32_To_Int32_Clip_loop: |
| 239 |
|
| 240 |
mov edx, dword ptr [esi] |
| 241 |
|
| 242 |
and edx, 0x7FFFFFFF |
| 243 |
cmp edx, 0x3F800000 |
| 244 |
|
| 245 |
jg Float32_To_Int32_Clip_clamp |
| 246 |
|
| 247 |
|
| 248 |
fld dword ptr [esi] |
| 249 |
add esi, eax |
| 250 |
|
| 251 |
fmul st(0), st(1) |
| 252 |
fistp dword ptr [edi] |
| 253 |
jmp Float32_To_Int32_Clip_stored |
| 254 |
|
| 255 |
Float32_To_Int32_Clip_clamp: |
| 256 |
mov edx, dword ptr [esi] |
| 257 |
shr edx, 31 |
| 258 |
add esi, eax |
| 259 |
|
| 260 |
add edx, 0x7FFFFFFF |
| 261 |
mov dword ptr [edi], edx |
| 262 |
|
| 263 |
Float32_To_Int32_Clip_stored: |
| 264 |
|
| 265 |
|
| 266 |
lea edi, [edi+ebx] |
| 267 |
|
| 268 |
cmp esi, ecx |
| 269 |
jne Float32_To_Int32_Clip_loop |
| 270 |
|
| 271 |
ffree st(0) |
| 272 |
fincstp |
| 273 |
|
| 274 |
fwait |
| 275 |
fnclex |
| 276 |
fldcw savedFpuControlWord |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
static void Float32_To_Int32_DitherClip( |
| 283 |
void *destinationBuffer, signed int destinationStride, |
| 284 |
void *sourceBuffer, signed int sourceStride, |
| 285 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 286 |
{ |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
short savedFpuControlWord; |
| 307 |
|
| 308 |
|
| 309 |
signed long sourceByteStride; |
| 310 |
signed long highpassedDither; |
| 311 |
|
| 312 |
|
| 313 |
unsigned long ditherPrevious = ditherGenerator->previous; |
| 314 |
unsigned long ditherRandSeed1 = ditherGenerator->randSeed1; |
| 315 |
unsigned long ditherRandSeed2 = ditherGenerator->randSeed2; |
| 316 |
|
| 317 |
__asm{ |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
mov esi, sourceBuffer |
| 326 |
|
| 327 |
mov edx, 4 |
| 328 |
mov eax, sourceStride |
| 329 |
imul eax, edx |
| 330 |
|
| 331 |
mov ecx, count |
| 332 |
imul ecx, eax |
| 333 |
add ecx, esi |
| 334 |
|
| 335 |
mov edi, destinationBuffer |
| 336 |
|
| 337 |
mov ebx, destinationStride |
| 338 |
imul ebx, edx |
| 339 |
|
| 340 |
fwait |
| 341 |
fstcw savedFpuControlWord |
| 342 |
fldcw fpuControlWord_ |
| 343 |
|
| 344 |
fld ditheredInt32Scaler_ |
| 345 |
|
| 346 |
Float32_To_Int32_DitherClip_loop: |
| 347 |
|
| 348 |
mov edx, dword ptr [esi] |
| 349 |
|
| 350 |
and edx, 0x7FFFFFFF |
| 351 |
cmp edx, 0x3F800000 |
| 352 |
|
| 353 |
jg Float32_To_Int32_DitherClip_clamp |
| 354 |
|
| 355 |
|
| 356 |
fld dword ptr [esi] |
| 357 |
add esi, eax |
| 358 |
|
| 359 |
fmul st(0), st(1) |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
mov sourceByteStride, eax |
| 374 |
mov edx, 196314165 |
| 375 |
mov eax, ditherRandSeed1 |
| 376 |
mul edx |
| 377 |
|
| 378 |
lea eax, [eax+907633515] |
| 379 |
mov ditherRandSeed1, eax |
| 380 |
mov edx, 196314165 |
| 381 |
mov eax, ditherRandSeed2 |
| 382 |
mul edx |
| 383 |
|
| 384 |
lea eax, [eax+907633515] |
| 385 |
mov edx, ditherRandSeed1 |
| 386 |
shr edx, PA_DITHER_SHIFT_ |
| 387 |
mov ditherRandSeed2, eax |
| 388 |
shr eax, PA_DITHER_SHIFT_ |
| 389 |
|
| 390 |
lea eax, [eax+edx] |
| 391 |
mov edx, ditherPrevious |
| 392 |
neg edx |
| 393 |
lea edx, [eax+edx] |
| 394 |
mov highpassedDither, edx |
| 395 |
mov ditherPrevious, eax |
| 396 |
mov eax, sourceByteStride |
| 397 |
fild highpassedDither |
| 398 |
fmul const_float_dither_scale_ |
| 399 |
|
| 400 |
|
| 401 |
faddp st(1), st(0) |
| 402 |
fistp dword ptr [edi] |
| 403 |
jmp Float32_To_Int32_DitherClip_stored |
| 404 |
|
| 405 |
Float32_To_Int32_DitherClip_clamp: |
| 406 |
mov edx, dword ptr [esi] |
| 407 |
shr edx, 31 |
| 408 |
add esi, eax |
| 409 |
|
| 410 |
add edx, 0x7FFFFFFF |
| 411 |
mov dword ptr [edi], edx |
| 412 |
|
| 413 |
Float32_To_Int32_DitherClip_stored: |
| 414 |
|
| 415 |
|
| 416 |
lea edi, [edi+ebx] |
| 417 |
|
| 418 |
cmp esi, ecx |
| 419 |
jne Float32_To_Int32_DitherClip_loop |
| 420 |
|
| 421 |
ffree st(0) |
| 422 |
fincstp |
| 423 |
|
| 424 |
fwait |
| 425 |
fnclex |
| 426 |
fldcw savedFpuControlWord |
| 427 |
} |
| 428 |
|
| 429 |
ditherGenerator->previous = ditherPrevious; |
| 430 |
ditherGenerator->randSeed1 = ditherRandSeed1; |
| 431 |
ditherGenerator->randSeed2 = ditherRandSeed2; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
static void Float32_To_Int24( |
| 437 |
void *destinationBuffer, signed int destinationStride, |
| 438 |
void *sourceBuffer, signed int sourceStride, |
| 439 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 440 |
{ |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
short savedFpuControlWord; |
| 464 |
|
| 465 |
signed long tempInt32; |
| 466 |
|
| 467 |
(void) ditherGenerator; |
| 468 |
|
| 469 |
__asm{ |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
mov esi, sourceBuffer |
| 478 |
|
| 479 |
mov edx, 4 |
| 480 |
mov eax, sourceStride |
| 481 |
imul eax, edx |
| 482 |
|
| 483 |
mov ecx, count |
| 484 |
imul ecx, eax |
| 485 |
add ecx, esi |
| 486 |
|
| 487 |
mov edi, destinationBuffer |
| 488 |
|
| 489 |
mov edx, 3 |
| 490 |
mov ebx, destinationStride |
| 491 |
imul ebx, edx |
| 492 |
|
| 493 |
fwait |
| 494 |
fstcw savedFpuControlWord |
| 495 |
fldcw fpuControlWord_ |
| 496 |
|
| 497 |
fld int24Scaler_ |
| 498 |
|
| 499 |
Float32_To_Int24_loop: |
| 500 |
|
| 501 |
|
| 502 |
fld dword ptr [esi] |
| 503 |
add esi, eax |
| 504 |
|
| 505 |
fmul st(0), st(1) |
| 506 |
fistp tempInt32 |
| 507 |
mov edx, tempInt32 |
| 508 |
|
| 509 |
mov byte ptr [edi], DL |
| 510 |
shr edx, 8 |
| 511 |
|
| 512 |
|
| 513 |
mov word ptr [edi+1], DX |
| 514 |
|
| 515 |
|
| 516 |
lea edi, [edi+ebx] |
| 517 |
|
| 518 |
cmp esi, ecx |
| 519 |
jne Float32_To_Int24_loop |
| 520 |
|
| 521 |
ffree st(0) |
| 522 |
fincstp |
| 523 |
|
| 524 |
fwait |
| 525 |
fnclex |
| 526 |
fldcw savedFpuControlWord |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
static void Float32_To_Int24_Clip( |
| 533 |
void *destinationBuffer, signed int destinationStride, |
| 534 |
void *sourceBuffer, signed int sourceStride, |
| 535 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 536 |
{ |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
short savedFpuControlWord; |
| 561 |
|
| 562 |
signed long tempInt32; |
| 563 |
|
| 564 |
(void) ditherGenerator; |
| 565 |
|
| 566 |
__asm{ |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
mov esi, sourceBuffer |
| 575 |
|
| 576 |
mov edx, 4 |
| 577 |
mov eax, sourceStride |
| 578 |
imul eax, edx |
| 579 |
|
| 580 |
mov ecx, count |
| 581 |
imul ecx, eax |
| 582 |
add ecx, esi |
| 583 |
|
| 584 |
mov edi, destinationBuffer |
| 585 |
|
| 586 |
mov edx, 3 |
| 587 |
mov ebx, destinationStride |
| 588 |
imul ebx, edx |
| 589 |
|
| 590 |
fwait |
| 591 |
fstcw savedFpuControlWord |
| 592 |
fldcw fpuControlWord_ |
| 593 |
|
| 594 |
fld int24Scaler_ |
| 595 |
|
| 596 |
Float32_To_Int24_Clip_loop: |
| 597 |
|
| 598 |
mov edx, dword ptr [esi] |
| 599 |
|
| 600 |
and edx, 0x7FFFFFFF |
| 601 |
cmp edx, 0x3F800000 |
| 602 |
|
| 603 |
jg Float32_To_Int24_Clip_clamp |
| 604 |
|
| 605 |
|
| 606 |
fld dword ptr [esi] |
| 607 |
add esi, eax |
| 608 |
|
| 609 |
fmul st(0), st(1) |
| 610 |
fistp tempInt32 |
| 611 |
mov edx, tempInt32 |
| 612 |
jmp Float32_To_Int24_Clip_store |
| 613 |
|
| 614 |
Float32_To_Int24_Clip_clamp: |
| 615 |
mov edx, dword ptr [esi] |
| 616 |
shr edx, 31 |
| 617 |
add esi, eax |
| 618 |
|
| 619 |
add edx, 0x7FFFFF |
| 620 |
|
| 621 |
Float32_To_Int24_Clip_store: |
| 622 |
|
| 623 |
mov byte ptr [edi], DL |
| 624 |
shr edx, 8 |
| 625 |
|
| 626 |
|
| 627 |
mov word ptr [edi+1], DX |
| 628 |
|
| 629 |
|
| 630 |
lea edi, [edi+ebx] |
| 631 |
|
| 632 |
cmp esi, ecx |
| 633 |
jne Float32_To_Int24_Clip_loop |
| 634 |
|
| 635 |
ffree st(0) |
| 636 |
fincstp |
| 637 |
|
| 638 |
fwait |
| 639 |
fnclex |
| 640 |
fldcw savedFpuControlWord |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
static void Float32_To_Int24_DitherClip( |
| 647 |
void *destinationBuffer, signed int destinationStride, |
| 648 |
void *sourceBuffer, signed int sourceStride, |
| 649 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 650 |
{ |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
short savedFpuControlWord; |
| 678 |
|
| 679 |
|
| 680 |
signed long sourceByteStride; |
| 681 |
signed long highpassedDither; |
| 682 |
|
| 683 |
|
| 684 |
unsigned long ditherPrevious = ditherGenerator->previous; |
| 685 |
unsigned long ditherRandSeed1 = ditherGenerator->randSeed1; |
| 686 |
unsigned long ditherRandSeed2 = ditherGenerator->randSeed2; |
| 687 |
|
| 688 |
signed long tempInt32; |
| 689 |
|
| 690 |
__asm{ |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
mov esi, sourceBuffer |
| 699 |
|
| 700 |
mov edx, 4 |
| 701 |
mov eax, sourceStride |
| 702 |
imul eax, edx |
| 703 |
|
| 704 |
mov ecx, count |
| 705 |
imul ecx, eax |
| 706 |
add ecx, esi |
| 707 |
|
| 708 |
mov edi, destinationBuffer |
| 709 |
|
| 710 |
mov edx, 3 |
| 711 |
mov ebx, destinationStride |
| 712 |
imul ebx, edx |
| 713 |
|
| 714 |
fwait |
| 715 |
fstcw savedFpuControlWord |
| 716 |
fldcw fpuControlWord_ |
| 717 |
|
| 718 |
fld ditheredInt24Scaler_ |
| 719 |
|
| 720 |
Float32_To_Int24_DitherClip_loop: |
| 721 |
|
| 722 |
mov edx, dword ptr [esi] |
| 723 |
|
| 724 |
and edx, 0x7FFFFFFF |
| 725 |
cmp edx, 0x3F800000 |
| 726 |
|
| 727 |
jg Float32_To_Int24_DitherClip_clamp |
| 728 |
|
| 729 |
|
| 730 |
fld dword ptr [esi] |
| 731 |
add esi, eax |
| 732 |
|
| 733 |
fmul st(0), st(1) |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
mov sourceByteStride, eax |
| 748 |
mov edx, 196314165 |
| 749 |
mov eax, ditherRandSeed1 |
| 750 |
mul edx |
| 751 |
|
| 752 |
lea eax, [eax+907633515] |
| 753 |
mov ditherRandSeed1, eax |
| 754 |
mov edx, 196314165 |
| 755 |
mov eax, ditherRandSeed2 |
| 756 |
mul edx |
| 757 |
|
| 758 |
lea eax, [eax+907633515] |
| 759 |
mov edx, ditherRandSeed1 |
| 760 |
shr edx, PA_DITHER_SHIFT_ |
| 761 |
mov ditherRandSeed2, eax |
| 762 |
shr eax, PA_DITHER_SHIFT_ |
| 763 |
|
| 764 |
lea eax, [eax+edx] |
| 765 |
mov edx, ditherPrevious |
| 766 |
neg edx |
| 767 |
lea edx, [eax+edx] |
| 768 |
mov highpassedDither, edx |
| 769 |
mov ditherPrevious, eax |
| 770 |
mov eax, sourceByteStride |
| 771 |
fild highpassedDither |
| 772 |
fmul const_float_dither_scale_ |
| 773 |
|
| 774 |
|
| 775 |
faddp st(1), st(0) |
| 776 |
fistp tempInt32 |
| 777 |
mov edx, tempInt32 |
| 778 |
jmp Float32_To_Int24_DitherClip_store |
| 779 |
|
| 780 |
Float32_To_Int24_DitherClip_clamp: |
| 781 |
mov edx, dword ptr [esi] |
| 782 |
shr edx, 31 |
| 783 |
add esi, eax |
| 784 |
|
| 785 |
add edx, 0x7FFFFF |
| 786 |
|
| 787 |
Float32_To_Int24_DitherClip_store: |
| 788 |
|
| 789 |
mov byte ptr [edi], DL |
| 790 |
shr edx, 8 |
| 791 |
|
| 792 |
|
| 793 |
mov word ptr [edi+1], DX |
| 794 |
|
| 795 |
|
| 796 |
lea edi, [edi+ebx] |
| 797 |
|
| 798 |
cmp esi, ecx |
| 799 |
jne Float32_To_Int24_DitherClip_loop |
| 800 |
|
| 801 |
ffree st(0) |
| 802 |
fincstp |
| 803 |
|
| 804 |
fwait |
| 805 |
fnclex |
| 806 |
fldcw savedFpuControlWord |
| 807 |
} |
| 808 |
|
| 809 |
ditherGenerator->previous = ditherPrevious; |
| 810 |
ditherGenerator->randSeed1 = ditherRandSeed1; |
| 811 |
ditherGenerator->randSeed2 = ditherRandSeed2; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
static void Float32_To_Int16( |
| 817 |
void *destinationBuffer, signed int destinationStride, |
| 818 |
void *sourceBuffer, signed int sourceStride, |
| 819 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 820 |
{ |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
short savedFpuControlWord; |
| 838 |
|
| 839 |
(void) ditherGenerator; |
| 840 |
|
| 841 |
__asm{ |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
mov esi, sourceBuffer |
| 850 |
|
| 851 |
mov edx, 4 |
| 852 |
mov eax, sourceStride |
| 853 |
imul eax, edx |
| 854 |
|
| 855 |
mov ecx, count |
| 856 |
imul ecx, eax |
| 857 |
add ecx, esi |
| 858 |
|
| 859 |
mov edi, destinationBuffer |
| 860 |
|
| 861 |
mov edx, 2 |
| 862 |
mov ebx, destinationStride |
| 863 |
imul ebx, edx |
| 864 |
|
| 865 |
fwait |
| 866 |
fstcw savedFpuControlWord |
| 867 |
fldcw fpuControlWord_ |
| 868 |
|
| 869 |
fld int16Scaler_ |
| 870 |
|
| 871 |
Float32_To_Int16_loop: |
| 872 |
|
| 873 |
|
| 874 |
fld dword ptr [esi] |
| 875 |
add esi, eax |
| 876 |
|
| 877 |
fmul st(0), st(1) |
| 878 |
fistp word ptr [edi] |
| 879 |
|
| 880 |
add edi, ebx |
| 881 |
|
| 882 |
|
| 883 |
cmp esi, ecx |
| 884 |
jne Float32_To_Int16_loop |
| 885 |
|
| 886 |
ffree st(0) |
| 887 |
fincstp |
| 888 |
|
| 889 |
fwait |
| 890 |
fnclex |
| 891 |
fldcw savedFpuControlWord |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
static void Float32_To_Int16_Clip( |
| 898 |
void *destinationBuffer, signed int destinationStride, |
| 899 |
void *sourceBuffer, signed int sourceStride, |
| 900 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 901 |
{ |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
short savedFpuControlWord; |
| 919 |
|
| 920 |
(void) ditherGenerator; |
| 921 |
|
| 922 |
__asm{ |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
mov esi, sourceBuffer |
| 931 |
|
| 932 |
mov edx, 4 |
| 933 |
mov eax, sourceStride |
| 934 |
imul eax, edx |
| 935 |
|
| 936 |
mov ecx, count |
| 937 |
imul ecx, eax |
| 938 |
add ecx, esi |
| 939 |
|
| 940 |
mov edi, destinationBuffer |
| 941 |
|
| 942 |
mov edx, 2 |
| 943 |
mov ebx, destinationStride |
| 944 |
imul ebx, edx |
| 945 |
|
| 946 |
fwait |
| 947 |
fstcw savedFpuControlWord |
| 948 |
fldcw fpuControlWord_ |
| 949 |
|
| 950 |
fld int16Scaler_ |
| 951 |
|
| 952 |
Float32_To_Int16_Clip_loop: |
| 953 |
|
| 954 |
mov edx, dword ptr [esi] |
| 955 |
|
| 956 |
and edx, 0x7FFFFFFF |
| 957 |
cmp edx, 0x3F800000 |
| 958 |
|
| 959 |
jg Float32_To_Int16_Clip_clamp |
| 960 |
|
| 961 |
|
| 962 |
fld dword ptr [esi] |
| 963 |
add esi, eax |
| 964 |
|
| 965 |
fmul st(0), st(1) |
| 966 |
fistp word ptr [edi] |
| 967 |
jmp Float32_To_Int16_Clip_stored |
| 968 |
|
| 969 |
Float32_To_Int16_Clip_clamp: |
| 970 |
mov edx, dword ptr [esi] |
| 971 |
shr edx, 31 |
| 972 |
add esi, eax |
| 973 |
|
| 974 |
add dx, 0x7FFF |
| 975 |
mov word ptr [edi], dx |
| 976 |
|
| 977 |
Float32_To_Int16_Clip_stored: |
| 978 |
|
| 979 |
add edi, ebx |
| 980 |
|
| 981 |
|
| 982 |
cmp esi, ecx |
| 983 |
jne Float32_To_Int16_Clip_loop |
| 984 |
|
| 985 |
ffree st(0) |
| 986 |
fincstp |
| 987 |
|
| 988 |
fwait |
| 989 |
fnclex |
| 990 |
fldcw savedFpuControlWord |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
static void Float32_To_Int16_DitherClip( |
| 997 |
void *destinationBuffer, signed int destinationStride, |
| 998 |
void *sourceBuffer, signed int sourceStride, |
| 999 |
unsigned int count, PaUtilTriangularDitherGenerator *ditherGenerator ) |
| 1000 |
{ |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
short savedFpuControlWord; |
| 1022 |
|
| 1023 |
|
| 1024 |
signed long sourceByteStride; |
| 1025 |
signed long highpassedDither; |
| 1026 |
|
| 1027 |
|
| 1028 |
unsigned long ditherPrevious = ditherGenerator->previous; |
| 1029 |
unsigned long ditherRandSeed1 = ditherGenerator->randSeed1; |
| 1030 |
unsigned long ditherRandSeed2 = ditherGenerator->randSeed2; |
| 1031 |
|
| 1032 |
__asm{ |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
mov esi, sourceBuffer |
| 1041 |
|
| 1042 |
mov edx, 4 |
| 1043 |
mov eax, sourceStride |
| 1044 |
imul eax, edx |
| 1045 |
|
| 1046 |
mov ecx, count |
| 1047 |
imul ecx, eax |
| 1048 |
add ecx, esi |
| 1049 |
|
| 1050 |
mov edi, destinationBuffer |
| 1051 |
|
| 1052 |
mov edx, 2 |
| 1053 |
mov ebx, destinationStride |
| 1054 |
imul ebx, edx |
| 1055 |
|
| 1056 |
fwait |
| 1057 |
fstcw savedFpuControlWord |
| 1058 |
fldcw fpuControlWord_ |
| 1059 |
|
| 1060 |
fld ditheredInt16Scaler_ |
| 1061 |
|
| 1062 |
Float32_To_Int16_DitherClip_loop: |
| 1063 |
|
| 1064 |
mov edx, dword ptr [esi] |
| 1065 |
|
| 1066 |
and edx, 0x7FFFFFFF |
| 1067 |
cmp edx, 0x3F800000 |
| 1068 |
|
| 1069 |
jg Float32_To_Int16_DitherClip_clamp |
| 1070 |
|
| 1071 |
|
| 1072 |
fld dword ptr [esi] |
| 1073 |
add esi, eax |
| 1074 |
|
| 1075 |
fmul st(0), st(1) |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
mov sourceByteStride, eax |
| 1090 |
mov edx, 196314165 |
| 1091 |
mov eax, ditherRandSeed1 |
| 1092 |
mul edx |
| 1093 |
|
| 1094 |
lea eax, [eax+907633515] |
| 1095 |
mov ditherRandSeed1, eax |
| 1096 |
mov edx, 196314165 |
| 1097 |
mov eax, ditherRandSeed2 |
| 1098 |
mul edx |
| 1099 |
|
| 1100 |
lea eax, [eax+907633515] |
| 1101 |
mov edx, ditherRandSeed1 |
| 1102 |
shr edx, PA_DITHER_SHIFT_ |
| 1103 |
mov ditherRandSeed2, eax |
| 1104 |
shr eax, PA_DITHER_SHIFT_ |
| 1105 |
|
| 1106 |
lea eax, [eax+edx] |
| 1107 |
mov edx, ditherPrevious |
| 1108 |
neg edx |
| 1109 |
lea edx, [eax+edx] |
| 1110 |
mov highpassedDither, edx |
| 1111 |
mov ditherPrevious, eax |
| 1112 |
mov eax, sourceByteStride |
| 1113 |
fild highpassedDither |
| 1114 |
fmul const_float_dither_scale_ |
| 1115 |
|
| 1116 |
|
| 1117 |
faddp st(1), st(0) |
| 1118 |
fistp word ptr [edi] |
| 1119 |
jmp Float32_To_Int16_DitherClip_stored |
| 1120 |
|
| 1121 |
Float32_To_Int16_DitherClip_clamp: |
| 1122 |
mov edx, dword ptr [esi] |
| 1123 |
shr edx, 31 |
| 1124 |
add esi, eax |
| 1125 |
|
| 1126 |
add dx, 0x7FFF |
| 1127 |
mov word ptr [edi], dx |
| 1128 |
|
| 1129 |
Float32_To_Int16_DitherClip_stored: |
| 1130 |
|
| 1131 |
add edi, ebx |
| 1132 |
|
| 1133 |
|
| 1134 |
cmp esi, ecx |
| 1135 |
jne Float32_To_Int16_DitherClip_loop |
| 1136 |
|
| 1137 |
ffree st(0) |
| 1138 |
fincstp |
| 1139 |
|
| 1140 |
fwait |
| 1141 |
fnclex |
| 1142 |
fldcw savedFpuControlWord |
| 1143 |
} |
| 1144 |
|
| 1145 |
ditherGenerator->previous = ditherPrevious; |
| 1146 |
ditherGenerator->randSeed1 = ditherRandSeed1; |
| 1147 |
ditherGenerator->randSeed2 = ditherRandSeed2; |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
void PaUtil_InitializeX86PlainConverters( void ) |
| 1153 |
{ |
| 1154 |
paConverters.Float32_To_Int32 = Float32_To_Int32; |
| 1155 |
paConverters.Float32_To_Int32_Clip = Float32_To_Int32_Clip; |
| 1156 |
paConverters.Float32_To_Int32_DitherClip = Float32_To_Int32_DitherClip; |
| 1157 |
|
| 1158 |
paConverters.Float32_To_Int24 = Float32_To_Int24; |
| 1159 |
paConverters.Float32_To_Int24_Clip = Float32_To_Int24_Clip; |
| 1160 |
paConverters.Float32_To_Int24_DitherClip = Float32_To_Int24_DitherClip; |
| 1161 |
|
| 1162 |
paConverters.Float32_To_Int16 = Float32_To_Int16; |
| 1163 |
paConverters.Float32_To_Int16_Clip = Float32_To_Int16_Clip; |
| 1164 |
paConverters.Float32_To_Int16_DitherClip = Float32_To_Int16_DitherClip; |
| 1165 |
} |
| 1166 |
|
| 1167 |
|