foo
[gbajam21] / libs / aas / AAS_Main.c
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 #include "AAS_Shared.h"
6 #include "../../src/debug.h"
7
8 extern const int AAS_data_v111;
9 int AAS_lib_v111 AAS_IN_EWRAM;
10
11 static AAS_BOOL AAS_da_active AAS_IN_EWRAM;
12 static AAS_BOOL AAS_db_active AAS_IN_EWRAM;
13 static AAS_BOOL AAS_dynamic_mix_rate AAS_IN_EWRAM;
14
15 /* 0 = 0 Hz mix rate */
16 /* 1 = 800 Hz mix rate, 16 byte mix buffer */
17 /* 2 = 1600 Hz mix rate, 32 byte mix buffer */
18 /* n = 800n Hz mix rate, 16n byte mix buffer */
19 /* n <= 40 */
20 /* REG_TM1D = 0x10000 - 16n; */
21 /* REG_TM0D = AAS_tick_rate[n]; // 0x10000 - ((int)(16777216/800n)); */
22 static AAS_u8 AAS_req_mix_rate AAS_IN_EWRAM;
23 static AAS_u8 AAS_next_mix_rate AAS_IN_EWRAM;
24
25 static AAS_u8 *AAS_next_mixing_buffer AAS_IN_EWRAM;
26
27 static AAS_BOOL AAS_DSA_first AAS_IN_EWRAM = AAS_TRUE;
28
29 static AAS_u8 AAS_MaxChans AAS_IN_EWRAM = 4;
30
31 static AAS_BOOL AAS_Loud AAS_IN_EWRAM = AAS_FALSE;
32 static AAS_u8 AAS_MixAudio_Mode AAS_IN_EWRAM = AAS_MIXAUDIO_MODE_NORMAL;
33
34
35 void AAS_MixAudio_SetMode_Normal();
36 void AAS_MixAudio_SetMode_Boost();
37 void AAS_MixAudio_SetMode_BoostAndClip();
38 void AAS_MOD_Interrupt();
39
40
41 void AAS_MixAudio_SetMode(int mode)
42 {
43         if(mode != AAS_MixAudio_Mode) {
44                 switch (mode) {
45                 case AAS_MIXAUDIO_MODE_NORMAL:
46                         AAS_MixAudio_SetMode_Normal();
47                         AAS_MixAudio_Mode = AAS_MIXAUDIO_MODE_NORMAL;
48                         AAS_changed[0] = AAS_TRUE;
49                         AAS_changed[1] = AAS_TRUE;
50                         break;
51
52                 case AAS_MIXAUDIO_MODE_BOOST:
53                         AAS_MixAudio_SetMode_Boost();
54                         AAS_MixAudio_Mode = AAS_MIXAUDIO_MODE_BOOST;
55                         AAS_changed[0] = AAS_TRUE;
56                         AAS_changed[1] = AAS_TRUE;
57                         break;
58
59                 case AAS_MIXAUDIO_MODE_BOOSTANDCLIP:
60                         AAS_MixAudio_SetMode_BoostAndClip();
61                         AAS_MixAudio_Mode = AAS_MIXAUDIO_MODE_BOOSTANDCLIP;
62                         AAS_changed[0] = AAS_TRUE;
63                         AAS_changed[1] = AAS_TRUE;
64                         break;
65
66                 default:
67                         break;
68                 }
69         }
70 }
71
72 static void AAS_DoConfig(int mix_rate, int volscale, AAS_BOOL stereo, AAS_BOOL dynamic,
73                          AAS_BOOL loud, int chans)
74 {
75         struct AAS_Channel *ch;
76         int i;
77
78         AAS_MOD_Stop();
79
80         if(!AAS_initialised) {
81                 REG_SOUNDCNT_X = 0x0080;        /* turn sound chip on */
82
83                 REG_DMA1SAD = (AAS_u32) AAS_mix_buffer; /*dma1 source */
84                 REG_DMA1DAD = 0x040000a0;       /*write to FIFO A address */
85                 REG_DMA1CNT_H = 0xb600; /*dma control: DMA enabled+ start on FIFO+32bit+repeat+increment source&dest */
86
87                 REG_DMA2SAD = (AAS_u32) (AAS_mix_buffer + 160); /*dma2 source */
88                 REG_DMA2DAD = 0x040000a4;       /*write to FIFO B address */
89                 REG_DMA2CNT_H = 0xb600; /*dma control: DMA enabled+ start on FIFO+32bit+repeat+increment source&dest */
90
91                 AAS_next_mixing_buffer = ((AAS_u8 *) AAS_mix_buffer) + 1280;
92
93                 REG_IE |= 0x10; /* Enable irq for timer 1 */
94                 REG_IME = 1;    /* Enable all interrupts */
95
96                 AAS_da_active = AAS_FALSE;
97                 AAS_db_active = AAS_FALSE;
98         }
99
100         REG_TM0CNT = 0x0;
101         REG_TM1CNT = 0x0;
102
103         if(chans != AAS_MaxChans) {
104                 switch (chans) {
105                 case 8:
106                         AAS_MixAudio_SetMaxChans_8();
107                         break;
108
109                 case 4:
110                         AAS_MixAudio_SetMaxChans_4();
111                         break;
112
113                 default:
114                         AAS_MixAudio_SetMaxChans_2();
115                         break;
116                 }
117                 AAS_MaxChans = chans;
118         }
119
120         AAS_next_mix_rate = AAS_req_mix_rate = mix_rate;
121         AAS_mix_scale = ((AAS_DivTable[mix_rate] * 82) + 128) >> 6;
122         AAS_dynamic_mix_rate = dynamic;
123
124         if(stereo) {
125                 const AAS_u8 chan_rearrange[AAS_MAX_CHANNELS] =
126                     { 0, 8, 9, 1, 2, 10, 11, 3, 4, 12, 13, 5, 6, 14, 15, 7 };
127
128                 for(i = 0; i < AAS_MAX_CHANNELS; ++i) {
129                         AAS_chan_rearrange[i] = chan_rearrange[i];
130                 }
131
132                 REG_SOUNDCNT_H = 0x9a0d;        /*enable DS A&B + fifo reset + use timer0 + 100% volume to L and R */
133         } else {
134                 int a, b;
135
136                 a = 0;
137                 for(b = 0; b < chans; ++b) {
138                         AAS_chan_rearrange[a] = b;
139                         ++a;
140                 }
141                 for(b = 0; b < chans; ++b) {
142                         AAS_chan_rearrange[a] = b + 8;
143                         ++a;
144                 }
145
146                 REG_SOUNDCNT_H = 0xbb0d;        /*enable DS A&B + fifo reset + use timer0 + 100% volume to L and R */
147         }
148
149         ch = &AAS_channels[0];
150         for(i = 16; i > 0; --i) {
151                 ch->active = AAS_FALSE;
152                 ch->loop_length = 0;
153                 ch->pos = 0;
154                 ch->end = 0;
155                 ch->delta = 0;
156                 ++ch;
157         }
158
159         AAS_volscale = volscale;
160
161         AAS_Loud = loud;
162         if(!loud)
163                 AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_NORMAL);
164
165         REG_TM0D = AAS_tick_rate[mix_rate];
166         REG_TM0CNT = 0x0080;    /* Enable timer0 */
167
168         REG_TM1D = 0x10000 - (mix_rate << 4);
169         REG_TM1CNT = 0xC4;      /*enable timer1 + irq and cascade from timer 0 */
170
171         AAS_lib_v111 = AAS_data_v111;
172 }
173
174 int AAS_SetConfig(int config_mix, int config_chans, int config_spatial, int config_dynamic)
175 {
176         int i, chans, mix_rate, volscale, ret;
177         AAS_BOOL stereo;
178         AAS_BOOL dynamic;
179         AAS_BOOL loud;
180
181         ret = AAS_OK;
182
183         switch (config_mix) {
184         case AAS_CONFIG_MIX_32KHZ:
185                 mix_rate = 40;
186                 break;
187
188         case AAS_CONFIG_MIX_28KHZ:
189                 mix_rate = 35;
190                 break;
191
192         case AAS_CONFIG_MIX_24KHZ:
193                 mix_rate = 30;
194                 break;
195
196         case AAS_CONFIG_MIX_20KHZ:
197                 mix_rate = 25;
198                 break;
199
200         case AAS_CONFIG_MIX_16KHZ:
201                 mix_rate = 20;
202                 break;
203
204         case AAS_CONFIG_MIX_12KHZ:
205                 mix_rate = 15;
206                 break;
207
208         case AAS_CONFIG_MIX_8KHZ:
209                 mix_rate = 10;
210                 break;
211
212         default:
213                 ret = AAS_ERROR_INVALID_CONFIG;
214                 break;
215         }
216
217         switch (config_chans) {
218         case AAS_CONFIG_CHANS_16_LOUD:
219                 volscale = 9;
220                 loud = AAS_TRUE;
221                 chans = 8;
222                 break;
223
224         case AAS_CONFIG_CHANS_8_LOUD:
225                 volscale = 8;
226                 loud = AAS_TRUE;
227                 chans = 4;
228                 break;
229
230         case AAS_CONFIG_CHANS_4_LOUD:
231                 volscale = 7;
232                 loud = AAS_TRUE;
233                 chans = 2;
234                 break;
235
236         case AAS_CONFIG_CHANS_16:
237                 volscale = 9;
238                 loud = AAS_FALSE;
239                 chans = 8;
240                 break;
241
242         case AAS_CONFIG_CHANS_8:
243                 volscale = 8;
244                 loud = AAS_FALSE;
245                 chans = 4;
246                 break;
247
248         case AAS_CONFIG_CHANS_4:
249                 volscale = 7;
250                 loud = AAS_FALSE;
251                 chans = 2;
252                 break;
253
254         default:
255                 ret = AAS_ERROR_INVALID_CONFIG;
256                 break;
257         }
258
259         switch (config_spatial) {
260         case AAS_CONFIG_SPATIAL_MONO:
261                 stereo = AAS_FALSE;
262                 break;
263
264         case AAS_CONFIG_SPATIAL_STEREO:
265                 stereo = AAS_TRUE;
266                 break;
267
268         default:
269                 ret = AAS_ERROR_INVALID_CONFIG;
270                 break;
271         }
272
273         switch (config_dynamic) {
274         case AAS_CONFIG_DYNAMIC_ON:
275                 dynamic = AAS_TRUE;
276                 break;
277
278         case AAS_CONFIG_DYNAMIC_OFF:
279                 dynamic = AAS_FALSE;
280                 break;
281
282         default:
283                 ret = AAS_ERROR_INVALID_CONFIG;
284                 break;
285         }
286
287         if(ret == AAS_OK) {
288                 AAS_DoConfig(mix_rate, volscale, stereo, dynamic, loud, chans);
289
290                 AAS_initialised = AAS_TRUE;
291         }
292
293         return ret;
294 }
295
296 const AAS_s8 *AAS_GetOutputBufferAddress(int buffer)
297 {
298         switch (buffer) {
299         case 0:
300                 if(AAS_da_active)
301                         return AAS_next_mixing_buffer;
302                 else
303                         return AAS_NULL;
304                 break;
305
306         case 1:
307                 if(AAS_db_active)
308                         return AAS_next_mixing_buffer + 640;
309                 else
310                         return AAS_NULL;
311                 break;
312
313         default:
314                 return AAS_NULL;
315                 break;
316         }
317 }
318
319 int AAS_GetOutputBufferLength()
320 {
321         return AAS_next_mix_rate * 16;
322 }
323
324 const AAS_u32 AAS_zero_vols[160] = { 0 };
325
326 static AAS_BOOL AAS_interrupt_occured AAS_IN_EWRAM = AAS_FALSE;
327
328 void AAS_FastTimer1InterruptHandler()
329 {
330         if(AAS_dynamic_mix_rate) {
331                 REG_TM0CNT = 0x0;
332                 REG_TM0D = AAS_tick_rate[AAS_next_mix_rate];
333                 REG_TM0CNT = 0x0080;    /* Enable timer0 */
334                 REG_TM1CNT = 0x0;
335                 REG_TM1D = 0x10000 - (AAS_next_mix_rate << 4);
336                 REG_TM1CNT = 0xC4;      /* Enable timer1 + irq and cascade from timer 0 */
337         }
338
339         REG_DMA1CNT = 0x84400004;
340         REG_DMA2CNT = 0x84400004;
341         REG_DMA1CNT_H = 0x0440;
342         REG_DMA2CNT_H = 0x0440;
343         if(AAS_da_active)
344                 REG_DMA1SAD = (unsigned long)AAS_next_mixing_buffer;    /* DMA1 source */
345         else
346                 REG_DMA1SAD = (unsigned long)AAS_zero_vols;
347         REG_DMA1CNT_H = 0xb600; /* DMA control: DMA enabled+start on FIFO+32bit+repeat+increment source&dest */
348         /* Get click on hardware when switch off DMA on Direct Sound B, so have to do it this way instead */
349         if(AAS_db_active)
350                 REG_DMA2SAD = (unsigned long)AAS_next_mixing_buffer + 640;      /* DMA2 source */
351         else
352                 REG_DMA2SAD = (unsigned long)AAS_zero_vols;     /* DMA2 source */
353         REG_DMA2CNT_H = 0xb600; /* DMA control: DMA enabled+start on FIFO+32bit+repeat+increment source&dest */
354
355         AAS_interrupt_occured = AAS_TRUE;
356 }
357
358 #define READCH1 \
359         if ( ch->active ) \
360         { \
361                 int vol = ch->volume; \
362                 if ( vol == 0 ) \
363                 { \
364                         int delta = ch->delta; \
365                         const AAS_s8* end_addr; \
366                         addr = ch->pos + ((delta*curr_mix_rate)>>6); \
367                         end_addr = (ch->end - (delta>>6)) - 1; \
368                         if ( addr >= end_addr ) \
369                         { \
370                                 int ll = ch->loop_length; \
371                                 if ( ll ) \
372                                 { \
373                                         while( addr >= end_addr ) \
374                                         { \
375                                                 addr -= ll; \
376                                         } \
377                                 } \
378                                 else \
379                                 { \
380                                         ch->active = AAS_FALSE; \
381                                 } \
382                         } \
383                         ch->pos = addr; \
384                 } \
385                 else \
386                 { \
387                         tmp1 += vol; \
388                 } \
389                 ch->effective_volume = vol; \
390         } \
391         else \
392         { \
393                 ch->effective_volume = 0; \
394         } \
395
396 #define READCH2 \
397         if ( ch->active ) \
398         { \
399                 int vol = ch->volume; \
400                 if ( vol == 0 ) \
401                 { \
402                         int delta = ch->delta; \
403                         const AAS_s8* end_addr; \
404                         addr = ch->pos + ((delta*curr_mix_rate)>>6); \
405                         end_addr = (ch->end - (delta>>6)) - 1; \
406                         if ( addr >= end_addr ) \
407                         { \
408                                 int ll = ch->loop_length; \
409                                 if ( ll ) \
410                                 { \
411                                         while( addr >= end_addr ) \
412                                         { \
413                                                 addr -= ll; \
414                                         } \
415                                 } \
416                                 else \
417                                 { \
418                                         ch->active = AAS_FALSE; \
419                                 } \
420                         } \
421                         ch->pos = addr; \
422                 } \
423                 else \
424                 { \
425                         tmp2 += vol; \
426                 } \
427                 ch->effective_volume = vol; \
428         } \
429         else \
430         { \
431                 ch->effective_volume = 0; \
432         } \
433
434 void AAS_DoWork()
435 {
436         if(AAS_interrupt_occured) {
437                 AAS_interrupt_occured = AAS_FALSE;
438
439                 if(AAS_next_mixing_buffer == (AAS_u8 *) AAS_mix_buffer)
440                         AAS_next_mixing_buffer = ((AAS_u8 *) AAS_mix_buffer) + 1280;
441                 else
442                         AAS_next_mixing_buffer = ((AAS_u8 *) AAS_mix_buffer);
443
444                 AAS_MOD_Interrupt();
445
446                 {
447                         int tmp1, tmp2, val, curr_mix_rate;
448                         struct AAS_Channel *ch;
449                         const AAS_s8 *addr;
450
451                         curr_mix_rate = AAS_req_mix_rate;
452
453                         if(AAS_dynamic_mix_rate) {
454                                 val = 0;
455                                 ch = &AAS_channels[0];
456                                 for(tmp2 = AAS_MaxChans; tmp2 > 0; --tmp2) {
457                                         if(ch->active && (ch->volume > 0)) {
458                                                 tmp1 = ch->frequency;
459                                                 if(tmp1 > val)
460                                                         val = tmp1;
461                                         }
462                                         ++ch;
463                                 }
464
465                                 ch = &AAS_channels[8];
466                                 for(tmp2 = AAS_MaxChans; tmp2 > 0; --tmp2) {
467                                         if(ch->active && (ch->volume > 0)) {
468                                                 tmp1 = ch->frequency;
469                                                 if(tmp1 > val)
470                                                         val = tmp1;
471                                         }
472                                         ++ch;
473                                 }
474
475                                 val = ((val * 82) >> 16) + 1;
476                                 if(val < curr_mix_rate)
477                                         curr_mix_rate = val;
478
479                                 if(AAS_next_mix_rate != curr_mix_rate) {
480                                         AAS_next_mix_rate = curr_mix_rate;
481                                         AAS_mix_scale = val = ((AAS_DivTable[curr_mix_rate] * 82) + 128) >> 6;
482                                         ch = &AAS_channels[0];
483                                         for(tmp2 = AAS_MaxChans; tmp2 > 0; --tmp2) {
484                                                 if(ch->active)
485                                                         ch->delta = AAS_Min(4095, ((ch->frequency * val) + 32768) >> 16);
486                                                 ++ch;
487                                         }
488
489                                         ch = &AAS_channels[8];
490                                         for(tmp2 = AAS_MaxChans; tmp2 > 0; --tmp2) {
491                                                 if(ch->active)
492                                                         ch->delta = AAS_Min(4095, ((ch->frequency * val) + 32768) >> 16);
493                                                 ++ch;
494                                         }
495
496                                         AAS_changed[0] = AAS_TRUE;
497                                         AAS_changed[1] = AAS_TRUE;
498                                 }
499                         }
500
501                         tmp1 = 0;
502                         tmp2 = 0;
503
504                         ch = &AAS_channels[0];
505                         switch (AAS_MaxChans) {
506                         case 8:
507                                 READCH1++ ch;
508                                 READCH1++ ch;
509                                 READCH1++ ch;
510                                 READCH1++ ch;
511                                 READCH1++ ch;
512                                 READCH1++ ch;
513                                 READCH1++ ch;
514                                 READCH1++ ch;
515                                 READCH2++ ch;
516                                 READCH2++ ch;
517                                 READCH2++ ch;
518                                 READCH2++ ch;
519                                 READCH2++ ch;
520                                 READCH2++ ch;
521                                 READCH2++ ch;
522                                 READCH2 break;
523
524                         case 4:
525                                 READCH1++ ch;
526                                 READCH1++ ch;
527                                 READCH1++ ch;
528                                 READCH1 ch = &AAS_channels[8];
529                                 READCH2++ ch;
530                                 READCH2++ ch;
531                                 READCH2++ ch;
532                                 READCH2 break;
533
534                         case 2:
535                         default:
536                                 READCH1++ ch;
537                                 READCH1 ch = &AAS_channels[8];
538                                 READCH2++ ch;
539                                 READCH2 break;
540                         }
541
542                         if(AAS_Loud) {
543                                 if(AAS_DSA_first) {
544                                         /* Direct Sound A */
545                                         if(tmp1) {
546                                                 if(tmp1 > 128) {
547                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOSTANDCLIP);
548                                                 } else {
549                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOST);
550                                                 }
551
552                                                 if(AAS_changed[0]) {
553                                                         AAS_INIT_BRANCH
554                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
555                                                 } else {
556                                                         AAS_INIT_BRANCH
557                                                         AAS_BRANCH(AAS_MixAudio_NoChange, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
558                                                 }
559                                                 AAS_da_active = AAS_TRUE;
560                                         } else {
561                                                 AAS_da_active = AAS_FALSE;
562                                         }
563
564                                         /* Direct Sound B */
565                                         if(tmp2) {
566                                                 if(tmp2 > 128) {
567                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOSTANDCLIP);
568                                                 } else {
569                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOST);
570                                                 }
571
572                                                 {
573                                                         AAS_INIT_BRANCH
574                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
575                                                 }
576
577                                                 AAS_db_active = AAS_TRUE;
578                                         } else {
579                                                 AAS_db_active = AAS_FALSE;
580                                         }
581
582                                         AAS_DSA_first = AAS_FALSE;
583                                 } else {
584                                         /* Direct Sound B */
585                                         if(tmp2) {
586                                                 if(tmp2 > 128) {
587                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOSTANDCLIP);
588                                                 } else {
589                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOST);
590                                                 }
591
592                                                 if(AAS_changed[1]) {
593                                                         AAS_INIT_BRANCH
594                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
595                                                 } else {
596                                                         AAS_INIT_BRANCH
597                                                         AAS_BRANCH(AAS_MixAudio_NoChange, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
598                                                 }
599                                                 AAS_db_active = AAS_TRUE;
600                                         } else {
601                                                 AAS_db_active = AAS_FALSE;
602                                         }
603
604                                         /* Direct Sound A */
605                                         if(tmp1) {
606                                                 if(tmp1 > 128) {
607                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOSTANDCLIP);
608                                                 } else {
609                                                         AAS_MixAudio_SetMode(AAS_MIXAUDIO_MODE_BOOST);
610                                                 }
611
612                                                 {
613                                                         AAS_INIT_BRANCH
614                                                     AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
615                                                 }
616
617                                                 AAS_da_active = AAS_TRUE;
618                                         } else {
619                                                 AAS_da_active = AAS_FALSE;
620                                         }
621
622                                         AAS_DSA_first = AAS_TRUE;
623                                 }
624                         } else {
625                                 if(AAS_DSA_first) {
626                                         /* Direct Sound A */
627                                         if(tmp1) {
628                                                 if(AAS_changed[0]) {
629                                                         AAS_INIT_BRANCH
630                                                     AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
631                                                 } else {
632                                                         AAS_INIT_BRANCH
633                                                         AAS_BRANCH(AAS_MixAudio_NoChange, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
634                                                 }
635                                                 AAS_da_active = AAS_TRUE;
636                                         } else {
637                                                 AAS_da_active = AAS_FALSE;
638                                         }
639
640                                         /* Direct Sound B */
641                                         if(tmp2) {
642                                                 {
643                                                         AAS_INIT_BRANCH
644                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
645                                                 }
646                                                 AAS_db_active = AAS_TRUE;
647                                         } else {
648                                                 AAS_db_active = AAS_FALSE;
649                                         }
650
651                                         AAS_DSA_first = AAS_FALSE;
652                                 } else {
653                                         /* Direct Sound B */
654                                         if(tmp2) {
655                                                 if(AAS_changed[1]) {
656                                                         AAS_INIT_BRANCH
657                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
658                                                 } else {
659                                                         AAS_INIT_BRANCH
660                                                         AAS_BRANCH(AAS_MixAudio_NoChange, AAS_next_mixing_buffer + 640, &AAS_channels[8], curr_mix_rate);
661                                                 }
662                                                 AAS_db_active = AAS_TRUE;
663                                         } else {
664                                                 AAS_db_active = AAS_FALSE;
665                                         }
666
667                                         /* Direct Sound A */
668                                         if(tmp1) {
669                                                 {
670                                                         AAS_INIT_BRANCH
671                                                         AAS_BRANCH(AAS_MixAudio, AAS_next_mixing_buffer, &AAS_channels[0], curr_mix_rate);
672                                                 }
673
674                                                 AAS_da_active = AAS_TRUE;
675                                         } else {
676                                                 AAS_da_active = AAS_FALSE;
677                                         }
678
679                                         AAS_DSA_first = AAS_TRUE;
680                                 }
681                         }
682
683                         AAS_changed[0] = AAS_FALSE;
684                         AAS_changed[1] = AAS_FALSE;
685                 }
686         }
687 }
688
689 void AAS_Timer1InterruptHandler()
690 {
691         AAS_FastTimer1InterruptHandler();
692         AAS_DoWork();
693 }
694
695 int AAS_GetActualMixRate()
696 {
697         return AAS_next_mix_rate * 800;
698 }