Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
31650.c
Go to the documentation of this file.
1#include "common.h"
2#include "audio.h"
3#include "nu/nualsgi.h"
4
5static s16 _getVol(s16 arg0, s32 arg1, s16 arg2, u16 arg3);
6
13
17u16 AuGlobalVolume = 0x7FFF;
19
20extern s16 AuEqPower[128];
21
22#define AU_EQPOW_MID_IDX 64
23#define AU_EQPOW_MAX_IDX 127
24
25void au_driver_init(AuSynDriver* driver, ALConfig* config) {
26 ALHeap* heap = config->heap;
27 s32 i;
28
29 if (gActiveSynDriverPtr != NULL) {
30 return;
31 }
32
33 driver->num_pvoice = config->num_pvoice;
34 driver->num_bus = config->num_bus;
35 driver->curSamples = 0;
36 driver->unk_04 = 0;
37 driver->outputRate = config->outputRate;
38 driver->dmaNew = config->dmaNew;
39
40 gActiveSynDriverPtr = driver;
41 gSynDriverPtr = driver;
42 AuUseGlobalVolume = FALSE;
43 AuGlobalVolume = 0x7FFF;
44 AuSynStereoDirty = TRUE;
45
47
48 // this is inlined alN_PVoiceNew
49 for (i = 0; i < config->num_pvoice; i++) {
50 AuPVoice* voice = &gSynDriverPtr->pvoices[i];
51 voice->decoder.state = alHeapAlloc(heap, 1, sizeof(*voice->decoder.state));
52 voice->decoder.lstate = alHeapAlloc(heap, 1, sizeof(*voice->decoder.lstate));
54 voice->decoder.lastsam = 0;
55 voice->decoder.first = 1;
56 voice->decoder.memin = NULL;
57 voice->resampler.state = alHeapAlloc(heap, 1, sizeof(*voice->resampler.state));
58 voice->resampler.delta = 0;
59 voice->resampler.first = 1;
60 voice->resampler.ratio = 1.0f;
61 voice->envMixer.state = alHeapAlloc(heap, 1, sizeof(*voice->envMixer.state));
62 voice->envMixer.first = 1;
63 voice->envMixer.motion = AL_STOPPED;
64 voice->envMixer.volume = 1;
65 voice->envMixer.ltgt = 1;
66 voice->envMixer.rtgt = 1;
67 voice->envMixer.cvolL = 1;
68 voice->envMixer.cvolR = 1;
69 voice->envMixer.dryamt = 0;
70 voice->envMixer.wetamt = 0;
71 voice->envMixer.lratm = 1;
72 voice->envMixer.lratl = 0;
73 voice->envMixer.rratm = 1;
74 voice->envMixer.rratl = 0;
75 voice->envMixer.delta = 0;
76 voice->envMixer.segEnd = 0;
77 voice->envMixer.pan = 64;
78 voice->unk_74 = 0;
79 voice->next = NULL;
80 voice->busId = FX_BUS_BGMA_MAIN;
81 voice->index = i;
82 }
83
84 gSynDriverPtr->fxBus = alHeapAlloc(heap, config->num_bus, sizeof(*gSynDriverPtr->fxBus));
85
86 for (i = 0; i < config->num_bus; i++) {
87 AuFxBus* fxBus = &gSynDriverPtr->fxBus[i];
88 fxBus->head = NULL;
89 fxBus->tail = NULL;
90 fxBus->gain = 0x7FFF;
92 fxBus->fxL = alHeapAlloc(heap, 1, sizeof(*fxBus->fxL));
93 fxBus->fxR = alHeapAlloc(heap, 1, sizeof(*fxBus->fxR));
94 func_80058E84(fxBus->fxL, fxBus->curEffectType, heap);
95 func_80058E84(fxBus->fxR, fxBus->curEffectType, heap);
96 }
97
102 AuDelayCount = 4;
103
106 for (i = 0; i < 4 * AUDIO_SAMPLES; i++) {
108 }
109
110 gSynDriverPtr->heap = heap;
111}
112
114 if (gActiveSynDriverPtr != NULL) {
115 gActiveSynDriverPtr = NULL;
116 }
117}
118
119Acmd* alAudioFrame(Acmd* cmdList, s32* cmdLen, s16* outBuf, s32 outLen) {
120 Acmd* cmdListPos;
121 AuPVoice* pvoice;
122 AuFxBus* fxBus;
123
124 s16* bufPos;
125 s16 auxOut;
126 s16 mainOut;
127
128 s32 i;
129 s32 first = FALSE;
130
131 cmdListPos = cmdList;
132 bufPos = outBuf;
133 if (gActiveSynDriverPtr == NULL) {
134 *cmdLen = 0;
135 } else {
137 if (AuSynStereoDirty) {
138 for (i = 0; i < gSynDriverPtr->num_pvoice; i++) {
139 pvoice = &gSynDriverPtr->pvoices[i];
140 if (pvoice->envMixer.motion == AL_PLAYING) {
141 au_syn_set_pan(i, pvoice->envMixer.pan);
142 }
143 }
144 AuSynStereoDirty = FALSE;
145 }
146 while (outLen > 0) {
148 for (i = 0; i < gSynDriverPtr->num_pvoice; i++) {
149 pvoice = &gSynDriverPtr->pvoices[i];
150
151 if ((pvoice->busId != 0xFF) && (pvoice->busId < gSynDriverPtr->num_bus)) {
152 fxBus = &gSynDriverPtr->fxBus[pvoice->busId];
153 if (fxBus->tail != NULL) {
154 fxBus->tail->next = pvoice;
155 } else {
156 fxBus->head = pvoice;
157 }
158 fxBus->tail = pvoice;
159 }
160 }
161 first = TRUE;
162 for (i = 0; i < gSynDriverPtr->num_bus; i++) {
163 fxBus = &gSynDriverPtr->fxBus[i];
164 if (fxBus->head != NULL) {
165 // clear all main and aux outputs
166 aClearBuffer(cmdListPos++, N_AL_MAIN_L_OUT, 8 * AUDIO_SAMPLES);
167 if (fxBus->head != NULL) {
168 AuPVoice* next;
169 do {
170 cmdListPos = au_pull_voice(fxBus->head, cmdListPos);
171 next = fxBus->head->next;
172 fxBus->head->next = NULL;
173 fxBus->head = next;
174 } while (next != NULL);
175 fxBus->tail = NULL;
176 }
177 if (fxBus->curEffectType != AU_FX_NONE) {
178 cmdListPos = au_pull_fx(fxBus->fxL, cmdListPos, N_AL_AUX_L_OUT, 0);
179 cmdListPos = au_pull_fx(fxBus->fxR, cmdListPos, N_AL_AUX_R_OUT, 0);
180 }
181
182 // apply channel delay
183 if (i == AuDelayedVoiceGroup) {
184 mainOut = -1;
185 switch (AuDelayedChannel) {
186 case 1:
187 mainOut = N_AL_MAIN_L_OUT;
188 auxOut = N_AL_AUX_L_OUT;
189 break;
190 case 2:
191 mainOut = N_AL_MAIN_R_OUT;
192 auxOut = N_AL_AUX_R_OUT;
193 break;
194 }
195 if (mainOut != -1) {
196 n_aSaveBuffer(cmdListPos++, 2 * AUDIO_SAMPLES, mainOut, osVirtualToPhysical(AuDelayBufferMain + (AuDelayCounter % AuDelayCount) * AUDIO_SAMPLES));
197 n_aLoadBuffer(cmdListPos++, 2 * AUDIO_SAMPLES, mainOut, osVirtualToPhysical(AuDelayBufferMain + ((AuDelayCounter + 1) % AuDelayCount) * AUDIO_SAMPLES));
198 n_aSaveBuffer(cmdListPos++, 2 * AUDIO_SAMPLES, auxOut, osVirtualToPhysical(AuDelayBufferAux + (AuDelayCounter % AuDelayCount) * AUDIO_SAMPLES));
199 n_aLoadBuffer(cmdListPos++, 2 * AUDIO_SAMPLES, auxOut, osVirtualToPhysical(AuDelayBufferAux + ((AuDelayCounter + 1) % AuDelayCount) * AUDIO_SAMPLES));
200 }
201 }
202
203 // mix voice groups
204 if (first) {
205 aClearBuffer(cmdListPos++, 0, 4 * AUDIO_SAMPLES);
206 } else {
207 n_aLoadBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, 0, osVirtualToPhysical(gSynDriverPtr->savedAuxOut));
208 }
209 aMix(cmdListPos++, 0, fxBus->gain, N_AL_AUX_L_OUT, 0);
210 aMix(cmdListPos++, 0, fxBus->gain, N_AL_AUX_R_OUT, 2 * AUDIO_SAMPLES);
211 n_aSaveBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, 0, osVirtualToPhysical(gSynDriverPtr->savedAuxOut));
212 if (first) {
213 aClearBuffer(cmdListPos++, 0, 4 * AUDIO_SAMPLES);
214 first = FALSE;
215 } else {
216 n_aLoadBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, 0, osVirtualToPhysical(gSynDriverPtr->savedMainOut));
217 }
218 aMix(cmdListPos++, 0, fxBus->gain, N_AL_MAIN_L_OUT, 0);
219 aMix(cmdListPos++, 0, fxBus->gain, N_AL_MAIN_R_OUT, 2 * AUDIO_SAMPLES);
220 n_aSaveBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, 0, osVirtualToPhysical(gSynDriverPtr->savedMainOut));
221 }
222 }
223
224 aDMEMMove(cmdListPos++, 0, N_AL_MAIN_L_OUT, 4 * AUDIO_SAMPLES);
225 n_aLoadBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, N_AL_AUX_L_OUT, osVirtualToPhysical(gSynDriverPtr->savedAuxOut));
226 aMix(cmdListPos++, 0, 0x7FFF, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT);
227 aMix(cmdListPos++, 0, 0x7FFF, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT);
228
229 if (AuUseGlobalVolume) {
230 u16 vol;
231 aDMEMMove(cmdListPos++, N_AL_MAIN_L_OUT, 0, 4 * AUDIO_SAMPLES);
232 aClearBuffer(cmdListPos++, N_AL_MAIN_L_OUT, 4 * AUDIO_SAMPLES);
233 vol = AuGlobalVolume;
234 aMix(cmdListPos++, 0, vol, 0, N_AL_MAIN_L_OUT);
235 aMix(cmdListPos++, 0, vol, 2 * AUDIO_SAMPLES, N_AL_MAIN_R_OUT);
236 }
237
238 outLen -= AUDIO_SAMPLES;
239 n_aInterleave(cmdListPos++);
240 n_aSaveBuffer(cmdListPos++, 4 * AUDIO_SAMPLES, 0, bufPos);
241 bufPos += 2 * AUDIO_SAMPLES;
244 }
245 *cmdLen = (cmdListPos - cmdList);
246 }
247 return cmdListPos;
248}
249
251 AuUseGlobalVolume = TRUE;
252}
253
254void au_set_global_volume(s16 arg0) {
255 AuGlobalVolume = arg0;
256}
257
259 return AuGlobalVolume;
260}
261
262void func_80056D5C(u8 bStereoSound) {
263 AuSynUseStereo = bStereoSound;
264 AuSynStereoDirty = TRUE;
265}
266
267void au_bus_set_volume(u8 index, u16 arg1) {
268 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
269
270 fxBus->gain = arg1 & 0x7FFF;
271}
272
273u16 au_bus_get_volume(u8 index, u16 arg1) {
274 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
275
276 return fxBus->gain;
277}
278
279void au_bus_set_effect(u8 index, u8 effectType) {
280 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
281
282 fxBus->curEffectType = effectType;
283 func_8005904C(fxBus->fxL, effectType);
284 func_8005904C(fxBus->fxR, effectType);
285}
286
287void au_bus_set_fx_params(u8 index, s16 delayIndex, s16 paramID, s32 value) {
288 AuFxBus* fxBus = &gSynDriverPtr->fxBus[index];
289
290 au_fx_param_hdl(fxBus->fxL, delayIndex, paramID, value);
291 au_fx_param_hdl(fxBus->fxR, delayIndex, paramID, value);
292}
293
294void au_pvoice_set_bus(u8 index, s8 busId) {
295 AuPVoice* pvoice = &gSynDriverPtr->pvoices[index];
296
297 pvoice->busId = busId;
298}
299
300// based on n_alSynStopVoice
301void au_syn_stop_voice(u8 voiceIdx) {
302 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
303 AuLoadFilter* decoder = &pvoice->decoder;
304
305 pvoice->envMixer.motion = AL_STOPPED;
306 pvoice->envMixer.first = 1;
307 pvoice->envMixer.volume = 1;
308 pvoice->resampler.delta = 0;
309 pvoice->resampler.first = 1;
310 decoder->lastsam = 0;
311 decoder->first = 1;
312 decoder->sample = 0;
313 if (decoder->instrument != NULL) {
314 decoder->memin = (s32)decoder->instrument->base;
315 if (decoder->instrument->type == AL_ADPCM_WAVE) {
316 if (decoder->instrument->loopEnd != 0){
317 decoder->loop.count = decoder->instrument->loopCount;
318 }
319 } else if (decoder->instrument->type == AL_RAW16_WAVE) {
320 if (decoder->instrument->loopEnd != 0){
321 decoder->loop.count = decoder->instrument->loopCount;
322 }
323 }
324 }
325}
326
327// based on n_alSynStartVoice, but without setting new wavetable
328void au_syn_start_voice(u8 voiceIdx) {
329 AuPVoice* pvoice = (AuPVoice*)&gSynDriverPtr->pvoices[voiceIdx];
330
331 pvoice->envMixer.motion = AL_PLAYING;
332}
333
334// based on n_alSynStartVoiceParams
335void au_syn_start_voice_params(u8 voiceIdx, u8 busId, Instrument* instrument, f32 pitch, s16 vol, u8 pan, u8 fxMix, s32 delta) {
336 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
337 AuLoadFilter* decoder = &pvoice->decoder;
338 AuEnvMixer* envMixer = &pvoice->envMixer;
339 AuResampler* resampler = &pvoice->resampler;
340
341 pvoice->busId = busId;
342 decoder->instrument = instrument;
343
344 pvoice->decoder.memin = (s32)decoder->instrument->base;
345 pvoice->decoder.sample = 0;
346
347 switch (decoder->instrument->type) {
348 case AL_ADPCM_WAVE:
350 pvoice->decoder.bookSize = decoder->instrument->dc_bookSize;
351 if (decoder->instrument->loopEnd == 0) {
352 decoder->loop.count = 0;
353 decoder->loop.end = 0;
354 decoder->loop.start = 0;
355 } else {
356 decoder->loop.start = decoder->instrument->loopStart;
357 decoder->loop.end = decoder->instrument->loopEnd;
358 decoder->loop.count = decoder->instrument->loopCount;
359 alCopy(decoder->instrument->loopPredictor, decoder->lstate, sizeof(ADPCM_STATE));
360 }
361 break;
362 case AL_RAW16_WAVE:
363 if (decoder->instrument->loopEnd != 0) {
364 decoder->loop.start = decoder->instrument->loopStart;
365 decoder->loop.end = decoder->instrument->loopEnd;
366 decoder->loop.count = decoder->instrument->loopCount;
367 } else {
368 decoder->loop.count = 0;
369 decoder->loop.end = 0;
370 decoder->loop.start = 0;
371 }
372 break;
373 }
374
375 envMixer->motion = AL_PLAYING;
376 envMixer->first = 1;
377 envMixer->delta = 0;
378 envMixer->segEnd = delta;
379 envMixer->pan = pan;
380 envMixer->volume = SQ(vol) >> 0xF;
381 envMixer->dryamt = AuEqPower[fxMix];
382 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
383 if (envMixer->segEnd != 0) {
384 envMixer->cvolL = 1;
385 envMixer->cvolR = 1;
386 } else {
387 if (!AuSynUseStereo) {
388 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
389 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
390 } else {
391 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
392 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
393 }
394 }
395 resampler->ratio = pitch;
396}
397
398void au_syn_set_wavetable(u8 voiceIdx, Instrument* instrument) {
399 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
400 AuLoadFilter* decoder = &pvoice->decoder;
401
402 pvoice->decoder.instrument = instrument;
403 pvoice->decoder.memin = (s32)decoder->instrument->base;
404 pvoice->decoder.sample = 0;
405
406 switch (decoder->instrument->type) {
407 case AL_ADPCM_WAVE:
409 pvoice->decoder.bookSize = decoder->instrument->dc_bookSize;
410 if (decoder->instrument->loopEnd == 0) {
411 pvoice->decoder.loop.count = 0;
412 pvoice->decoder.loop.end = 0;
413 pvoice->decoder.loop.start = 0;
414 } else {
415 pvoice->decoder.loop.start = decoder->instrument->loopStart;
416 pvoice->decoder.loop.end = decoder->instrument->loopEnd;
417 pvoice->decoder.loop.count = decoder->instrument->loopCount;
418 alCopy(decoder->instrument->loopPredictor, pvoice->decoder.lstate, sizeof(ADPCM_STATE));
419 }
420 break;
421 case AL_RAW16_WAVE:
422 if (decoder->instrument->loopEnd != 0) {
423 pvoice->decoder.loop.start = decoder->instrument->loopStart;
424 pvoice->decoder.loop.end = decoder->instrument->loopEnd;
425 pvoice->decoder.loop.count = decoder->instrument->loopCount;
426 } else {
427 pvoice->decoder.loop.count = 0;
428 pvoice->decoder.loop.end = 0;
429 pvoice->decoder.loop.start = 0;
430 }
431 break;
432 }
433}
434
435// based on n_alSynSetPitch
436void au_syn_set_pitch(u8 voiceIdx, f32 pitch) {
437 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
438
439 pvoice->resampler.ratio = pitch;
440}
441
442void au_syn_set_mixer_params(u8 voiceIdx, s16 volume, s32 delta, u8 pan, u8 fxMix) {
443 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
444 AuEnvMixer* envMixer = &pvoice->envMixer;
445
446 if (envMixer->delta >= envMixer->segEnd) {
447 envMixer->delta = envMixer->segEnd;
448 if (!AuSynUseStereo) {
449 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
450 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
451 } else {
452 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
453 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
454 }
455 } else {
456 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
457 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
458 }
459 if (envMixer->cvolL == 0) {
460 envMixer->cvolL = 1;
461 }
462 if (envMixer->cvolR == 0) {
463 envMixer->cvolR = 1;
464 }
465
466 envMixer->delta = 0;
467 envMixer->segEnd = delta;
468 envMixer->pan = pan;
469 envMixer->volume = SQ(volume) >> 0xF;
470 envMixer->dryamt = AuEqPower[fxMix];
471 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
472 envMixer->first = 1;
473}
474
475void au_syn_set_pan_fxmix(u8 voiceIdx, u8 pan, u8 fxMix) {
476 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
477 AuEnvMixer* envMixer = &pvoice->envMixer;
478
479 if (envMixer->delta >= envMixer->segEnd) {
480 envMixer->delta = envMixer->segEnd;
481 if (!AuSynUseStereo) {
482 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
483 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
484 } else {
485 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
486 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
487 }
488 } else {
489 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
490 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
491 }
492 if (envMixer->cvolL == 0) {
493 envMixer->cvolL = 1;
494 }
495 if (envMixer->cvolR == 0) {
496 envMixer->cvolR = 1;
497 }
498
499 envMixer->pan = pan;
500 envMixer->dryamt = AuEqPower[fxMix];
501 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
502 envMixer->first = 1;
503}
504
505void au_syn_set_volume_delta(u8 voiceIdx, s16 vol, s32 delta) {
506 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
507 AuEnvMixer* envMixer = &pvoice->envMixer;
508
509 if (envMixer->delta >= envMixer->segEnd) {
510 envMixer->delta = envMixer->segEnd;
511 if (!AuSynUseStereo) {
512 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
513 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
514 } else {
515 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
516 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
517 }
518 } else {
519 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
520 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
521 }
522 if (envMixer->cvolL == 0) {
523 envMixer->cvolL = 1;
524 }
525 if (envMixer->cvolR == 0) {
526 envMixer->cvolR = 1;
527 }
528
529 envMixer->volume = SQ(vol) >> 0xF;
530 envMixer->delta = 0;
531 envMixer->segEnd = delta;
532 envMixer->first = 1;
533}
534
535void au_syn_set_pan(u8 voiceIdx, u8 pan) {
536 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
537 AuEnvMixer* envMixer = &pvoice->envMixer;
538
539 if (envMixer->delta >= envMixer->segEnd) {
540 envMixer->delta = envMixer->segEnd;
541 if (!AuSynUseStereo) {
542 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
543 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
544 } else {
545 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
546 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
547 }
548 } else {
549 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
550 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
551 }
552 if (envMixer->cvolL == 0) {
553 envMixer->cvolL = 1;
554 }
555 if (envMixer->cvolR == 0) {
556 envMixer->cvolR = 1;
557 }
558
559 envMixer->pan = pan;
560 envMixer->first = 1;
561}
562
563void au_syn_set_fxmix(u8 voiceIdx, u8 fxMix) {
564 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
565 AuEnvMixer* envMixer = &pvoice->envMixer;
566
567 if (envMixer->delta >= envMixer->segEnd) {
568 envMixer->delta = envMixer->segEnd;
569 if (!AuSynUseStereo) {
570 envMixer->cvolL = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
571 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MID_IDX]) >> 0xF;
572 } else {
573 envMixer->cvolL = (envMixer->volume * AuEqPower[envMixer->pan]) >> 0xF;
574 envMixer->cvolR = (envMixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envMixer->pan]) >> 0xF;
575 }
576 } else {
577 envMixer->cvolL = _getVol(envMixer->cvolL, envMixer->delta, envMixer->lratm, envMixer->lratl);
578 envMixer->cvolR = _getVol(envMixer->cvolR, envMixer->delta, envMixer->rratm, envMixer->rratl);
579 }
580 if (envMixer->cvolL == 0) {
581 envMixer->cvolL = 1;
582 }
583 if (envMixer->cvolR == 0) {
584 envMixer->cvolR = 1;
585 }
586
587 envMixer->dryamt = AuEqPower[fxMix];
588 envMixer->wetamt = AuEqPower[AU_EQPOW_MAX_IDX - fxMix];
589 envMixer->first = 1;
590}
591
592s32 au_syn_get_playing(u8 voiceIdx) {
593 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
594
595 return pvoice->envMixer.motion;
596}
597
598s32 au_syn_get_bus(u8 voiceIdx) {
599 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
600
601 return pvoice->busId;
602}
603
604f32 au_syn_get_pitch(u8 voiceIdx) {
605 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
606
607 return pvoice->resampler.ratio;
608}
609
610u8 au_syn_get_pan(u8 voiceIdx) {
611 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
612
613 return pvoice->envMixer.pan;
614}
615
616s16 au_syn_get_dryamt(u8 voiceIdx) {
617 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
618
619 return pvoice->envMixer.dryamt;
620}
621
622s16 au_syn_get_wetamt(u8 voiceIdx) {
623 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
624
625 return pvoice->envMixer.wetamt;
626}
627
628s32 au_syn_get_volume_left(u8 voiceIdx) {
629 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
630 AuEnvMixer* envmixer = &pvoice->envMixer;
631 u32 retVal;
632
633 if (envmixer->delta >= envmixer->segEnd) {
634 if (!AuSynUseStereo) {
635 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MID_IDX] * 2) >> 0x10;
636 } else {
637 retVal = (envmixer->volume * AuEqPower[envmixer->pan] * 2) >> 0x10;
638 }
639 } else {
640 retVal = _getVol(envmixer->cvolL, envmixer->delta, envmixer->lratm, envmixer->lratl);
641 }
642 return retVal;
643}
644
645s32 au_syn_get_volume_right(u8 voiceIdx) {
646 AuPVoice* pvoice = &gSynDriverPtr->pvoices[voiceIdx];
647 AuEnvMixer* envmixer = &pvoice->envMixer;
648 u32 retVal;
649
650 if (envmixer->delta >= envmixer->segEnd) {
651 if (!AuSynUseStereo) {
652 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MID_IDX] * 2) >> 0x10;
653 } else {
654 retVal = (envmixer->volume * AuEqPower[AU_EQPOW_MAX_IDX - envmixer->pan] * 2) >> 0x10;
655 }
656 } else {
657 retVal = _getVol(envmixer->cvolL, envmixer->delta, envmixer->lratm, envmixer->lratl);
658 }
659 return retVal;
660}
661
662void au_set_delay_time(s32 arg0) {
663 if (arg0 < 2) {
664 AuDelayCount = 0;
666 }
667
668 AuDelayCount = arg0;
669 if (arg0 > 4) {
670 AuDelayCount = 4;
671 }
672}
673
674void au_delay_left_channel(u8 groupIdx) {
675 s32* phi_a1 = (s32*)AuDelayBufferMain;
676 s32* phi_v1 = (s32*)AuDelayBufferAux;
677 s32 i;
678
679 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
680 *phi_a1++ = 0;
681 *phi_v1++ = 0;
682 }
683
684 AuDelayedVoiceGroup = groupIdx;
686 AuDelayCounter = 0;
687}
688
689void au_delay_right_channel(u8 groupIdx) {
690 s32* phi_a1 = (s32*)AuDelayBufferMain;
691 s32* phi_v1 = (s32*)AuDelayBufferAux;
692 s32 i;
693
694 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
695 *phi_a1++ = 0;
696 *phi_v1++ = 0;
697 }
698
699 AuDelayedVoiceGroup = groupIdx;
701 AuDelayCounter = 0;
702}
703
709
710void au_delay_channel(s16 arg0) {
711 s32* phi_a1 = (s32*)AuDelayBufferMain;
712 s32* phi_v1 = (s32*)AuDelayBufferAux;
713 s32 i;
714
715 for (i = 0; i < 2 * AUDIO_SAMPLES; i++) {
716 *phi_a1++ = 0;
717 *phi_v1++ = 0;
718 }
719
721 AuDelayedChannel = arg0;
722 AuDelayCounter = 0;
723}
724
725void alHeapInit(ALHeap* hp, u8* base, s32 len) {
726 u32 i;
727 s32 alignBytes = 0x10 - ((s32)base & 0xF);
728
729 if (alignBytes != 0x10) {
730 hp->base = base + alignBytes;
731 } else {
732 hp->base = base;
733 }
734 hp->len = len;
735 hp->count = 0;
736 hp->cur = hp->base;
737
738 for (i = 0; i < (u32)(hp->len) >> 2; i++) {
739 ((u32*)hp->base)[i] = 0;
740 }
741}
742
743void* alHeapAlloc(ALHeap* heap, s32 count, s32 size) {
744 void* ret = NULL;
745 u8* newCur = &heap->cur[ALIGN16(count * size)];
746
747 if (&heap->base[heap->len] >= newCur) {
748 ret = heap->cur;
749 heap->cur = newCur;
750 }
751
752 return ret;
753}
754
755void alCopy(void* src, void* dst, s32 size) {
756 s32 i;
757 u8* srcIt = src;
758 u8* dstIt = dst;
759
760 for (i = 0; i < size; i++) {
761 *dstIt++ = *srcIt++;
762 }
763}
764
765static s16 _getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel) {
766 s32 tmpl;
767 samples = samples >> 3;
768 if (samples == 0) {
769 return ivol;
770 }
771 tmpl = ratel * samples;
772 tmpl = tmpl >> 16;
773 tmpl += ratem * samples;
774 return ivol + tmpl;
775}
void au_update_players_main(void)
void au_update_clients_2(void)
void au_bus_set_volume(u8 index, u16 arg1)
Definition 31650.c:267
#define AU_EQPOW_MID_IDX
Definition 31650.c:22
BSS s16 AuDelayedChannel
Definition 31650.c:11
void au_set_global_volume(s16 arg0)
Definition 31650.c:254
f32 au_syn_get_pitch(u8 voiceIdx)
Definition 31650.c:604
void au_use_global_volume(void)
Definition 31650.c:250
void au_syn_set_volume_delta(u8 voiceIdx, s16 vol, s32 delta)
Definition 31650.c:505
BSS u8 AuDelayedVoiceGroup
Definition 31650.c:10
void au_disable_channel_delay(void)
Definition 31650.c:704
s16 au_syn_get_wetamt(u8 voiceIdx)
Definition 31650.c:622
AuSynDriver * gActiveSynDriverPtr
Definition 31650.c:14
void au_delay_right_channel(u8 groupIdx)
Definition 31650.c:689
#define AU_EQPOW_MAX_IDX
Definition 31650.c:23
void au_pvoice_set_bus(u8 index, s8 busId)
Definition 31650.c:294
BSS s16 * AuDelayBufferAux
Definition 31650.c:8
void au_driver_init(AuSynDriver *driver, ALConfig *config)
Definition 31650.c:25
BSS s16 * AuDelayBufferMain
Definition 31650.c:7
void au_syn_set_fxmix(u8 voiceIdx, u8 fxMix)
Definition 31650.c:563
Acmd * alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
Definition 31650.c:119
void alHeapInit(ALHeap *hp, u8 *base, s32 len)
Definition 31650.c:725
u8 au_syn_get_pan(u8 voiceIdx)
Definition 31650.c:610
void au_syn_stop_voice(u8 voiceIdx)
Definition 31650.c:301
void func_80056D5C(u8 bStereoSound)
Definition 31650.c:262
BSS s32 AuDelayCounter
Definition 31650.c:9
u8 AuUseGlobalVolume
Definition 31650.c:16
void au_syn_set_pitch(u8 voiceIdx, f32 pitch)
Definition 31650.c:436
s32 au_syn_get_volume_right(u8 voiceIdx)
Definition 31650.c:645
AuSynDriver * gSynDriverPtr
Definition 31650.c:15
void alCopy(void *src, void *dst, s32 size)
Definition 31650.c:755
void au_set_delay_time(s32 arg0)
Definition 31650.c:662
void au_syn_set_pan(u8 voiceIdx, u8 pan)
Definition 31650.c:535
s16 au_syn_get_dryamt(u8 voiceIdx)
Definition 31650.c:616
u16 AuGlobalVolume
Definition 31650.c:17
void * alHeapAlloc(ALHeap *heap, s32 count, s32 size)
Definition 31650.c:743
void au_syn_start_voice(u8 voiceIdx)
Definition 31650.c:328
void au_bus_set_fx_params(u8 index, s16 delayIndex, s16 paramID, s32 value)
Definition 31650.c:287
void au_driver_release(void)
Definition 31650.c:113
void au_delay_channel(s16 arg0)
Definition 31650.c:710
u16 au_bus_get_volume(u8 index, u16 arg1)
Definition 31650.c:273
void au_bus_set_effect(u8 index, u8 effectType)
Definition 31650.c:279
void au_syn_set_pan_fxmix(u8 voiceIdx, u8 pan, u8 fxMix)
Definition 31650.c:475
void au_syn_start_voice_params(u8 voiceIdx, u8 busId, Instrument *instrument, f32 pitch, s16 vol, u8 pan, u8 fxMix, s32 delta)
Definition 31650.c:335
s16 au_get_global_volume(void)
Definition 31650.c:258
BSS s32 AuDelayCount
Definition 31650.c:12
u8 AuSynStereoDirty
Definition 31650.c:18
void au_delay_left_channel(u8 groupIdx)
Definition 31650.c:674
s32 au_syn_get_bus(u8 voiceIdx)
Definition 31650.c:598
s32 au_syn_get_playing(u8 voiceIdx)
Definition 31650.c:592
s32 au_syn_get_volume_left(u8 voiceIdx)
Definition 31650.c:628
s16 AuEqPower[128]
Definition 33450.c:9
void au_syn_set_mixer_params(u8 voiceIdx, s16 volume, s32 delta, u8 pan, u8 fxMix)
Definition 31650.c:442
void au_syn_set_wavetable(u8 voiceIdx, Instrument *instrument)
Definition 31650.c:398
Acmd * au_pull_voice(AuPVoice *pvoice, Acmd *cmdBufPos)
Definition 33450.c:32
ALHeap * heap
Definition audio.h:1186
s32 unk_04
Definition audio.h:511
f32 delta
Definition audio.h:470
s32 * savedMainOut
Definition audio.h:519
s16 dryamt
Definition audio.h:481
u16 gain
Definition audio.h:437
@ AU_FX_NONE
Definition audio.h:87
volatile u8 AuSynUseStereo
f32 ratio
Definition audio.h:469
s32 num_pvoice
Definition audio.h:1180
struct AuPVoice * next
Definition audio.h:497
#define N_AL_AUX_R_OUT
Definition audio.h:37
s16 wetamt
Definition audio.h:482
s32 segEnd
Definition audio.h:490
s16 rtgt
Definition audio.h:488
s32 curSamples
Definition audio.h:510
s16 cvolR
Definition audio.h:480
ALDMANew2 dmaNew
Definition audio.h:515
s16 unk_74
Definition audio.h:501
s32 outputRate
Definition audio.h:512
s32 loopEnd
Definition audio.h:554
u8 curEffectType
Definition audio.h:441
s16 lratm
Definition audio.h:484
s32 bookSize
Definition audio.h:457
s32 * savedAuxOut
Definition audio.h:520
AuLoadFilter decoder
Definition audio.h:498
ADPCM_STATE * state
Definition audio.h:453
void * dmaNew
Definition audio.h:1185
#define AUDIO_SAMPLES
Definition audio.h:44
s32 first
Definition audio.h:471
u32 wavDataLength
Definition audio.h:551
s32 loopCount
Definition audio.h:555
s16 rratm
Definition audio.h:487
s16 volume
Definition audio.h:478
u16 dc_bookSize
Definition audio.h:557
AuPVoice * pvoices
Definition audio.h:517
s16 pan
Definition audio.h:477
s32 delta
Definition audio.h:489
u8 * base
Definition audio.h:550
ENVMIX_STATE * state
Definition audio.h:476
s32 loopStart
Definition audio.h:553
s32 lastsam
Definition audio.h:461
AuFxBus * fxBus
Definition audio.h:518
struct Instrument * instrument
Definition audio.h:456
AuResampler resampler
Definition audio.h:499
#define ADPCMFBYTES
Definition audio.h:47
ALHeap * heap
Definition audio.h:516
@ FX_BUS_BGMA_MAIN
Definition audio.h:119
s16 cvolL
Definition audio.h:479
s32 num_pvoice
Definition audio.h:513
s16 rratl
Definition audio.h:486
AuFX * fxR
Definition audio.h:440
s16 lratl
Definition audio.h:483
u8 index
Definition audio.h:504
struct AuPVoice * tail
Definition audio.h:444
ALDMAproc2 dmaFunc
Definition audio.h:458
s32 first
Definition audio.h:491
struct AuPVoice * head
Definition audio.h:443
UNK_PTR loopPredictor
Definition audio.h:552
#define N_AL_MAIN_R_OUT
Definition audio.h:35
ALRawLoop loop
Definition audio.h:455
u8 busId
Definition audio.h:503
s32 motion
Definition audio.h:492
ADPCM_STATE * lstate
Definition audio.h:454
#define N_AL_AUX_L_OUT
Definition audio.h:36
NUDMAState * dmaState
Definition audio.h:459
s32 num_bus
Definition audio.h:514
s32 outputRate
Definition audio.h:1182
AuEnvMixer envMixer
Definition audio.h:500
s32 memin
Definition audio.h:463
RESAMPLE_STATE * state
Definition audio.h:468
s32 num_bus
Definition audio.h:1181
s16 ltgt
Definition audio.h:485
u8 type
Definition audio.h:563
s32 first
Definition audio.h:462
#define N_AL_MAIN_L_OUT
Definition audio.h:34
AuFX * fxL
Definition audio.h:439
s32 sample
Definition audio.h:460
s32 au_fx_param_hdl(AuFX *fx, s16 index, s16 paramID, s32 value)
Definition reverb.c:384
void func_8005904C(AuFX *fx, u8 effectType)
Definition reverb.c:180
void func_80058E84(AuFX *fx, u8 mode, ALHeap *heap)
Definition reverb.c:137
Acmd * au_pull_fx(AuFX *fx, Acmd *cmdBusPos, s16, s16)
Definition reverb.c:267
#define ALIGN16(val)
Definition macros.h:20
#define BSS
Definition macros.h:7
#define SQ(x)
Definition macros.h:166