added apex audio system
[gbajam21] / libs / aas / AAS_Mixer.h
1 /* Copyright (c) 2003-2021 James Daniels */
2 /* Distributed under the MIT License */
3 /* license terms: see LICENSE file in root or http://opensource.org/licenses/MIT */
4
5 /* Mixer-specific AAS include */
6 /* */
7 /* The functions and variables declared here should only be used if you need */
8 /* to directly access AAS_MixAudio(). This is not recommended and doing so */
9 /* will make it unsafe to use any other AAS functions except AAS_ShowLogo() */
10 /* and AAS_DoDMA3(). See the "Mixer" section of the documentation for more */
11 /* information. */
12
13 #ifndef __AAS_MIXER__
14 #define __AAS_MIXER__
15
16 #include "AAS.h"
17
18 AAS_BEGIN_DECLS
19
20 #define AAS_IN_IWRAM __attribute__ ((section (".iwram")))
21 #define AAS_IN_EWRAM __attribute__ ((section (".ewram")))
22
23 struct AAS_Channel
24 {
25         AAS_u8 effective_volume;  /* 0 : effective_volume = (active&volume)?volume:0 */
26         AAS_BOOL active;          /* 1 : 0 = Channel inactive, 1 = channel active */
27         AAS_u8 volume;            /* 2 : Total vol of chan set must be <= 256, each vol usually in range 0-64 */
28         AAS_u8 pos_fraction;      /* 3 : Fraction component of pos */
29         AAS_u16 frequency;        /* 4 : Frequency (Hz) */
30         AAS_u16 delta;            /* 6 : Delta */
31         const AAS_s8* pos;        /* 8 : Current sample address, fraction component in pos_fraction */
32         const AAS_s8* end;        /* 12 : Address of end of sample */
33         AAS_u32 loop_length;      /* 16 : 0 = No repeat, Other value = Bytes from end back to restart point */
34 }; /* Length = 20 bytes */
35
36 extern struct AAS_Channel AAS_channels[16] AAS_IN_EWRAM;
37 extern AAS_u32 AAS_mix_buffer[640] AAS_IN_EWRAM;
38
39 #define AAS_INIT_BRANCH void (*ptr2Function)();
40 #define AAS_BRANCH(a,b...) ({ ptr2Function = a; ptr2Function(b); })
41
42 /* AAS_MixAudio() is in IWRAM, call from ROM as follows: (same for AAS_MixAudio_NoChange()) */
43 /*   AAS_INIT_BRANCH */
44 /*   AAS_BRANCH( AAS_MixAudio, mix_buffer, chans, iterations ); */
45
46 void AAS_MixAudio( AAS_s8* mix_buffer, struct AAS_Channel chans[], int iterations );
47 void AAS_MixAudio_NoChange( AAS_s8* mix_buffer, struct AAS_Channel chans[], int iterations ); /* Only call if no changes to chans[] since previous call to AAS_MixAudio(). Do not call twice in a row. */
48
49 #define AAS_MIXAUDIO_MODE_NORMAL        0  /* Total vol must be <= 256, normal vol - default */
50 #define AAS_MIXAUDIO_MODE_BOOST         1  /* Total vol must be <= 128, double vol */
51 #define AAS_MIXAUDIO_MODE_BOOSTANDCLIP  2  /* Total vol must be <= 256, double vol */
52
53 void AAS_MixAudio_SetMode( int mode ); /* Set mixer mode, only call if 100% sure AAS_MixAudio won't interrupt */
54
55 /* Set maximum number of channels in set (lower=faster), only call if 100% sure AAS_MixAudio won't interrupt */
56 void AAS_MixAudio_SetMaxChans_2();
57 void AAS_MixAudio_SetMaxChans_4(); /* Default */
58 void AAS_MixAudio_SetMaxChans_8();
59
60 AAS_END_DECLS
61
62 #endif