core1/done/audio/n_env.c done

This commit is contained in:
Banjo Kazooie
2022-10-12 20:10:14 -05:00
parent 1269168e3d
commit bc88d7394b
16 changed files with 498 additions and 79 deletions

12
src/core1/audio/n_env.c Normal file
View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_env/func_80260860.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_env/func_802609E0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_env/func_80260BD4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_env/n_alEnvmixerPull.s")

View File

@@ -25,7 +25,7 @@ void func_80263840(void){}
void func_80263848(void){}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_25E20/func_80263850.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_seq/func_80263850.s")
void func_802639FC(struct struct_core2_25E20_1 *arg0, struct struct_core2_25E20_0 *arg1, u32 arg2) {
u32 var_v0;

View File

@@ -4,7 +4,7 @@
#include "2.0L/PR/sched.h"
#include "n_libaudio.h"
extern void func_8025C320(s32, ALSynConfig *);
extern void n_alInit(N_ALGlobals *, ALSynConfig *);
typedef struct AudioInfo_s {
short *data; /* Output data pointer */
@@ -51,7 +51,7 @@ typedef struct struct_core1_1D00_5_s{
}unkC;
}OscState;
void func_8023FBB8(void);
void amgrCreate(void);
void func_8023FE80(void *);
// void func_802403B8(void);
void amgrHandleDoneMsg(AudioInfo *info);
@@ -160,7 +160,7 @@ Struct_1D00_3 D_8027D5C0[90];
s32 D_8027DCC8;
s32 D_8027DCCC;
s32 D_8027DCD0;
N_ALSynth D_8027DCD8;
N_ALGlobals D_8027DCD8;
ALSynConfig D_8027DD50;
s32 D_8027DD74;
s32 D_8027DD78;
@@ -287,14 +287,13 @@ void func_8023FB1C(void){
alHeapInit(&D_8027CFF0, D_8027D000, 0x21000);
if(osTvType != OS_TV_NTSC)
osViClock = 0x2e6025c;
func_8023FBB8();
amgrCreate();
func_80335220();
func_8024F4E0();
amgrStartThread();
}
//amgrCreate
void func_8023FBB8(void) {
void amgrCreate(void) {
int i;
osCreateMesgQueue(&D_8027D008, &D_8027D020, 0x32);
@@ -315,7 +314,7 @@ void func_8023FBB8(void) {
D_8027DD50.params = (void*) &D_8027577C;
D_8027DD50.heap = &D_8027CFF0;
D_8027DD50.outputRate = osAiSetFrequency(22000);
func_8025C320(&D_8027DCD8, &D_8027DD50);
n_alInit(&D_8027DCD8, &D_8027DD50);
D_8027D5C0[0].unk0.prev = NULL;
D_8027D5C0[0].unk0.next = NULL;
for(i = 0; i < 89; i++){

View File

@@ -1,8 +0,0 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
n_alSynSetPriority(ALVoice *voice, s16 priority){
voice->priority = priority;
}

View File

@@ -1,22 +1,6 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
void func_8025F610(void){
n_syn->head = NULL;
n_syn->n_seqp1 = NULL;
n_syn->n_seqp2 = NULL;
n_syn->unk5C = NULL;
n_syn->unk60 = NULL;
n_syn->unk64 = NULL;
n_syn->unk68 = NULL;
n_syn->unk6C = NULL;
n_syn->unk70 = NULL;
n_syn->n_sndp = NULL;
}
void func_8025F5C0(N_ALSeqPlayer *arg0, u8 arg1){
ALEvent evt;

View File

@@ -0,0 +1,417 @@
#include <ultra64.h>
#include "n_synth.h"
#include "functions.h"
#include "variables.h"
#include "assert.h"
#ifdef AUD_PROFILE
extern u32 cnt_index, env_num, env_cnt, env_max, env_min, lastCnt[];
extern u32 rate_num, rate_cnt, rate_max, rate_min;
extern u32 vol_num, vol_cnt, vol_max, vol_min;
#endif
#define EQPOWER_LENGTH 128
static s16 eqpower[ EQPOWER_LENGTH ] = {
32767, 32764, 32757, 32744, 32727, 32704,
32677, 32644, 32607, 32564, 32517, 32464,
32407, 32344, 32277, 32205, 32127, 32045,
31958, 31866, 31770, 31668, 31561, 31450,
31334, 31213, 31087, 30957, 30822, 30682,
30537, 30388, 30234, 30075, 29912, 29744,
29572, 29395, 29214, 29028, 28838, 28643,
28444, 28241, 28033, 27821, 27605, 27385,
27160, 26931, 26698, 26461, 26220, 25975,
25726, 25473, 25216, 24956, 24691, 24423,
24151, 23875, 23596, 23313, 23026, 22736,
22442, 22145, 21845, 21541, 21234, 20924,
20610, 20294, 19974, 19651, 19325, 18997,
18665, 18331, 17993, 17653, 17310, 16965,
16617, 16266, 15913, 15558, 15200, 14840,
14477, 14113, 13746, 13377, 13006, 12633,
12258, 11881, 11503, 11122, 10740, 10357,
9971, 9584, 9196, 8806, 8415, 8023,
7630, 7235, 6839, 6442, 6044, 5646,
5246, 4845, 4444, 4042, 3640, 3237,
2833, 2429, 2025, 1620, 1216, 810,
405, 0
};
extern f64 __pow(f64, f64);
/*
* prototypes for private enveloper functions
*/
static Acmd *__n_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, Acmd *p) ; //__n_pullSubFrame
static s16 __n_getRate(f64 vol, f64 tgt, s32 count, u16* ratel); //_getRate
static s16 __n_getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel);
/***********************************************************************
* Enveloper filter public interfaces
***********************************************************************/
Acmd *n_alEnvmixerPull(void *filter, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
N_PVoice *e = (N_PVoice *)filter;
s16 inp;
s32 lastOffset;
s32 thisOffset = sampleOffset;
s32 samples;
s16 loutp = 0;
s32 fVol;
int count = 0xb8;
s32 outCount = count;
ALParam *thisParam;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
/*
* Force the input to be the resampler output
*/
inp = AL_RESAMPLER_OUT;
while (e->em_ctrlList != 0) {
lastOffset = thisOffset;
thisOffset = ((e->em_ctrlList->delta + 0x5C)/count)*count;
samples = thisOffset - lastOffset;
if (samples > outCount)
break;
if(samples < 0){
samples = 0;
}
switch (e->em_ctrlList->type) {
case (AL_FILTER_START_VOICE_ALT):
{
ALStartParamAlt *param = (ALStartParamAlt *)e->em_ctrlList;
if (param->unity) {
e->rs_upitch = 1;
}
n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, param->wave);
e->em_motion = 1;
e->em_first = 1;
e->em_delta = 0;
e->em_segEnd = ((param->samples + 0x5C)/count)*count;
fVol = (param->volume + param->volume)/2;
e->em_volume = fVol;
e->em_pan = param->pan;
e->em_dryamt = eqpower[param->fxMix];
e->em_wetamt = eqpower[EQPOWER_LENGTH - param->fxMix - 1];
if (param->samples) {
e->em_cvolL = 1;
e->em_cvolR = 1;
} else {
/*
* Attack time is zero. Simply set the
* volume. We don't want an attack segment.
*/
e->em_cvolL = (e->em_volume * eqpower[e->em_pan]) >> 15;
e->em_cvolR = (e->em_volume *
eqpower[EQPOWER_LENGTH - e->em_pan - 1]) >> 15;
}
e->rs_ratio = param->pitch;
}
break;
case (AL_FILTER_SET_FXAMT):
case (AL_FILTER_SET_PAN):
case (AL_FILTER_SET_VOLUME):
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
if (e->em_delta >= e->em_segEnd){
/*
* We should have reached our target, calculate
* target in case e->segEnd was 0
*/
e->em_ltgt = (e->em_volume * eqpower[e->em_pan]) >> 15;
e->em_rtgt = (e->em_volume *
eqpower[EQPOWER_LENGTH - e->em_pan - 1]) >> 15;
e->em_delta = e->em_segEnd; /* To prevent overflow */
e->em_cvolL = e->em_ltgt;
e->em_cvolR = e->em_rtgt;
} else {
/*
* Estimate the current volume
*/
e->em_cvolL = __n_getVol(e->em_cvolL, e->em_delta, e->em_lratm, e->em_lratl);
e->em_cvolR = __n_getVol(e->em_cvolR, e->em_delta, e->em_rratm, e->em_rratl);
}
/*
* We can't have volume of zero, because the envelope
* would never go anywhere from there
*/
if( e->em_cvolL == 0 ) e->em_cvolL = 1;
if( e->em_cvolR == 0 ) e->em_cvolR = 1;
if (e->em_ctrlList->type == AL_FILTER_SET_PAN)
/*
* This should result in a change to the current
* segment rate and target
*/
e->em_pan = (s16) e->em_ctrlList->data.i;
if (e->em_ctrlList->type == AL_FILTER_SET_VOLUME){
s32 Vol;
/*
* Switching to a new segment
*/
e->em_delta = 0;
/*
* Map volume non-linearly to give something close to
* loudness
*/
Vol = e->em_ctrlList->data.i;
Vol+= Vol;
Vol /= 2;
e->em_volume = Vol;
e->em_segEnd = ((e->em_ctrlList->moredata.i + 0x5C)/count)*count;
}
if (e->em_ctrlList->type == AL_FILTER_SET_FXAMT){
e->em_dryamt = eqpower[e->em_ctrlList->data.i];
e->em_wetamt = eqpower[EQPOWER_LENGTH - e->em_ctrlList->data.i - 1];
}
/*
* Force a volume update
*/
e->em_first = 1;
break;
case (AL_FILTER_START_VOICE):
{
ALStartParam *p = (ALStartParam *)e->em_ctrlList;
/*
* Changing to PLAYING (since the previous state was
* persumable STOPPED, we'll just bump the output
* pointer rather than pull a subframe of zeros).
*/
if (p->unity) {
e->rs_upitch = 1;
}
n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, p->wave);
e->em_motion = 1;
}
break;
case (AL_FILTER_STOP_VOICE):
{
/*
* Changing to STOPPED and reset the filter
*/
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
n_alEnvmixerResampleParam(e, 4, 0);
}
break;
case (AL_FILTER_FREE_VOICE):
{
ALFreeParam *param = (ALFreeParam *)e->em_ctrlList;
((N_PVoice *)(param->pvoice))->offset = 0;
_n_freePVoice((PVoice *)param->pvoice);
}
break;
case 7:
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
e->rs_ratio = e->em_ctrlList->data.f;
break;
case 8:
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
e->rs_upitch = 1;
break;
case (AL_FILTER_SET_WAVETABLE):
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, e->em_ctrlList->data.i);
break;
default:
/*
* Pull the reuired number of samples and then pass the message
* on down the chain
*/
ptr = __n_pullSubFrame(e, &inp, &loutp, samples, ptr);
n_alEnvmixerResampleParam(e, e->em_ctrlList->type, e->em_ctrlList->data.i);
break;
}
loutp += (samples<<1);
outCount -= samples;
/*
* put the param record back on the free list
*/
thisParam = e->em_ctrlList;
e->em_ctrlList = e->em_ctrlList->next;
if (e->em_ctrlList == 0)
e->em_ctrlTail = 0;
__n_freeParam(thisParam);
}
ptr = __n_pullSubFrame(e, &inp, &loutp, outCount, ptr);
/*
* Prevent overflow in e->delta
*/
if (e->em_delta > e->em_segEnd)
e->em_delta = e->em_segEnd;
#ifdef AUD_PROFILE
PROFILE_AUD(env_num, env_cnt, env_max, env_min);
#endif
return ptr;
}
static
Acmd* __n_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, Acmd *p)
{
Acmd *ptr = p;
N_PVoice *e = (N_PVoice *)filter;
s32 sp68 = 0xb8;
/* filter must be playing and request non-zero output samples to pull. */
if (e->em_motion != AL_PLAYING || !outCount)
return ptr;
/*
* ask all filters upstream from us to build their command
* lists.
*/
ptr = n_alResamplePull(e, inp, ptr);
/*
* construct our portion of the command list
*/
if (e->em_first){
e->em_first = 0;
/*
* Calculate derived parameters
*/
e->em_ltgt = (e->em_volume * eqpower[e->em_pan]) >> 15;
e->em_lratm = __n_getRate(e->em_cvolL, e->em_ltgt,
e->em_segEnd, &(e->em_lratl));
e->em_rtgt = (e->em_volume *
eqpower[EQPOWER_LENGTH - e->em_pan - 1]) >> 15;
e->em_rratm = __n_getRate(e->em_cvolR, e->em_rtgt, e->em_segEnd,
&(e->em_rratl));
n_aSetVolume(ptr++, A_RATE, e->em_ltgt, e->em_lratm, e->em_lratl);\
n_aSetVolume(ptr++, A_LEFT | A_VOL, e->em_cvolL, e->em_dryamt, e->em_wetamt);\
n_aSetVolume(ptr++, A_RIGHT | A_VOL, e->em_rtgt, e->em_rratm, e->em_rratl);\
n_aEnvMixer(ptr++, A_INIT | A_NOAUX, e->em_cvolR, osVirtualToPhysical(e->em_state));
}
else
n_aEnvMixer(ptr++, A_CONTINUE | A_NOAUX, 0, osVirtualToPhysical(e->em_state));
/*
* bump the input buffer pointer
*/
*inp += sp68 * 2;
e->em_delta += sp68;
return ptr;
}
#define EXP_MASK 0x7f800000
#define MANT_MASK 0x807fffff
/*
__n_getRate() -- This function determines how to go from the
current volume level (vol) to the target
volume level (tgt) in some number of steps
(count). Two values are returned that are
used as multipliers to incrementally scale
the volume. Some tricky math is used and
is explained below.
RWW 28jun95
*/
static
s16 __n_getRate(f64 vol, f64 tgt, s32 count, u16* ratel)
{
s16 s;
s16 tmp;
f64 invn;
f64 a;
f64 f;
if (count == 0) {
if (tgt >= vol) {
*ratel = 0xffff;
return 0x7fff;
} else {
*ratel = -0;
return 0;
}
}
invn = 1.0 / count;
if (tgt < 1.0) {
tgt = 1.0;
}
if (vol <= 0.0) {
vol = 1.0;
}
a = (tgt - vol) * invn * 8.0;
s = a;
f = a - s;
s--;
f += 1.0;
tmp = f;
s += tmp;
f -= tmp;
*ratel = 65535.0 * f;
return s;
}
static
s16 __n_getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel)
{
s32 r;
s32 m;
s32 l;
samples >>= 3;
if (samples == 0) {
return (s16) ivol;
}
m = ((ratel * samples));
m >>= 0x10;
m += (ratem * samples);
ivol += m;
return (s16) ivol;
}

