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 1
deleted file mode 100644
... ...
@@ -1,226 +0,0 @@
1
-/* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
2
- * Developed and maintained by the Pcsx2 Development Team.
3
- *
4
- * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
5
- *
6
- * SPU2-X is free software: you can redistribute it and/or modify it under the terms
7
- * of the GNU Lesser General Public License as published by the Free Software Found-
8
- * ation, either version 3 of the License, or (at your option) any later version.
9
- *
10
- * SPU2-X is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
- * PURPOSE.  See the GNU Lesser General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Lesser General Public License
15
- * along with SPU2-X.  If not, see <http://www.gnu.org/licenses/>.
16
- */
17
-
18
-#include <cassert>
19
-#include "../types.h"
20
-#include "SndOut.h"
21
-
22
-//----------------
23
-static const int SndOutLatencyMS = 160;
24
-static bool timeStretchDisabled = false;
25
-//----------------
26
-
27
-StereoOut32 StereoOut32::Empty;
28
-
29
-StereoOut32::StereoOut32(const StereoOut16 &src) : Left(src.Left), Right(src.Right)
30
-{
31
-}
32
-
33
-StereoOut32::StereoOut32(const StereoOutFloat &src) : Left(static_cast<int32_t>(src.Left * 2147483647.0f)), Right(static_cast<int32_t>(src.Right * 2147483647.0f))
34
-{
35
-}
36
-
37
-StereoOut16 StereoOut32::DownSample() const
38
-{
39
-	return StereoOut16((Left >> SndOutVolumeShift) & 0xFFFF, (Right >> SndOutVolumeShift) & 0xFFFF);
40
-}
41
-
42
-std::unique_ptr<StereoOut32[]> SndBuffer::m_buffer;
43
-int32_t SndBuffer::m_size;
44
-int32_t SndBuffer::m_rpos;
45
-int32_t SndBuffer::m_wpos;
46
-int32_t SndBuffer::m_data;
47
-
48
-bool SndBuffer::m_underrun_freeze;
49
-std::unique_ptr<StereoOut32[]> SndBuffer::sndTempBuffer;
50
-int SndBuffer::sndTempProgress = 0;
51
-
52
-inline int GetAlignedBufferSize(int comp)
53
-{
54
-	return (comp + SndOutPacketSize - 1) & ~(SndOutPacketSize - 1);
55
-}
56
-
57
-// Returns true if there is data to be output, or false if no data
58
-// is available to be copied.
59
-bool SndBuffer::CheckUnderrunStatus(int &nSamples, int &quietSampleCount)
60
-{
61
-	quietSampleCount = 0;
62
-	if (m_underrun_freeze)
63
-	{
64
-		int toFill = static_cast<int>(m_size * (timeStretchDisabled ? 0.50f : 0.1f));
65
-		toFill = GetAlignedBufferSize(toFill);
66
-
67
-		// toFill is now aligned to a SndOutPacket
68
-
69
-		if (m_data < toFill)
70
-		{
71
-			quietSampleCount = nSamples;
72
-			return false;
73
-		}
74
-
75
-		m_underrun_freeze = false;
76
-		//TODO
77
-		//if( MsgOverruns() )
78
-			printf(" * SPU2 > Underrun compensation (%d packets buffered)\n", toFill / SndOutPacketSize);
79
-		lastPct = 0.0; // normalize timestretcher
80
-	}
81
-	else if (m_data < nSamples)
82
-	{
83
-		nSamples = m_data;
84
-		quietSampleCount = SndOutPacketSize - m_data;
85
-		m_underrun_freeze = true;
86
-
87
-		if (!timeStretchDisabled)
88
-			timeStretchUnderrun();
89
-
90
-		return !!nSamples;
91
-	}
92
-
93
-	return true;
94
-}
95
-
96
-void SndBuffer::_InitFail()
97
-{
98
-	// If a failure occurs, just initialize the NoSound driver.  This'll allow
99
-	// the game to emulate properly (hopefully), albeit without sound.
100
-	//OutputModule = FindOutputModuleById( NullOut.GetIdent() );
101
-	//mods[OutputModule]->Init();
102
-}
103
-
104
-void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
105
-{
106
-	int free = m_size - m_data;
107
-	m_predictData = 0;
108
-
109
-	assert(m_data <= m_size);
110
-
111
-	// Problem:
112
-	//  If the SPU2 gets out of sync with the SndOut device, the writepos of the
113
-	//  circular buffer will overtake the readpos, leading to a prolonged period
114
-	//  of hopscotching read/write accesses (ie, lots of staticy crap sound for
115
-	//  several seconds).
116
-	//
117
-	// Compromise:
118
-	//  When an overrun occurs, we adapt by discarding a portion of the buffer.
119
-	//  The older portion of the buffer is discarded rather than incoming data,
120
-	//  so that the overall audio synchronization is better.
121
-
122
-	if (free < nSamples)
123
-	{
124
-		// Buffer overrun!
125
-		// Dump samples from the read portion of the buffer instead of dropping
126
-		// the newly written stuff.
127
-
128
-		int32_t comp;
129
-
130
-		if (!timeStretchDisabled)
131
-			comp = timeStretchOverrun();
132
-		else
133
-		{
134
-			// Toss half the buffer plus whatever's being written anew:
135
-			comp = GetAlignedBufferSize((m_size + nSamples) / 2);
136
-			if (comp > m_size - SndOutPacketSize)
137
-				comp = m_size - SndOutPacketSize;
138
-		}
139
-
140
-		m_data -= comp;
141
-		m_rpos = (m_rpos + comp) % m_size;
142
-		//TODO
143
-		//if( MsgOverruns() )
144
-			printf(" * SPU2 > Overrun Compensation (%d packets tossed)\n", comp / SndOutPacketSize);
145
-		lastPct = 0.0; // normalize the timestretcher
146
-	}
147
-
148
-	// copy in two phases, since there's a chance the packet
149
-	// wraps around the buffer (it'd be nice to deal in packets only, but
150
-	// the timestretcher and DSP options require flexibility).
151
-
152
-	int endPos = m_wpos + nSamples;
153
-	int secondCopyLen = endPos - m_size;
154
-	StereoOut32 *wposbuffer = &m_buffer[m_wpos];
155
-
156
-	m_data += nSamples;
157
-	if (secondCopyLen > 0)
158
-	{
159
-		nSamples -= secondCopyLen;
160
-		memcpy(m_buffer.get(), &bData[nSamples], secondCopyLen * sizeof(*bData));
161
-		m_wpos = secondCopyLen;
162
-	}
163
-	else
164
-		m_wpos += nSamples;
165
-
166
-	memcpy(wposbuffer, bData, nSamples * sizeof(*bData));
167
-}
168
-
169
-void SndBuffer::Init()
170
-{
171
-	// initialize sound buffer
172
-	// Buffer actually attempts to run ~50%, so allocate near double what
173
-	// the requested latency is:
174
-
175
-	m_rpos = m_wpos = m_data = 0;
176
-
177
-	try
178
-	{
179
-		float latencyMS = SndOutLatencyMS * (timeStretchDisabled ? 1.5f : 2.0f);
180
-		m_size = GetAlignedBufferSize(static_cast<int>(latencyMS * SampleRate / 1000.0f));
181
-		m_buffer.reset(new StereoOut32[m_size]);
182
-		m_underrun_freeze = false;
183
-
184
-		sndTempBuffer.reset(new StereoOut32[SndOutPacketSize]);
185
-	}
186
-	catch(const std::bad_alloc &)
187
-	{
188
-		// out of memory exception (most likely)
189
-
190
-		printf("Out of memory error occurred while initializing SPU2.");
191
-		_InitFail();
192
-		return;
193
-	}
194
-
195
-	// clear buffers!
196
-	// Fixes loopy sounds on emu resets.
197
-	memset(sndTempBuffer.get(), 0, sizeof(StereoOut32) * SndOutPacketSize);
198
-
199
-	sndTempProgress = 0;
200
-
201
-	soundtouchInit(); // initializes the timestretching
202
-
203
-	// some crap
204
-	//spdif_set51(mods[OutputModule]->Is51Out());
205
-
206
-	// initialize module
207
-	//if( mods[OutputModule]->Init() == -1 ) _InitFail();
208
-}
209
-
210
-void SndBuffer::Write(const StereoOut32 &Sample)
211
-{
212
-	//if(mods[OutputModule] == &NullOut) // null output doesn't need buffering or stretching! :p
213
-	//	return;
214
-
215
-	sndTempBuffer[sndTempProgress++] = Sample;
216
-
217
-	// If we haven't accumulated a full packet yet, do nothing more:
218
-	if (sndTempProgress < SndOutPacketSize)
219
-		return;
220
-	sndTempProgress = 0;
221
-
222
-	if( !timeStretchDisabled )
223
-		timeStretchWrite();
224
-	else
225
-		_WriteSamples(sndTempBuffer.get(), SndOutPacketSize);
226
-}
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
... ...
@@ -20,8 +20,8 @@
20 20
 #include "SndOut.h"
