Browse code

update for C++17 compliance, update to latest 2sf, add WINE cross-compile makefiles

Adam Higerd authored on 2021/02/11 15:36:17
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
 	Copyright 2006 Theo Berkau
3
-	Copyright (C) 2006-2010 DeSmuME team
3
+	Copyright (C) 2006-2015 DeSmuME team
4 4
 
5 5
 	This file is free software: you can redistribute it and/or modify
6 6
 	it under the terms of the GNU General Public License as published by
... ...
@@ -16,50 +16,58 @@
16 16
 	along with the this software.  If not, see <http://www.gnu.org/licenses/>.
17 17
 */
18 18
 
19
-#pragma once
19
+#ifndef SPU_H
20
+#define SPU_H
20 21
 
21
-#include <memory>
22 22
 #include <iosfwd>
23 23
 #include <string>
24
-#include <cassert>
24
+#include <assert.h>
25
+#include <stdio.h>
26
+#include <memory>
27
+
25 28
 #include "types.h"
26 29
 #include "matrix.h"
27
-#include "emufile.h"
28 30
 #include "metaspu/metaspu.h"
29 31
 
30
-const int SNDCORE_DEFAULT = -1;
31
-const int SNDCORE_DUMMY = 0;
32
+class EMUFILE;
32 33
 
33
-const uint8_t CHANSTAT_STOPPED = 0;
34
-const uint8_t CHANSTAT_PLAY = 1;
34
+#define SNDCORE_DEFAULT         -1
35
+#define SNDCORE_DUMMY           0
35 36
 
