annotate src/psf2/peops/reverb.c @ 2895:92fc55b8da15

Use Glib types.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 13 Aug 2008 01:59:25 +0300
parents 62cc6d667119
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /***************************************************************************
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 reverb.c - description
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 -------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 begin : Wed May 15 2002
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 copyright : (C) 2002 by Pete Bernert
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 email : BlackDove@addcom.de
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7 ***************************************************************************/
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 /***************************************************************************
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10 * *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 * (at your option) any later version. See also the license.txt file for *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 * additional informations. *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 * *
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 ***************************************************************************/
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 //*************************************************************************//
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 // History of changes:
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 // 2003/03/17 - xodnizel
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 // - Implemented Neill's 44.1Khz-22050Hz downsampling data
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 // I also need to check if the ~4 sample delay doesn't screw any sounds
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 // up by making things too out of phase. It could be fixed easily(elsewhere).
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 // 2003/01/19 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 // - added Neill's reverb (see at the end of file)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 // 2002/12/26 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 // - adjusted reverb handling
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 // 2002/08/14 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 // - added extra reverb
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 // 2002/05/15 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 // - generic cleanup for the Peops release
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 //*************************************************************************//
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 #define _IN_REVERB
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 // will be included from spu.c
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 #ifdef _IN_SPU
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 // globals
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 // REVERB info and timing vars...
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 static INLINE s64 g_buffer(int iOff) // get_buffer content helper: takes care about wraps
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 s16 * p=(s16 *)spuMem;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 iOff=(iOff*4)+rvb.CurrAddr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 while(iOff>0x3FFFF) iOff=rvb.StartAddr+(iOff-0x40000);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 while(iOff<rvb.StartAddr) iOff=0x3ffff-(rvb.StartAddr-iOff);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 return (int)(s16)BFLIP16(*(p+iOff));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 static INLINE void s_buffer(int iOff,int iVal) // set_buffer content helper: takes care about wraps and clipping
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67 s16 * p=(s16 *)spuMem;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 iOff=(iOff*4)+rvb.CurrAddr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 while(iOff>0x3FFFF) iOff=rvb.StartAddr+(iOff-0x40000);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 while(iOff<rvb.StartAddr) iOff=0x3ffff-(rvb.StartAddr-iOff);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 if(iVal<-32768L) iVal=-32768L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 if(iVal>32767L) iVal=32767L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 *(p+iOff)=(s16)BFLIP16((s16)iVal);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 static INLINE void s_buffer1(int iOff,int iVal) // set_buffer (+1 sample) content helper: takes care about wraps and clipping
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 s16 * p=(s16 *)spuMem;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 iOff=(iOff*4)+rvb.CurrAddr+1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 while(iOff>0x3FFFF) iOff=rvb.StartAddr+(iOff-0x40000);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 while(iOff<rvb.StartAddr) iOff=0x3ffff-(rvb.StartAddr-iOff);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 if(iVal<-32768L) iVal=-32768L;if(iVal>32767L) iVal=32767L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 *(p+iOff)=(s16)BFLIP16((s16)iVal);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88 static INLINE void MixREVERBLeftRight(s32 *oleft, s32 *oright, s32 inleft, s32 inright)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 static s32 downbuf[2][8];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 static s32 upbuf[2][8];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 static int dbpos=0,ubpos=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 static s32 downcoeffs[8]={ /* Symmetry is sexy. */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 1283,5344,10895,15243,
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 15243,10895,5344,1283
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 };
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 int x;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 if(!rvb.StartAddr) // reverb is off
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 rvb.iRVBLeft=rvb.iRVBRight=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 return;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105 //if(inleft<-32767 || inleft>32767) printf("%d\n",inleft);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 //if(inright<-32767 || inright>32767) printf("%d\n",inright);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 downbuf[0][dbpos]=inleft;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 downbuf[1][dbpos]=inright;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 dbpos=(dbpos+1)&7;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 if(dbpos&1) // we work on every second left value: downsample to 22 khz
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 if(spuCtrl&0x80) // -> reverb on? oki
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115 int ACC0,ACC1,FB_A0,FB_A1,FB_B0,FB_B1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116 s32 INPUT_SAMPLE_L=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 s32 INPUT_SAMPLE_R=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 for(x=0;x<8;x++)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 INPUT_SAMPLE_L+=(downbuf[0][(dbpos+x)&7]*downcoeffs[x])>>8; /* Lose insignificant
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 digits to prevent
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 overflow(check this) */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 INPUT_SAMPLE_R+=(downbuf[1][(dbpos+x)&7]*downcoeffs[x])>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 INPUT_SAMPLE_L>>=(16-8);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128 INPUT_SAMPLE_R>>=(16-8);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 const s64 IIR_INPUT_A0 = ((g_buffer(rvb.IIR_SRC_A0) * rvb.IIR_COEF)>>15) + ((INPUT_SAMPLE_L * rvb.IN_COEF_L)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131 const s64 IIR_INPUT_A1 = ((g_buffer(rvb.IIR_SRC_A1) * rvb.IIR_COEF)>>15) + ((INPUT_SAMPLE_R * rvb.IN_COEF_R)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 const s64 IIR_INPUT_B0 = ((g_buffer(rvb.IIR_SRC_B0) * rvb.IIR_COEF)>>15) + ((INPUT_SAMPLE_L * rvb.IN_COEF_L)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 const s64 IIR_INPUT_B1 = ((g_buffer(rvb.IIR_SRC_B1) * rvb.IIR_COEF)>>15) + ((INPUT_SAMPLE_R * rvb.IN_COEF_R)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 const s64 IIR_A0 = ((IIR_INPUT_A0 * rvb.IIR_ALPHA)>>15) + ((g_buffer(rvb.IIR_DEST_A0) * (32768L - rvb.IIR_ALPHA))>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 const s64 IIR_A1 = ((IIR_INPUT_A1 * rvb.IIR_ALPHA)>>15) + ((g_buffer(rvb.IIR_DEST_A1) * (32768L - rvb.IIR_ALPHA))>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 const s64 IIR_B0 = ((IIR_INPUT_B0 * rvb.IIR_ALPHA)>>15) + ((g_buffer(rvb.IIR_DEST_B0) * (32768L - rvb.IIR_ALPHA))>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 const s64 IIR_B1 = ((IIR_INPUT_B1 * rvb.IIR_ALPHA)>>15) + ((g_buffer(rvb.IIR_DEST_B1) * (32768L - rvb.IIR_ALPHA))>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 s_buffer1(rvb.IIR_DEST_A0, IIR_A0);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 s_buffer1(rvb.IIR_DEST_A1, IIR_A1);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 s_buffer1(rvb.IIR_DEST_B0, IIR_B0);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 s_buffer1(rvb.IIR_DEST_B1, IIR_B1);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144 ACC0 = ((g_buffer(rvb.ACC_SRC_A0) * rvb.ACC_COEF_A)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 ((g_buffer(rvb.ACC_SRC_B0) * rvb.ACC_COEF_B)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 ((g_buffer(rvb.ACC_SRC_C0) * rvb.ACC_COEF_C)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147 ((g_buffer(rvb.ACC_SRC_D0) * rvb.ACC_COEF_D)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 ACC1 = ((g_buffer(rvb.ACC_SRC_A1) * rvb.ACC_COEF_A)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 ((g_buffer(rvb.ACC_SRC_B1) * rvb.ACC_COEF_B)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150 ((g_buffer(rvb.ACC_SRC_C1) * rvb.ACC_COEF_C)>>15) +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 ((g_buffer(rvb.ACC_SRC_D1) * rvb.ACC_COEF_D)>>15);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
153 FB_A0 = g_buffer(rvb.MIX_DEST_A0 - rvb.FB_SRC_A);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
154 FB_A1 = g_buffer(rvb.MIX_DEST_A1 - rvb.FB_SRC_A);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 FB_B0 = g_buffer(rvb.MIX_DEST_B0 - rvb.FB_SRC_B);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156 FB_B1 = g_buffer(rvb.MIX_DEST_B1 - rvb.FB_SRC_B);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
157
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158 s_buffer(rvb.MIX_DEST_A0, ACC0 - ((FB_A0 * rvb.FB_ALPHA)>>15));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159 s_buffer(rvb.MIX_DEST_A1, ACC1 - ((FB_A1 * rvb.FB_ALPHA)>>15));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
161 s_buffer(rvb.MIX_DEST_B0, ((rvb.FB_ALPHA * ACC0)>>15) - ((FB_A0 * (int)(rvb.FB_ALPHA^0xFFFF8000))>>15) - ((FB_B0 * rvb.FB_X)>>15));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162 s_buffer(rvb.MIX_DEST_B1, ((rvb.FB_ALPHA * ACC1)>>15) - ((FB_A1 * (int)(rvb.FB_ALPHA^0xFFFF8000))>>15) - ((FB_B1 * rvb.FB_X)>>15));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
164 rvb.iRVBLeft = (g_buffer(rvb.MIX_DEST_A0)+g_buffer(rvb.MIX_DEST_B0))/3;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 rvb.iRVBRight = (g_buffer(rvb.MIX_DEST_A1)+g_buffer(rvb.MIX_DEST_B1))/3;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
166
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
167 rvb.iRVBLeft = ((s64)rvb.iRVBLeft * rvb.VolLeft) >> 14;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168 rvb.iRVBRight = ((s64)rvb.iRVBRight * rvb.VolRight) >> 14;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170 upbuf[0][ubpos]=rvb.iRVBLeft;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171 upbuf[1][ubpos]=rvb.iRVBRight;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172 ubpos=(ubpos+1)&7;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173 } // Bracket hack(et).
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175 else // -> reverb off
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177 rvb.iRVBLeft=rvb.iRVBRight=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
178 return;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
179 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
180 rvb.CurrAddr++;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
181 if(rvb.CurrAddr>0x3ffff) rvb.CurrAddr=rvb.StartAddr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
183 else
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
184 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
185 upbuf[0][ubpos]=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
186 upbuf[1][ubpos]=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
187 ubpos=(ubpos+1)&7;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
188 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
189 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 s32 retl=0,retr=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191 for(x=0;x<8;x++)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 retl+=(upbuf[0][(ubpos+x)&7]*downcoeffs[x])>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 retr+=(upbuf[1][(ubpos+x)&7]*downcoeffs[x])>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
195 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
196 retl>>=(16-8-1); /* -1 To adjust for the null padding. */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197 retr>>=(16-8-1);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
198
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
199 *oleft+=retl;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200 *oright+=retr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
204 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
206 #endif
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
208 /*
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 PSX reverb hardware notes
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211 by Neill Corlett
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214 Yadda yadda disclaimer yadda probably not perfect yadda well it's okay anyway
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 yadda yadda.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 Basics
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220 ------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 - The reverb buffer is 22khz 16-bit mono PCM.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223 - It starts at the reverb address given by 1DA2, extends to
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224 the end of sound RAM, and wraps back to the 1DA2 address.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 Setting the address at 1DA2 resets the current reverb work address.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228 This work address ALWAYS increments every 1/22050 sec., regardless of
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 whether reverb is enabled (bit 7 of 1DAA set).
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231 And the contents of the reverb buffer ALWAYS play, scaled by the
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232 "reverberation depth left/right" volumes (1D84/1D86).
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 (which, by the way, appear to be scaled so 3FFF=approx. 1.0, 4000=-1.0)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 Register names
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 --------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240 These are probably not their real names.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241 These are probably not even correct names.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242 We will use them anyway, because we can.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 1DC0: FB_SRC_A (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245 1DC2: FB_SRC_B (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 1DC4: IIR_ALPHA (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 1DC6: ACC_COEF_A (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248 1DC8: ACC_COEF_B (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 1DCA: ACC_COEF_C (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 1DCC: ACC_COEF_D (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 1DCE: IIR_COEF (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
252 1DD0: FB_ALPHA (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 1DD2: FB_X (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 1DD4: IIR_DEST_A0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255 1DD6: IIR_DEST_A1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256 1DD8: ACC_SRC_A0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 1DDA: ACC_SRC_A1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 1DDC: ACC_SRC_B0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 1DDE: ACC_SRC_B1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 1DE0: IIR_SRC_A0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 1DE2: IIR_SRC_A1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262 1DE4: IIR_DEST_B0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 1DE6: IIR_DEST_B1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264 1DE8: ACC_SRC_C0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 1DEA: ACC_SRC_C1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 1DEC: ACC_SRC_D0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267 1DEE: ACC_SRC_D1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268 1DF0: IIR_SRC_B1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 1DF2: IIR_SRC_B0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 1DF4: MIX_DEST_A0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271 1DF6: MIX_DEST_A1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 1DF8: MIX_DEST_B0 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273 1DFA: MIX_DEST_B1 (offset)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 1DFC: IN_COEF_L (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275 1DFE: IN_COEF_R (coef.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
277 The coefficients are signed fractional values.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278 -32768 would be -1.0
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279 32768 would be 1.0 (if it were possible... the highest is of course 32767)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281 The offsets are (byte/8) offsets into the reverb buffer.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282 i.e. you multiply them by 8, you get byte offsets.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 You can also think of them as (samples/4) offsets.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 They appear to be signed. They can be negative.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 None of the documented presets make them negative, though.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 Yes, 1DF0 and 1DF2 appear to be backwards. Not a typo.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 What it does
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292 ------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294 We take all reverb sources:
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295 - regular channels that have the reverb bit on
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296 - cd and external sources, if their reverb bits are on
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297 and mix them into one stereo 44100hz signal.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 Lowpass/downsample that to 22050hz. The PSX uses a proper bandlimiting
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 algorithm here, but I haven't figured out the hysterically exact specifics.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301 I use an 8-tap filter with these coefficients, which are nice but probably
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 not the real ones:
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304 0.037828187894
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 0.157538631280
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 0.321159685278
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 0.449322115345
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 0.449322115345
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309 0.321159685278
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310 0.157538631280
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311 0.037828187894
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313 So we have two input samples (INPUT_SAMPLE_L, INPUT_SAMPLE_R) every 22050hz.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
314
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
315 * IN MY EMULATION, I divide these by 2 to make it clip less.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316 (and of course the L/R output coefficients are adjusted to compensate)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317 The real thing appears to not do this.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319 At every 22050hz tick:
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
320 - If the reverb bit is enabled (bit 7 of 1DAA), execute the reverb
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321 steady-state algorithm described below
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322 - AFTERWARDS, retrieve the "wet out" L and R samples from the reverb buffer
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323 (This part may not be exactly right and I guessed at the coefs. TODO: check later.)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 L is: 0.333 * (buffer[MIX_DEST_A0] + buffer[MIX_DEST_B0])
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
325 R is: 0.333 * (buffer[MIX_DEST_A1] + buffer[MIX_DEST_B1])
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
326 - Advance the current buffer position by 1 sample
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
327
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
328 The wet out L and R are then upsampled to 44100hz and played at the
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
329 "reverberation depth left/right" (1D84/1D86) volume, independent of the main
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
330 volume.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
331
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
332 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
333
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
334 Reverb steady-state
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
335 -------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
336
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
337 The reverb steady-state algorithm is fairly clever, and of course by
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
338 "clever" I mean "batshit insane".
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
339
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
340 buffer[x] is relative to the current buffer position, not the beginning of
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
341 the buffer. Note that all buffer offsets must wrap around so they're
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
342 contained within the reverb work area.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
343
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
344 Clipping is performed at the end... maybe also sooner, but definitely at
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
345 the end.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
346
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
347 IIR_INPUT_A0 = buffer[IIR_SRC_A0] * IIR_COEF + INPUT_SAMPLE_L * IN_COEF_L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
348 IIR_INPUT_A1 = buffer[IIR_SRC_A1] * IIR_COEF + INPUT_SAMPLE_R * IN_COEF_R;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
349 IIR_INPUT_B0 = buffer[IIR_SRC_B0] * IIR_COEF + INPUT_SAMPLE_L * IN_COEF_L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
350 IIR_INPUT_B1 = buffer[IIR_SRC_B1] * IIR_COEF + INPUT_SAMPLE_R * IN_COEF_R;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
351
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
352 IIR_A0 = IIR_INPUT_A0 * IIR_ALPHA + buffer[IIR_DEST_A0] * (1.0 - IIR_ALPHA);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
353 IIR_A1 = IIR_INPUT_A1 * IIR_ALPHA + buffer[IIR_DEST_A1] * (1.0 - IIR_ALPHA);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
354 IIR_B0 = IIR_INPUT_B0 * IIR_ALPHA + buffer[IIR_DEST_B0] * (1.0 - IIR_ALPHA);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
355 IIR_B1 = IIR_INPUT_B1 * IIR_ALPHA + buffer[IIR_DEST_B1] * (1.0 - IIR_ALPHA);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
356
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
357 buffer[IIR_DEST_A0 + 1sample] = IIR_A0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
358 buffer[IIR_DEST_A1 + 1sample] = IIR_A1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
359 buffer[IIR_DEST_B0 + 1sample] = IIR_B0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
360 buffer[IIR_DEST_B1 + 1sample] = IIR_B1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
361
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
362 ACC0 = buffer[ACC_SRC_A0] * ACC_COEF_A +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
363 buffer[ACC_SRC_B0] * ACC_COEF_B +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
364 buffer[ACC_SRC_C0] * ACC_COEF_C +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
365 buffer[ACC_SRC_D0] * ACC_COEF_D;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
366 ACC1 = buffer[ACC_SRC_A1] * ACC_COEF_A +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
367 buffer[ACC_SRC_B1] * ACC_COEF_B +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
368 buffer[ACC_SRC_C1] * ACC_COEF_C +
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
369 buffer[ACC_SRC_D1] * ACC_COEF_D;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
370
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
371 FB_A0 = buffer[MIX_DEST_A0 - FB_SRC_A];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
372 FB_A1 = buffer[MIX_DEST_A1 - FB_SRC_A];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
373 FB_B0 = buffer[MIX_DEST_B0 - FB_SRC_B];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
374 FB_B1 = buffer[MIX_DEST_B1 - FB_SRC_B];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
375
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
376 buffer[MIX_DEST_A0] = ACC0 - FB_A0 * FB_ALPHA;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
377 buffer[MIX_DEST_A1] = ACC1 - FB_A1 * FB_ALPHA;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
378 buffer[MIX_DEST_B0] = (FB_ALPHA * ACC0) - FB_A0 * (FB_ALPHA^0x8000) - FB_B0 * FB_X;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
379 buffer[MIX_DEST_B1] = (FB_ALPHA * ACC1) - FB_A1 * (FB_ALPHA^0x8000) - FB_B1 * FB_X;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
380
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
381 -----------------------------------------------------------------------------
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
382 */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
383