Browse code

Very minor optimization on decoding ADPCM when reading an SWAV.

Naram Qashat authored on 2013/04/12 13:13:27
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - SDAT SWAV (Waveform/Sample) structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-10
4
+ * Last modification on 2013-04-12
5 5
  *
6 6
  * Nintendo DS Nitro Composer (SDAT) Specification document found at
7 7
  * http://www.feshrine.net/hacking/doc/nds-sdat.html
... ...
@@ -62,20 +62,21 @@ static inline void DecodeADPCMNibble(int32_t nibble, int32_t &stepIndex, int32_t
62 62
 		predictedValue = 0x7FFF;
63 63
 }
64 64
 
65
-void SWAV::DecodeADPCM(const std::vector<uint8_t> &origData)
65
+void SWAV::DecodeADPCM(const uint8_t *origData, uint32_t len)
66 66
 {
67 67
 	int32_t predictedValue = origData[0] | (origData[1] << 8);
68 68
 	int32_t stepIndex = origData[2] | (origData[3] << 8);
69
+	auto finalData = &this->data[0];
69 70
 
70
-	for (int i = 0, len = origData.size() - 4; i < len; ++i)
71
+	for (uint32_t i = 0; i < len; ++i)
71 72
 	{
72 73
 		int32_t nibble = origData[i + 4] & 0x0F;
73 74
 		DecodeADPCMNibble(nibble, stepIndex, predictedValue);
74
-		this->data[2 * i] = predictedValue;
75
+		finalData[2 * i] = predictedValue;
75 76
 
76 77
 		nibble = (origData[i + 4] >> 4) & 0x0F;
77 78
 		DecodeADPCMNibble(nibble, stepIndex, predictedValue);
78
-		this->data[2 * i + 1] = predictedValue;
79
+		finalData[2 * i + 1] = predictedValue;
79 80
 	}
80 81
 }
81 82
 
... ...
@@ -114,7 +115,7 @@ void SWAV::Read(PseudoFile &file)
114 115
 	{
115 116
 		// IMA ADPCM -> PCM signed 16-bit
116 117
 		this->data.resize((origData.size() - 4) * 2, 0);
117
-		this->DecodeADPCM(origData);
118
+		this->DecodeADPCM(&origData[0], origData.size() - 4);
118 119
 		--this->loopOffset;
119 120
 		this->loopOffset *= 8;
120 121
 		this->nonLoopLength *= 8;
... ...
@@ -26,7 +26,7 @@ struct SWAV
26 26
 	SWAV();
27 27
 
28 28
 	void Read(PseudoFile &file);
29
-	void DecodeADPCM(const std::vector<uint8_t> &data);
29
+	void DecodeADPCM(const uint8_t *origData, uint32_t len);
30 30
 };
31 31
 
32 32
 #endif