1 // Copyright 2008 Dolphin Emulator Project 2 // Licensed under GPLv2+ 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include "Common/CommonTypes.h" 8 9 namespace DSP::HLE 10 { 11 struct PBMixer 12 { 13 u16 left; 14 u16 left_delta; 15 u16 right; 16 u16 right_delta; 17 18 u16 auxA_left; 19 u16 auxA_left_delta; 20 u16 auxA_right; 21 u16 auxA_right_delta; 22 23 u16 auxB_left; 24 u16 auxB_left_delta; 25 u16 auxB_right; 26 u16 auxB_right_delta; 27 28 u16 auxB_surround; 29 u16 auxB_surround_delta; 30 u16 surround; 31 u16 surround_delta; 32 u16 auxA_surround; 33 u16 auxA_surround_delta; 34 }; 35 36 struct PBMixerWii 37 { 38 // volume mixing values in .15, 0x8000 = ca. 1.0 39 u16 left; 40 u16 left_delta; 41 u16 right; 42 u16 right_delta; 43 44 u16 auxA_left; 45 u16 auxA_left_delta; 46 u16 auxA_right; 47 u16 auxA_right_delta; 48 49 u16 auxB_left; 50 u16 auxB_left_delta; 51 u16 auxB_right; 52 u16 auxB_right_delta; 53 54 // Note: the following elements usage changes a little in DPL2 mode 55 // TODO: implement and comment it in the mixer 56 u16 auxC_left; 57 u16 auxC_left_delta; 58 u16 auxC_right; 59 u16 auxC_right_delta; 60 61 u16 surround; 62 u16 surround_delta; 63 u16 auxA_surround; 64 u16 auxA_surround_delta; 65 u16 auxB_surround; 66 u16 auxB_surround_delta; 67 u16 auxC_surround; 68 u16 auxC_surround_delta; 69 }; 70 71 struct PBMixerWM 72 { 73 u16 main0; 74 u16 main0_delta; 75 u16 aux0; 76 u16 aux0_delta; 77 78 u16 main1; 79 u16 main1_delta; 80 u16 aux1; 81 u16 aux1_delta; 82 83 u16 main2; 84 u16 main2_delta; 85 u16 aux2; 86 u16 aux2_delta; 87 88 u16 main3; 89 u16 main3_delta; 90 u16 aux3; 91 u16 aux3_delta; 92 }; 93 94 struct PBInitialTimeDelay 95 { 96 u16 on; 97 u16 addrMemHigh; 98 u16 addrMemLow; 99 u16 offsetLeft; 100 u16 offsetRight; 101 u16 targetLeft; 102 u16 targetRight; 103 }; 104 105 // Update data - read these each 1ms subframe and use them! 106 // It seems that to provide higher time precisions for MIDI events, some games 107 // use this thing to update the parameter blocks per 1ms sub-block (a block is 5ms). 108 // Using this data should fix games that are missing MIDI notes. 109 struct PBUpdates 110 { 111 u16 num_updates[5]; 112 u16 data_hi; // These point to main RAM. Not sure about the structure of the data. 113 u16 data_lo; 114 }; 115 116 // The DSP stores the final sample values for each voice after every frame of processing. 117 // The values are then accumulated for all dropped voices, added to the next frame of audio, 118 // and ramped down on a per-sample basis to provide a gentle "roll off." 119 struct PBDpop 120 { 121 s16 left; 122 s16 auxA_left; 123 s16 auxB_left; 124 125 s16 right; 126 s16 auxA_right; 127 s16 auxB_right; 128 129 s16 surround; 130 s16 auxA_surround; 131 s16 auxB_surround; 132 }; 133 134 struct PBDpopWii 135 { 136 s16 left; 137 s16 auxA_left; 138 s16 auxB_left; 139 s16 auxC_left; 140 141 s16 right; 142 s16 auxA_right; 143 s16 auxB_right; 144 s16 auxC_right; 145 146 s16 surround; 147 s16 auxA_surround; 148 s16 auxB_surround; 149 s16 auxC_surround; 150 }; 151 152 struct PBDpopWM 153 { 154 s16 main0; 155 s16 main1; 156 s16 main2; 157 s16 main3; 158 159 s16 aux0; 160 s16 aux1; 161 s16 aux2; 162 s16 aux3; 163 }; 164 165 struct PBVolumeEnvelope 166 { 167 u16 cur_volume; // Volume at start of frame 168 s16 cur_volume_delta; // Signed per sample delta (96 samples per frame) 169 }; 170 171 struct PBUnknown2 172 { 173 u16 unknown_reserved[3]; 174 }; 175 176 struct PBAudioAddr 177 { 178 u16 looping; 179 u16 sample_format; 180 u16 loop_addr_hi; // Start of loop (this will point to a shared "zero" buffer if one-shot mode is 181 // active) 182 u16 loop_addr_lo; 183 u16 end_addr_hi; // End of sample (and loop), inclusive 184 u16 end_addr_lo; 185 u16 cur_addr_hi; 186 u16 cur_addr_lo; 187 }; 188 189 struct PBADPCMInfo 190 { 191 s16 coefs[16]; 192 u16 gain; 193 u16 pred_scale; 194 s16 yn1; 195 s16 yn2; 196 }; 197 198 struct PBSampleRateConverter 199 { 200 // ratio = (f32)ratio * 0x10000; 201 // valid range is 1/512 to 4.0000 202 u16 ratio_hi; // integer part of sampling ratio 203 u16 ratio_lo; // fraction part of sampling ratio 204 u16 cur_addr_frac; 205 s16 last_samples[4]; 206 }; 207 208 struct PBSampleRateConverterWM 209 { 210 u16 cur_addr_frac; 211 s16 last_samples[4]; 212 }; 213 214 struct PBADPCMLoopInfo 215 { 216 u16 pred_scale; 217 u16 yn1; 218 u16 yn2; 219 }; 220 221 struct PBLowPassFilter 222 { 223 u16 enabled; 224 s16 yn1; 225 u16 a0; 226 u16 b0; 227 }; 228 229 struct AXPB 230 { 231 u16 next_pb_hi; 232 u16 next_pb_lo; 233 u16 this_pb_hi; 234 u16 this_pb_lo; 235 236 u16 src_type; // Type of sample rate converter (none, ?, linear) 237 u16 coef_select; 238 u16 mixer_control; 239 240 u16 running; // 1=RUN 0=STOP 241 u16 is_stream; // 1 = stream, 0 = one shot 242 243 PBMixer mixer; 244 PBInitialTimeDelay initial_time_delay; 245 PBUpdates updates; 246 PBDpop dpop; 247 PBVolumeEnvelope vol_env; 248 PBUnknown2 unknown3; 249 PBAudioAddr audio_addr; 250 PBADPCMInfo adpcm; 251 PBSampleRateConverter src; 252 PBADPCMLoopInfo adpcm_loop_info; 253 PBLowPassFilter lpf; // Skipped when writing to/reading from MRAM/ARAM for certain AX UCodes 254 u16 loop_counter; 255 256 u16 padding[24]; 257 }; 258 259 struct PBBiquadFilter 260 { 261 u16 on; // on = 2, off = 0 262 u16 xn1; // History data 263 u16 xn2; 264 u16 yn1; 265 u16 yn2; 266 u16 b0; // Filter coefficients 267 u16 b1; 268 u16 b2; 269 u16 a1; 270 u16 a2; 271 }; 272 273 union PBInfImpulseResponseWM 274 { 275 PBLowPassFilter lpf; 276 PBBiquadFilter biquad; 277 }; 278 279 struct AXPBWii 280 { 281 u16 next_pb_hi; 282 u16 next_pb_lo; 283 u16 this_pb_hi; 284 u16 this_pb_lo; 285 286 u16 src_type; // Type of sample rate converter (none, 4-tap, linear) 287 u16 coef_select; // coef for the 4-tap src 288 u16 mixer_control_hi; 289 u16 mixer_control_lo; 290 291 u16 running; // 1=RUN 0=STOP 292 u16 is_stream; // 1 = stream, 0 = one shot 293 294 PBMixerWii mixer; 295 PBInitialTimeDelay initial_time_delay; 296 PBDpopWii dpop; 297 PBVolumeEnvelope vol_env; 298 PBAudioAddr audio_addr; 299 PBADPCMInfo adpcm; 300 PBSampleRateConverter src; 301 PBADPCMLoopInfo adpcm_loop_info; 302 PBLowPassFilter lpf; 303 PBBiquadFilter biquad; 304 305 // WIIMOTE :D 306 u16 remote; 307 u16 remote_mixer_control; 308 309 PBMixerWM remote_mixer; 310 PBDpopWM remote_dpop; 311 PBSampleRateConverterWM remote_src; 312 PBInfImpulseResponseWM remote_iir; 313 314 u16 pad[12]; // align us, captain! (32B) 315 }; 316 317 // TODO: All these enums have changed a lot for Wii 318 enum 319 { 320 AUDIOFORMAT_ADPCM = 0, 321 AUDIOFORMAT_PCM8 = 0x19, 322 AUDIOFORMAT_PCM16 = 0xA, 323 }; 324 325 enum 326 { 327 SRCTYPE_POLYPHASE = 0, 328 SRCTYPE_LINEAR = 1, 329 SRCTYPE_NEAREST = 2, 330 }; 331 332 // Both may be used at once 333 enum 334 { 335 FILTER_LOWPASS = 1, 336 FILTER_BIQUAD = 2, 337 }; 338 } // namespace DSP::HLE 339