diff --git a/lib/asm/non_matchings/unknown_0C9C90/alSynAddPlayer.s b/lib/asm/non_matchings/unknown_0C9C90/alSynAddPlayer.s deleted file mode 100644 index 246146b5..00000000 --- a/lib/asm/non_matchings/unknown_0C9C90/alSynAddPlayer.s +++ /dev/null @@ -1,22 +0,0 @@ -glabel alSynAddPlayer -/* 0C9FD0 800C93D0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0C9FD4 800C93D4 AFBF0014 */ sw $ra, 0x14($sp) -/* 0C9FD8 800C93D8 00803025 */ move $a2, $a0 -/* 0C9FDC 800C93DC AFA60018 */ sw $a2, 0x18($sp) -/* 0C9FE0 800C93E0 24040001 */ li $a0, 1 -/* 0C9FE4 800C93E4 0C03268C */ jal osSetIntMask -/* 0C9FE8 800C93E8 AFA5001C */ sw $a1, 0x1c($sp) -/* 0C9FEC 800C93EC 8FA60018 */ lw $a2, 0x18($sp) -/* 0C9FF0 800C93F0 8FA5001C */ lw $a1, 0x1c($sp) -/* 0C9FF4 800C93F4 00402025 */ move $a0, $v0 -/* 0C9FF8 800C93F8 8CCE0020 */ lw $t6, 0x20($a2) -/* 0C9FFC 800C93FC ACAE0010 */ sw $t6, 0x10($a1) -/* 0CA000 800C9400 8CCF0000 */ lw $t7, ($a2) -/* 0CA004 800C9404 ACAF0000 */ sw $t7, ($a1) -/* 0CA008 800C9408 0C03268C */ jal osSetIntMask -/* 0CA00C 800C940C ACC50000 */ sw $a1, ($a2) -/* 0CA010 800C9410 8FBF0014 */ lw $ra, 0x14($sp) -/* 0CA014 800C9414 27BD0018 */ addiu $sp, $sp, 0x18 -/* 0CA018 800C9418 03E00008 */ jr $ra -/* 0CA01C 800C941C 00000000 */ nop - diff --git a/lib/src/unknown_0C9C90.c b/lib/src/unknown_0C9C90.c index 2a1aa949..a7a91823 100644 --- a/lib/src/unknown_0C9C90.c +++ b/lib/src/unknown_0C9C90.c @@ -157,7 +157,6 @@ void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount){ } } -//GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9C90/alSynAddPlayer.s") void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) { OSIntMask mask = osSetIntMask(OS_IM_NONE); @@ -169,5 +168,113 @@ void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) osSetIntMask(mask); } +#if 1 GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9C90/_allocatePVoice.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9C90/alSynAllocVoice.s") +#else +s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority) +{ + ALLink *dl; + PVoice *pv; + s32 stolen = 0; + + if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else { /* steal one */ + for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) { + pv = (PVoice *)dl; + + /* + * if it is lower priority and not already stolen, keep it + * as a candidate for stealing + */ + if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) { + *pvoice = pv; + priority = pv->vvoice->priority; + stolen = 1; + } + } + } + + return stolen; +} +#endif + +//GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9C90/alSynAllocVoice.s") +s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc) +{ + PVoice *pvoice = 0; + ALFilter *f; + ALParam *update; + s32 stolen; + +#ifdef _DEBUG + /* need two updates if voice is stolen */ + if (drvr->paramList == 0) { + __osError(ERR_ALSYN_NO_UPDATE, 0); + return 0; + } else if (drvr->paramList->next == 0) { + __osError(ERR_ALSYN_NO_UPDATE, 0); + return 0; + } +#endif + + voice->priority = vc->priority; + voice->unityPitch = vc->unityPitch; + voice->table = 0; + voice->fxBus = vc->fxBus; + voice->state = AL_STOPPED; + voice->pvoice = 0; + + stolen = _allocatePVoice(drvr, &pvoice, vc->priority); + + if (pvoice) { /* if we were able to allocate a voice */ + + f = pvoice->channelKnob; + + if (stolen) { + + pvoice->offset = 512; + pvoice->vvoice->pvoice = 0; /* zero stolen voice */ + + /* + * ramp down stolen voice + */ + update = __allocParam(); + update->delta = drvr->paramSamples; + update->type = AL_FILTER_SET_VOLUME; + update->data.i = 0; + update->moredata.i = pvoice->offset - 64; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + + /* + * stop stolen voice + */ + update = __allocParam(); + if (update) { + update->delta = drvr->paramSamples + pvoice->offset; + update->type = AL_FILTER_STOP_VOICE; + update->next = 0; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } else { +#ifdef _DEBUG + __osError(ERR_ALSYN_NO_UPDATE, 0); +#endif + } + + } else { + pvoice->offset = 0; + } + + pvoice->vvoice = voice; /* assign new voice */ + voice->pvoice = pvoice; + + } + + return (pvoice != 0); +} \ No newline at end of file