1 /*---------------------------------------------------------------------------* 2 Project: AXART library 3 File: axart.h 4 5 Copyright (C) Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 *---------------------------------------------------------------------------*/ 14 15 #include <cafe/os.h> 16 17 #ifndef __AXART_H__ 18 #define __AXART_H__ 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 25 /*---------------------------------------------------------------------------* 26 AXART_ART generic articulator header 27 *---------------------------------------------------------------------------*/ 28 typedef struct 29 { 30 31 void *next; 32 u32 type; 33 34 } AXART_ART; 35 36 // articulator types 37 #define AXART_TYPE_3D 1 38 #define AXART_TYPE_PANNING 2 39 #define AXART_TYPE_ITD 3 40 #define AXART_TYPE_SRCTYPE 4 41 #define AXART_TYPE_PITCH 5 42 #define AXART_TYPE_PITCH_ENV 6 43 #define AXART_TYPE_PITCH_MOD 7 44 #define AXART_TYPE_VOLUME 8 45 #define AXART_TYPE_AUXA_VOLUME 9 46 #define AXART_TYPE_AUXB_VOLUME 10 47 #define AXART_TYPE_AUXC_VOLUME 11 48 #define AXART_TYPE_VOLUME_ENV 12 49 #define AXART_TYPE_AUXA_VOLUME_ENV 13 50 #define AXART_TYPE_AUXB_VOLUME_ENV 14 51 #define AXART_TYPE_AUXC_VOLUME_ENV 15 52 #define AXART_TYPE_VOLUME_MOD 16 53 #define AXART_TYPE_AUXA_VOLUME_MOD 17 54 #define AXART_TYPE_AUXB_VOLUME_MOD 18 55 #define AXART_TYPE_AUXC_VOLUME_MOD 19 56 #define AXART_TYPE_LPF 20 57 #define AXART_TYPE_FADER 21 58 #define AXART_TYPE_RMT 22 59 #define AXART_TYPE_RMT_FADER 24 60 #define AXART_TYPE_RMT_AUX_VOLUME 25 61 #define AXART_TYPE_DRC 26 62 63 64 /*---------------------------------------------------------------------------* 65 LFO used with modulation articulators 66 *---------------------------------------------------------------------------*/ 67 typedef struct 68 { 69 70 f32 *lfo; // lfo samples in RAM 71 u32 length; // lfo samples for 1 period 72 f32 delta; // lfo delta per 5ms 73 74 u32 sampleIndex; // lfo sample index 75 f32 counter; // lfo counter 76 f32 sample1; // lfo last sample for interpolation 77 f32 sample; // lfo sample 78 f32 output; // lfo output 79 80 } AXART_LFO; 81 82 #define AXART_SINE_SAMPLES 64 83 #define AXART_SQUARE_SAMPLES 64 84 #define AXART_SAW_SAMPLES 64 85 #define AXART_REVERSESAW_SAMPLES 64 86 #define AXART_TRIANGLE_SAMPLES 64 87 #define AXART_NOISE_SAMPLES 64 88 89 extern f32 AXARTSine[AXART_SINE_SAMPLES]; 90 extern f32 AXARTSquare[AXART_SQUARE_SAMPLES]; 91 extern f32 AXARTSaw[AXART_SAW_SAMPLES]; 92 extern f32 AXARTReverseSaw[AXART_REVERSESAW_SAMPLES]; 93 extern f32 AXARTTriangle[AXART_TRIANGLE_SAMPLES]; 94 extern f32 AXARTNoise[AXART_NOISE_SAMPLES]; 95 96 97 /*---------------------------------------------------------------------------* 98 articulators 99 *---------------------------------------------------------------------------*/ 100 101 #ifdef __MWERKS__ 102 #pragma warn_padding off 103 #endif 104 105 typedef struct 106 { 107 AXART_ART art; 108 109 // runtime user params 110 111 f32 hAngle; // horizontal angle 112 f32 vAngle; // vertical angle 113 f32 dist; // distance from listener 114 f32 closingSpeed; // for Doppler effect 115 u32 update; // set to true after changing params 116 117 // do not write to these params 118 119 u8 pan; 120 u8 span; 121 u8 src; 122 u16 itdL; 123 u16 itdR; 124 f32 pitch; 125 s32 attenuation; 126 127 } AXART_3D; 128 129 typedef struct 130 { 131 AXART_ART art; 132 133 // runtime user params 134 135 u8 pan; // left - right 0 - 127, 64 is center 136 u8 span; // rear - front 0 - 127, 127 is front 137 138 } AXART_PANNING; 139 140 typedef struct 141 { 142 143 AXART_ART art; 144 145 // runtime user params 146 147 u8 src; // use one of the following 148 // AX_SRC_TYPE_NONE 149 // AX_SRC_TYPE_LINEAR 150 // AX_SRC_TYPE_4TAP_8K 151 // AX_SRC_TYPE_4TAP_12K 152 // AX_SRC_TYPE_4TAP_16K 153 154 } AXART_SRCTYPE; 155 156 #ifdef __MWERKS__ 157 #pragma warn_padding reset 158 #endif 159 160 typedef struct 161 { 162 AXART_ART art; 163 164 // runtime user params 165 166 u16 itdL; // sample shift left, 0 - 31 167 u16 itdR; // sample shift right, 0 - 31 168 169 } AXART_ITD; 170 171 typedef struct 172 { 173 AXART_ART art; 174 175 // runtime user params 176 177 s32 cents; 178 179 } AXART_PITCH; 180 181 typedef struct 182 { 183 AXART_ART art; 184 185 // runtime user params 186 187 s32 delta; 188 s32 target; 189 s32 cents; 190 191 } AXART_PITCH_ENV; 192 193 typedef struct 194 { 195 AXART_ART art; 196 AXART_LFO lfo; 197 198 // runtime user params 199 200 s32 cents; 201 202 } AXART_PITCH_MOD; 203 204 typedef struct 205 { 206 AXART_ART art; 207 208 // runtime user params 209 210 s32 attenuation; 211 212 } AXART_VOLUME; 213 214 typedef struct 215 { 216 AXART_ART art; 217 218 // runtime user params 219 220 s32 attenuation; 221 222 } AXART_AUXA_VOLUME; 223 224 typedef struct 225 { 226 AXART_ART art; 227 228 // runtime user params 229 230 s32 attenuation; 231 232 } AXART_AUXB_VOLUME; 233 234 typedef struct 235 { 236 AXART_ART art; 237 238 // runtime user params 239 240 s32 attenuation; 241 242 } AXART_AUXC_VOLUME; 243 244 typedef struct 245 { 246 AXART_ART art; 247 248 // runtime user params 249 250 s32 delta; 251 s32 target; 252 s32 attenuation; 253 254 } AXART_VOLUME_ENV; 255 256 typedef struct 257 { 258 AXART_ART art; 259 260 // runtime user params 261 262 s32 delta; 263 s32 target; 264 s32 attenuation; 265 266 } AXART_AUXA_VOLUME_ENV; 267 268 typedef struct 269 { 270 AXART_ART art; 271 272 // runtime user params 273 274 s32 delta; 275 s32 target; 276 s32 attenuation; 277 278 } AXART_AUXB_VOLUME_ENV; 279 280 typedef struct 281 { 282 AXART_ART art; 283 284 // runtime user params 285 286 s32 delta; 287 s32 target; 288 s32 attenuation; 289 290 } AXART_AUXC_VOLUME_ENV; 291 292 typedef struct 293 { 294 AXART_ART art; 295 AXART_LFO lfo; 296 297 // runtime user params 298 299 s32 attenuation; 300 301 } AXART_VOLUME_MOD; 302 303 typedef struct 304 { 305 AXART_ART art; 306 AXART_LFO lfo; 307 308 // runtime user params 309 310 s32 attenuation; 311 312 } AXART_AUXA_VOLUME_MOD; 313 314 typedef struct 315 { 316 AXART_ART art; 317 AXART_LFO lfo; 318 319 // runtime user params 320 321 s32 attenuation; 322 323 } AXART_AUXB_VOLUME_MOD; 324 325 typedef struct 326 { 327 AXART_ART art; 328 AXART_LFO lfo; 329 330 // runtime user params 331 332 s32 attenuation; 333 334 } AXART_AUXC_VOLUME_MOD; 335 336 typedef struct 337 { 338 AXART_ART art; 339 u32 initLPF; 340 341 // runtime user params 342 u32 frequency; // indexed roll-off frequency, see below 343 u32 update; // set to TRUE after changing type or frequency 344 345 } AXART_LPF; 346 347 #define AXART_LPF_FREQ_16000_HZ 0 348 #define AXART_LPF_FREQ_12800_HZ 1 349 #define AXART_LPF_FREQ_10240_HZ 2 350 #define AXART_LPF_FREQ_8000_HZ 3 351 #define AXART_LPF_FREQ_6400_HZ 4 352 #define AXART_LPF_FREQ_5120_HZ 5 353 #define AXART_LPF_FREQ_4000_HZ 6 354 #define AXART_LPF_FREQ_3200_HZ 7 355 #define AXART_LPF_FREQ_2560_HZ 8 356 #define AXART_LPF_FREQ_2000_HZ 9 357 #define AXART_LPF_FREQ_1600_HZ 10 358 #define AXART_LPF_FREQ_1280_HZ 11 359 #define AXART_LPF_FREQ_1000_HZ 12 360 #define AXART_LPF_FREQ_800_HZ 13 361 #define AXART_LPF_FREQ_640_HZ 14 362 #define AXART_LPF_FREQ_500_HZ 15 363 #define AXART_LPF_FREQ_400_HZ 16 364 #define AXART_LPF_FREQ_320_HZ 17 365 #define AXART_LPF_FREQ_256_HZ 18 366 #define AXART_LPF_FREQ_200_HZ 19 367 #define AXART_LPF_FREQ_160_HZ 20 368 #define AXART_LPF_FREQ_128_HZ 21 369 #define AXART_LPF_FREQ_100_HZ 22 370 #define AXART_LPF_FREQ_80_HZ 23 371 372 typedef struct 373 { 374 AXART_ART art; 375 376 // runtime user params 377 378 s32 attenuation; 379 380 } AXART_FADER; 381 382 383 /*---------------------------------------------------------------------------* 384 articulators for remote speakers 385 *---------------------------------------------------------------------------*/ 386 387 // enable/disable flag of remote outputs 388 typedef struct 389 { 390 AXART_ART art; 391 392 // runtime user params 393 394 u16 on; 395 396 } AXART_RMT; 397 398 typedef struct 399 { 400 AXART_ART art; 401 402 // runtime user params 403 404 u16 on; 405 406 } AXART_DRC; 407 408 // fader value 409 typedef struct 410 { 411 AXART_ART art; 412 413 // runtime user params 414 415 s32 attenuation0; 416 s32 attenuation1; 417 s32 attenuation2; 418 s32 attenuation3; 419 420 } AXART_RMT_FADER; 421 422 // aux send level 423 typedef struct 424 { 425 AXART_ART art; 426 427 // runtime user params 428 429 s32 attenuation0; 430 s32 attenuation1; 431 s32 attenuation2; 432 s32 attenuation3; 433 434 } AXART_RMT_AUX_VOLUME; 435 436 437 /*---------------------------------------------------------------------------* 438 AXART_SOUND struct used per sound in sound list to articulate 439 *---------------------------------------------------------------------------*/ 440 typedef struct 441 { 442 443 void *next; // next sound in list 444 void *prev; // prev sound in list 445 446 AXVPB *axvpb; // user acquired voice 447 f32 sampleRate; // normal sample rate 448 449 AXART_ART *articulators; // list of articulators 450 451 } AXART_SOUND; 452 453 454 /*---------------------------------------------------------------------------* 455 function prototypes 456 *---------------------------------------------------------------------------*/ 457 458 void AXARTInit (void); 459 void AXARTQuit (void); 460 void AXARTServiceSounds (void); 461 void AXARTInitSound (AXART_SOUND *sound, AXVPB *voice, u32 sampleRate); 462 void AXARTAddSound (AXART_SOUND *sound); 463 void AXARTRemoveSound (AXART_SOUND *sound); 464 void AXARTSet3DDistanceScale (f32 scale); 465 void AXARTSet3DDopplerScale (f32 scale); 466 void AXARTAddArticulator (AXART_SOUND *sound, AXART_ART *articulator); 467 BOOL AXARTRemoveArticulator (AXART_SOUND *sound, AXART_ART *articulator); 468 469 void AXARTInitLfo (AXART_LFO *lfo, f32 *samples, u32 length, f32 delta); 470 471 void AXARTInitArt3D (AXART_3D *articulator); 472 void AXARTInitArtPanning (AXART_PANNING *articulator); 473 void AXARTInitArtItd (AXART_ITD *articulator); 474 void AXARTInitArtSrctype (AXART_SRCTYPE *articulator); 475 476 void AXARTInitArtPitch (AXART_PITCH *articulator); 477 void AXARTInitArtPitchEnv (AXART_PITCH_ENV *articulator); 478 void AXARTInitArtPitchMod (AXART_PITCH_MOD *articulator); 479 480 void AXARTInitArtVolume (AXART_VOLUME *articulator); 481 void AXARTInitArtAuxAVolume (AXART_AUXA_VOLUME *articulator); 482 void AXARTInitArtAuxBVolume (AXART_AUXB_VOLUME *articulator); 483 void AXARTInitArtAuxCVolume (AXART_AUXC_VOLUME *articulator); 484 485 void AXARTInitArtVolumeEnv (AXART_VOLUME_ENV *articulator); 486 void AXARTInitArtAuxAVolumeEnv (AXART_AUXA_VOLUME_ENV *articulator); 487 void AXARTInitArtAuxBVolumeEnv (AXART_AUXB_VOLUME_ENV *articulator); 488 void AXARTInitArtAuxCVolumeEnv (AXART_AUXC_VOLUME_ENV *articulator); 489 490 void AXARTInitArtVolumeMod (AXART_VOLUME_MOD *articulator); 491 void AXARTInitArtAuxAVolumeMod (AXART_AUXA_VOLUME_MOD *articulator); 492 void AXARTInitArtAuxBVolumeMod (AXART_AUXB_VOLUME_MOD *articulator); 493 void AXARTInitArtAuxCVolumeMod (AXART_AUXC_VOLUME_MOD *articulator); 494 495 void AXARTInitArtLpf (AXART_LPF *articulator); 496 void AXARTInitArtFader (AXART_FADER *articulator); 497 498 void AXARTInitArtDRC (AXART_DRC *articulator); 499 500 void AXARTInitArtRmt (AXART_RMT *articulator); 501 void AXARTInitArtRmtFader (AXART_RMT_FADER *articulator); 502 void AXARTInitArtRmtAuxVolume (AXART_RMT_AUX_VOLUME *articulator); 503 504 505 #ifdef __cplusplus 506 } 507 #endif 508 509 #endif // __AXART_H__ 510