View File

@@ -8,29 +8,28 @@
extern N_ALSynth *D_80276E80;
extern N_ALSynth *D_80276E84;
void func_8025C2E0(s32 a0)
void n_alInit(N_ALGlobals *g, ALSynConfig *config)
{
if (D_80276E80 != NULL)
return;
D_80276E80 = &g->drvr;
if (D_80276E84 != NULL)
return;
D_80276E84 = &g->drvr;
n_alSynNew(config);
}
void n_alClose(N_ALGlobals *glob)
{
if (D_80276E80)
{
func_8025F610();
n_alSynDelete();
D_80276E80 = NULL;
D_80276E84 = NULL;
}
}
void func_8025C320(N_ALSynth *synth, ALSynConfig *config)
{
if (D_80276E80 != NULL)
return;
D_80276E80 = synth;
if (D_80276E84 != NULL)
return;
D_80276E84 = synth;
n_alSynNew(config);
}

View File

@@ -0,0 +1,16 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynDelete(void){
n_syn->head = NULL;
n_syn->n_seqp1 = NULL;
n_syn->n_seqp2 = NULL;
n_syn->unk5C = NULL;
n_syn->unk60 = NULL;
n_syn->unk64 = NULL;
n_syn->unk68 = NULL;
n_syn->unk6C = NULL;
n_syn->unk70 = NULL;
n_syn->n_sndp = NULL;
}

View File

@@ -0,0 +1,6 @@
#include <ultra64.h>
#include <n_libaudio.h>
void n_alSynSetPriority(N_ALVoice *voice, s16 priority){
voice->priority = priority;
}

View File

@@ -1,12 +0,0 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#pragma GLOBAL_ASM("asm/nonmatchings/core1/n_env/func_80260860.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/n_env/func_802609E0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/n_env/func_80260BD4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/n_env/n_alEnvmixerPull.s")