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