aboutsummaryrefslogtreecommitdiff
path: root/plugins/dfsound/reverb.c
diff options
context:
space:
mode:
authornotaz2015-01-25 23:21:40 +0200
committernotaz2015-01-25 23:21:40 +0200
commit4e9adec1930817da2031fd044dc74c0f454a0079 (patch)
tree854c202544c75e486d4243b34366162f03f082eb /plugins/dfsound/reverb.c
parentbe1294d017cba3f18cf66597f0cbed207fed26bf (diff)
parentba10822d813767632c528102055e3eeb54730b2c (diff)
downloadpcsx_rearmed-4e9adec1930817da2031fd044dc74c0f454a0079.tar.gz
pcsx_rearmed-4e9adec1930817da2031fd044dc74c0f454a0079.tar.bz2
pcsx_rearmed-4e9adec1930817da2031fd044dc74c0f454a0079.zip
Merge branch 'upstream' into libretro
Diffstat (limited to 'plugins/dfsound/reverb.c')
-rw-r--r--plugins/dfsound/reverb.c162
1 files changed, 62 insertions, 100 deletions
diff --git a/plugins/dfsound/reverb.c b/plugins/dfsound/reverb.c
index bb5ee8e..2ff6edc 100644
--- a/plugins/dfsound/reverb.c
+++ b/plugins/dfsound/reverb.c
@@ -32,20 +32,11 @@
INLINE void StartREVERB(int ch)
{
- if(s_chan[ch].bReverb && (spu.spuCtrl&0x80)) // reverb possible?
+ if(spu.s_chan[ch].bReverb && (spu.spuCtrl&0x80)) // reverb possible?
{
- s_chan[ch].bRVBActive=!!spu_config.iUseReverb;
+ spu.s_chan[ch].bRVBActive=!!spu_config.iUseReverb;
}
- else s_chan[ch].bRVBActive=0; // else -> no reverb
-}
-
-////////////////////////////////////////////////////////////////////////
-// HELPER FOR NEILL'S REVERB: re-inits our reverb mixing buf
-////////////////////////////////////////////////////////////////////////
-
-INLINE void InitREVERB(int ns_to)
-{
- memset(spu.sRVBStart,0,ns_to*sizeof(spu.sRVBStart[0])*2);
+ else spu.s_chan[ch].bRVBActive=0; // else -> no reverb
}
////////////////////////////////////////////////////////////////////////
@@ -59,41 +50,40 @@ INLINE int rvb2ram_offs(int curr, int space, int iOff)
// get_buffer content helper: takes care about wraps
#define g_buffer(var) \
- ((int)(signed short)spu.spuMem[rvb2ram_offs(curr_addr, space, rvb.n##var)])
+ ((int)(signed short)spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->n##var)])
// saturate iVal and store it as var
#define s_buffer(var, iVal) \
ssat32_to_16(iVal); \
- spu.spuMem[rvb2ram_offs(curr_addr, space, rvb.n##var)] = iVal
+ spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->n##var)] = iVal
#define s_buffer1(var, iVal) \
ssat32_to_16(iVal); \
- spu.spuMem[rvb2ram_offs(curr_addr, space, rvb.n##var + 1)] = iVal
+ spu.spuMem[rvb2ram_offs(curr_addr, space, rvb->n##var + 1)] = iVal
////////////////////////////////////////////////////////////////////////
// portions based on spu2-x from PCSX2
-static void MixREVERB(int ns_to)
+static void MixREVERB(int *SSumLR, int *RVB, int ns_to, int curr_addr)
{
- int l_old = rvb.iRVBLeft;
- int r_old = rvb.iRVBRight;
- int curr_addr = rvb.CurrAddr;
- int space = 0x40000 - rvb.StartAddr;
- int l = 0, r = 0, ns;
+ const REVERBInfo *rvb = spu.rvb;
+ int IIR_ALPHA = rvb->IIR_ALPHA;
+ int IIR_COEF = rvb->IIR_COEF;
+ int space = 0x40000 - rvb->StartAddr;
+ int l, r, ns;
for (ns = 0; ns < ns_to * 2; )
{
- int IIR_ALPHA = rvb.IIR_ALPHA;
int ACC0, ACC1, FB_A0, FB_A1, FB_B0, FB_B1;
int mix_dest_a0, mix_dest_a1, mix_dest_b0, mix_dest_b1;
- int input_L = spu.sRVBStart[ns] * rvb.IN_COEF_L;
- int input_R = spu.sRVBStart[ns+1] * rvb.IN_COEF_R;
+ int input_L = RVB[ns] * rvb->IN_COEF_L;
+ int input_R = RVB[ns+1] * rvb->IN_COEF_R;
- int IIR_INPUT_A0 = ((g_buffer(IIR_SRC_A0) * rvb.IIR_COEF) + input_L) >> 15;
- int IIR_INPUT_A1 = ((g_buffer(IIR_SRC_A1) * rvb.IIR_COEF) + input_R) >> 15;
- int IIR_INPUT_B0 = ((g_buffer(IIR_SRC_B0) * rvb.IIR_COEF) + input_L) >> 15;
- int IIR_INPUT_B1 = ((g_buffer(IIR_SRC_B1) * rvb.IIR_COEF) + input_R) >> 15;
+ int IIR_INPUT_A0 = ((g_buffer(IIR_SRC_A0) * IIR_COEF) + input_L) >> 15;
+ int IIR_INPUT_A1 = ((g_buffer(IIR_SRC_A1) * IIR_COEF) + input_R) >> 15;
+ int IIR_INPUT_B0 = ((g_buffer(IIR_SRC_B0) * IIR_COEF) + input_L) >> 15;
+ int IIR_INPUT_B1 = ((g_buffer(IIR_SRC_B1) * IIR_COEF) + input_R) >> 15;
int iir_dest_a0 = g_buffer(IIR_DEST_A0);
int iir_dest_a1 = g_buffer(IIR_DEST_A1);
@@ -105,30 +95,34 @@ static void MixREVERB(int ns_to)
int IIR_B0 = iir_dest_b0 + ((IIR_INPUT_B0 - iir_dest_b0) * IIR_ALPHA >> 15);
int IIR_B1 = iir_dest_b1 + ((IIR_INPUT_B1 - iir_dest_b1) * IIR_ALPHA >> 15);
+ preload(SSumLR + ns + 64*2/4 - 4);
+
s_buffer1(IIR_DEST_A0, IIR_A0);
s_buffer1(IIR_DEST_A1, IIR_A1);
s_buffer1(IIR_DEST_B0, IIR_B0);
s_buffer1(IIR_DEST_B1, IIR_B1);
- ACC0 = (g_buffer(ACC_SRC_A0) * rvb.ACC_COEF_A +
- g_buffer(ACC_SRC_B0) * rvb.ACC_COEF_B +
- g_buffer(ACC_SRC_C0) * rvb.ACC_COEF_C +
- g_buffer(ACC_SRC_D0) * rvb.ACC_COEF_D) >> 15;
- ACC1 = (g_buffer(ACC_SRC_A1) * rvb.ACC_COEF_A +
- g_buffer(ACC_SRC_B1) * rvb.ACC_COEF_B +
- g_buffer(ACC_SRC_C1) * rvb.ACC_COEF_C +
- g_buffer(ACC_SRC_D1) * rvb.ACC_COEF_D) >> 15;
+ preload(RVB + ns + 64*2/4 - 4);
+
+ ACC0 = (g_buffer(ACC_SRC_A0) * rvb->ACC_COEF_A +
+ g_buffer(ACC_SRC_B0) * rvb->ACC_COEF_B +
+ g_buffer(ACC_SRC_C0) * rvb->ACC_COEF_C +
+ g_buffer(ACC_SRC_D0) * rvb->ACC_COEF_D) >> 15;
+ ACC1 = (g_buffer(ACC_SRC_A1) * rvb->ACC_COEF_A +
+ g_buffer(ACC_SRC_B1) * rvb->ACC_COEF_B +
+ g_buffer(ACC_SRC_C1) * rvb->ACC_COEF_C +
+ g_buffer(ACC_SRC_D1) * rvb->ACC_COEF_D) >> 15;
FB_A0 = g_buffer(FB_SRC_A0);
FB_A1 = g_buffer(FB_SRC_A1);
FB_B0 = g_buffer(FB_SRC_B0);
FB_B1 = g_buffer(FB_SRC_B1);
- mix_dest_a0 = ACC0 - ((FB_A0 * rvb.FB_ALPHA) >> 15);
- mix_dest_a1 = ACC1 - ((FB_A1 * rvb.FB_ALPHA) >> 15);
+ mix_dest_a0 = ACC0 - ((FB_A0 * rvb->FB_ALPHA) >> 15);
+ mix_dest_a1 = ACC1 - ((FB_A1 * rvb->FB_ALPHA) >> 15);
- mix_dest_b0 = FB_A0 + (((ACC0 - FB_A0) * rvb.FB_ALPHA - FB_B0 * rvb.FB_X) >> 15);
- mix_dest_b1 = FB_A1 + (((ACC1 - FB_A1) * rvb.FB_ALPHA - FB_B1 * rvb.FB_X) >> 15);
+ mix_dest_b0 = FB_A0 + (((ACC0 - FB_A0) * rvb->FB_ALPHA - FB_B0 * rvb->FB_X) >> 15);
+ mix_dest_b1 = FB_A1 + (((ACC1 - FB_A1) * rvb->FB_ALPHA - FB_B1 * rvb->FB_X) >> 15);
s_buffer(MIX_DEST_A0, mix_dest_a0);
s_buffer(MIX_DEST_A1, mix_dest_a1);
@@ -138,73 +132,60 @@ static void MixREVERB(int ns_to)
l = (mix_dest_a0 + mix_dest_b0) / 2;
r = (mix_dest_a1 + mix_dest_b1) / 2;
- l = (l * rvb.VolLeft) >> 15; // 15?
- r = (r * rvb.VolRight) >> 15;
+ l = (l * rvb->VolLeft) >> 15; // 15?
+ r = (r * rvb->VolRight) >> 15;
- SSumLR[ns++] += (l + l_old) / 2;
- SSumLR[ns++] += (r + r_old) / 2;
SSumLR[ns++] += l;
SSumLR[ns++] += r;
-
- l_old = l;
- r_old = r;
+ SSumLR[ns++] += l;
+ SSumLR[ns++] += r;
curr_addr++;
- if (curr_addr >= 0x40000) curr_addr = rvb.StartAddr;
+ if (curr_addr >= 0x40000) curr_addr = rvb->StartAddr;
}
-
- rvb.iRVBLeft = l;
- rvb.iRVBRight = r;
- rvb.CurrAddr = curr_addr;
}
-static void MixREVERB_off(int ns_to)
+static void MixREVERB_off(int *SSumLR, int ns_to, int curr_addr)
{
- int l_old = rvb.iRVBLeft;
- int r_old = rvb.iRVBRight;
- int curr_addr = rvb.CurrAddr;
- int space = 0x40000 - rvb.StartAddr;
- int l = 0, r = 0, ns;
+ const REVERBInfo *rvb = spu.rvb;
+ int space = 0x40000 - rvb->StartAddr;
+ int l, r, ns;
for (ns = 0; ns < ns_to * 2; )
{
+ preload(SSumLR + ns + 64*2/4 - 4);
+
l = (g_buffer(MIX_DEST_A0) + g_buffer(MIX_DEST_B0)) / 2;
r = (g_buffer(MIX_DEST_A1) + g_buffer(MIX_DEST_B1)) / 2;
- l = (l * rvb.VolLeft) >> 15;
- r = (r * rvb.VolRight) >> 15;
+ l = (l * rvb->VolLeft) >> 15;
+ r = (r * rvb->VolRight) >> 15;
- SSumLR[ns++] += (l + l_old) / 2;
- SSumLR[ns++] += (r + r_old) / 2;
SSumLR[ns++] += l;
SSumLR[ns++] += r;
-
- l_old = l;
- r_old = r;
+ SSumLR[ns++] += l;
+ SSumLR[ns++] += r;
curr_addr++;
- if (curr_addr >= 0x40000) curr_addr = rvb.StartAddr;
+ if (curr_addr >= 0x40000) curr_addr = rvb->StartAddr;
}
-
- rvb.iRVBLeft = l;
- rvb.iRVBRight = r;
- rvb.CurrAddr = curr_addr;
}
-static void prepare_offsets(void)
+static void REVERBPrep(void)
{
- int space = 0x40000 - rvb.StartAddr;
+ REVERBInfo *rvb = spu.rvb;
+ int space = 0x40000 - rvb->StartAddr;
int t;
#define prep_offs(v) \
- t = rvb.v; \
+ t = rvb->v; \
while (t >= space) \
t -= space; \
- rvb.n##v = t
+ rvb->n##v = t
#define prep_offs2(d, v1, v2) \
- t = rvb.v1 - rvb.v2; \
+ t = rvb->v1 - rvb->v2; \
while (t >= space) \
t -= space; \
- rvb.n##d = t
+ rvb->n##d = t
prep_offs(IIR_SRC_A0);
prep_offs(IIR_SRC_A1);
@@ -233,37 +214,18 @@ static void prepare_offsets(void)
#undef prep_offs
#undef prep_offs2
- rvb.dirty = 0;
+ rvb->dirty = 0;
}
-INLINE void REVERBDo(int ns_to)
+INLINE void REVERBDo(int *SSumLR, int *RVB, int ns_to, int curr_addr)
{
- if (!rvb.StartAddr) // reverb is off
- {
- rvb.iRVBLeft = rvb.iRVBRight = 0;
- return;
- }
-
if (spu.spuCtrl & 0x80) // -> reverb on? oki
{
- if (unlikely(rvb.dirty))
- prepare_offsets();
-
- MixREVERB(ns_to);
- }
- else if (rvb.VolLeft || rvb.VolRight)
- {
- if (unlikely(rvb.dirty))
- prepare_offsets();
-
- MixREVERB_off(ns_to);
+ MixREVERB(SSumLR, RVB, ns_to, curr_addr);
}
- else // -> reverb off
+ else if (spu.rvb->VolLeft || spu.rvb->VolRight)
{
- // reverb runs anyway
- rvb.CurrAddr += ns_to / 2;
- while (rvb.CurrAddr >= 0x40000)
- rvb.CurrAddr -= 0x40000 - rvb.StartAddr;
+ MixREVERB_off(SSumLR, ns_to, curr_addr);
}
}