annotate src/psf2/peops/spu.c @ 2954:f1482af6384c

Warning clean.
author William Pitcock <nenolod@atheme.org>
date Wed, 15 Oct 2008 14:31:23 -0500
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 spu.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/01 - linuzappz
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 // - libraryName changes using ALSA
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 // 2003/02/28 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26 // - added option for type of interpolation
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 // - adjusted spu irqs again (Thousant Arms, Valkyrie Profile)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 // - added MONO support for MSWindows DirectSound
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 // 2003/02/20 - kode54
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 // - amended interpolation code, goto GOON could skip initialization of gpos and cause segfault
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 // 2003/02/19 - kode54
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 // - moved SPU IRQ handler and changed sample flag processing
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 // 2003/02/18 - kode54
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 // - moved ADSR calculation outside of the sample decode loop, somehow I doubt that
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 // ADSR timing is relative to the frequency at which a sample is played... I guess
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 // this remains to be seen, and I don't know whether ADSR is applied to noise channels...
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 // 2003/02/09 - kode54
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 // - one-shot samples now process the end block before stopping
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 // - in light of removing fmod hack, now processing ADSR on frequency channel as well
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 // 2003/02/08 - kode54
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 // - replaced easy interpolation with gaussian
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 // - removed fmod averaging hack
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 // - changed .sinc to be updated from .iRawPitch, no idea why it wasn't done this way already (<- Pete: because I sometimes fail to see the obvious, haharhar :)
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 // 2003/02/08 - linuzappz
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 // - small bugfix for one usleep that was 1 instead of 1000
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 // - added iDisStereo for no stereo (Linux)
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 // 2003/01/22 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 // - added easy interpolation & small noise adjustments
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 // 2003/01/19 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 // - added Neill's reverb
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 // 2003/01/12 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 // - added recording window handlers
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 // 2003/01/06 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 // - added Neill's ADSR timings
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 // 2002/12/28 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67 // - adjusted spu irq handling, fmod handling and loop handling
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 // 2002/08/14 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 // - added extra reverb
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 // 2002/06/08 - linuzappz
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 // - SPUupdate changed for SPUasync
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 // 2002/05/15 - Pete
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 // - generic cleanup for the Peops release
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 //*************************************************************************//
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 #define _IN_SPU
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 #include "../peops/stdafx.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 #include "../peops/externals.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 #include "../peops/regs.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 #include "../peops/registers.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 #include "../peops/spu.h"
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 void SPUirq(void) ;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89
2954
f1482af6384c Warning clean.
William Pitcock <nenolod@atheme.org>
parents: 2737
diff changeset
90 void spu_update(unsigned char* pSound,long lBytes);
f1482af6384c Warning clean.
William Pitcock <nenolod@atheme.org>
parents: 2737
diff changeset
91
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 //#include "PsxMem.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 //#include "driver.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 // globals
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 ////////////////////////////////////////////////////////////////////////
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 // psx buffer / addresses
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 static u16 regArea[0x200];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 static u16 spuMem[256*1024];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 static u8 * spuMemC;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 static u8 * pSpuIrq=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105 static u8 * pSpuBuffer;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 // user settings
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 static int iVolume;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110 // MAIN infos struct for each channel
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 static SPUCHAN s_chan[MAXCHAN+1]; // channel + 1 infos (1 is security for fmod handling)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 static REVERBInfo rvb;
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 static u32 dwNoiseVal=1; // global noise generator
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 static u16 spuCtrl=0; // some vars to store psx reg infos
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 static u16 spuStat=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 static u16 spuIrq=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120 static u32 spuAddr=0xffffffff; // address into spu mem
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 static int bSPUIsOpen=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 static const int f[5][2] = {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 { 0, 0 },
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 { 60, 0 },
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 { 115, -52 },
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 { 98, -55 },
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128 { 122, -60 } };
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129 s16 * pS;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 static s32 ttemp;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 // CODE AREA
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 // dirty inline func includes
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 #include "../peops/reverb.c"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 #include "../peops/adsr.c"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 // Try this to increase speed.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 #include "../peops/registers.c"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143 #include "../peops/dma.c"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 // helpers for so-called "gauss interpolation"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 #define gval0 (((int *)(&s_chan[ch].SB[29]))[gpos])
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 #define gval(x) (((int *)(&s_chan[ch].SB[29]))[(gpos+x)&3])
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 #include "gauss_i.h"
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 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
154
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156 // START SOUND... called by main thread to setup a new sound on a channel
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
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159 static INLINE void StartSound(int ch)
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 StartADSR(ch);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163 s_chan[ch].pCurr=s_chan[ch].pStart; // set sample start
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
164
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 s_chan[ch].s_1=0; // init mixing vars
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
166 s_chan[ch].s_2=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
167 s_chan[ch].iSBPos=28;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169 s_chan[ch].bNew=0; // init channel flags
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170 s_chan[ch].bStop=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171 s_chan[ch].bOn=1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173 s_chan[ch].SB[29]=0; // init our interpolation helpers
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174 s_chan[ch].SB[30]=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 s_chan[ch].spos=0x40000L;s_chan[ch].SB[28]=0; // -> start with more decoding
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
178
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 // MAIN SPU FUNCTION
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
181 // here is the main job handler... thread, timer or direct func call
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 // basically the whole sound processing is done in this fat func!
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
183 ////////////////////////////////////////////////////////////////////////
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 static u32 sampcount;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
186 static u32 decaybegin;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
187 static u32 decayend;
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 // Counting to 65536 results in full volume offage.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 void setlength(s32 stop, s32 fade)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192 if(stop==~0)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 decaybegin=~0;
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 else
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
198 stop=(stop*441)/10;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
199 fade=(fade*441)/10;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 decaybegin=stop;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202 decayend=stop+fade;
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 #define CLIP(_x) {if(_x>32767) _x=32767; if(_x<-32767) _x=-32767;}
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207 int SPUasync(u32 cycles)
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 int volmul=iVolume;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 static s32 dosampies;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211 s32 temp;
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 ttemp+=cycles;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214 dosampies=ttemp/384;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 if(!dosampies) return(1);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216 ttemp-=dosampies*384;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217 temp=dosampies;
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 while(temp)
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 s32 revLeft=0, revRight=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 s32 sl=0, sr=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223 int ch,fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225 temp--;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 //--------------------------------------------------//
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227 //- main channel loop -//
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228 //--------------------------------------------------//
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230 for(ch=0;ch<MAXCHAN;ch++) // loop em all.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232 if(s_chan[ch].bNew) StartSound(ch); // start new sound
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 if(!s_chan[ch].bOn) continue; // channel not playing? next
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 if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq) // new psx frequency?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 s_chan[ch].iUsedFreq=s_chan[ch].iActFreq; // -> take it and calc steps
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239 s_chan[ch].sinc=s_chan[ch].iRawPitch<<4;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240 if(!s_chan[ch].sinc) s_chan[ch].sinc=1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243 while(s_chan[ch].spos>=0x10000L)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245 if(s_chan[ch].iSBPos==28) // 28 reached?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 int predict_nr,shift_factor,flags,d,s;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248 u8* start;unsigned int nSample;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 int s_1,s_2;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 start=s_chan[ch].pCurr; // set up the current pos
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
252
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 if (start == (u8*)-1) // special "stop" sign
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255 s_chan[ch].bOn=0; // -> turn everything off
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256 s_chan[ch].ADSRX.lVolume=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 s_chan[ch].ADSRX.EnvelopeVol=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 goto ENDX; // -> and done for this channel
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 s_chan[ch].iSBPos=0; // Reset buffer play index.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 //////////////////////////////////////////// spu irq handler here? mmm... do it later
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 s_1=s_chan[ch].s_1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 s_2=s_chan[ch].s_2;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268 predict_nr=(int)*start;start++;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 shift_factor=predict_nr&0xf;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 predict_nr >>= 4;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271 flags=(int)*start;start++;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273 // -------------------------------------- //
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 // Decode new samples into s_chan[ch].SB[0 through 27]
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275 for (nSample=0;nSample<28;start++)
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 d=(int)*start;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278 s=((d&0xf)<<12);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279 if(s&0x8000) s|=0xffff0000;
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 fa=(s >> shift_factor);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282 fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 s_2=s_1;s_1=fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 s=((d & 0xf0) << 8);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 s_chan[ch].SB[nSample++]=fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288 if(s&0x8000) s|=0xffff0000;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 fa=(s>>shift_factor);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290 fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 s_2=s_1;s_1=fa;
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 s_chan[ch].SB[nSample++]=fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296 //////////////////////////////////////////// irq check
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298 if(spuCtrl&0x40) // irq active?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 if((pSpuIrq > start-16 && // irq address reached?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301 pSpuIrq <= start) ||
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 ((flags&1) && // special: irq on looping addr, when stop/loop flag is set
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303 (pSpuIrq > s_chan[ch].pLoop-16 &&
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304 pSpuIrq <= s_chan[ch].pLoop)))
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 //extern s32 spuirqvoodoo;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 s_chan[ch].iIrqDone=1; // -> debug flag
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 SPUirq();
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309 //puts("IRQ");
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310 //if(spuirqvoodoo!=-1)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311 //{
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312 // spuirqvoodoo=temp*384;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313 // temp=0;
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 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318 //////////////////////////////////////////// flag handler
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
320 if((flags&4) && (!s_chan[ch].bIgnoreLoop))
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321 s_chan[ch].pLoop=start-16; // loop adress
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323 if(flags&1) // 1: stop/loop
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
325 // We play this block out first...
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
326 //if(!(flags&2)) // 1+2: do loop... otherwise: stop
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
327 if(flags!=3 || s_chan[ch].pLoop==NULL) // PETE: if we don't check exactly for 3, loop hang ups will happen (DQ4, for example)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
328 { // and checking if pLoop is set avoids crashes, yeah
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
329 start = (u8*)-1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
330 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
331 else
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 start = s_chan[ch].pLoop;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
334 }
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 s_chan[ch].pCurr=start; // store values for next cycle
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
338 s_chan[ch].s_1=s_1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
339 s_chan[ch].s_2=s_2;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
340
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
341 ////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
342 }
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 fa=s_chan[ch].SB[s_chan[ch].iSBPos++]; // get sample data
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
345
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
346 if((spuCtrl&0x4000)==0) fa=0; // muted?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
347 else CLIP(fa);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
348
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
349 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
350 int gpos;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
351 gpos = s_chan[ch].SB[28];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
352 gval0 = fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
353 gpos = (gpos+1) & 3;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
354 s_chan[ch].SB[28] = gpos;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
355 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
356 s_chan[ch].spos -= 0x10000L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
357 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
358
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
359 ////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
360 // noise handler... just produces some noise data
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
361 // surely wrong... and no noise frequency (spuCtrl&0x3f00) will be used...
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
362 // and sometimes the noise will be used as fmod modulation... pfff
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
363
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
364 if(s_chan[ch].bNoise)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
365 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
366 //puts("Noise");
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
367 if((dwNoiseVal<<=1)&0x80000000L)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
368 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
369 dwNoiseVal^=0x0040001L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
370 fa=((dwNoiseVal>>2)&0x7fff);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
371 fa=-fa;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
372 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
373 else fa=(dwNoiseVal>>2)&0x7fff;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
374
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
375 // mmm... depending on the noise freq we allow bigger/smaller changes to the previous val
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
376 fa=s_chan[ch].iOldNoise+((fa-s_chan[ch].iOldNoise)/((0x001f-((spuCtrl&0x3f00)>>9))+1));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
377 if(fa>32767L) fa=32767L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
378 if(fa<-32767L) fa=-32767L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
379 s_chan[ch].iOldNoise=fa;
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 else // NO NOISE (NORMAL SAMPLE DATA) HERE
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
383 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
384 int vl, vr, gpos;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
385 vl = (s_chan[ch].spos >> 6) & ~3;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
386 gpos = s_chan[ch].SB[28];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
387 vr=(gauss[vl]*gval0)>>9;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
388 vr+=(gauss[vl+1]*gval(1))>>9;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
389 vr+=(gauss[vl+2]*gval(2))>>9;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
390 vr+=(gauss[vl+3]*gval(3))>>9;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
391 fa = vr>>2;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
392 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
393
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
394 s_chan[ch].sval = (MixADSR(ch) * fa)>>10; // / 1023; // add adsr
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
395 if(s_chan[ch].bFMod==2) // fmod freq channel
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
396 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
397 int NP=s_chan[ch+1].iRawPitch;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
398 NP=((32768L+s_chan[ch].sval)*NP)>>15; ///32768L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
399
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
400 if(NP>0x3fff) NP=0x3fff;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
401 if(NP<0x1) NP=0x1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
402
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
403 // mmmm... if I do this, all is screwed
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
404 // s_chan[ch+1].iRawPitch=NP;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
405
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
406 NP=(44100L*NP)/(4096L); // calc frequency
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
407
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
408 s_chan[ch+1].iActFreq=NP;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
409 s_chan[ch+1].iUsedFreq=NP;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
410 s_chan[ch+1].sinc=(((NP/10)<<16)/4410);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
411 if(!s_chan[ch+1].sinc) s_chan[ch+1].sinc=1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
412
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
413 // mmmm... set up freq decoding positions?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
414 // s_chan[ch+1].iSBPos=28;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
415 // s_chan[ch+1].spos=0x10000L;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
416 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
417 else
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
418 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
419 //////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
420 // ok, left/right sound volume (psx volume goes from 0 ... 0x3fff)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
421 int tmpl,tmpr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
422
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
423 if (1) //ao_channel_enable[ch+PSF_1]) {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
424 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
425 tmpl=(s_chan[ch].sval*s_chan[ch].iLeftVolume)>>14;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
426 tmpr=(s_chan[ch].sval*s_chan[ch].iRightVolume)>>14;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
427 } else {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
428 tmpl = 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
429 tmpr = 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
430 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
431 sl+=tmpl;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
432 sr+=tmpr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
433
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
434 if(((rvb.Enabled>>ch)&1) && (spuCtrl&0x80))
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
435 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
436 revLeft+=tmpl;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
437 revRight+=tmpr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
438 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
439 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
440
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
441 s_chan[ch].spos += s_chan[ch].sinc;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
442 ENDX: ;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
443 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
444 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
445
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
446 ///////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
447 // mix all channels (including reverb) into one buffer
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
448 MixREVERBLeftRight(&sl,&sr,revLeft,revRight);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
449 // printf("sampcount %d decaybegin %d decayend %d\n", sampcount, decaybegin, decayend);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
450 if(sampcount>=decaybegin)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
451 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
452 s32 dmul;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
453 if(decaybegin!=~0) // Is anyone REALLY going to be playing a song
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
454 // for 13 hours?
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
455 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
456 if(sampcount>=decayend)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
457 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
458 // ao_song_done = 1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
459 return(0);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
460 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
461 dmul=256-(256*(sampcount-decaybegin)/(decayend-decaybegin));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
462 sl=(sl*dmul)>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
463 sr=(sr*dmul)>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
464 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
465 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
466
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
467 sampcount++;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
468 sl=(sl*volmul)>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
469 sr=(sr*volmul)>>8;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
470
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
471 //{
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
472 // static double asl=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
473 // static double asr=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
474
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
475 // asl+=(sl-asl)/5;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
476 // asr+=(sl-asr)/5;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
477
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
478 //sl-=asl;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
479 //sr-=asr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
480
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
481 // if(sl>32767 || sl < -32767) printf("Left: %d, %f\n",sl,asl);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
482 // if(sr>32767 || sr < -32767) printf("Right: %d, %f\n",sl,asl);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
483 //}
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
484
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
485 if(sl>32767) sl=32767; if(sl<-32767) sl=-32767;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
486 if(sr>32767) sr=32767; if(sr<-32767) sr=-32767;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
487
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
488 *pS++=sl;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
489 *pS++=sr;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
490 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
491
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
492 return(1);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
493 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
494
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
495 void SPU_flushboot(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
496 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
497 if((u8*)pS>((u8*)pSpuBuffer+1024))
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
498 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
499 spu_update((u8*)pSpuBuffer,(u8*)pS-(u8*)pSpuBuffer);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
500 pS=(s16 *)pSpuBuffer;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
501 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
502 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
503
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
504 #ifdef TIMEO
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
505 static u64 begintime;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
506 static u64 gettime64(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
507 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
508 struct timeval tv;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
509 u64 ret;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
510
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
511 gettimeofday(&tv,0);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
512 ret=tv.tv_sec;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
513 ret*=1000000;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
514 ret+=tv.tv_usec;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
515 return(ret);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
516 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
517 #endif
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
518 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
519 // INIT/EXIT STUFF
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
520 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
521
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
522 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
523 // SPUINIT: this func will be called first by the main emu
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
524 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
525
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
526 int SPUinit(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
527 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
528 spuMemC=(u8*)spuMem; // just small setup
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
529 memset((void *)s_chan,0,MAXCHAN*sizeof(SPUCHAN));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
530 memset((void *)&rvb,0,sizeof(REVERBInfo));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
531 memset(regArea,0,sizeof(regArea));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
532 memset(spuMem,0,sizeof(spuMem));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
533 InitADSR();
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
534 sampcount=ttemp=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
535 #ifdef TIMEO
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
536 begintime=gettime64();
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
537 #endif
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
538 return 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
539 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
540
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
541 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
542 // SETUPSTREAMS: init most of the spu buffers
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
543 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
544
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
545 void SetupStreams(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
546 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
547 int i;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
548
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
549 pSpuBuffer=(u8*)malloc(32768); // alloc mixing buffer
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
550 pS=(s16 *)pSpuBuffer;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
551
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
552 for(i=0;i<MAXCHAN;i++) // loop sound channels
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
553 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
554 s_chan[i].ADSRX.SustainLevel = 1024; // -> init sustain
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
555 s_chan[i].iIrqDone=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
556 s_chan[i].pLoop=spuMemC;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
557 s_chan[i].pStart=spuMemC;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
558 s_chan[i].pCurr=spuMemC;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
559 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
560 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
561
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
562 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
563 // REMOVESTREAMS: free most buffer
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
564 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
565
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
566 void RemoveStreams(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
567 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
568 free(pSpuBuffer); // free mixing buffer
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
569 pSpuBuffer=NULL;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
570
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
571 #ifdef TIMEO
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
572 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
573 u64 tmp;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
574 tmp=gettime64();
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
575 tmp-=begintime;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
576 if(tmp)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
577 tmp=(u64)sampcount*1000000/tmp;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
578 printf("%lld samples per second\n",tmp);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
579 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
580 #endif
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
581 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
582
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
583
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
584 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
585 // SPUOPEN: called by main emu after init
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
586 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
587
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
588 int SPUopen(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
589 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
590 if(bSPUIsOpen) return 0; // security for some stupid main emus
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
591 spuIrq=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
592
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
593 spuStat=spuCtrl=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
594 spuAddr=0xffffffff;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
595 dwNoiseVal=1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
596
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
597 spuMemC=(u8*)spuMem;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
598 memset((void *)s_chan,0,(MAXCHAN+1)*sizeof(SPUCHAN));
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
599 pSpuIrq=0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
600
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
601 iVolume=255; //85;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
602 SetupStreams(); // prepare streaming
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
603
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
604 bSPUIsOpen=1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
605
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
606 return 1;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
607 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
608
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
609 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
610
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
611 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
612 // SPUCLOSE: called before shutdown
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
613 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
614
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
615 int SPUclose(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
616 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
617 if(!bSPUIsOpen) return 0; // some security
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
618
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
619 bSPUIsOpen=0; // no more open
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
620
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
621 RemoveStreams(); // no more streaming
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
622
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
623 return 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
624 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
625
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
626 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
627 // SPUSHUTDOWN: called by main emu on final exit
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
628 ////////////////////////////////////////////////////////////////////////
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
629
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
630 int SPUshutdown(void)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
631 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
632 return 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
633 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
634
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
635 void SPUinjectRAMImage(u16 *pIncoming)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
636 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
637 int i;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
638
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
639 for (i = 0; i < (256*1024); i++)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
640 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
641 spuMem[i] = pIncoming[i];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
642 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
643 }