21 21
 
22 22
 //----------------
23
-int SndOutLatencyMS = 160;
24
-bool timeStretchDisabled = false;
23
+static const int SndOutLatencyMS = 160;
24
+static bool timeStretchDisabled = false;
25 25
 //----------------
26 26
 
27 27
 StereoOut32 StereoOut32::Empty;
Browse code

Removed a bunch of casts, they seem to be fine without them in most cases.

Naram Qashat authored on 2013/04/18 23:22:54
Showing 1 changed files
... ...
@@ -36,7 +36,7 @@ StereoOut32::StereoOut32(const StereoOutFloat &src) : Left(static_cast<int32_t>(
36 36
 
37 37
 StereoOut16 StereoOut32::DownSample() const
38 38
 {
39
-	return StereoOut16(static_cast<int16_t>(Left >> SndOutVolumeShift), static_cast<int16_t>(Right >> SndOutVolumeShift));
39
+	return StereoOut16((Left >> SndOutVolumeShift) & 0xFFFF, (Right >> SndOutVolumeShift) & 0xFFFF);
40 40
 }
41 41
 
42 42
 std::unique_ptr<StereoOut32[]> SndBuffer::m_buffer;
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
... ...
@@ -16,8 +16,6 @@
16 16
  */
17 17
 
18 18
 #include <cassert>
19
-
20
-//#include "Global.h"
21 19
 #include "../types.h"
22 20
 #include "SndOut.h"
23 21
 
... ...
@@ -26,119 +24,49 @@ int SndOutLatencyMS = 160;
26 24
 bool timeStretchDisabled = false;
27 25
 //----------------
28 26
 
29
-StereoOut32 StereoOut32::Empty( 0, 0 );
27
+StereoOut32 StereoOut32::Empty;
30 28
 
31
-StereoOut32::StereoOut32( const StereoOut16& src ) :
32
-	Left( src.Left ),
33
-	Right( src.Right )
29
+StereoOut32::StereoOut32(const StereoOut16 &src) : Left(src.Left), Right(src.Right)
34 30
 {
35 31
 }
36 32
 
37
-StereoOut32::StereoOut32( const StereoOutFloat& src ) :
38
-	Left( (int32_t)(src.Left * 2147483647.0f) ),
39
-	Right( (int32_t)(src.Right * 2147483647.0f) )
33
+StereoOut32::StereoOut32(const StereoOutFloat &src) : Left(static_cast<int32_t>(src.Left * 2147483647.0f)), Right(static_cast<int32_t>(src.Right * 2147483647.0f))
40 34
 {
41 35
 }
42 36
 
43 37
 StereoOut16 StereoOut32::DownSample() const
44 38
 {
45
-	return StereoOut16(
46
-		static_cast<int16_t>(Left >> SndOutVolumeShift),
47
-		static_cast<int16_t>(Right >> SndOutVolumeShift)
48
-	);
39
+	return StereoOut16(static_cast<int16_t>(Left >> SndOutVolumeShift), static_cast<int16_t>(Right >> SndOutVolumeShift));
49 40
 }
50 41
 
51
-/*StereoOut32 StereoOut16::UpSample() const
52
-{
53
-	return StereoOut32(
54
-		Left << SndOutVolumeShift,
55
-		Right << SndOutVolumeShift
56
-	);
57
-
58
-}*/
59
-
60
-//class NullOutModule: public SndOutModule
61
-//{
62
-//public:
63
-//	int32_t  Init()  { return 0; }
64
-//	void Close() { }
65
-//	int32_t  Test() const { return 0; }
66
-//	void Configure(uptr parent)  { }
67
-//	bool Is51Out() const { return false; }
68
-//	int GetEmptySampleCount() const { return 0; }
69
-//
70
-//	const wchar_t* GetIdent() const
71
-//	{
72
-//		return L"nullout";
73
-//	}
74
-//
75
-//	const wchar_t* GetLongName() const
76
-//	{
77
-//		return L"No Sound (Emulate SPU2 only)";
78
-//	}
79
-//
80
-//	void ReadSettings()
81
-//	{
82
-//	}
83
-//
84
-//	void WriteSettings() const
85
-//	{
86
-//	}
87
-//
88
-//} NullOut;
89
-//
90
-//SndOutModule* mods[]=
91
-//{
92
-//	&NullOut,
93
-//#ifdef _MSC_VER
94
-//	XAudio2Out,
95
-//	DSoundOut,
96
-//	WaveOut,
97
-//#endif
98
-//	NULL		// signals the end of our list
99
-//};
100
-//
101
-//int FindOutputModuleById( const wchar_t* omodid )
102
-//{
103
-//	int modcnt = 0;
104
-//	while( mods[modcnt] != NULL )
105
-//	{
106
-//		if( wcscmp( mods[modcnt]->GetIdent(), omodid ) == 0 )
107
-//			break;
108
-//		++modcnt;
109
-//	}
110
-//	return modcnt;
111
-//}
112
-
113
-StereoOut32 *SndBuffer::m_buffer;
42
+std::unique_ptr<StereoOut32[]> SndBuffer::m_buffer;
114 43
 int32_t SndBuffer::m_size;
115 44
 int32_t SndBuffer::m_rpos;
116 45
 int32_t SndBuffer::m_wpos;
117 46
 int32_t SndBuffer::m_data;
118 47
 
119 48
 bool SndBuffer::m_underrun_freeze;
120
-StereoOut32* SndBuffer::sndTempBuffer = NULL;
121
-StereoOut16* SndBuffer::sndTempBuffer16 = NULL;
49
+std::unique_ptr<StereoOut32[]> SndBuffer::sndTempBuffer;
122 50
 int SndBuffer::sndTempProgress = 0;
123 51
 
124
-static int GetAlignedBufferSize( int comp )
52
+inline int GetAlignedBufferSize(int comp)
125 53
 {
126
-	return (comp + SndOutPacketSize-1) & ~(SndOutPacketSize-1);
54
+	return (comp + SndOutPacketSize - 1) & ~(SndOutPacketSize - 1);
127 55
 }
128 56
 
129 57
 // Returns true if there is data to be output, or false if no data
130 58
 // is available to be copied.
131
-bool SndBuffer::CheckUnderrunStatus( int& nSamples, int& quietSampleCount )
59
+bool SndBuffer::CheckUnderrunStatus(int &nSamples, int &quietSampleCount)
132 60
 {
133 61
 	quietSampleCount = 0;
134
-	if( m_underrun_freeze )
62
+	if (m_underrun_freeze)
135 63
 	{
136
-		int toFill = (int)(m_size * ( timeStretchDisabled ? 0.50f : 0.1f ) );
137
-		toFill = GetAlignedBufferSize( toFill );
64
+		int toFill = static_cast<int>(m_size * (timeStretchDisabled ? 0.50f : 0.1f));
65
+		toFill = GetAlignedBufferSize(toFill);
138 66
 
139 67
 		// toFill is now aligned to a SndOutPacket
140 68
 
141
-		if( m_data < toFill )
69
+		if (m_data < toFill)
142 70
 		{
143 71
 			quietSampleCount = nSamples;
144 72
 			return false;
... ...
@@ -147,19 +75,19 @@ bool SndBuffer::CheckUnderrunStatus( int& nSamples, int& quietSampleCount )
147 75
 		m_underrun_freeze = false;
148 76
 		//TODO
149 77
 		//if( MsgOverruns() )
150
-			printf(" * SPU2 > Underrun compensation (%d packets buffered)\n", toFill / SndOutPacketSize );
151
-		lastPct = 0.0;		// normalize timestretcher
78
+			printf(" * SPU2 > Underrun compensation (%d packets buffered)\n", toFill / SndOutPacketSize);
79
+		lastPct = 0.0; // normalize timestretcher
152 80
 	}
153
-	else if( m_data < nSamples )
81
+	else if (m_data < nSamples)
154 82
 	{
155 83
 		nSamples = m_data;
156 84
 		quietSampleCount = SndOutPacketSize - m_data;
157 85
 		m_underrun_freeze = true;
158 86
 
159
-		if( !timeStretchDisabled )
87
+		if (!timeStretchDisabled)
160 88
 			timeStretchUnderrun();
161 89
 
162
-		return nSamples != 0;
90
+		return !!nSamples;
163 91
 	}
164 92
 
165 93
 	return true;
... ...
@@ -175,10 +103,10 @@ void SndBuffer::_InitFail()
175 103
 
176 104
 void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
177 105
 {
178
-	int free = m_size-m_data;
106
+	int free = m_size - m_data;
179 107
 	m_predictData = 0;
180 108
 
181
-	assert( m_data <= m_size );
109
+	assert(m_data <= m_size);
182 110
 
183 111
 	// Problem:
184 112
 	//  If the SPU2 gets out of sync with the SndOut device, the writepos of the
... ...
@@ -191,7 +119,7 @@ void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
191 119
 	//  The older portion of the buffer is discarded rather than incoming data,
192 120
 	//  so that the overall audio synchronization is better.
193 121
 
194
-	if( free < nSamples )
122
+	if (free < nSamples)
195 123
 	{
196 124
 		// Buffer overrun!
197 125
 		// Dump samples from the read portion of the buffer instead of dropping
... ...
@@ -199,90 +127,78 @@ void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
199 127
 
200 128
 		int32_t comp;
201 129
 
202
-		if( !timeStretchDisabled )
203
-		{
130
+		if (!timeStretchDisabled)
204 131
 			comp = timeStretchOverrun();
205
-		}
206 132
 		else
207 133
 		{
208 134
 			// Toss half the buffer plus whatever's being written anew:
209
-			comp = GetAlignedBufferSize( (m_size + nSamples ) / 2 );
210
-			if( comp > (m_size-SndOutPacketSize) ) comp = m_size-SndOutPacketSize;
135
+			comp = GetAlignedBufferSize((m_size + nSamples) / 2);
136
+			if (comp > m_size - SndOutPacketSize)
137
+				comp = m_size - SndOutPacketSize;
211 138
 		}
212 139
 
213 140
 		m_data -= comp;
214
-		m_rpos = (m_rpos+comp) % m_size;
141
+		m_rpos = (m_rpos + comp) % m_size;
215 142
 		//TODO
216 143
 		//if( MsgOverruns() )
217
-			printf(" * SPU2 > Overrun Compensation (%d packets tossed)\n", comp / SndOutPacketSize );
218
-		lastPct = 0.0;		// normalize the timestretcher
144
+			printf(" * SPU2 > Overrun Compensation (%d packets tossed)\n", comp / SndOutPacketSize);
145
+		lastPct = 0.0; // normalize the timestretcher
219 146
 	}
220 147
 
221 148
 	// copy in two phases, since there's a chance the packet
222 149
 	// wraps around the buffer (it'd be nice to deal in packets only, but
223 150
 	// the timestretcher and DSP options require flexibility).
224 151
 
225
-	const int endPos = m_wpos + nSamples;
226
-	const int secondCopyLen = endPos - m_size;
227
-	StereoOut32* wposbuffer = &m_buffer[m_wpos];
152
+	int endPos = m_wpos + nSamples;
153
+	int secondCopyLen = endPos - m_size;
154
+	StereoOut32 *wposbuffer = &m_buffer[m_wpos];
228 155
 
229 156
 	m_data += nSamples;
230
-	if( secondCopyLen > 0 )
157
+	if (secondCopyLen > 0)
231 158
 	{
232 159
 		nSamples -= secondCopyLen;
233
-		memcpy( m_buffer, &bData[nSamples], secondCopyLen * sizeof( *bData ) );
160
+		memcpy(m_buffer.get(), &bData[nSamples], secondCopyLen * sizeof(*bData));
234 161
 		m_wpos = secondCopyLen;
235 162
 	}
236 163
 	else
237 164
 		m_wpos += nSamples;
238 165
 
239
-	memcpy( wposbuffer, bData, nSamples * sizeof( *bData ) );
166
+	memcpy(wposbuffer, bData, nSamples * sizeof(*bData));
240 167
 }
241 168
 
242 169
 void SndBuffer::Init()
243 170
 {
244
-	//if( mods[OutputModule] == NULL )
245
-	//{
246
-	//	_InitFail();
247
-	//	return;
248
-	//}
249
-
250 171
 	// initialize sound buffer
251 172
 	// Buffer actually attempts to run ~50%, so allocate near double what
252 173
 	// the requested latency is:
253 174
 
254
-
255
-	m_rpos = 0;
256
-	m_wpos = 0;
257
-	m_data = 0;
175
+	m_rpos = m_wpos = m_data = 0;
258 176
 
259 177
 	try
260 178
 	{
261
-		const float latencyMS = SndOutLatencyMS * (timeStretchDisabled ? 1.5f : 2.0f );
262
-		m_size = GetAlignedBufferSize( (int)(latencyMS * SampleRate / 1000.0f ) );
263
-		m_buffer = new StereoOut32[m_size];
179
+		float latencyMS = SndOutLatencyMS * (timeStretchDisabled ? 1.5f : 2.0f);
180
+		m_size = GetAlignedBufferSize(static_cast<int>(latencyMS * SampleRate / 1000.0f));
181
+		m_buffer.reset(new StereoOut32[m_size]);
264 182
 		m_underrun_freeze = false;
265 183
 
266
-		sndTempBuffer = new StereoOut32[SndOutPacketSize];
267
-		sndTempBuffer16 = new StereoOut16[SndOutPacketSize];
184
+		sndTempBuffer.reset(new StereoOut32[SndOutPacketSize]);
268 185
 	}
269
-	catch( std::bad_alloc& )
186
+	catch(const std::bad_alloc &)
270 187
 	{
271 188
 		// out of memory exception (most likely)
272 189
 
273
-		printf( "Out of memory error occurred while initializing SPU2." );
190
+		printf("Out of memory error occurred while initializing SPU2.");
274 191
 		_InitFail();
275 192
 		return;
276 193
 	}
277 194
 
278 195
 	// clear buffers!
279 196
 	// Fixes loopy sounds on emu resets.
280
-	memset( sndTempBuffer, 0, sizeof(StereoOut32) * SndOutPacketSize );
281
-	memset( sndTempBuffer16, 0, sizeof(StereoOut16) * SndOutPacketSize );
197
+	memset(sndTempBuffer.get(), 0, sizeof(StereoOut32) * SndOutPacketSize);
282 198
 
283 199
 	sndTempProgress = 0;
284 200
 
285
-	soundtouchInit();		// initializes the timestretching
201
+	soundtouchInit(); // initializes the timestretching
286 202
 
287 203
 	// some crap
288 204
 	//spdif_set51(mods[OutputModule]->Is51Out());
... ...
@@ -291,98 +207,20 @@ void SndBuffer::Init()
291 207
 	//if( mods[OutputModule]->Init() == -1 ) _InitFail();
292 208
 }
293 209
 
294
-/*void SndBuffer::Cleanup()
295
-{
296
-	//mods[OutputModule]->Close();
297
-
298
-	soundtouchCleanup();
299
-
300
-	//safe_delete_array( m_buffer );
301
-	//safe_delete_array( sndTempBuffer );
302
-	//safe_delete_array( sndTempBuffer16 );
303
-	delete[] m_buffer;
304
-	delete[] sndTempBuffer;
305
-	delete[] sndTempBuffer16;
306
-}*/
307
-
308
-//int SndBuffer::m_dsp_progress = 0;
309
-
310
-//int SndBuffer::m_timestretch_progress = 0;
311
-//int SndBuffer::ssFreeze = 0;
312
-
313
-/*void SndBuffer::ClearContents()
210
+void SndBuffer::Write(const StereoOut32 &Sample)
314 211
 {
315
-	SndBuffer::soundtouchClearContents();
316
-	SndBuffer::ssFreeze = 30; //Delays sound output for about half a second.
317
-}*/
318
-
319
-void SndBuffer::Write( const StereoOut32& Sample )
320
-{
321
-	// Log final output to wavefile.
322
-	//WaveDump::WriteCore( 1, CoreSrc_External, Sample.DownSample() );
323
-
324
-	//RecordWrite( Sample.DownSample() );
325
-
326 212
 	//if(mods[OutputModule] == &NullOut) // null output doesn't need buffering or stretching! :p
327 213
 	//	return;
328 214
 
329 215
 	sndTempBuffer[sndTempProgress++] = Sample;
330 216
 
331 217
 	// If we haven't accumulated a full packet yet, do nothing more:
332
-	if(sndTempProgress < SndOutPacketSize) return;
218
+	if (sndTempProgress < SndOutPacketSize)
219
+		return;
333 220
 	sndTempProgress = 0;
334 221
 
335
-	//Don't play anything directly after loading a savestate, avoids static killing your speakers.
336
-//	if ( ssFreeze > 0 )
337
-//	{
338
-//		ssFreeze--;
339
-//		return;
340
-//	}
341
-//#ifndef __LINUX__
342
-//	else if( dspPluginEnabled )
343
-//	{
344
-//		// Convert in, send to winamp DSP, and convert out.
345
-//
346
-//		for( int i=0; i<SndOutPacketSize; ++i ) { sndTempBuffer16[i] = sndTempBuffer[i].DownSample(); }
347
-//		m_dsp_progress += DspProcess( (s16*)sndTempBuffer16, SndOutPacketSize );
348
-//
349
-//		// Some ugly code to ensure full packet handling:
350
-//		int ei = 0;
351
-//		while( m_dsp_progress >= SndOutPacketSize )
352
-//		{
353
-//			for( int i=0; i<SndOutPacketSize; ++i, ++ei ) { sndTempBuffer[i] = sndTempBuffer16[ei].UpSample(); }
354
-//
355
-//			if( !timeStretchDisabled )
356
-//				timeStretchWrite();
357
-//			else
358
-//				_WriteSamples(sndTempBuffer, sndTempProgress);
359
-//
360
-//			m_dsp_progress -= SndOutPacketSize;
361
-//		}
362
-//
363
-//		// copy any leftovers to the front of the dsp buffer.
364
-//		if( m_dsp_progress > 0 )
365
-//		{
366
-//			memcpy( &sndTempBuffer16[ei], sndTempBuffer16,
367
-//				sizeof(sndTempBuffer16[0]) * m_dsp_progress
368
-//			);
369
-//		}
370
-//	}
371
-//#endif
372
-//	else
373
-	{
374
-		if( !timeStretchDisabled )
375
-			timeStretchWrite();
376
-		else
377
-			_WriteSamples(sndTempBuffer, SndOutPacketSize);
378
-	}
222
+	if( !timeStretchDisabled )
223
+		timeStretchWrite();
224
+	else
225
+		_WriteSamples(sndTempBuffer.get(), SndOutPacketSize);
379 226
 }
380
-
381
-/*int32_t SndBuffer::Test()
382
-{
383
-	//if( mods[OutputModule] == NULL )
384
-	//	return -1;
385
-
386
-	//return mods[OutputModule]->Test();
387
-	return 0;
388
-}*/
Browse code

Cleanup of some warnings, updating modification dates, using nullptr instead of NULL in some cases.

Naram Qashat authored on 2013/03/30 16:17:42
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 #include <cassert>
19 19
 
20 20
 //#include "Global.h"
21
-#include "types.h"
21
+#include "../types.h"
22 22
 #include "SndOut.h"
23 23
 
24 24
 //----------------
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,388 @@
1
+/* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
2
+ * Developed and maintained by the Pcsx2 Development Team.
3
+ *
4
+ * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
5
+ *
6
+ * SPU2-X is free software: you can redistribute it and/or modify it under the terms
7
+ * of the GNU Lesser General Public License as published by the Free Software Found-
8
+ * ation, either version 3 of the License, or (at your option) any later version.
9
+ *
10
+ * SPU2-X is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
+ * PURPOSE.  See the GNU Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public License
15
+ * along with SPU2-X.  If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+#include <cassert>
19
+
20
+//#include "Global.h"
21
+#include "types.h"
22
+#include "SndOut.h"
23
+
24
+//----------------
25
+int SndOutLatencyMS = 160;
26
+bool timeStretchDisabled = false;
27
+//----------------
28
+
29
+StereoOut32 StereoOut32::Empty( 0, 0 );
30
+
31
+StereoOut32::StereoOut32( const StereoOut16& src ) :
32
+	Left( src.Left ),
33
+	Right( src.Right )
34
+{
35
+}
36
+
37
+StereoOut32::StereoOut32( const StereoOutFloat& src ) :
38
+	Left( (int32_t)(src.Left * 2147483647.0f) ),
39
+	Right( (int32_t)(src.Right * 2147483647.0f) )
40
+{
41
+}
42
+
43
+StereoOut16 StereoOut32::DownSample() const
44
+{
45
+	return StereoOut16(
46
+		static_cast<int16_t>(Left >> SndOutVolumeShift),
47
+		static_cast<int16_t>(Right >> SndOutVolumeShift)
48
+	);
49
+}
50
+
51
+/*StereoOut32 StereoOut16::UpSample() const
52
+{
53
+	return StereoOut32(
54
+		Left << SndOutVolumeShift,
55
+		Right << SndOutVolumeShift
56
+	);
57
+
58
+}*/
59
+
60
+//class NullOutModule: public SndOutModule
61
+//{
62
+//public:
63
+//	int32_t  Init()  { return 0; }
64
+//	void Close() { }
65
+//	int32_t  Test() const { return 0; }
66
+//	void Configure(uptr parent)  { }
67
+//	bool Is51Out() const { return false; }
68
+//	int GetEmptySampleCount() const { return 0; }
69
+//
70
+//	const wchar_t* GetIdent() const
71
+//	{
72
+//		return L"nullout";
73
+//	}
74
+//
75
+//	const wchar_t* GetLongName() const
76
+//	{
77
+//		return L"No Sound (Emulate SPU2 only)";
78
+//	}
79
+//
80
+//	void ReadSettings()
81
+//	{
82
+//	}
83
+//
84
+//	void WriteSettings() const
85
+//	{
86
+//	}
87
+//
88
+//} NullOut;
89
+//
90
+//SndOutModule* mods[]=
91
+//{
92
+//	&NullOut,
93
+//#ifdef _MSC_VER
94
+//	XAudio2Out,
95
+//	DSoundOut,
96
+//	WaveOut,
97
+//#endif
98
+//	NULL		// signals the end of our list
99
+//};
100
+//
101
+//int FindOutputModuleById( const wchar_t* omodid )
102
+//{
103
+//	int modcnt = 0;
104
+//	while( mods[modcnt] != NULL )
105
+//	{
106
+//		if( wcscmp( mods[modcnt]->GetIdent(), omodid ) == 0 )
107
+//			break;
108
+//		++modcnt;
109
+//	}
110
+//	return modcnt;
111
+//}
112
+
113
+StereoOut32 *SndBuffer::m_buffer;
114
+int32_t SndBuffer::m_size;
115
+int32_t SndBuffer::m_rpos;
116
+int32_t SndBuffer::m_wpos;
117
+int32_t SndBuffer::m_data;
118
+
119
+bool SndBuffer::m_underrun_freeze;
120
+StereoOut32* SndBuffer::sndTempBuffer = NULL;
121
+StereoOut16* SndBuffer::sndTempBuffer16 = NULL;
122
+int SndBuffer::sndTempProgress = 0;
123
+
124
+static int GetAlignedBufferSize( int comp )
125
+{
126
+	return (comp + SndOutPacketSize-1) & ~(SndOutPacketSize-1);
127
+}
128
+
129
+// Returns true if there is data to be output, or false if no data
130
+// is available to be copied.
131
+bool SndBuffer::CheckUnderrunStatus( int& nSamples, int& quietSampleCount )
132
+{
133
+	quietSampleCount = 0;
134
+	if( m_underrun_freeze )
135
+	{
136
+		int toFill = (int)(m_size * ( timeStretchDisabled ? 0.50f : 0.1f ) );
137
+		toFill = GetAlignedBufferSize( toFill );
138
+
139
+		// toFill is now aligned to a SndOutPacket
140
+
141
+		if( m_data < toFill )
142
+		{
143
+			quietSampleCount = nSamples;
144
+			return false;
145
+		}
146
+
147
+		m_underrun_freeze = false;
148
+		//TODO
149
+		//if( MsgOverruns() )
150
+			printf(" * SPU2 > Underrun compensation (%d packets buffered)\n", toFill / SndOutPacketSize );
151
+		lastPct = 0.0;		// normalize timestretcher
152
+	}
153
+	else if( m_data < nSamples )
154
+	{
155
+		nSamples = m_data;
156
+		quietSampleCount = SndOutPacketSize - m_data;
157
+		m_underrun_freeze = true;
158
+
159
+		if( !timeStretchDisabled )
160
+			timeStretchUnderrun();
161
+
162
+		return nSamples != 0;
163
+	}
164
+
165
+	return true;
166
+}
167
+
168
+void SndBuffer::_InitFail()
169
+{
170
+	// If a failure occurs, just initialize the NoSound driver.  This'll allow
171
+	// the game to emulate properly (hopefully), albeit without sound.
172
+	//OutputModule = FindOutputModuleById( NullOut.GetIdent() );
173
+	//mods[OutputModule]->Init();
174
+}
175
+
176
+void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
177
+{
178
+	int free = m_size-m_data;
179
+	m_predictData = 0;
180
+
181
+	assert( m_data <= m_size );
182
+
183
+	// Problem:
184
+	//  If the SPU2 gets out of sync with the SndOut device, the writepos of the
185
+	//  circular buffer will overtake the readpos, leading to a prolonged period
186
+	//  of hopscotching read/write accesses (ie, lots of staticy crap sound for
187
+	//  several seconds).
188
+	//
189
+	// Compromise:
190
+	//  When an overrun occurs, we adapt by discarding a portion of the buffer.
191
+	//  The older portion of the buffer is discarded rather than incoming data,
192
+	//  so that the overall audio synchronization is better.
193
+
194
+	if( free < nSamples )
195
+	{
196
+		// Buffer overrun!
197
+		// Dump samples from the read portion of the buffer instead of dropping
198
+		// the newly written stuff.
199
+
200
+		int32_t comp;
201
+
202
+		if( !timeStretchDisabled )
203
+		{
204
+			comp = timeStretchOverrun();
205
+		}
206
+		else
207
+		{
208
+			// Toss half the buffer plus whatever's being written anew:
209
+			comp = GetAlignedBufferSize( (m_size + nSamples ) / 2 );
210
+			if( comp > (m_size-SndOutPacketSize) ) comp = m_size-SndOutPacketSize;
211
+		}
212
+
213
+		m_data -= comp;
214
+		m_rpos = (m_rpos+comp) % m_size;
215
+		//TODO
216
+		//if( MsgOverruns() )
217
+			printf(" * SPU2 > Overrun Compensation (%d packets tossed)\n", comp / SndOutPacketSize );
218
+		lastPct = 0.0;		// normalize the timestretcher
219
+	}
220
+
221
+	// copy in two phases, since there's a chance the packet
222
+	// wraps around the buffer (it'd be nice to deal in packets only, but
223
+	// the timestretcher and DSP options require flexibility).
224
+
225
+	const int endPos = m_wpos + nSamples;
226
+	const int secondCopyLen = endPos - m_size;
227
+	StereoOut32* wposbuffer = &m_buffer[m_wpos];
228
+
229
+	m_data += nSamples;
230
+	if( secondCopyLen > 0 )
231
+	{
232
+		nSamples -= secondCopyLen;
233
+		memcpy( m_buffer, &bData[nSamples], secondCopyLen * sizeof( *bData ) );
234
+		m_wpos = secondCopyLen;
235
+	}
236
+	else
237
+		m_wpos += nSamples;
238
+
239
+	memcpy( wposbuffer, bData, nSamples * sizeof( *bData ) );
240
+}
241
+
242
+void SndBuffer::Init()
243
+{
244
+	//if( mods[OutputModule] == NULL )
245
+	//{
246
+	//	_InitFail();
247
+	//	return;
248
+	//}
249
+
250
+	// initialize sound buffer
251
+	// Buffer actually attempts to run ~50%, so allocate near double what
252
+	// the requested latency is:
253
+
254
+
255
+	m_rpos = 0;
256
+	m_wpos = 0;
257
+	m_data = 0;
258
+
259
+	try
260
+	{
261
+		const float latencyMS = SndOutLatencyMS * (timeStretchDisabled ? 1.5f : 2.0f );
262
+		m_size = GetAlignedBufferSize( (int)(latencyMS * SampleRate / 1000.0f ) );
263
+		m_buffer = new StereoOut32[m_size];
264
+		m_underrun_freeze = false;
265
+
266
+		sndTempBuffer = new StereoOut32[SndOutPacketSize];
267
+		sndTempBuffer16 = new StereoOut16[SndOutPacketSize];
268
+	}
269
+	catch( std::bad_alloc& )
270
+	{
271
+		// out of memory exception (most likely)
272
+
273
+		printf( "Out of memory error occurred while initializing SPU2." );
274
+		_InitFail();
275
+		return;
276
+	}
277
+
278
+	// clear buffers!
279
+	// Fixes loopy sounds on emu resets.
280
+	memset( sndTempBuffer, 0, sizeof(StereoOut32) * SndOutPacketSize );
281
+	memset( sndTempBuffer16, 0, sizeof(StereoOut16) * SndOutPacketSize );
282
+
283
+	sndTempProgress = 0;
284
+
285
+	soundtouchInit();		// initializes the timestretching
286
+
287
+	// some crap
288
+	//spdif_set51(mods[OutputModule]->Is51Out());
289
+
290
+	// initialize module
291
+	//if( mods[OutputModule]->Init() == -1 ) _InitFail();
292
+}
293
+
294
+/*void SndBuffer::Cleanup()
295
+{
296
+	//mods[OutputModule]->Close();
297
+
298
+	soundtouchCleanup();
299
+
300
+	//safe_delete_array( m_buffer );
301
+	//safe_delete_array( sndTempBuffer );
302
+	//safe_delete_array( sndTempBuffer16 );
303
+	delete[] m_buffer;
304
+	delete[] sndTempBuffer;
305
+	delete[] sndTempBuffer16;
306
+}*/
307
+
308
+//int SndBuffer::m_dsp_progress = 0;
309
+
310
+//int SndBuffer::m_timestretch_progress = 0;
311
+//int SndBuffer::ssFreeze = 0;
312
+
313
+/*void SndBuffer::ClearContents()
314
+{
315
+	SndBuffer::soundtouchClearContents();
316
+	SndBuffer::ssFreeze = 30; //Delays sound output for about half a second.
317
+}*/
318
+
319
+void SndBuffer::Write( const StereoOut32& Sample )
320
+{
321
+	// Log final output to wavefile.
322
+	//WaveDump::WriteCore( 1, CoreSrc_External, Sample.DownSample() );
323
+
324
+	//RecordWrite( Sample.DownSample() );
325
+
326
+	//if(mods[OutputModule] == &NullOut) // null output doesn't need buffering or stretching! :p
327
+	//	return;
328
+
329
+	sndTempBuffer[sndTempProgress++] = Sample;
330
+
331
+	// If we haven't accumulated a full packet yet, do nothing more:
332
+	if(sndTempProgress < SndOutPacketSize) return;
333
+	sndTempProgress = 0;
334
+
335
+	//Don't play anything directly after loading a savestate, avoids static killing your speakers.
336
+//	if ( ssFreeze > 0 )
337
+//	{
338
+//		ssFreeze--;
339
+//		return;
340
+//	}
341
+//#ifndef __LINUX__
342
+//	else if( dspPluginEnabled )
343
+//	{
344
+//		// Convert in, send to winamp DSP, and convert out.
345
+//
346
+//		for( int i=0; i<SndOutPacketSize; ++i ) { sndTempBuffer16[i] = sndTempBuffer[i].DownSample(); }
347
+//		m_dsp_progress += DspProcess( (s16*)sndTempBuffer16, SndOutPacketSize );
348
+//
349
+//		// Some ugly code to ensure full packet handling:
350
+//		int ei = 0;
351
+//		while( m_dsp_progress >= SndOutPacketSize )
352
+//		{
353
+//			for( int i=0; i<SndOutPacketSize; ++i, ++ei ) { sndTempBuffer[i] = sndTempBuffer16[ei].UpSample(); }
354
+//
355
+//			if( !timeStretchDisabled )
356
+//				timeStretchWrite();
357
+//			else
358
+//				_WriteSamples(sndTempBuffer, sndTempProgress);
359
+//
360
+//			m_dsp_progress -= SndOutPacketSize;
361
+//		}
362
+//
363
+//		// copy any leftovers to the front of the dsp buffer.
364
+//		if( m_dsp_progress > 0 )
365
+//		{
366
+//			memcpy( &sndTempBuffer16[ei], sndTempBuffer16,
367
+//				sizeof(sndTempBuffer16[0]) * m_dsp_progress
368
+//			);
369
+//		}
370
+//	}
371
+//#endif
372
+//	else
373
+	{
374
+		if( !timeStretchDisabled )
375
+			timeStretchWrite();
376
+		else
377
+			_WriteSamples(sndTempBuffer, SndOutPacketSize);
378
+	}
379
+}
380
+
381
+/*int32_t SndBuffer::Test()
382
+{
383
+	//if( mods[OutputModule] == NULL )
384
+	//	return -1;
385
+
386
+	//return mods[OutputModule]->Test();
387
+	return 0;
388
+}*/