| 1 | /* Mednafen - Multi-system Emulator |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #ifndef __MDFN_OKIADPCM_H |
| 19 | #define __MDFN_OKIADPCM_Hcxx . . $ `mednafen/okiadpcm.h:19:9`! |
| 20 | |
| 21 | // PC-FX ADPCM decoder not finished! |
| 22 | |
| 23 | typedef enumcxx . . $ $anonymous_type_c661c2f23fffc02b_0# |
| 24 | { |
| 25 | OKIADPCM_MSM5205cxx . . $ OKIADPCM_MSM5205. = 0, |
| 26 | OKIADPCM_MSM5218cxx . . $ OKIADPCM_MSM5218. = 1, |
| 27 | OKIADPCM_COUNTcxx . . $ OKIADPCM_COUNT. |
| 28 | } OKIADPCM_Chipcxx . . $ OKIADPCM_Chip#; |
| 29 | |
| 30 | extern const int OKIADPCM_StepSizescxx . . $ OKIADPCM_StepSizes.[49]; |
| 31 | extern const int OKIADPCM_StepIndexDeltascxx . . $ OKIADPCM_StepIndexDeltas.[16]; |
| 32 | extern const int32cxx . . $ int32# OKIADPCM_DeltaTablecxx . . $ OKIADPCM_DeltaTable.[49][16]; |
| 33 | |
| 34 | template <OKIADPCM_Chipcxx . . $ OKIADPCM_Chip# CHIP_TYPE> |
| 35 | class OKIADPCM_Decodercxx . . $ OKIADPCM_Decoder# |
| 36 | { |
| 37 | public: |
| 38 | |
| 39 | OKIADPCM_Decodercxx . . $ OKIADPCM_Decoder#`OKIADPCM_Decoder<CHIP_TYPE>`(49f6e7a06ebc5aa8).() |
| 40 | { |
| 41 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(CHIP_TYPE < OKIADPCM_COUNT); |
| 42 | |
| 43 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. = 0x0800; |
| 44 | |
| 45 | StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. = 0; |
| 46 | } |
| 47 | ~cxx . . $ OKIADPCM_Decoder#`~OKIADPCM_Decoder<CHIP_TYPE>`(49f6e7a06ebc5aa8).OKIADPCM_Decoder() |
| 48 | { |
| 49 | |
| 50 | } |
| 51 | |
| 52 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint16cxx . . $ uint16# GetSamplecxx . . $ OKIADPCM_Decoder#GetSample(32a7769d58713265).(void) |
| 53 | { |
| 54 | return(CurSamplecxx . . $ OKIADPCM_Decoder#CurSample.); |
| 55 | } |
| 56 | |
| 57 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void SetSamplecxx . . $ OKIADPCM_Decoder#SetSample(ed53e3bbd3fa2f69).(uint16cxx . . $ uint16# new_sample) |
| 58 | { |
| 59 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(new_sample <= 0xFFF); |
| 60 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. = new_sample; |
| 61 | } |
| 62 | |
| 63 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint8cxx . . $ uint8# GetSSIcxx . . $ OKIADPCM_Decoder#GetSSI(7c4be072098b358f).(void) |
| 64 | { |
| 65 | return(StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex.); |
| 66 | } |
| 67 | |
| 68 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void SetSSIcxx . . $ OKIADPCM_Decoder#SetSSI(ac50b47256ae7414).(uint8cxx . . $ uint8# new_ssi) |
| 69 | { |
| 70 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(new_ssi <= 48); |
| 71 | StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. = new_ssi; |
| 72 | } |
| 73 | |
| 74 | // DecodeDelta returns the coded delta for the given nibble and (previous) predictor. |
| 75 | // It will not wrap nor saturate the returned value, and CurSample is not updated. |
| 76 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! int32cxx . . $ int32# DecodeDeltacxx . . $ OKIADPCM_Decoder#DecodeDelta(b27dbea426b7b93).(const uint8cxx . . $ uint8# nibble) |
| 77 | { |
| 78 | int32cxx . . $ int32# ret = OKIADPCM_DeltaTablecxx . . $ OKIADPCM_DeltaTable.[StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex.][nibble]; |
| 79 | |
| 80 | StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. += OKIADPCM_StepIndexDeltascxx . . $ OKIADPCM_StepIndexDeltas.[nibble]; |
| 81 | |
| 82 | if(StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. < 0) |
| 83 | StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. = 0; |
| 84 | |
| 85 | if(StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. > 48) |
| 86 | StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex. = 48; |
| 87 | |
| 88 | return(ret); |
| 89 | } |
| 90 | |
| 91 | // This function will return the full 12-bits, it's up to the caller to |
| 92 | // truncate as necessary(MSM5205 only has a 10-bit D/A, MSM5218 has a 12-bit D/A) |
| 93 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint16cxx . . $ uint16# Decodecxx . . $ OKIADPCM_Decoder#Decode(3706112bcd2aff3a).(const uint8cxx . . $ uint8# nibble) |
| 94 | { |
| 95 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. += DecodeDeltacxx . . $ OKIADPCM_Decoder#DecodeDelta(b27dbea426b7b93).(nibble); |
| 96 | |
| 97 | if(CHIP_TYPE == OKIADPCM_MSM5205cxx . . $ OKIADPCM_MSM5205.) |
| 98 | { |
| 99 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. &= 0xFFF; |
| 100 | } |
| 101 | else if(CHIP_TYPE == OKIADPCM_MSM5218cxx . . $ OKIADPCM_MSM5218.) |
| 102 | { |
| 103 | if(CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. > 0xFFF) |
| 104 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. = 0xFFF; |
| 105 | if(CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. < 0) |
| 106 | CurSamplecxx . . $ OKIADPCM_Decoder#CurSample. = 0; |
| 107 | } |
| 108 | return(CurSamplecxx . . $ OKIADPCM_Decoder#CurSample.); |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | int32cxx . . $ int32# CurSamplecxx . . $ OKIADPCM_Decoder#CurSample.; |
| 113 | int32cxx . . $ int32# StepSizeIndexcxx . . $ OKIADPCM_Decoder#StepSizeIndex.; |
| 114 | }; |
| 115 | |
| 116 | template <OKIADPCM_Chipcxx . . $ OKIADPCM_Chip# CHIP_TYPE> |
| 117 | class OKIADPCM_Encodercxx . . $ OKIADPCM_Encoder# |
| 118 | { |
| 119 | public: |
| 120 | |
| 121 | OKIADPCM_Encodercxx . . $ OKIADPCM_Encoder#`OKIADPCM_Encoder<CHIP_TYPE>`(49f6e7a06ebc5aa8).() |
| 122 | { |
| 123 | Accumcxx . . $ OKIADPCM_Encoder#Accum. = 0x800; |
| 124 | StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. = 0; |
| 125 | } |
| 126 | |
| 127 | ~cxx . . $ OKIADPCM_Encoder#`~OKIADPCM_Encoder<CHIP_TYPE>`(49f6e7a06ebc5aa8).OKIADPCM_Encoder() |
| 128 | { |
| 129 | |
| 130 | } |
| 131 | |
| 132 | uint8cxx . . $ uint8# EncodeSamplecxx . . $ OKIADPCM_Encoder#EncodeSample(6699a9687259e5ab).(uint16cxx . . $ uint16# in_sample) |
| 133 | { |
| 134 | uint8cxx . . $ uint8# nibble = 0; |
| 135 | int32cxx . . $ int32# sample_delta = in_sample - Accumcxx . . $ OKIADPCM_Encoder#Accum.; |
| 136 | int piece; |
| 137 | |
| 138 | piece = (abscxx . . $ abs(a1851578aea3f541).(sample_delta) * 4 / OKIADPCM_StepSizescxx . . $ OKIADPCM_StepSizes.[StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex.]); |
| 139 | if(piece > 0x7) |
| 140 | piece = 0x7; |
| 141 | |
| 142 | nibble = ((uint32cxx . . $ uint32#)(sample_delta >> 31) & 0x8) | piece; |
| 143 | |
| 144 | // Update Accum and StepSizeIndex! |
| 145 | Accumcxx . . $ OKIADPCM_Encoder#Accum. += OKIADPCM_DeltaTablecxx . . $ OKIADPCM_DeltaTable.[StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex.][nibble]; |
| 146 | StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. += OKIADPCM_StepIndexDeltascxx . . $ OKIADPCM_StepIndexDeltas.[nibble]; |
| 147 | |
| 148 | if(Accumcxx . . $ OKIADPCM_Encoder#Accum. > 0xFFF) Accumcxx . . $ OKIADPCM_Encoder#Accum. = 0xFFF; |
| 149 | if(Accumcxx . . $ OKIADPCM_Encoder#Accum. < 0) Accumcxx . . $ OKIADPCM_Encoder#Accum. = 0; |
| 150 | |
| 151 | if(StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. < 0) |
| 152 | StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. = 0; |
| 153 | |
| 154 | if(StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. > 48) |
| 155 | StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex. = 48; |
| 156 | |
| 157 | return(nibble); |
| 158 | } |
| 159 | |
| 160 | private: |
| 161 | int32cxx . . $ int32# Accumcxx . . $ OKIADPCM_Encoder#Accum.; |
| 162 | int32cxx . . $ int32# StepSizeIndexcxx . . $ OKIADPCM_Encoder#StepSizeIndex.; |
| 163 | OKIADPCM_Chipcxx . . $ OKIADPCM_Chip# ChipTypecxx . . $ OKIADPCM_Encoder#ChipType.; |
| 164 | }; |
| 165 | #endif |