Compare commits
1 Commits
main
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adc268a27f |
@@ -1447,10 +1447,10 @@ config.libs = [
|
||||
Object(Matching, "axfx/AXFXReverbHi.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiExp.c"),
|
||||
Object(NonMatching, "axfx/AXFXReverbHiExpDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiExpDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXDelay.c"),
|
||||
Object(Matching, "axfx/AXFXReverbStd.c"),
|
||||
Object(NonMatching, "axfx/AXFXReverbStdExp.c"),
|
||||
Object(Matching, "axfx/AXFXReverbStdExp.c"),
|
||||
Object(Matching, "axfx/AXFXChorus.c"),
|
||||
Object(NonMatching, "axfx/AXFXChorusExp.c"),
|
||||
Object(Matching, "axfx/AXFXLfoTable.c"),
|
||||
|
||||
@@ -14,7 +14,7 @@ typedef struct AXFX_CHORUS {
|
||||
u32 period; // 0xA8
|
||||
} AXFX_CHORUS;
|
||||
|
||||
u32 AXFXChorusGetMemSize(const AXFX_CHORUS* fx);
|
||||
u32 AXFXChorusGetMemSize(AXFX_CHORUS* fx);
|
||||
BOOL AXFXChorusInit(AXFX_CHORUS* fx);
|
||||
BOOL AXFXChorusShutdown(AXFX_CHORUS* fx);
|
||||
BOOL AXFXChorusSettings(AXFX_CHORUS* fx);
|
||||
|
||||
@@ -45,11 +45,11 @@ typedef struct AXFX_CHORUS_EXP {
|
||||
f32 sendGain; // 0x9C
|
||||
} AXFX_CHORUS_EXP;
|
||||
|
||||
u32 AXFXChorusExpGetMemSize(const AXFX_CHORUS_EXP* fx);
|
||||
u32 AXFXChorusExpGetMemSize(AXFX_CHORUS_EXP* fx);
|
||||
BOOL AXFXChorusExpInit(AXFX_CHORUS_EXP* fx);
|
||||
void AXFXChorusExpShutdown(AXFX_CHORUS_EXP* fx);
|
||||
BOOL AXFXChorusExpSettings(AXFX_CHORUS_EXP* fx);
|
||||
void AXFXChorusExpCallback(AXFX_BUFFERUPDATE* update, AXFX_CHORUS_EXP* fx);
|
||||
void AXFXChorusExpCallback(AXFX_BUS* update, AXFX_CHORUS_EXP* fx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AXFX_STEREO_CHANNEL_MAX 3
|
||||
|
||||
typedef struct AXFX_BUS {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
@@ -19,6 +21,13 @@ typedef struct AXFX_BUFFERUPDATE {
|
||||
s32* surround; // 0x08
|
||||
} AXFX_BUFFERUPDATE;
|
||||
|
||||
typedef struct AXFX_BUS_DPL2 {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
s32* left_surround; // 0x08
|
||||
s32* right_surround; // 0x0C
|
||||
} AXFX_BUS_DPL2;
|
||||
|
||||
typedef struct AXFX_BUFFERUPDATE_DPL2 {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
|
||||
@@ -49,13 +49,13 @@ typedef struct AXFX_REVERBHI_EXP_DPL2 {
|
||||
f32 crosstalk; // 0x15C
|
||||
f32 earlyGain; // 0x160
|
||||
f32 fusedGain; // 0x164
|
||||
AXFX_BUS* busIn; // 0x168
|
||||
AXFX_BUS* busOut; // 0x16C
|
||||
AXFX_BUS_DPL2* busIn; // 0x168
|
||||
AXFX_BUS_DPL2* busOut; // 0x16C
|
||||
f32 outGain; // 0x170
|
||||
f32 sendGain; // 0x174
|
||||
} AXFX_REVERBHI_EXP_DPL2;
|
||||
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(const AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
BOOL AXFXReverbHiExpInitDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
void AXFXReverbHiExpShutdownDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
BOOL AXFXReverbHiExpSettingsDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
|
||||
@@ -49,11 +49,11 @@ typedef struct AXFX_REVERBSTD_EXP {
|
||||
f32 sendGain; // 0xE4
|
||||
} AXFX_REVERBSTD_EXP;
|
||||
|
||||
u32 AXFXReverbStdExpGetMemSize(const AXFX_REVERBSTD_EXP* fx);
|
||||
u32 AXFXReverbStdExpGetMemSize(AXFX_REVERBSTD_EXP* fx);
|
||||
BOOL AXFXReverbStdExpInit(AXFX_REVERBSTD_EXP* fx);
|
||||
void AXFXReverbStdExpShutdown(AXFX_REVERBSTD_EXP* fx);
|
||||
BOOL AXFXReverbStdExpSettings(AXFX_REVERBSTD_EXP* fx);
|
||||
void AXFXReverbStdExpCallback(void* chans, AXFX_REVERBSTD_EXP* context);
|
||||
void AXFXReverbStdExpCallback(AXFX_BUS* update, AXFX_REVERBSTD_EXP* fx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
static void __ParamConvert(AXFX_CHORUS* fx);
|
||||
|
||||
u32 AXFXChorusGetMemSize(const AXFX_CHORUS* fx) {
|
||||
u32 AXFXChorusGetMemSize(AXFX_CHORUS* fx) {
|
||||
return AXFXChorusExpGetMemSize(&fx->chorusInner);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ BOOL AXFXChorusSettings(AXFX_CHORUS* fx) {
|
||||
}
|
||||
|
||||
void AXFXChorusCallback(void* chans, void* context) {
|
||||
AXFXChorusExpCallback((AXFX_BUFFERUPDATE*)chans, (AXFX_CHORUS_EXP*)context);
|
||||
AXFXChorusExpCallback((AXFX_BUS*)chans, (AXFX_CHORUS_EXP*)context);
|
||||
}
|
||||
|
||||
static void __ParamConvert(AXFX_CHORUS* fx) {
|
||||
|
||||
368
libs/RVL_SDK/src/axfx/AXFXChorusExp.c
Normal file
368
libs/RVL_SDK/src/axfx/AXFXChorusExp.c
Normal file
@@ -0,0 +1,368 @@
|
||||
#include <private/axfx.h>
|
||||
#include <revolution/axfx.h>
|
||||
|
||||
#include <revolution/ax.h>
|
||||
|
||||
#include <revolution/os.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
static BOOL __AllocDelay(AXFX_CHORUS_EXP* chorus);
|
||||
static BOOL __InitDelay(AXFX_CHORUS_EXP* chorus);
|
||||
static void __FreeDelay(AXFX_CHORUS_EXP* chorus);
|
||||
|
||||
static BOOL __InitParams(AXFX_CHORUS_EXP* chorus);
|
||||
static void __CalcLFO(s32* lfoBuf, AXFX_CHORUS_EXP_LFO* lfo);
|
||||
|
||||
u32 AXFXChorusExpGetMemSize(AXFX_CHORUS_EXP* chorus) {
|
||||
return 0x3200 * AXFX_STEREO_CHANNEL_MAX;
|
||||
}
|
||||
|
||||
BOOL AXFXChorusExpInit(AXFX_CHORUS_EXP* chorus) {
|
||||
BOOL result;
|
||||
BOOL enabled;
|
||||
|
||||
enabled = OSDisableInterrupts();
|
||||
|
||||
chorus->active |= 1;
|
||||
|
||||
result = __AllocDelay(chorus);
|
||||
if (result == FALSE) {
|
||||
AXFXChorusExpShutdown(chorus);
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
result = __InitDelay(chorus);
|
||||
if (result == FALSE) {
|
||||
AXFXChorusExpShutdown(chorus);
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
result = __InitParams(chorus);
|
||||
if (result == FALSE) {
|
||||
AXFXChorusExpShutdown(chorus);
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chorus->active &= ~1;
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AXFXChorusExpSettings(AXFX_CHORUS_EXP* chorus) {
|
||||
BOOL result;
|
||||
BOOL enabled = OSDisableInterrupts();
|
||||
|
||||
chorus->active |= 1;
|
||||
|
||||
AXFXChorusExpShutdown(chorus);
|
||||
result = AXFXChorusExpInit(chorus);
|
||||
if (!result) {
|
||||
AXFXChorusExpShutdown(chorus);
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chorus->active |= 2;
|
||||
chorus->active &= ~1;
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AXFXChorusExpShutdown(AXFX_CHORUS_EXP* reverb) {
|
||||
BOOL enabled = OSDisableInterrupts();
|
||||
|
||||
reverb->active |= 1;
|
||||
|
||||
__FreeDelay(reverb);
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
void AXFXChorusExpCallback(AXFX_BUS* bus, AXFX_CHORUS_EXP* chorus) {
|
||||
u32 ch;
|
||||
u32 samp;
|
||||
s32* input[3];
|
||||
s32* inBusData[3];
|
||||
s32* outBusData[3];
|
||||
s32 lfoOut[96];
|
||||
s32 pos;
|
||||
s32 diff;
|
||||
u32 steps;
|
||||
u32 frac;
|
||||
u32 walk;
|
||||
u32 histIdx;
|
||||
u32 i;
|
||||
f32* coef;
|
||||
f32 data;
|
||||
f32 fir;
|
||||
AXFX_CHORUS_EXP* fx;
|
||||
|
||||
fx = chorus;
|
||||
|
||||
if (fx->active != 0) {
|
||||
fx->active &= ~2;
|
||||
return;
|
||||
}
|
||||
|
||||
input[0] = bus->left;
|
||||
input[1] = bus->right;
|
||||
input[2] = bus->surround;
|
||||
|
||||
if (fx->busIn != NULL) {
|
||||
inBusData[0] = fx->busIn->left;
|
||||
inBusData[1] = fx->busIn->right;
|
||||
inBusData[2] = fx->busIn->surround;
|
||||
}
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
outBusData[0] = fx->busOut->left;
|
||||
outBusData[1] = fx->busOut->right;
|
||||
outBusData[2] = fx->busOut->surround;
|
||||
}
|
||||
|
||||
__CalcLFO(lfoOut, &fx->lfo);
|
||||
|
||||
for (samp = 0; samp < 96; samp++) {
|
||||
pos = fx->delay.outPos + lfoOut[samp];
|
||||
if (pos >= (s32)fx->delay.sizeFP) {
|
||||
pos -= fx->delay.sizeFP;
|
||||
} else if (pos < 0) {
|
||||
pos += fx->delay.sizeFP;
|
||||
}
|
||||
|
||||
diff = pos - fx->delay.lastPos;
|
||||
if (diff < 0) {
|
||||
diff += fx->delay.sizeFP;
|
||||
}
|
||||
|
||||
steps = (u32)(diff >> 16) & 0xFFFF;
|
||||
frac = diff & 0xFFFF;
|
||||
walk = fx->delay.lastPos >> 16;
|
||||
histIdx = fx->histIndex;
|
||||
|
||||
while (steps--) {
|
||||
fx->history[0][histIdx] = fx->delay.line[0][walk];
|
||||
fx->history[1][histIdx] = fx->delay.line[1][walk];
|
||||
fx->history[2][histIdx++] = fx->delay.line[2][walk++];
|
||||
histIdx &= 3;
|
||||
if (walk >= fx->delay.size) {
|
||||
walk = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fx->delay.lastPos = pos & 0xFFFF0000;
|
||||
coef = __AXFXGetSrcCoef((frac >> 9) & 0x7F);
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
fir = 0.0f;
|
||||
fir += coef[0] * fx->history[ch][histIdx++];
|
||||
histIdx &= 3;
|
||||
fir += coef[1] * fx->history[ch][histIdx++];
|
||||
histIdx &= 3;
|
||||
fir += coef[2] * fx->history[ch][histIdx++];
|
||||
histIdx &= 3;
|
||||
fir += coef[3] * fx->history[ch][histIdx++];
|
||||
histIdx &= 3;
|
||||
|
||||
if (fx->busIn != NULL) {
|
||||
data = (f32)(*(input[ch]) + *(inBusData[ch]++));
|
||||
} else {
|
||||
data = (f32)(*input[ch]);
|
||||
}
|
||||
|
||||
fx->delay.line[ch][fx->delay.inPos] = data + fir * fx->feedback;
|
||||
|
||||
*(input[ch]++) = (s32)(fir * fx->outGain);
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
*(outBusData[ch]++) = (s32)(fir * fx->sendGain);
|
||||
}
|
||||
}
|
||||
|
||||
fx->histIndex = histIdx;
|
||||
|
||||
if (++fx->delay.inPos >= fx->delay.size) {
|
||||
fx->delay.inPos = 0;
|
||||
}
|
||||
|
||||
fx->delay.outPos += 0x10000;
|
||||
if (fx->delay.outPos >= fx->delay.sizeFP) {
|
||||
fx->delay.outPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __AllocDelay(AXFX_CHORUS_EXP* chorus) {
|
||||
AXFX_CHORUS_EXP* pChorus = chorus;
|
||||
u32 i;
|
||||
|
||||
pChorus->delay.size = 0xC80;
|
||||
for (i = 0; i < AXFX_STEREO_CHANNEL_MAX; i++) {
|
||||
pChorus->delay.line[i] = __AXFXAlloc(pChorus->delay.size * 4);
|
||||
ASSERTMSGLINE(443, pChorus->delay.line[i], "Can't allocate the memory.");
|
||||
if (!pChorus->delay.line[i]) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL __InitDelay(AXFX_CHORUS_EXP* chorus) {
|
||||
AXFX_CHORUS_EXP* pChorus = chorus;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < AXFX_STEREO_CHANNEL_MAX; i++) {
|
||||
ASSERTMSGLINE(469, pChorus->delay.line[i], "Buffer is not allocated.");
|
||||
if (!pChorus->delay.line[i]) {
|
||||
return FALSE;
|
||||
}
|
||||
memset(pChorus->delay.line[i], 0, pChorus->delay.size * 4);
|
||||
}
|
||||
|
||||
pChorus->delay.inPos = 0;
|
||||
pChorus->delay.outPos = pChorus->delay.size - (u32)(32.0f * chorus->delayTime);
|
||||
pChorus->delay.outPos <<= 0x10;
|
||||
pChorus->delay.lastPos = pChorus->delay.outPos;
|
||||
pChorus->delay.sizeFP = pChorus->delay.size << 0x10;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __FreeDelay(AXFX_CHORUS_EXP* chorus) {
|
||||
u32 i;
|
||||
AXFX_CHORUS_EXP* pChorus;
|
||||
|
||||
pChorus = chorus;
|
||||
|
||||
for (i = 0; i < AXFX_STEREO_CHANNEL_MAX; i++) {
|
||||
if (pChorus->delay.line[i]) {
|
||||
__AXFXFree(pChorus->delay.line[i]);
|
||||
}
|
||||
pChorus->delay.line[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __InitParams(AXFX_CHORUS_EXP* chorus) {
|
||||
u32 i, j;
|
||||
|
||||
f32 var_f28;
|
||||
f32 var_f30;
|
||||
f32 var_f29;
|
||||
f32 var_f31;
|
||||
|
||||
ASSERTMSGLINE(767, chorus->delayTime >= 0.1f && chorus->delayTime <= 50.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->delayTime < 0.1f || chorus->delayTime > 50.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ASSERTMSGLINE(767, chorus->depth >= 0.0f && chorus->depth <= 1.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->depth < 0.0f || chorus->depth > 1.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ASSERTMSGLINE(767, chorus->rate >= 0.1f && chorus->rate <= 2.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->rate < 0.1f || chorus->rate > 2.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ASSERTMSGLINE(767, chorus->feedback >= 0.0f && chorus->feedback < 1.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->feedback < 0.0f || chorus->feedback >= 1.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ASSERTMSGLINE(767, chorus->outGain >= 0.0f && chorus->outGain <= 1.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->outGain < 0.0f || chorus->outGain > 1.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ASSERTMSGLINE(767, chorus->sendGain >= 0.0f && chorus->sendGain <= 1.0f, "The value of specified parameter is out of range.");
|
||||
if (chorus->sendGain < 0.0f || chorus->sendGain > 1.0f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chorus->lfo.table = __AXFXGetLfoSinTable();
|
||||
|
||||
var_f30 = 32.0f * chorus->delayTime;
|
||||
var_f31 = var_f30 * chorus->depth;
|
||||
|
||||
if (var_f31 >= var_f30) {
|
||||
var_f31 -= 1.0f;
|
||||
if (var_f31 < 0.0f) {
|
||||
var_f31 = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
chorus->lfo.depthSamp = (65536.0f * var_f31);
|
||||
chorus->lfo.phaseAdd = (65536.0f * ((256.0f * chorus->rate) / 32000.0f));
|
||||
var_f29 = (32000.0f / chorus->rate) * 0.00390625f;
|
||||
chorus->lfo.stepSamp = (65536.0f * var_f29);
|
||||
var_f28 = var_f31 / var_f29;
|
||||
chorus->lfo.gradFactor = (65536.0f * var_f28);
|
||||
chorus->lfo.phase = 0;
|
||||
chorus->lfo.sign = 0;
|
||||
chorus->lfo.lastNum = -1;
|
||||
chorus->lfo.lastValue = 0;
|
||||
chorus->lfo.grad = 0;
|
||||
|
||||
for (i = 0; i < AXFX_STEREO_CHANNEL_MAX; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
chorus->history[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
chorus->histIndex = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __CalcLFO(s32* lfoBuf, AXFX_CHORUS_EXP_LFO* lfo) {
|
||||
u32 i;
|
||||
|
||||
s32 srcCoefIndex;
|
||||
s32 var_r24;
|
||||
s32 var_r25;
|
||||
u32 histIndex;
|
||||
s64 var_r31;
|
||||
s64 var_r28;
|
||||
|
||||
var_r31 = 0;
|
||||
|
||||
for (i = 0; i < 96; i++) {
|
||||
histIndex = lfo->phase & 0xFFFF0000;
|
||||
if (histIndex != lfo->lastNum) {
|
||||
lfo->lastNum = histIndex;
|
||||
histIndex = histIndex >> 0x10U;
|
||||
var_r25 = histIndex + 1;
|
||||
var_r25 &= 0x7F;
|
||||
var_r24 = lfo->table[histIndex];
|
||||
srcCoefIndex = lfo->table[var_r25];
|
||||
var_r28 = srcCoefIndex - var_r24;
|
||||
var_r28 = var_r28 * lfo->gradFactor;
|
||||
var_r28 = var_r28 >> 0x18;
|
||||
lfo->grad = var_r28;
|
||||
var_r31 = (s64)var_r24 * (s64)lfo->depthSamp;
|
||||
var_r31 = var_r31 >> 0x18;
|
||||
} else {
|
||||
var_r31 = lfo->lastValue + lfo->grad;
|
||||
}
|
||||
lfo->lastValue = var_r31;
|
||||
if (lfo->sign >= 1) {
|
||||
var_r31 *= -1;
|
||||
}
|
||||
lfo->phase += lfo->phaseAdd;
|
||||
if ((lfo->phase & 0xFF800000) != 0) {
|
||||
lfo->phase &= 0x7FFFFF;
|
||||
lfo->sign ^= 1;
|
||||
}
|
||||
lfoBuf[i] = var_r31;
|
||||
}
|
||||
}
|
||||
461
libs/RVL_SDK/src/axfx/AXFXReverbHiExpDpl2.c
Normal file
461
libs/RVL_SDK/src/axfx/AXFXReverbHiExpDpl2.c
Normal file
@@ -0,0 +1,461 @@
|
||||
#include <private/axfx.h>
|
||||
#include <revolution/AXFX.h>
|
||||
#include <revolution/MEM.h>
|
||||
#include <revolution/OS.h>
|
||||
#include <revolution/ax.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static void __BzeroDelayLines(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static void __FreeDelayLine(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static BOOL __InitParams(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
|
||||
static u32 __EarlySizeTable[8][3] = {{157, 479, 829}, {317, 809, 1117}, {479, 941, 1487}, {641, 1259, 1949},
|
||||
{797, 1667, 2579}, {967, 1901, 2903}, {1123, 2179, 3413}, {1279, 2477, 3889}};
|
||||
|
||||
static f32 __EarlyCoefTable[8][3] = {{0.4f, -1.0f, 0.3f}, {0.5f, -0.95f, 0.3f}, {0.6f, -0.9f, 0.3f}, {0.75f, -0.85f, 0.3f},
|
||||
{-0.9f, 0.8f, 0.3f}, {-1.0f, 0.7f, 0.3f}, {-1.0f, 0.7f, 0.3f}, {-1.0f, 0.7f, 0.3f}};
|
||||
|
||||
static u32 __FilterSizeTable[7][9] = {{1789, 1999, 2333, 433, 149, 47, 73, 67, 71}, {149, 293, 449, 251, 103, 47, 73, 67, 71},
|
||||
{947, 1361, 1531, 433, 137, 47, 73, 67, 71}, {1279, 1531, 1973, 509, 149, 47, 73, 67, 71},
|
||||
{1531, 1847, 2297, 563, 179, 47, 73, 67, 71}, {1823, 2357, 2693, 571, 137, 47, 73, 67, 71},
|
||||
{1823, 2357, 2693, 571, 179, 47, 73, 67, 71}};
|
||||
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 sum = 0;
|
||||
u32 i = 0;
|
||||
|
||||
sum += __EarlySizeTable[7][2];
|
||||
sum += (int)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 4;
|
||||
|
||||
for (i = 5; i < 9; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 4;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbHiExpInitDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
BOOL result = TRUE;
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
|
||||
if (AXGetMode() != AX_OUTPUT_DPL2) {
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active = 1;
|
||||
|
||||
if (fx->preDelayTimeMax < 0.0f) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->earlyMaxLength = __EarlySizeTable[8 - 1][2];
|
||||
fx->preDelayMaxLength = (u32)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
fx->combMaxLength[i] = __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassMaxLength[i] = __FilterSizeTable[6][3 + i];
|
||||
}
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
fx->lastAllpassMaxLength[ch] = __FilterSizeTable[6][5 + ch];
|
||||
}
|
||||
|
||||
result = __AllocDelayLine(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
__BzeroDelayLines(fx);
|
||||
result = __InitParams(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbHiExpSettingsDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active = fx->active | 1;
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
|
||||
if (!AXFXReverbHiExpInitDpl2(fx)) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->active |= 2;
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AXFXReverbHiExpShutdownDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active |= 1;
|
||||
__FreeDelayLine(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
}
|
||||
|
||||
void AXFXReverbHiExpCallbackDpl2(AXFX_BUFFERUPDATE_DPL2* bufferUpdate, AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
u32 samp;
|
||||
s32* input[4];
|
||||
f32 data;
|
||||
f32 output[4];
|
||||
f32* earlyLine;
|
||||
f32 earlyOut;
|
||||
f32* preDelayLine;
|
||||
f32 preDelayOut;
|
||||
f32 filterOut;
|
||||
f32* combLine;
|
||||
f32 combOutOne;
|
||||
f32* allpass;
|
||||
f32 outTmp;
|
||||
f32 allpassIn;
|
||||
f32 allpassCoef;
|
||||
f32 lpfOut;
|
||||
f32 lpfCoef1;
|
||||
f32 lpfCoef2;
|
||||
f32 fusedOut[4];
|
||||
f32 fusedGain;
|
||||
f32 crosstalkGain;
|
||||
f32 crosstalkL;
|
||||
f32 crosstalkR;
|
||||
f32 crosstalkLs;
|
||||
f32 crosstalkRs;
|
||||
s32* inBusData[4];
|
||||
s32* outBusData[4];
|
||||
|
||||
if (fx->active != 0) {
|
||||
fx->active &= ~2;
|
||||
return;
|
||||
}
|
||||
|
||||
input[0] = bufferUpdate->left;
|
||||
input[1] = bufferUpdate->right;
|
||||
input[2] = bufferUpdate->left_surround;
|
||||
input[3] = bufferUpdate->right_surround;
|
||||
|
||||
if (fx->busIn != NULL) {
|
||||
inBusData[0] = fx->busIn->left;
|
||||
inBusData[1] = fx->busIn->right;
|
||||
inBusData[2] = fx->busIn->left_surround;
|
||||
inBusData[3] = fx->busIn->right_surround;
|
||||
}
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
outBusData[0] = fx->busOut->left;
|
||||
outBusData[1] = fx->busOut->right;
|
||||
outBusData[2] = fx->busOut->left_surround;
|
||||
outBusData[3] = fx->busOut->right_surround;
|
||||
}
|
||||
|
||||
lpfCoef1 = 1.0f - fx->lpfCoef;
|
||||
lpfCoef2 = fx->lpfCoef;
|
||||
allpassCoef = fx->allpassCoef;
|
||||
fusedGain = fx->fusedGain * 0.6f;
|
||||
crosstalkGain = fx->crosstalk * 0.333333f;
|
||||
|
||||
for (samp = 0; samp < 96; samp++) {
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->busIn != NULL) {
|
||||
data = (f32)(*(input[ch]) + *(inBusData[ch]++));
|
||||
} else {
|
||||
data = (f32)(*input[ch]);
|
||||
}
|
||||
|
||||
earlyLine = fx->earlyLine[ch];
|
||||
earlyOut = earlyLine[fx->earlyPos[0]] * fx->earlyCoef[0] + earlyLine[fx->earlyPos[1]] * fx->earlyCoef[1] +
|
||||
earlyLine[fx->earlyPos[2]] * fx->earlyCoef[2];
|
||||
|
||||
earlyLine[fx->earlyPos[2]] = data;
|
||||
|
||||
if (fx->preDelayLength != 0) {
|
||||
preDelayLine = fx->preDelayLine[ch];
|
||||
preDelayOut = preDelayLine[fx->preDelayPos];
|
||||
preDelayLine[fx->preDelayPos] = data;
|
||||
} else {
|
||||
preDelayOut = data;
|
||||
}
|
||||
|
||||
filterOut = 0.0f;
|
||||
for (i = 0; i < 3; i++) {
|
||||
combLine = fx->combLine[ch][i];
|
||||
combOutOne = combLine[fx->combPos[i]];
|
||||
combLine[fx->combPos[i]] = preDelayOut + (combOutOne * fx->combCoef[i]);
|
||||
filterOut += combOutOne;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
allpass = fx->allpassLine[ch][i];
|
||||
outTmp = allpass[fx->allpassPos[i]];
|
||||
allpassIn = filterOut + outTmp * allpassCoef;
|
||||
allpass[fx->allpassPos[i]] = allpassIn;
|
||||
filterOut = outTmp - allpassIn * allpassCoef;
|
||||
}
|
||||
|
||||
lpfOut = lpfCoef1 * filterOut + lpfCoef2 * fx->lastLpfOut[ch];
|
||||
fx->lastLpfOut[ch] = lpfOut;
|
||||
allpass = fx->lastAllpassLine[ch];
|
||||
outTmp = allpass[fx->lastAllpassPos[ch]];
|
||||
allpassIn = lpfOut + outTmp * allpassCoef;
|
||||
allpass[fx->lastAllpassPos[ch]] = allpassIn;
|
||||
fusedOut[ch] = outTmp - allpassIn * allpassCoef;
|
||||
if (++fx->lastAllpassPos[ch] >= fx->lastAllpassLength[ch]) {
|
||||
fx->lastAllpassPos[ch] = 0;
|
||||
}
|
||||
|
||||
fusedOut[ch] *= fusedGain;
|
||||
fusedOut[ch] += earlyOut;
|
||||
}
|
||||
|
||||
crosstalkL = fusedOut[1] + fusedOut[2] + fusedOut[3];
|
||||
crosstalkR = fusedOut[0] + fusedOut[2] + fusedOut[3];
|
||||
crosstalkLs = fusedOut[0] + fusedOut[1] + fusedOut[3];
|
||||
crosstalkRs = fusedOut[0] + fusedOut[1] + fusedOut[2];
|
||||
|
||||
output[0] = fusedOut[0] + crosstalkL * crosstalkGain;
|
||||
output[1] = fusedOut[1] + crosstalkR * crosstalkGain;
|
||||
output[2] = fusedOut[2] + crosstalkLs * crosstalkGain;
|
||||
output[3] = fusedOut[3] + crosstalkRs * crosstalkGain;
|
||||
|
||||
*(input[0]++) = (s32)(output[0] * fx->outGain);
|
||||
*(input[1]++) = (s32)(output[1] * fx->outGain);
|
||||
*(input[2]++) = (s32)(output[2] * fx->outGain);
|
||||
*(input[3]++) = (s32)(output[3] * fx->outGain);
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
*(outBusData[0]++) = (s32)(output[0] * fx->sendGain);
|
||||
*(outBusData[1]++) = (s32)(output[1] * fx->sendGain);
|
||||
*(outBusData[2]++) = (s32)(output[2] * fx->sendGain);
|
||||
*(outBusData[3]++) = (s32)(output[3] * fx->sendGain);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (++fx->earlyPos[i] >= fx->earlyLength) {
|
||||
fx->earlyPos[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->preDelayLength != 0) {
|
||||
if (++fx->preDelayPos >= fx->preDelayLength) {
|
||||
fx->preDelayPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (++fx->combPos[i] >= fx->combLength[i]) {
|
||||
fx->combPos[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (++fx->allpassPos[i] >= fx->allpassLength[i]) {
|
||||
fx->allpassPos[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
fx->earlyLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->earlyMaxLength);
|
||||
if (fx->earlyLine[ch] == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayMaxLength != 0) {
|
||||
fx->preDelayLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->preDelayMaxLength);
|
||||
if (fx->preDelayLine[ch] == NULL)
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
fx->combLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->combMaxLength[i]);
|
||||
if (fx->combLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
if (fx->allpassLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->lastAllpassLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->lastAllpassMaxLength[ch]);
|
||||
if (fx->lastAllpassLine[ch] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __BzeroDelayLines(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->earlyLine[ch] != NULL) {
|
||||
memset(fx->earlyLine[ch], 0, sizeof(f32) * fx->earlyMaxLength);
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch] != NULL) {
|
||||
memset(fx->preDelayLine[ch], 0, sizeof(f32) * fx->preDelayMaxLength);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (fx->combLine[ch][i] != NULL) {
|
||||
memset(fx->combLine[ch][i], 0, sizeof(f32) * fx->combMaxLength[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i] != NULL) {
|
||||
memset(fx->allpassLine[ch][i], 0, sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->lastAllpassLine[ch] != NULL) {
|
||||
memset(fx->lastAllpassLine[ch], 0, sizeof(f32) * fx->lastAllpassMaxLength[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __FreeDelayLine(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->earlyLine[ch] != NULL) {
|
||||
__AXFXFree(fx->earlyLine[ch]);
|
||||
fx->earlyLine[ch] = NULL;
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch] != NULL) {
|
||||
__AXFXFree(fx->preDelayLine[ch]);
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (fx->combLine[ch][i] != NULL) {
|
||||
__AXFXFree(fx->combLine[ch][i]);
|
||||
fx->combLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i] != NULL) {
|
||||
__AXFXFree(fx->allpassLine[ch][i]);
|
||||
fx->allpassLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->lastAllpassLine[ch] != NULL) {
|
||||
__AXFXFree(fx->lastAllpassLine[ch]);
|
||||
fx->lastAllpassLine[ch] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DECOMP_FORCE_LITERAL(AXFXReverbHiExpDpl2_c, -3.0f, 10.0);
|
||||
|
||||
static BOOL __InitParams(AXFX_REVERBHI_EXP_DPL2* reverb) {
|
||||
u32 ch, i;
|
||||
|
||||
if (reverb->earlyMode >= 8)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->preDelayTime < 0.0f || reverb->preDelayTime > reverb->preDelayTimeMax)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedMode >= 6)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedTime < 0.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->coloration < 0.0f || reverb->coloration > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->damping < 0.0f || reverb->damping > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->crosstalk < 0.0f || reverb->crosstalk > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->earlyGain < 0.0f || reverb->earlyGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedGain < 0.0f || reverb->fusedGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->outGain < 0.0f || reverb->outGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->sendGain < 0.0f || reverb->sendGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
reverb->earlyLength = __EarlySizeTable[reverb->earlyMode][2];
|
||||
for (i = 0; i < 3; i++) {
|
||||
reverb->earlyPos[i] = reverb->earlyLength - __EarlySizeTable[reverb->earlyMode][i];
|
||||
reverb->earlyCoef[i] = __EarlyCoefTable[reverb->earlyMode][i] * reverb->earlyGain * 0.6f;
|
||||
}
|
||||
|
||||
reverb->preDelayPos = 0;
|
||||
reverb->preDelayLength = (u32)(reverb->preDelayTime * (f32)32000);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
reverb->combPos[i] = 0;
|
||||
reverb->combLength[i] = __FilterSizeTable[reverb->fusedMode][i];
|
||||
reverb->combCoef[i] = pow(10.0f, (-3.0f * (f32)(reverb->combLength[i]) / (f32)(reverb->fusedTime * 32000)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
reverb->allpassPos[i] = 0;
|
||||
reverb->allpassLength[i] = __FilterSizeTable[reverb->fusedMode][3 + i];
|
||||
}
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
reverb->lastAllpassPos[ch] = 0;
|
||||
reverb->lastAllpassLength[ch] = __FilterSizeTable[reverb->fusedMode][5 + ch];
|
||||
}
|
||||
|
||||
reverb->allpassCoef = reverb->coloration;
|
||||
reverb->lpfCoef = 1.0f - reverb->damping;
|
||||
if (reverb->lpfCoef > 0.95f)
|
||||
reverb->lpfCoef = 0.95f;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
reverb->lastLpfOut[ch] = 0.0f;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ BOOL AXFXReverbStdSettings(AXFX_REVERBSTD* fx) {
|
||||
}
|
||||
|
||||
void AXFXReverbStdCallback(void* chans, void* context) {
|
||||
AXFXReverbStdExpCallback((AXFX_BUFFERUPDATE*)chans, (AXFX_REVERBSTD_EXP*)context);
|
||||
AXFXReverbStdExpCallback((AXFX_BUS*)chans, (AXFX_REVERBSTD_EXP*)context);
|
||||
}
|
||||
|
||||
static void __ParamConvert(AXFX_REVERBSTD* fx) {
|
||||
|
||||
397
libs/RVL_SDK/src/axfx/AXFXReverbStdExp.c
Normal file
397
libs/RVL_SDK/src/axfx/AXFXReverbStdExp.c
Normal file
@@ -0,0 +1,397 @@
|
||||
#include <private/axfx.h>
|
||||
#include <revolution/AXFX.h>
|
||||
#include <revolution/MEM.h>
|
||||
#include <revolution/OS.h>
|
||||
#include <revolution/ax.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBSTD_EXP* fx);
|
||||
static void __BzeroDelayLines(AXFX_REVERBSTD_EXP* fx);
|
||||
static void __FreeDelayLine(AXFX_REVERBSTD_EXP* fx);
|
||||
static BOOL __InitParams(AXFX_REVERBSTD_EXP* fx);
|
||||
|
||||
static u32 __EarlySizeTable[8] = {163, 317, 479, 641, 797, 967, 1123, 1283};
|
||||
|
||||
static u32 __FilterSizeTable[7][4] = {{1789, 1999, 433, 149}, {149, 293, 251, 103}, {947, 1361, 433, 137},
|
||||
{1279, 1531, 509, 149}, {1531, 1847, 563, 179}, {1823, 2357, 571, 137},
|
||||
{1823, 2357, 571, 179}};
|
||||
|
||||
u32 AXFXReverbStdExpGetMemSize(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 sum = 0;
|
||||
u32 i = 0;
|
||||
|
||||
sum += __EarlySizeTable[7];
|
||||
sum += (int)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 3;
|
||||
sum *= 4;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbStdExpInit(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
BOOL result = TRUE;
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
|
||||
fx->active = 1;
|
||||
|
||||
if (fx->preDelayTimeMax < 0.0f) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->earlyMaxLength = __EarlySizeTable[8 - 1];
|
||||
fx->preDelayMaxLength = (u32)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->combMaxLength[i] = __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassMaxLength[i] = __FilterSizeTable[6][2 + i];
|
||||
}
|
||||
|
||||
result = __AllocDelayLine(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
__BzeroDelayLines(fx);
|
||||
result = __InitParams(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbStdExpSettings(AXFX_REVERBSTD_EXP* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active = fx->active | 1;
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
|
||||
if (!AXFXReverbStdExpInit(fx)) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->active |= 2;
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AXFXReverbStdExpShutdown(AXFX_REVERBSTD_EXP* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active |= 1;
|
||||
__FreeDelayLine(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
}
|
||||
|
||||
|
||||
void AXFXReverbStdExpCallback(AXFX_BUS* bus, AXFX_REVERBSTD_EXP* reverb) {
|
||||
u32 i, j;
|
||||
|
||||
s32* busParam[AXFX_STEREO_CHANNEL_MAX];
|
||||
s32* busIn[AXFX_STEREO_CHANNEL_MAX];
|
||||
s32* busOut[AXFX_STEREO_CHANNEL_MAX];
|
||||
u32 earlyPos;
|
||||
u32 preDelayPos;
|
||||
u32 combPos0;
|
||||
u32 combPos1;
|
||||
u32 allpassPos0;
|
||||
u32 allpassPos1;
|
||||
f32 sp64;
|
||||
f32 sp60;
|
||||
f32* earlyLine;
|
||||
f32 sp58;
|
||||
f32 earlyCoef;
|
||||
f32* preDelayLine;
|
||||
f32 sp4C;
|
||||
f32* combLine0;
|
||||
f32* combLine1;
|
||||
f32 sp40;
|
||||
f32 sp3C;
|
||||
f32 sp38;
|
||||
f32 combCoef0;
|
||||
f32 combCoef1;
|
||||
f32 sp2C;
|
||||
f32 sp28;
|
||||
f32 sp24;
|
||||
f32 sp20;
|
||||
f32 allpassCoef;
|
||||
f32 sp18;
|
||||
f32 sp14;
|
||||
f32 lpfCoef;
|
||||
f32 spC;
|
||||
f32 sp8;
|
||||
f32* allpassLine;
|
||||
|
||||
if (reverb->active != 0) {
|
||||
reverb->active &= ~2;
|
||||
return;
|
||||
}
|
||||
busParam[AX_STEREO_L] = bus->left;
|
||||
busParam[AX_STEREO_R] = bus->right;
|
||||
busParam[AX_STEREO_S] = bus->surround;
|
||||
if (reverb->busIn) {
|
||||
busIn[AX_STEREO_L] = reverb->busIn->left;
|
||||
busIn[AX_STEREO_R] = reverb->busIn->right;
|
||||
busIn[AX_STEREO_S] = reverb->busIn->surround;
|
||||
}
|
||||
if (reverb->busOut) {
|
||||
busOut[AX_STEREO_L] = reverb->busOut->left;
|
||||
busOut[AX_STEREO_R] = reverb->busOut->right;
|
||||
busOut[AX_STEREO_S] = reverb->busOut->surround;
|
||||
}
|
||||
sp14 = 1.0f - reverb->lpfCoef;
|
||||
lpfCoef = reverb->lpfCoef;
|
||||
earlyCoef = reverb->earlyCoef;
|
||||
combCoef0 = reverb->combCoef[0];
|
||||
combCoef1 = reverb->combCoef[1];
|
||||
allpassCoef = reverb->allpassCoef;
|
||||
spC = 0.6f * reverb->earlyGain;
|
||||
sp8 = 0.6f * reverb->fusedGain;
|
||||
|
||||
for (i = 0; i < 96; i++) {
|
||||
earlyPos = reverb->earlyPos;
|
||||
preDelayPos = reverb->preDelayPos;
|
||||
combPos0 = reverb->combPos[0];
|
||||
combPos1 = reverb->combPos[1];
|
||||
allpassPos0 = reverb->allpassPos[0];
|
||||
allpassPos1 = reverb->allpassPos[1];
|
||||
|
||||
for (j = 0; j < AXFX_STEREO_CHANNEL_MAX; j++) {
|
||||
if (reverb->busIn) {
|
||||
sp64 = *busParam[j] + *busIn[j]++;
|
||||
} else {
|
||||
sp64 = *busParam[j];
|
||||
}
|
||||
earlyLine = reverb->earlyLine[j];
|
||||
sp58 = earlyLine[earlyPos];
|
||||
earlyLine[earlyPos] = sp64 + (sp58 * earlyCoef);
|
||||
if (reverb->preDelayLength != 0) {
|
||||
preDelayLine = reverb->preDelayLine[j];
|
||||
sp4C = preDelayLine[preDelayPos];
|
||||
preDelayLine[preDelayPos] = sp64;
|
||||
} else {
|
||||
sp4C = sp64;
|
||||
}
|
||||
combLine0 = reverb->combLine[j][0];
|
||||
sp40 = combLine0[combPos0];
|
||||
combLine0[combPos0] = sp4C + (sp40 * combCoef0);
|
||||
combLine1 = reverb->combLine[j][1];
|
||||
sp3C = combLine1[combPos1];
|
||||
combLine1[combPos1] = sp4C + (sp3C * combCoef1);
|
||||
sp38 = sp40 + sp3C;
|
||||
allpassLine = reverb->allpassLine[j][0];
|
||||
sp2C = allpassLine[allpassPos0];
|
||||
sp28 = sp38 + (sp2C * allpassCoef);
|
||||
allpassLine[allpassPos0] = sp28;
|
||||
sp24 = sp2C - (sp28 * allpassCoef);
|
||||
sp18 = (sp14 * sp24) + (lpfCoef * reverb->lastLpfOut[j]);
|
||||
reverb->lastLpfOut[j] = sp18;
|
||||
allpassLine = reverb->allpassLine[j][1];
|
||||
sp2C = allpassLine[allpassPos1];
|
||||
sp28 = sp18 + (sp2C * allpassCoef);
|
||||
allpassLine[allpassPos1] = sp28;
|
||||
sp20 = sp2C - (sp28 * allpassCoef);
|
||||
sp60 = (sp58 * spC) + (sp20 * sp8);
|
||||
*busParam[j]++ = (sp60 * reverb->outGain);
|
||||
if (reverb->busOut) {
|
||||
*busOut[j]++ = (sp60 * reverb->sendGain);
|
||||
}
|
||||
}
|
||||
if (++reverb->earlyPos >= reverb->earlyLength) {
|
||||
reverb->earlyPos = 0;
|
||||
}
|
||||
if (reverb->preDelayLength != 0) {
|
||||
if (++reverb->preDelayPos >= reverb->preDelayLength) {
|
||||
reverb->preDelayPos = 0;
|
||||
}
|
||||
}
|
||||
if (++reverb->combPos[0] >= reverb->combLength[0]) {
|
||||
reverb->combPos[0] = 0;
|
||||
}
|
||||
if (++reverb->combPos[1] >= reverb->combLength[1]) {
|
||||
reverb->combPos[1] = 0;
|
||||
}
|
||||
if (++reverb->allpassPos[0] >= reverb->allpassLength[0]) {
|
||||
reverb->allpassPos[0] = 0;
|
||||
}
|
||||
if (++reverb->allpassPos[1] >= reverb->allpassLength[1]) {
|
||||
reverb->allpassPos[1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
fx->earlyLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->earlyMaxLength);
|
||||
if (fx->earlyLine[ch] == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayMaxLength) {
|
||||
fx->preDelayLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->preDelayMaxLength);
|
||||
if (fx->preDelayLine[ch] == NULL)
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->combLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->combMaxLength[i]);
|
||||
if (fx->combLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
if (fx->allpassLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __BzeroDelayLines(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
if (fx->earlyLine[ch])
|
||||
memset(fx->earlyLine[ch], 0, sizeof(f32) * fx->earlyMaxLength);
|
||||
|
||||
if (fx->preDelayLine[ch])
|
||||
memset(fx->preDelayLine[ch], 0, sizeof(f32) * fx->preDelayMaxLength);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->combLine[ch][i])
|
||||
memset(fx->combLine[ch][i], 0, sizeof(f32) * fx->combMaxLength[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i])
|
||||
memset(fx->allpassLine[ch][i], 0, sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __FreeDelayLine(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
if (fx->earlyLine[ch]) {
|
||||
__AXFXFree(fx->earlyLine[ch]);
|
||||
fx->earlyLine[ch] = NULL;
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch]) {
|
||||
__AXFXFree(fx->preDelayLine[ch]);
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->combLine[ch][i]) {
|
||||
__AXFXFree(fx->combLine[ch][i]);
|
||||
fx->combLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i]) {
|
||||
__AXFXFree(fx->allpassLine[ch][i]);
|
||||
fx->allpassLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static BOOL __InitParams(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 i;
|
||||
|
||||
if (fx->earlyMode >= 8)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayTime < 0.0f || fx->preDelayTime > fx->preDelayTimeMax)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedMode >= 6)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedTime < 0.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->coloration < 0.0f || fx->coloration > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->damping < 0.0f || fx->damping > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->earlyGain < 0.0f || fx->earlyGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedGain < 0.0f || fx->fusedGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->outGain < 0.0f || fx->outGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->sendGain < 0.0f || fx->sendGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
fx->earlyPos = 0;
|
||||
fx->earlyLength = __EarlySizeTable[fx->earlyMode];
|
||||
if (fx->earlyMode <= 3) {
|
||||
fx->earlyCoef = -0.33f;
|
||||
} else {
|
||||
fx->earlyCoef = 0.33f;
|
||||
}
|
||||
|
||||
fx->preDelayPos = 0;
|
||||
fx->preDelayLength = (u32)(fx->preDelayTime * 32000);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
f32 t;
|
||||
fx->combPos[i] = 0;
|
||||
fx->combLength[i] = __FilterSizeTable[fx->fusedMode][i];
|
||||
t = -3.0f * (f32)(fx->combLength[i]) / (f32)(fx->fusedTime * 32000);
|
||||
fx->combCoef[i] = pow(10.0f, t);
|
||||
}
|
||||
|
||||
fx->allpassPos[0] = 0;
|
||||
fx->allpassLength[0] = __FilterSizeTable[fx->fusedMode][2];
|
||||
fx->allpassPos[1] = 0;
|
||||
fx->allpassLength[1] = __FilterSizeTable[fx->fusedMode][3];
|
||||
|
||||
fx->allpassCoef = fx->coloration;
|
||||
fx->lpfCoef = 1.0f - fx->damping;
|
||||
if (fx->lpfCoef > 0.95f) {
|
||||
fx->lpfCoef = 0.95f;
|
||||
}
|
||||
|
||||
fx->lastLpfOut[0] = 0.0f;
|
||||
fx->lastLpfOut[1] = 0.0f;
|
||||
fx->lastLpfOut[2] = 0.0f;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
Reference in New Issue
Block a user