Browse code

Fix unsigned underflow with a loop offset of 0 on an ADPCM SWAV.

Also a minor optimization when reading the SWAVs.

Naram Qashat authored on 2014/12/06 18:41:35
Showing 1 changed files
... ...
@@ -96,8 +96,8 @@ void SWAV::Read(PseudoFile &file)
96 96
 	if (!this->waveType)
97 97
 	{
98 98
 		// PCM 8-bit -> PCM signed 16-bit
99
-		this->data.resize(origData.size(), 0);
100
-		for (size_t i = 0, len = origData.size(); i < len; ++i)
99
+		this->data.resize(size, 0);
100
+		for (size_t i = 0; i < size; ++i)
101 101
 			this->data[i] = origData[i] << 8;
102 102
 		this->loopOffset *= 4;
103 103
 		this->nonLoopLength *= 4;
... ...
@@ -105,8 +105,8 @@ void SWAV::Read(PseudoFile &file)
105 105
 	else if (this->waveType == 1)
106 106
 	{
107 107
 		// PCM signed 16-bit, no conversion
108
-		this->data.resize(origData.size() / 2, 0);
109
-		for (size_t i = 0, len = origData.size() / 2; i < len; ++i)
108
+		this->data.resize(size / 2, 0);
109
+		for (size_t i = 0; i < size / 2; ++i)
110 110
 			this->data[i] = ReadLE<int16_t>(&origData[2 * i]);
111 111
 		this->loopOffset *= 2;
112 112
 		this->nonLoopLength *= 2;
... ...
@@ -114,9 +114,10 @@ void SWAV::Read(PseudoFile &file)
114 114
 	else if (this->waveType == 2)
115 115
 	{
116 116
 		// IMA ADPCM -> PCM signed 16-bit
117
-		this->data.resize((origData.size() - 4) * 2, 0);
118
-		this->DecodeADPCM(&origData[0], origData.size() - 4);
119
-		--this->loopOffset;
117
+		this->data.resize((size - 4) * 2, 0);
118
+		this->DecodeADPCM(&origData[0], size - 4);
119
+		if (this->loopOffset)
120
+			--this->loopOffset;
120 121
 		this->loopOffset *= 8;
121 122
 		this->nonLoopLength *= 8;
122 123
 	}