36
-inline int32_t spumuldiv7(int32_t val, uint8_t multiplier)
37
-{
37
+#define CHANSTAT_STOPPED          0
38
+#define CHANSTAT_PLAY             1
39
+
40
+
41
+//who made these static? theyre used in multiple places.
42
+FORCEINLINE u32 sputrunc(float f) { return u32floor(f); }
43
+FORCEINLINE u32 sputrunc(double d) { return u32floor(d); }
44
+FORCEINLINE s32 spumuldiv7(s32 val, u8 multiplier) {
38 45
 	assert(multiplier <= 127);
39
-	return multiplier == 127 ? val : ((val * multiplier) >> 7);
46
+	return (multiplier == 127) ? val : ((val * multiplier) >> 7);
40 47
 }
41 48
 
42 49
 enum SPUInterpolationMode
43 50
 {
44
-	SPUInterpolation_None,
45
-	SPUInterpolation_Linear,
46
-	SPUInterpolation_Cosine
51
+	SPUInterpolation_None   = 0,
52
+	SPUInterpolation_Linear = 1,
53
+	SPUInterpolation_Cosine = 2,
54
+	SPUInterpolation_Sharp  = 3
47 55
 };
48 56
 
49 57
 struct SoundInterface_struct
50 58
 {
51
-	int id;
52
-	const char *Name;
53
-	int (*Init)(int buffersize);
54
-	void (*DeInit)();
55
-	void (*UpdateAudio)(int16_t *buffer, uint32_t num_samples);
56
-	uint32_t (*GetAudioSpace)();
57
-	void (*MuteAudio)();
58
-	void (*UnMuteAudio)();
59
-	void (*SetVolume)(int volume);
60
-	void (*ClearBuffer)();
61
-	void (*FetchSamples)(int16_t *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
62
-	size_t (*PostProcessSamples)(int16_t *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
59
+   int id;
60
+   const char *Name;
61
+   int (*Init)(int buffersize);
62
+   void (*DeInit)();
63
+   void (*UpdateAudio)(s16 *buffer, u32 num_samples);
64
+   u32 (*GetAudioSpace)();
65
+   void (*MuteAudio)();
66
+   void (*UnMuteAudio)();
67
+   void (*SetVolume)(int volume);
68
+   void (*ClearBuffer)();
69
+   void (*FetchSamples)(s16 *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
70
+   size_t (*PostProcessSamples)(s16 *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
63 71
 };
64 72
 
65 73
 extern SoundInterface_struct SNDDummy;
... ...
@@ -68,43 +76,69 @@ extern int SPU_currentCoreNum;
68 76
 
69 77
 struct channel_struct
70 78
 {
71
-	channel_struct() { }
72
-	uint32_t num;
73
-	uint8_t vol;
74
-	uint8_t datashift;
75
-	uint8_t hold;
76
-	uint8_t pan;
77
-	uint8_t waveduty;
78
-	uint8_t repeat;
79
-	uint8_t format;
80
-	uint8_t keyon;
81
-	uint8_t status;
82
-	uint32_t addr;
83
-	uint16_t timer;
84
-	uint16_t loopstart;
85
-	uint32_t length;
86
-	uint32_t totlength;
87
-	double double_totlength_shifted;
88
-	double sampcnt;
89
-	double sampinc;
90
-	// ADPCM specific
91
-	uint32_t lastsampcnt;
92
-	int16_t pcm16b, pcm16b_last;
93
-	int16_t loop_pcm16b;
94
-	int32_t index;
95
-	int loop_index;
96
-	uint16_t x;
97
-	int16_t psgnoise_last;
79
+	channel_struct() :	num(0),
80
+						vol(0),
81
+						volumeDiv(0),
82
+						hold(0),
83
+						pan(0),
84
+						waveduty(0),
85
+						repeat(0),
86
+						format(0),
87
+						keyon(0),
88
+						status(0),
89
+						addr(0),
90
+						timer(0),
91
+						loopstart(0),
92
+						length(0),
93
+						totlength(0),
94
+						double_totlength_shifted(0.0),
95
+						sampcnt(0.0),
96
+						sampinc(0.0),
97
+						lastsampcnt(0),
98
+						pcm16b(0),
99
+						pcm16b_last(0),
100
+						loop_pcm16b(0),
101
+						index(0),
102
+						loop_index(0),
103
+						x(0),
104
+						psgnoise_last(0)
105
+	{}
106
+	u32 num;
107
+   u8 vol;
108
+   u8 volumeDiv;
109
+   u8 hold;
110
+   u8 pan;
111
+   u8 waveduty;
112
+   u8 repeat;
113
+   u8 format;
114
+   u8 keyon;
115
+   u8 status;
116
+   u32 addr;
117
+   u16 timer;
118
+   u16 loopstart;
119
+   u32 length;
120
+   u32 totlength;
121
+   double double_totlength_shifted;
122
+   double sampcnt;
123
+   double sampinc;
124
+   // ADPCM specific
125
+   u32 lastsampcnt;
126
+   s16 pcm16b, pcm16b_last;
127
+   s16 loop_pcm16b;
128
+   s32 index;
129
+   int loop_index;
130
+   u16 x;
131
+   s16 psgnoise_last;
98 132
 };
99 133
 
100 134
 class SPUFifo
101 135
 {
102 136
 public:
103 137
 	SPUFifo();
104
-	void enqueue(int16_t val);
105
-	int16_t dequeue();
106
-	int16_t buffer[16];
107
-	int32_t head, tail, size;
138
+	void enqueue(s16 val);
139
+	s16 dequeue();
140
+	s16 buffer[16];
141
+	s32 head,tail,size;
108 142
 	void reset();
109 143
 };
110 144
 
... ...
@@ -112,98 +146,122 @@ class SPU_struct
112 146
 {
113 147
 public:
114 148
 	SPU_struct(int buffersize);
115
-	uint32_t bufpos;
116
-	uint32_t buflength;
117
-	std::unique_ptr<int32_t[]> sndbuf;
118
-	int32_t lastdata; //the last sample that a channel generated
119
-	std::unique_ptr<int16_t[]> outbuf;
120
-	uint32_t bufsize;
121
-	channel_struct channels[16];
122
-
123
-	// registers
124
-	struct REGS
125
-	{
126
-		REGS() : mastervol(0), ctl_left(0), ctl_right(0), ctl_ch1bypass(0), ctl_ch3bypass(0), masteren(0), soundbias(0) { }
127
-
128
-		uint8_t mastervol;
129
-		uint8_t ctl_left, ctl_right;
130
-		uint8_t ctl_ch1bypass, ctl_ch3bypass;
131
-		uint8_t masteren;
132
-		uint16_t soundbias;
133
-
134
-		enum LeftOutputMode
135
-		{
136
-			LOM_LEFT_MIXER,
137
-			LOM_CH1,
138
-			LOM_CH3,
139
-			LOM_CH1_PLUS_CH3
140
-		};
141
-
142
-		enum RightOutputMode
143
-		{
144
-			ROM_RIGHT_MIXER,
145
-			ROM_CH1,
146
-			ROM_CH3,
147
-			ROM_CH1_PLUS_CH3
148
-		};
149
-
150
-		struct CAP
151
-		{
152
-			CAP() : add(0), source(0), oneshot(0), bits8(0), active(0), dad(0), len(0) { }
153
-			uint8_t add, source, oneshot, bits8, active;
154
-			uint32_t dad;
155
-			uint16_t len;
156
-			struct Runtime
157
-			{
158
-				Runtime() : running(0), curdad(0), maxdad(0) { }
159
-				uint8_t running;
160
-				uint32_t curdad;
161
-				uint32_t maxdad;
162
-				double sampcnt;
163
-				SPUFifo fifo;
164
-			} runtime;
165
-		} cap[2];
166
-	} regs;
149
+   u32 bufpos;
150
+   u32 buflength;
151
+   s32 *sndbuf;
152
+   s32 lastdata; //the last sample that a channel generated
153
+   s16 *outbuf;
154
+   u32 bufsize;
155
+   channel_struct channels[16];
167 156
 
168
-	void reset();
169
-	void KeyOff(int channel);
170
-	void KeyOn(int channel);
171
-	void KeyProbe(int channel);
172
-	void ProbeCapture(int which);
173
-	void WriteByte(uint32_t addr, uint8_t val);
174
-	uint8_t ReadByte(uint32_t addr);
175
-	uint16_t ReadWord(uint32_t addr);
176
-	uint32_t ReadLong(uint32_t addr);
177
-	void WriteWord(uint32_t addr, uint16_t val);
178
-	void WriteLong(uint32_t addr, uint32_t val);
179
-
180
-	// kills all channels but leaves SPU otherwise running normally
181
-	void ShutUp();
157
+   //registers
158
+   struct REGS {
159
+	   REGS()
160
+			: mastervol(0)
161
+			, ctl_left(0)
162
+			, ctl_right(0)
163
+			, ctl_ch1bypass(0)
164
+			, ctl_ch3bypass(0)
165
+			, masteren(0)
166
+			, soundbias(0)
167
+	   {}
168
+
169
+	   u8 mastervol;
170
+	   u8 ctl_left, ctl_right;
171
+	   u8 ctl_ch1bypass, ctl_ch3bypass;
172
+	   u8 masteren;
173
+	   u16 soundbias;
174
+
175
+	   enum LeftOutputMode
176
+	   {
177
+		   LOM_LEFT_MIXER=0, LOM_CH1=1, LOM_CH3=2, LOM_CH1_PLUS_CH3=3
178
+	   };
179
+
180
+	   enum RightOutputMode
181
+	   {
182
+		   ROM_RIGHT_MIXER=0, ROM_CH1=1, ROM_CH3=2, ROM_CH1_PLUS_CH3=3
183
+	   };
184
+
185
+	   struct CAP {
186
+		   CAP()
187
+			   : add(0), source(0), oneshot(0), bits8(0), active(0), dad(0), len(0)
188
+		   {}
189
+		   u8 add, source, oneshot, bits8, active;
190
+		   u32 dad;
191
+		   u16 len;
192
+		   struct Runtime {
193
+			   Runtime()
194
+				   : running(0), curdad(0), maxdad(0)
195
+			   {}
196
+			   u8 running;
197
+			   u32 curdad;
198
+			   u32 maxdad;
199
+			   double sampcnt;
200
+			   SPUFifo fifo;
201
+		   } runtime;
202
+	   } cap[2];
203
+   } regs;
204
+
205
+   void reset();
206
+   ~SPU_struct();
207
+   void KeyOff(int channel);
208
+   void KeyOn(int channel);
209
+   void KeyProbe(int channel);
210
+   void ProbeCapture(int which);
211
+   void WriteByte(u32 addr, u8 val);
212
+   void WriteWord(u32 addr, u16 val);
213
+   void WriteLong(u32 addr, u32 val);
214
+   u8 ReadByte(u32 addr);
215
+   u16 ReadWord(u32 addr);
216
+   u32 ReadLong(u32 addr);
217
+   bool isSPU(u32 addr) { return ((addr >= 0x04000400) && (addr < 0x04000520)); }
218
+
219
+   //kills all channels but leaves SPU otherwise running normally
220
+   void ShutUp();
182 221
 };
183 222
 
223
+extern SPU_struct *SPU_core;
224
+extern int spu_core_samples;
225
+
184 226
 int SPU_ChangeSoundCore(int coreid, int buffersize);
227
+SoundInterface_struct *SPU_SoundCore();
185 228
 
186
-void SPU_ReInit();
229
+void SPU_ReInit(bool fakeBoot = false);
187 230
 int SPU_Init(int coreid, int buffersize);
188
-void SPU_SetSynchMode(ESynchMode mode, ESynchMethod method);
189
-void SPU_Reset();
190
-void SPU_DeInit();
231
+void SPU_Pause(int pause);
232
+void SPU_SetVolume(int volume);
233
+void SPU_SetSynchMode(int mode, int method);
234
+void SPU_ClearOutputBuffer(void);
235
+void SPU_Reset(void);
236
+void SPU_DeInit(void);
191 237
 void SPU_KeyOn(int channel);
192
-void SPU_WriteByte(uint32_t addr, uint8_t val);
193
-void SPU_WriteWord(uint32_t addr, uint16_t val);
194
-void SPU_WriteLong(uint32_t addr, uint32_t val);
195
-uint8_t SPU_ReadByte(uint32_t addr);
196
-uint16_t SPU_ReadWord(uint32_t addr);
197
-uint32_t SPU_ReadLong(uint32_t addr);
198
-void SPU_Emulate_core();
238
+static FORCEINLINE void SPU_WriteByte(u32 addr, u8 val)
239
+{
240
+	addr &= 0xFFF;
241
+
242
+	SPU_core->WriteByte(addr,val);
243
+}
244
+static FORCEINLINE void SPU_WriteWord(u32 addr, u16 val)
245
+{
246
+	addr &= 0xFFF;
247
+
248
+	SPU_core->WriteWord(addr,val);
249
+}
250
+static FORCEINLINE void SPU_WriteLong(u32 addr, u32 val)
251
+{
252
+	addr &= 0xFFF;
253
+
254
+	SPU_core->WriteLong(addr,val);
255
+}
256
+static FORCEINLINE u8 SPU_ReadByte(u32 addr) { return SPU_core->ReadByte(addr & 0x0FFF); }
257
+static FORCEINLINE u16 SPU_ReadWord(u32 addr) { return SPU_core->ReadWord(addr & 0x0FFF); }
258
+static FORCEINLINE u32 SPU_ReadLong(u32 addr) { return SPU_core->ReadLong(addr & 0x0FFF); }
259
+void SPU_Emulate_core(void);
199 260
 void SPU_Emulate_user(bool mix = true);
200
-void SPU_DefaultFetchSamples(int16_t *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
201
-size_t SPU_DefaultPostProcessSamples(int16_t *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
261
+void SPU_DefaultFetchSamples(s16 *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
262
+size_t SPU_DefaultPostProcessSamples(s16 *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
202 263
 
203
-extern std::unique_ptr<SPU_struct> SPU_core, SPU_user;
204
-extern int spu_core_samples;
264
+extern double DESMUME_SAMPLE_RATE;
265
+void SetDesmumeSampleRate(double rate);
205 266
 
206
-// we should make this configurable eventually
207
-// but at least defining it somewhere is probably a step in the right direction
208
-const int DESMUME_SAMPLE_RATE = 44100;
209
-//#define DESMUME_SAMPLE_RATE 48000
267
+#endif
Browse code

* Small Makefile changes.

* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).

Naram Qashat authored on 2014/09/25 12:28:21
Showing 1 changed files
... ...
@@ -41,7 +41,7 @@ inline int32_t spumuldiv7(int32_t val, uint8_t multiplier)
41 41
 
42 42
 enum SPUInterpolationMode
43 43
 {
44
-	SPUInterpolation_None ,
44
+	SPUInterpolation_None,
45 45
 	SPUInterpolation_Linear,
46 46
 	SPUInterpolation_Cosine
47 47
 };
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -18,6 +18,7 @@
18 18
 
19 19
 #pragma once
20 20
 
21
+#include <memory>
21 22
 #include <iosfwd>
22 23
 #include <string>
23 24
 #include <cassert>
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -16,8 +16,7 @@
16 16
 	along with the this software.  If not, see <http://www.gnu.org/licenses/>.
17 17
 */
18 18
 
19
-#ifndef SPU_H
20
-#define SPU_H
19
+#pragma once
21 20
 
22 21
 #include <iosfwd>
23 22
 #include <string>
... ...
@@ -207,5 +206,3 @@ extern int spu_core_samples;
207 206
 // but at least defining it somewhere is probably a step in the right direction
208 207
 const int DESMUME_SAMPLE_RATE = 44100;
209 208
 //#define DESMUME_SAMPLE_RATE 48000
210
-
211
-#endif
Browse code

Updating in_2sf to use a newish version of DeSmuME, 0.9.9 from SVN. Somewhat cleaned up as well, but not everything because it's a pain in the ass.

Naram Qashat authored on 2013/04/18 17:22:55
Showing 1 changed files
... ...
@@ -22,46 +22,44 @@
22 22
 #include <iosfwd>
23 23
 #include <string>
24 24
 #include <cassert>
25
-
26 25
 #include "types.h"
27 26
 #include "matrix.h"
28 27
 #include "emufile.h"
29
-
30 28
 #include "metaspu/metaspu.h"
31 29
 
32
-#define SNDCORE_DEFAULT         -1
33
-#define SNDCORE_DUMMY           0
30
+const int SNDCORE_DEFAULT = -1;
31
+const int SNDCORE_DUMMY = 0;
34 32
 
35
-#define CHANSTAT_STOPPED          0
36
-#define CHANSTAT_PLAY             1
33
+const uint8_t CHANSTAT_STOPPED = 0;
34
+const uint8_t CHANSTAT_PLAY = 1;
37 35
 
38
-//who made these static? theyre used in multiple places.
39
-//inline uint32_t sputrunc(float f) { return u32floor(f); }
40
-//inline uint32_t sputrunc(double d) { return u32floor(d); }
41
-inline int32_t spumuldiv7(int32_t val, uint8_t multiplier) {
36
+inline int32_t spumuldiv7(int32_t val, uint8_t multiplier)
37
+{
42 38
 	assert(multiplier <= 127);
43 39
 	return multiplier == 127 ? val : ((val * multiplier) >> 7);
44 40
 }
45 41
 
46 42
 enum SPUInterpolationMode
47 43
 {
48
-	SPUInterpolation_None = 0,
49
-	SPUInterpolation_Linear = 1,
50
-	SPUInterpolation_Cosine = 2
44
+	SPUInterpolation_None ,
45
+	SPUInterpolation_Linear,
46
+	SPUInterpolation_Cosine
51 47
 };
52 48
 
53 49
 struct SoundInterface_struct
54 50
 {
55
-   int id;
56
-   const char *Name;
57
-   int (*Init)(int buffersize);
58
-   void (*DeInit)();
59
-   void (*UpdateAudio)(int16_t *buffer, uint32_t num_samples);
60
-   uint32_t (*GetAudioSpace)();
61
-   void (*MuteAudio)();
62
-   void (*UnMuteAudio)();
63
-   void (*SetVolume)(int volume);
64
-   void (*ClearBuffer)();
51
+	int id;
52
+	const char *Name;
53
+	int (*Init)(int buffersize);
54
+	void (*DeInit)();
55
+	void (*UpdateAudio)(int16_t *buffer, uint32_t num_samples);
56
+	uint32_t (*GetAudioSpace)();
57
+	void (*MuteAudio)();
58
+	void (*UnMuteAudio)();
59
+	void (*SetVolume)(int volume);
60
+	void (*ClearBuffer)();
61
+	void (*FetchSamples)(int16_t *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
62
+	size_t (*PostProcessSamples)(int16_t *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
65 63
 };
66 64
 
67 65
 extern SoundInterface_struct SNDDummy;
... ...
@@ -70,38 +68,33 @@ extern int SPU_currentCoreNum;
70 68
 
71 69
 struct channel_struct
72 70
 {
73
-	channel_struct()
74
-	{}
71
+	channel_struct() { }
75 72
 	uint32_t num;
76
-   uint8_t vol;
77
-   uint8_t datashift;
78
-   uint8_t hold;
79
-   uint8_t pan;
80
-   uint8_t waveduty;
81
-   uint8_t repeat;
82
-   uint8_t format;
83
-   uint8_t keyon;
84
-   uint8_t status;
85
-   uint32_t addr;
86
-   uint16_t timer;
87
-   uint16_t loopstart;
88
-   uint32_t length;
89
-   uint32_t totlength;
90
-   double double_totlength_shifted;
91
-   union {
92
-		int8_t *buf8;
93
-		int16_t *buf16;
94
-   };
95
-   double sampcnt;
96
-   double sampinc;
97
-   // ADPCM specific
98
-   uint32_t lastsampcnt;
99
-   int16_t pcm16b, pcm16b_last;
100
-   int16_t loop_pcm16b;
101
-   int32_t index;
102
-   int loop_index;
103
-   uint16_t x;
104
-   int16_t psgnoise_last;
73
+	uint8_t vol;
74
+	uint8_t datashift;
75
+	uint8_t hold;
76
+	uint8_t pan;
77
+	uint8_t waveduty;
78
+	uint8_t repeat;
79
+	uint8_t format;
80
+	uint8_t keyon;
81
+	uint8_t status;
82
+	uint32_t addr;
83
+	uint16_t timer;
84
+	uint16_t loopstart;
85
+	uint32_t length;
86
+	uint32_t totlength;
87
+	double double_totlength_shifted;
88
+	double sampcnt;
89
+	double sampinc;
90
+	// ADPCM specific
91
+	uint32_t lastsampcnt;
92
+	int16_t pcm16b, pcm16b_last;
93
+	int16_t loop_pcm16b;
94
+	int32_t index;
95
+	int loop_index;
96
+	uint16_t x;
97
+	int16_t psgnoise_last;
105 98
 };
106 99
 
107 100
 class SPUFifo
... ...
@@ -111,9 +104,7 @@ public:
111 104
 	void enqueue(int16_t val);
112 105
 	int16_t dequeue();
113 106
 	int16_t buffer[16];
114
-	int32_t head,tail,size;
115
-	//void save(EMUFILE* fp);
116
-	bool load(EMUFILE* fp);
107
+	int32_t head, tail, size;
117 108
 	void reset();
118 109
 };
119 110
 
... ...
@@ -121,88 +112,80 @@ class SPU_struct
121 112
 {
122 113
 public:
123 114
 	SPU_struct(int buffersize);
124
-   uint32_t bufpos;
125
-   uint32_t buflength;
126
-   int32_t *sndbuf;
127
-   int32_t lastdata; //the last sample that a channel generated
128
-   int16_t *outbuf;
129
-   uint32_t bufsize;
130
-   channel_struct channels[16];
131
-
132
-   //registers
133
-   struct REGS {
134
-	   REGS()
135
-			: mastervol(0)
136
-			, ctl_left(0)
137
-			, ctl_right(0)
138
-			, ctl_ch1bypass(0)
139
-			, ctl_ch3bypass(0)
140
-			, masteren(0)
141
-			, soundbias(0)
142
-	   {}
143
-
144
-	   uint8_t mastervol;
145
-	   uint8_t ctl_left, ctl_right;
146
-	   uint8_t ctl_ch1bypass, ctl_ch3bypass;
147
-	   uint8_t masteren;
148
-	   uint16_t soundbias;
149
-
150
-	   enum LeftOutputMode
151
-	   {
152
-		   LOM_LEFT_MIXER=0, LOM_CH1=1, LOM_CH3=2, LOM_CH1_PLUS_CH3=3
153
-	   };
154
-
155
-	   enum RightOutputMode
156
-	   {
157
-		   ROM_RIGHT_MIXER=0, ROM_CH1=1, ROM_CH3=2, ROM_CH1_PLUS_CH3=3
158
-	   };
159
-
160
-	   struct CAP {
161
-		   CAP()
162
-			   : add(0), source(0), oneshot(0), bits8(0), active(0), dad(0), len(0)
163
-		   {}
164
-		   uint8_t add, source, oneshot, bits8, active;
165
-		   uint32_t dad;
166
-		   uint16_t len;
167
-		   struct Runtime {
168
-			   Runtime()
169
-				   : running(0), curdad(0), maxdad(0)
170
-			   {}
171
-			   uint8_t running;
172
-			   uint32_t curdad;
173
-			   uint32_t maxdad;
174
-			   double sampcnt;
175
-			   SPUFifo fifo;
176
-		   } runtime;
177
-	   } cap[2];
178
-   } regs;
179
-
180
-   void reset();
181
-   ~SPU_struct();
182
-   void KeyOff(int channel);
183
-   void KeyOn(int channel);
184
-   void KeyProbe(int channel);
185
-   void ProbeCapture(int which);
186
-   void WriteByte(uint32_t addr, uint8_t val);
187
-   uint8_t ReadByte(uint32_t addr);
188
-   uint16_t ReadWord(uint32_t addr);
189
-   uint32_t ReadLong(uint32_t addr);
190
-   void WriteWord(uint32_t addr, uint16_t val);
191
-   void WriteLong(uint32_t addr, uint32_t val);
192
-
193
-   //kills all channels but leaves SPU otherwise running normally
194
-   void ShutUp();
115
+	uint32_t bufpos;
116
+	uint32_t buflength;
117
+	std::unique_ptr<int32_t[]> sndbuf;
118
+	int32_t lastdata; //the last sample that a channel generated
119
+	std::unique_ptr<int16_t[]> outbuf;
120
+	uint32_t bufsize;
121
+	channel_struct channels[16];
122
+
123
+	// registers
124
+	struct REGS
125
+	{
126
+		REGS() : mastervol(0), ctl_left(0), ctl_right(0), ctl_ch1bypass(0), ctl_ch3bypass(0), masteren(0), soundbias(0) { }
127
+
128
+		uint8_t mastervol;
129
+		uint8_t ctl_left, ctl_right;
130
+		uint8_t ctl_ch1bypass, ctl_ch3bypass;
131
+		uint8_t masteren;
132
+		uint16_t soundbias;
133
+
134
+		enum LeftOutputMode
135
+		{
136
+			LOM_LEFT_MIXER,
137
+			LOM_CH1,
138
+			LOM_CH3,
139
+			LOM_CH1_PLUS_CH3
140
+		};
141
+
142
+		enum RightOutputMode
143
+		{
144
+			ROM_RIGHT_MIXER,
145
+			ROM_CH1,
146
+			ROM_CH3,
147
+			ROM_CH1_PLUS_CH3
148
+		};
149
+
150
+		struct CAP
151
+		{
152
+			CAP() : add(0), source(0), oneshot(0), bits8(0), active(0), dad(0), len(0) { }
153
+			uint8_t add, source, oneshot, bits8, active;
154
+			uint32_t dad;
155
+			uint16_t len;
156
+			struct Runtime
157
+			{
158
+				Runtime() : running(0), curdad(0), maxdad(0) { }
159
+				uint8_t running;
160
+				uint32_t curdad;
161
+				uint32_t maxdad;
162
+				double sampcnt;
163
+				SPUFifo fifo;
164
+			} runtime;
165
+		} cap[2];
166
+	} regs;
167
+
168
+	void reset();
169
+	void KeyOff(int channel);
170
+	void KeyOn(int channel);
171
+	void KeyProbe(int channel);
172
+	void ProbeCapture(int which);
173
+	void WriteByte(uint32_t addr, uint8_t val);
174
+	uint8_t ReadByte(uint32_t addr);
175
+	uint16_t ReadWord(uint32_t addr);
176
+	uint32_t ReadLong(uint32_t addr);
177
+	void WriteWord(uint32_t addr, uint16_t val);
178
+	void WriteLong(uint32_t addr, uint32_t val);
179
+
180
+	// kills all channels but leaves SPU otherwise running normally
181
+	void ShutUp();
195 182
 };
196 183
 
197 184
 int SPU_ChangeSoundCore(int coreid, int buffersize);
198
-//SoundInterface_struct *SPU_SoundCore();
199 185
 
200 186
 void SPU_ReInit();
201 187
 int SPU_Init(int coreid, int buffersize);
202
-//void SPU_Pause(int pause);
203
-//void SPU_SetVolume(int volume);
204 188
 void SPU_SetSynchMode(ESynchMode mode, ESynchMethod method);
205
-//void SPU_ClearOutputBuffer();
206 189
 void SPU_Reset();
207 190
 void SPU_DeInit();
208 191
 void SPU_KeyOn(int channel);
... ...
@@ -214,41 +197,15 @@ uint16_t SPU_ReadWord(uint32_t addr);
214 197
 uint32_t SPU_ReadLong(uint32_t addr);
215 198
 void SPU_Emulate_core();
216 199
 void SPU_Emulate_user(bool mix = true);
200
+void SPU_DefaultFetchSamples(int16_t *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
201
+size_t SPU_DefaultPostProcessSamples(int16_t *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
217 202
 
218
-extern SPU_struct *SPU_core, *SPU_user;
203
+extern std::unique_ptr<SPU_struct> SPU_core, SPU_user;
219 204
 extern int spu_core_samples;
220 205
 
221
-//void spu_savestate(EMUFILE* os);
222
-bool spu_loadstate(EMUFILE* is, int size);
223
-
224
-/*enum WAVMode
225
-{
226
-	WAVMODE_ANY = -1,
227
-	WAVMODE_CORE = 0,
228
-	WAVMODE_USER = 1
229
-};*/
230
-
231
-/*class WavWriter
232
-{
233
-public:
234
-	WavWriter();
235
-	bool open(const std::string & fname);
236
-	void close();
237
-	void update(void* soundData, int numSamples);
238
-	bool isRecording() const;
239
-	WAVMode mode;
240
-private:
241
-	FILE *spufp;
242
-};*/
243
-
244
-//void WAV_End();
245
-//bool WAV_Begin(const char* fname, WAVMode mode=WAVMODE_CORE);
246
-//bool WAV_IsRecording(WAVMode mode=WAVMODE_ANY);
247
-//void WAV_WavSoundUpdate(void* soundData, int numSamples, WAVMode mode=WAVMODE_CORE);
248
-
249 206
 // we should make this configurable eventually
250 207
 // but at least defining it somewhere is probably a step in the right direction
251
-#define DESMUME_SAMPLE_RATE 44100
208
+const int DESMUME_SAMPLE_RATE = 44100;
252 209
 //#define DESMUME_SAMPLE_RATE 48000
253 210
 
254 211
 #endif
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,254 @@
1
+/*
2
+	Copyright 2006 Theo Berkau
3
+	Copyright (C) 2006-2010 DeSmuME team
4
+
5
+	This file is free software: you can redistribute it and/or modify
6
+	it under the terms of the GNU General Public License as published by
7
+	the Free Software Foundation, either version 2 of the License, or
8
+	(at your option) any later version.
9
+
10
+	This file is distributed in the hope that it will be useful,
11
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+	GNU General Public License for more details.
14
+
15
+	You should have received a copy of the GNU General Public License
16
+	along with the this software.  If not, see <http://www.gnu.org/licenses/>.
17
+*/
18
+
19
+#ifndef SPU_H
20
+#define SPU_H
21
+
22
+#include <iosfwd>
23
+#include <string>
24
+#include <cassert>
25
+
26
+#include "types.h"
27
+#include "matrix.h"
28
+#include "emufile.h"
29
+
30
+#include "metaspu/metaspu.h"
31
+
32
+#define SNDCORE_DEFAULT         -1
33
+#define SNDCORE_DUMMY           0
34
+
35
+#define CHANSTAT_STOPPED          0
36
+#define CHANSTAT_PLAY             1
37
+
38
+//who made these static? theyre used in multiple places.
39
+//inline uint32_t sputrunc(float f) { return u32floor(f); }
40
+//inline uint32_t sputrunc(double d) { return u32floor(d); }
41
+inline int32_t spumuldiv7(int32_t val, uint8_t multiplier) {
42
+	assert(multiplier <= 127);
43
+	return multiplier == 127 ? val : ((val * multiplier) >> 7);
44
+}
45
+
46
+enum SPUInterpolationMode
47
+{
48
+	SPUInterpolation_None = 0,
49
+	SPUInterpolation_Linear = 1,
50
+	SPUInterpolation_Cosine = 2
51
+};
52
+
53
+struct SoundInterface_struct
54
+{
55
+   int id;
56
+   const char *Name;
57
+   int (*Init)(int buffersize);
58
+   void (*DeInit)();
59
+   void (*UpdateAudio)(int16_t *buffer, uint32_t num_samples);
60
+   uint32_t (*GetAudioSpace)();
61
+   void (*MuteAudio)();
62
+   void (*UnMuteAudio)();
63
+   void (*SetVolume)(int volume);
64
+   void (*ClearBuffer)();
65
+};
66
+
67
+extern SoundInterface_struct SNDDummy;
68
+extern SoundInterface_struct SNDFile;
69
+extern int SPU_currentCoreNum;
70
+
71
+struct channel_struct
72
+{
73
+	channel_struct()
74
+	{}
75
+	uint32_t num;
76
+   uint8_t vol;
77
+   uint8_t datashift;
78
+   uint8_t hold;
79
+   uint8_t pan;
80
+   uint8_t waveduty;
81
+   uint8_t repeat;
82
+   uint8_t format;
83
+   uint8_t keyon;
84
+   uint8_t status;
85
+   uint32_t addr;
86
+   uint16_t timer;
87
+   uint16_t loopstart;
88
+   uint32_t length;
89
+   uint32_t totlength;
90
+   double double_totlength_shifted;
91
+   union {
92
+		int8_t *buf8;
93
+		int16_t *buf16;
94
+   };
95
+   double sampcnt;
96
+   double sampinc;
97
+   // ADPCM specific
98
+   uint32_t lastsampcnt;
99
+   int16_t pcm16b, pcm16b_last;
100
+   int16_t loop_pcm16b;
101
+   int32_t index;
102
+   int loop_index;
103
+   uint16_t x;
104
+   int16_t psgnoise_last;
105
+};
106
+
107
+class SPUFifo
108
+{
109
+public:
110
+	SPUFifo();
111
+	void enqueue(int16_t val);
112
+	int16_t dequeue();
113
+	int16_t buffer[16];
114
+	int32_t head,tail,size;
115
+	//void save(EMUFILE* fp);
116
+	bool load(EMUFILE* fp);
117
+	void reset();
118
+};
119
+
120
+class SPU_struct
121
+{
122
+public:
123
+	SPU_struct(int buffersize);
124
+   uint32_t bufpos;
125
+   uint32_t buflength;
126
+   int32_t *sndbuf;
127
+   int32_t lastdata; //the last sample that a channel generated
128
+   int16_t *outbuf;
129
+   uint32_t bufsize;
130
+   channel_struct channels[16];
131
+
132
+   //registers
133
+   struct REGS {
134
+	   REGS()
135
+			: mastervol(0)
136
+			, ctl_left(0)
137
+			, ctl_right(0)
138
+			, ctl_ch1bypass(0)
139
+			, ctl_ch3bypass(0)
140
+			, masteren(0)
141
+			, soundbias(0)
142
+	   {}
143
+
144
+	   uint8_t mastervol;
145
+	   uint8_t ctl_left, ctl_right;
146
+	   uint8_t ctl_ch1bypass, ctl_ch3bypass;
147
+	   uint8_t masteren;
148
+	   uint16_t soundbias;
149
+
150
+	   enum LeftOutputMode
151
+	   {
152
+		   LOM_LEFT_MIXER=0, LOM_CH1=1, LOM_CH3=2, LOM_CH1_PLUS_CH3=3
153
+	   };
154
+
155
+	   enum RightOutputMode
156
+	   {
157
+		   ROM_RIGHT_MIXER=0, ROM_CH1=1, ROM_CH3=2, ROM_CH1_PLUS_CH3=3
158
+	   };
159
+
160
+	   struct CAP {
161
+		   CAP()
162
+			   : add(0), source(0), oneshot(0), bits8(0), active(0), dad(0), len(0)
163
+		   {}
164
+		   uint8_t add, source, oneshot, bits8, active;
165
+		   uint32_t dad;
166
+		   uint16_t len;
167
+		   struct Runtime {
168
+			   Runtime()
169
+				   : running(0), curdad(0), maxdad(0)
170
+			   {}
171
+			   uint8_t running;
172
+			   uint32_t curdad;
173
+			   uint32_t maxdad;
174
+			   double sampcnt;
175
+			   SPUFifo fifo;
176
+		   } runtime;
177
+	   } cap[2];
178
+   } regs;
179
+
180
+   void reset();
181
+   ~SPU_struct();
182
+   void KeyOff(int channel);
183
+   void KeyOn(int channel);
184
+   void KeyProbe(int channel);
185
+   void ProbeCapture(int which);
186
+   void WriteByte(uint32_t addr, uint8_t val);
187
+   uint8_t ReadByte(uint32_t addr);
188
+   uint16_t ReadWord(uint32_t addr);
189
+   uint32_t ReadLong(uint32_t addr);
190
+   void WriteWord(uint32_t addr, uint16_t val);
191
+   void WriteLong(uint32_t addr, uint32_t val);
192
+
193
+   //kills all channels but leaves SPU otherwise running normally
194
+   void ShutUp();
195
+};
196
+
197
+int SPU_ChangeSoundCore(int coreid, int buffersize);
198
+//SoundInterface_struct *SPU_SoundCore();
199
+
200
+void SPU_ReInit();
201
+int SPU_Init(int coreid, int buffersize);
202
+//void SPU_Pause(int pause);
203
+//void SPU_SetVolume(int volume);
204
+void SPU_SetSynchMode(ESynchMode mode, ESynchMethod method);
205
+//void SPU_ClearOutputBuffer();
206
+void SPU_Reset();
207
+void SPU_DeInit();
208
+void SPU_KeyOn(int channel);
209
+void SPU_WriteByte(uint32_t addr, uint8_t val);
210
+void SPU_WriteWord(uint32_t addr, uint16_t val);
211
+void SPU_WriteLong(uint32_t addr, uint32_t val);
212
+uint8_t SPU_ReadByte(uint32_t addr);
213
+uint16_t SPU_ReadWord(uint32_t addr);
214
+uint32_t SPU_ReadLong(uint32_t addr);
215
+void SPU_Emulate_core();
216
+void SPU_Emulate_user(bool mix = true);
217
+
218
+extern SPU_struct *SPU_core, *SPU_user;
219
+extern int spu_core_samples;
220
+
221
+//void spu_savestate(EMUFILE* os);
222
+bool spu_loadstate(EMUFILE* is, int size);
223
+
224
+/*enum WAVMode
225
+{
226
+	WAVMODE_ANY = -1,
227
+	WAVMODE_CORE = 0,
228
+	WAVMODE_USER = 1
229
+};*/
230
+
231
+/*class WavWriter
232
+{
233
+public:
234
+	WavWriter();
235
+	bool open(const std::string & fname);
236
+	void close();
237
+	void update(void* soundData, int numSamples);
238
+	bool isRecording() const;
239
+	WAVMode mode;
240
+private:
241
+	FILE *spufp;
242
+};*/
243
+
244
+//void WAV_End();
245
+//bool WAV_Begin(const char* fname, WAVMode mode=WAVMODE_CORE);
246
+//bool WAV_IsRecording(WAVMode mode=WAVMODE_ANY);
247
+//void WAV_WavSoundUpdate(void* soundData, int numSamples, WAVMode mode=WAVMODE_CORE);
248
+
249
+// we should make this configurable eventually
250
+// but at least defining it somewhere is probably a step in the right direction
251
+#define DESMUME_SAMPLE_RATE 44100
252
+//#define DESMUME_SAMPLE_RATE 48000
253
+
254
+#endif