| 646 | #endif |
| 647 | |
| 648 | void AudioHLEState::ADPCMDecode( u8 flags, u32 address ) |
| 649 | { |
| 650 | bool init( (flags&0x1) != 0 ); |
| 651 | bool loop( (flags&0x2) != 0 ); |
| 652 | |
| 653 | u16 inPtr=0; |
| 654 | s16 *out=(s16 *)(Buffer+OutBuffer); |
| 655 | |
| 656 | if(init) |
| 657 | { |
| 658 | memset( out, 0, 32 ); |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | u32 addr( loop ? LoopVal : address ); |
| 663 | memmove( out, &rdram[addr], 32 ); |
| 664 | } |
| 665 | |
| 666 | s32 l1=out[15]; |
| 667 | s32 l2=out[14]; |
| 668 | out+=16; |
| 669 | |
| 670 | s32 inp1[8]; |
| 671 | s32 inp2[8]; |
| 672 | |
| 673 | s32 count = (s16)Count; // XXXX why convert this to signed? |
| 674 | while(count>0) |
| 675 | { |
| 676 | // the first iteration through, these values are |
| 677 | // either 0 in the case of A_INIT, from a special |
| 678 | // area of memory in the case of A_LOOP or just |
| 679 | // the values we calculated the last time |
| 680 | |
| 681 | u8 code=Buffer[(InBuffer+inPtr)^3]; |
| 682 | u32 index=code&0xf; // index into the adpcm code table |
| 683 | s16 * book1=(s16 *)&ADPCMTable[index<<4]; |
| 684 | s16 * book2=book1+8; |
| 685 | code>>=4; // upper nibble is scale |
| 686 | |
| 687 | inPtr++; // coded adpcm data lies next |
| 688 | |
| 689 | if( code < 12 ) |
| 690 | { |
| 691 | s32 vscale=(0x8000>>((12-code)-1)); // very strange. 0x8000 would be .5 in 16:16 format |
| 692 | // so this appears to be a fractional scale based |
| 693 | // on the 12 based inverse of the scale value. note |
| 694 | // that this could be negative, in which case we do |
| 695 | // not use the calculated vscale value... see the |
| 696 | // if(code>12) check below |
| 697 | ExtractSamplesScale( inp1, inPtr + 0, vscale ); |
| 698 | ExtractSamplesScale( inp2, inPtr + 4, vscale ); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | ExtractSamples( inp1, inPtr + 0 ); |
| 703 | ExtractSamples( inp2, inPtr + 4 ); |
| 704 | } |
| 705 |
no test coverage detected