Mercurial > audlegacy-plugins
annotate src/modplug/load_ams.cxx @ 2229:33ffac81f4c7
eliminate warnings.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 15 Dec 2007 00:03:37 +0900 |
parents | 6b5a52635b3b |
children | 032053ca08ab 3673c7ec4ea2 |
rev | line source |
---|---|
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
1 /* |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
2 * This source code is public domain. |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
3 * |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
4 * Authors: Olivier Lapicque <olivierl@jps.net> |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
5 */ |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
6 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
7 ////////////////////////////////////////////// |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
8 // AMS module loader // |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
9 ////////////////////////////////////////////// |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
10 #include "stdafx.h" |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
11 #include "sndfile.h" |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
12 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
13 //#pragma warning(disable:4244) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
14 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
15 #pragma pack(1) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
16 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
17 typedef struct AMSFILEHEADER |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
18 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
19 char szHeader[7]; // "Extreme" // changed from CHAR |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
20 BYTE verlo, verhi; // 0x??,0x01 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
21 BYTE chncfg; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
22 BYTE samples; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
23 WORD patterns; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
24 WORD orders; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
25 BYTE vmidi; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
26 WORD extra; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
27 } AMSFILEHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
28 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
29 typedef struct AMSSAMPLEHEADER |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
30 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
31 DWORD length; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
32 DWORD loopstart; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
33 DWORD loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
34 BYTE finetune_and_pan; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
35 WORD samplerate; // C-2 = 8363 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
36 BYTE volume; // 0-127 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
37 BYTE infobyte; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
38 } AMSSAMPLEHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
39 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
40 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
41 #pragma pack() |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
42 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
43 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
44 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
45 BOOL CSoundFile::ReadAMS(LPCBYTE lpStream, DWORD dwMemLength) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
46 //----------------------------------------------------------- |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
47 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
48 BYTE pkinf[MAX_SAMPLES]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
49 AMSFILEHEADER *pfh = (AMSFILEHEADER *)lpStream; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
50 DWORD dwMemPos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
51 UINT tmp, tmp2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
52 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
53 if ((!lpStream) || (dwMemLength < 1024)) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
54 if ((pfh->verhi != 0x01) || (strncmp(pfh->szHeader, "Extreme", 7)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
55 || (!pfh->patterns) || (!pfh->orders) || (!pfh->samples) || (pfh->samples > MAX_SAMPLES) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
56 || (pfh->patterns > MAX_PATTERNS) || (pfh->orders > MAX_ORDERS)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
57 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
58 return ReadAMS2(lpStream, dwMemLength); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
59 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
60 dwMemPos = sizeof(AMSFILEHEADER) + pfh->extra; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
61 if (dwMemPos + pfh->samples * sizeof(AMSSAMPLEHEADER) + 256 >= dwMemLength) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
62 m_nType = MOD_TYPE_AMS; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
63 m_nInstruments = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
64 m_nChannels = (pfh->chncfg & 0x1F) + 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
65 m_nSamples = pfh->samples; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
66 for (UINT nSmp=1; nSmp<=m_nSamples; nSmp++, dwMemPos += sizeof(AMSSAMPLEHEADER)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
67 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
68 AMSSAMPLEHEADER *psh = (AMSSAMPLEHEADER *)(lpStream + dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
69 MODINSTRUMENT *pins = &Ins[nSmp]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
70 pins->nLength = psh->length; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
71 pins->nLoopStart = psh->loopstart; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
72 pins->nLoopEnd = psh->loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
73 pins->nGlobalVol = 64; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
74 pins->nVolume = psh->volume << 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
75 pins->nC4Speed = psh->samplerate; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
76 pins->nPan = (psh->finetune_and_pan & 0xF0); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
77 if (pins->nPan < 0x80) pins->nPan += 0x10; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
78 pins->nFineTune = MOD2XMFineTune(psh->finetune_and_pan & 0x0F); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
79 pins->uFlags = (psh->infobyte & 0x80) ? CHN_16BIT : 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
80 if ((pins->nLoopEnd <= pins->nLength) && (pins->nLoopStart+4 <= pins->nLoopEnd)) pins->uFlags |= CHN_LOOP; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
81 pkinf[nSmp] = psh->infobyte; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
82 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
83 // Read Song Name |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
84 tmp = lpStream[dwMemPos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
85 if (dwMemPos + tmp + 1 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
86 tmp2 = (tmp < 32) ? tmp : 31; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
87 if (tmp2) memcpy(m_szNames[0], lpStream+dwMemPos, tmp2); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
88 m_szNames[0][tmp2] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
89 dwMemPos += tmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
90 // Read sample names |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
91 for (UINT sNam=1; sNam<=m_nSamples; sNam++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
92 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
93 if (dwMemPos + 32 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
94 tmp = lpStream[dwMemPos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
95 tmp2 = (tmp < 32) ? tmp : 31; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
96 if (tmp2) memcpy(m_szNames[sNam], lpStream+dwMemPos, tmp2); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
97 dwMemPos += tmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
98 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
99 // Skip Channel names |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
100 for (UINT cNam=0; cNam<m_nChannels; cNam++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
101 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
102 if (dwMemPos + 32 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
103 tmp = lpStream[dwMemPos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
104 dwMemPos += tmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
105 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
106 // Read Pattern Names |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
107 m_lpszPatternNames = new char[pfh->patterns * 32]; // changed from CHAR |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
108 if (!m_lpszPatternNames) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
109 m_nPatternNames = pfh->patterns; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
110 memset(m_lpszPatternNames, 0, m_nPatternNames * 32); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
111 for (UINT pNam=0; pNam < m_nPatternNames; pNam++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
112 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
113 if (dwMemPos + 32 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
114 tmp = lpStream[dwMemPos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
115 tmp2 = (tmp < 32) ? tmp : 31; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
116 if (tmp2) memcpy(m_lpszPatternNames+pNam*32, lpStream+dwMemPos, tmp2); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
117 dwMemPos += tmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
118 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
119 // Read Song Comments |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
120 tmp = *((WORD *)(lpStream+dwMemPos)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
121 dwMemPos += 2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
122 if (dwMemPos + tmp >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
123 if (tmp) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
124 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
125 m_lpszSongComments = new char[tmp+1]; // changed from CHAR |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
126 if (!m_lpszSongComments) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
127 memset(m_lpszSongComments, 0, tmp+1); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
128 memcpy(m_lpszSongComments, lpStream + dwMemPos, tmp); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
129 dwMemPos += tmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
130 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
131 // Read Order List |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
132 for (UINT iOrd=0; iOrd<pfh->orders; iOrd++, dwMemPos += 2) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
133 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
134 UINT n = *((WORD *)(lpStream+dwMemPos)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
135 Order[iOrd] = (BYTE)n; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
136 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
137 // Read Patterns |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
138 for (UINT iPat=0; iPat<pfh->patterns; iPat++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
139 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
140 if (dwMemPos + 4 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
141 UINT len = *((DWORD *)(lpStream + dwMemPos)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
142 dwMemPos += 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
143 if ((len >= dwMemLength) || (dwMemPos + len > dwMemLength)) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
144 PatternSize[iPat] = 64; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
145 MODCOMMAND *m = AllocatePattern(PatternSize[iPat], m_nChannels); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
146 if (!m) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
147 Patterns[iPat] = m; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
148 const BYTE *p = lpStream + dwMemPos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
149 UINT row = 0, i = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
150 while ((row < PatternSize[iPat]) && (i+2 < len)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
151 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
152 BYTE b0 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
153 BYTE b1 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
154 BYTE b2 = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
155 UINT ch = b0 & 0x3F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
156 // Note+Instr |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
157 if (!(b0 & 0x40)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
158 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
159 b2 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
160 if (ch < m_nChannels) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
161 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
162 if (b1 & 0x7F) m[ch].note = (b1 & 0x7F) + 25; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
163 m[ch].instr = b2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
164 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
165 if (b1 & 0x80) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
166 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
167 b0 |= 0x40; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
168 b1 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
169 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
170 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
171 // Effect |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
172 if (b0 & 0x40) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
173 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
174 anothercommand: |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
175 if (b1 & 0x40) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
176 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
177 if (ch < m_nChannels) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
178 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
179 m[ch].volcmd = VOLCMD_VOLUME; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
180 m[ch].vol = b1 & 0x3F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
181 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
182 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
183 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
184 b2 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
185 if (ch < m_nChannels) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
186 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
187 UINT cmd = b1 & 0x3F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
188 if (cmd == 0x0C) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
189 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
190 m[ch].volcmd = VOLCMD_VOLUME; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
191 m[ch].vol = b2 >> 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
192 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
193 if (cmd == 0x0E) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
194 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
195 if (!m[ch].command) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
196 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
197 UINT command = CMD_S3MCMDEX; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
198 UINT param = b2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
199 switch(param & 0xF0) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
200 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
201 case 0x00: if (param & 0x08) { param &= 0x07; param |= 0x90; } else {command=param=0;} break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
202 case 0x10: command = CMD_PORTAMENTOUP; param |= 0xF0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
203 case 0x20: command = CMD_PORTAMENTODOWN; param |= 0xF0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
204 case 0x30: param = (param & 0x0F) | 0x10; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
205 case 0x40: param = (param & 0x0F) | 0x30; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
206 case 0x50: param = (param & 0x0F) | 0x20; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
207 case 0x60: param = (param & 0x0F) | 0xB0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
208 case 0x70: param = (param & 0x0F) | 0x40; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
209 case 0x90: command = CMD_RETRIG; param &= 0x0F; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
210 case 0xA0: if (param & 0x0F) { command = CMD_VOLUMESLIDE; param = (param << 4) | 0x0F; } else command=param=0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
211 case 0xB0: if (param & 0x0F) { command = CMD_VOLUMESLIDE; param |= 0xF0; } else command=param=0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
212 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
213 m[ch].command = command; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
214 m[ch].param = param; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
215 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
216 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
217 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
218 m[ch].command = cmd; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
219 m[ch].param = b2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
220 ConvertModCommand(&m[ch]); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
221 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
222 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
223 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
224 if (b1 & 0x80) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
225 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
226 b1 = p[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
227 if (i <= len) goto anothercommand; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
228 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
229 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
230 if (b0 & 0x80) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
231 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
232 row++; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
233 m += m_nChannels; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
234 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
235 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
236 dwMemPos += len; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
237 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
238 // Read Samples |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
239 for (UINT iSmp=1; iSmp<=m_nSamples; iSmp++) if (Ins[iSmp].nLength) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
240 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
241 if (dwMemPos >= dwMemLength - 9) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
242 UINT flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
243 dwMemPos += ReadSample(&Ins[iSmp], flags, (LPSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
244 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
245 return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
246 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
247 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
248 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
249 ///////////////////////////////////////////////////////////////////// |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
250 // AMS 2.2 loader |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
251 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
252 #pragma pack(1) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
253 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
254 typedef struct AMS2FILEHEADER |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
255 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
256 DWORD dwHdr1; // AMShdr |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
257 WORD wHdr2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
258 BYTE b1A; // 0x1A |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
259 BYTE titlelen; // 30-bytes max |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
260 CHAR szTitle[30]; // [titlelen] |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
261 } AMS2FILEHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
262 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
263 typedef struct AMS2SONGHEADER |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
264 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
265 WORD version; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
266 BYTE instruments; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
267 WORD patterns; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
268 WORD orders; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
269 WORD bpm; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
270 BYTE speed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
271 BYTE channels; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
272 BYTE commands; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
273 BYTE rows; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
274 WORD flags; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
275 } AMS2SONGHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
276 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
277 typedef struct AMS2INSTRUMENT |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
278 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
279 BYTE samples; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
280 BYTE notemap[120]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
281 } AMS2INSTRUMENT; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
282 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
283 typedef struct AMS2ENVELOPE |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
284 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
285 BYTE speed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
286 BYTE sustain; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
287 BYTE loopbegin; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
288 BYTE loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
289 BYTE points; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
290 BYTE info[3]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
291 } AMS2ENVELOPE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
292 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
293 typedef struct AMS2SAMPLE |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
294 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
295 DWORD length; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
296 DWORD loopstart; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
297 DWORD loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
298 WORD frequency; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
299 BYTE finetune; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
300 WORD c4speed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
301 CHAR transpose; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
302 BYTE volume; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
303 BYTE flags; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
304 } AMS2SAMPLE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
305 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
306 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
307 #pragma pack() |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
308 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
309 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
310 BOOL CSoundFile::ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
311 //------------------------------------------------------------ |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
312 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
313 AMS2FILEHEADER *pfh = (AMS2FILEHEADER *)lpStream; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
314 AMS2SONGHEADER *psh; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
315 DWORD dwMemPos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
316 BYTE smpmap[16]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
317 BYTE packedsamples[MAX_SAMPLES]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
318 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
319 if ((pfh->dwHdr1 != 0x68534D41) || (pfh->wHdr2 != 0x7264) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
320 || (pfh->b1A != 0x1A) || (pfh->titlelen > 30)) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
321 dwMemPos = pfh->titlelen + 8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
322 psh = (AMS2SONGHEADER *)(lpStream + dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
323 if (((psh->version & 0xFF00) != 0x0200) || (!psh->instruments) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
324 || (psh->instruments > MAX_INSTRUMENTS) || (!psh->patterns) || (!psh->orders)) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
325 dwMemPos += sizeof(AMS2SONGHEADER); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
326 if (pfh->titlelen) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
327 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
328 memcpy(m_szNames, pfh->szTitle, pfh->titlelen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
329 m_szNames[0][pfh->titlelen] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
330 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
331 m_nType = MOD_TYPE_AMS; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
332 m_nChannels = 32; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
333 m_nDefaultTempo = psh->bpm >> 8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
334 m_nDefaultSpeed = psh->speed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
335 m_nInstruments = psh->instruments; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
336 m_nSamples = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
337 if (psh->flags & 0x40) m_dwSongFlags |= SONG_LINEARSLIDES; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
338 for (UINT nIns=1; nIns<=m_nInstruments; nIns++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
339 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
340 UINT insnamelen = lpStream[dwMemPos]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
341 CHAR *pinsname = (CHAR *)(lpStream+dwMemPos+1); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
342 dwMemPos += insnamelen + 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
343 AMS2INSTRUMENT *pins = (AMS2INSTRUMENT *)(lpStream + dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
344 dwMemPos += sizeof(AMS2INSTRUMENT); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
345 if (dwMemPos + 1024 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
346 AMS2ENVELOPE *volenv, *panenv, *pitchenv; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
347 volenv = (AMS2ENVELOPE *)(lpStream+dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
348 dwMemPos += 5 + volenv->points*3; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
349 panenv = (AMS2ENVELOPE *)(lpStream+dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
350 dwMemPos += 5 + panenv->points*3; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
351 pitchenv = (AMS2ENVELOPE *)(lpStream+dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
352 dwMemPos += 5 + pitchenv->points*3; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
353 INSTRUMENTHEADER *penv = new INSTRUMENTHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
354 if (!penv) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
355 memset(smpmap, 0, sizeof(smpmap)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
356 memset(penv, 0, sizeof(INSTRUMENTHEADER)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
357 for (UINT ismpmap=0; ismpmap<pins->samples; ismpmap++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
358 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
359 if ((ismpmap >= 16) || (m_nSamples+1 >= MAX_SAMPLES)) break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
360 m_nSamples++; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
361 smpmap[ismpmap] = m_nSamples; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
362 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
363 penv->nGlobalVol = 64; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
364 penv->nPan = 128; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
365 penv->nPPC = 60; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
366 Headers[nIns] = penv; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
367 if (insnamelen) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
368 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
369 if (insnamelen > 31) insnamelen = 31; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
370 memcpy(penv->name, pinsname, insnamelen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
371 penv->name[insnamelen] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
372 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
373 for (UINT inotemap=0; inotemap<120; inotemap++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
374 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
375 penv->NoteMap[inotemap] = inotemap+1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
376 penv->Keyboard[inotemap] = smpmap[pins->notemap[inotemap] & 0x0F]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
377 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
378 // Volume Envelope |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
379 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
380 UINT pos = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
381 penv->nVolEnv = (volenv->points > 16) ? 16 : volenv->points; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
382 penv->nVolSustainBegin = penv->nVolSustainEnd = volenv->sustain; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
383 penv->nVolLoopStart = volenv->loopbegin; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
384 penv->nVolLoopEnd = volenv->loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
385 for (UINT i=0; i<penv->nVolEnv; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
386 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
387 penv->VolEnv[i] = (BYTE)((volenv->info[i*3+2] & 0x7F) >> 1); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
388 pos += volenv->info[i*3] + ((volenv->info[i*3+1] & 1) << 8); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
389 penv->VolPoints[i] = (WORD)pos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
390 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
391 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
392 penv->nFadeOut = (((lpStream[dwMemPos+2] & 0x0F) << 8) | (lpStream[dwMemPos+1])) << 3; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
393 UINT envflags = lpStream[dwMemPos+3]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
394 if (envflags & 0x01) penv->dwFlags |= ENV_VOLLOOP; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
395 if (envflags & 0x02) penv->dwFlags |= ENV_VOLSUSTAIN; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
396 if (envflags & 0x04) penv->dwFlags |= ENV_VOLUME; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
397 dwMemPos += 5; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
398 // Read Samples |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
399 for (UINT ismp=0; ismp<pins->samples; ismp++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
400 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
401 MODINSTRUMENT *psmp = ((ismp < 16) && (smpmap[ismp])) ? &Ins[smpmap[ismp]] : NULL; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
402 UINT smpnamelen = lpStream[dwMemPos]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
403 if ((psmp) && (smpnamelen) && (smpnamelen <= 22)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
404 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
405 memcpy(m_szNames[smpmap[ismp]], lpStream+dwMemPos+1, smpnamelen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
406 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
407 dwMemPos += smpnamelen + 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
408 if (psmp) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
409 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
410 AMS2SAMPLE *pams = (AMS2SAMPLE *)(lpStream+dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
411 psmp->nGlobalVol = 64; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
412 psmp->nPan = 128; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
413 psmp->nLength = pams->length; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
414 psmp->nLoopStart = pams->loopstart; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
415 psmp->nLoopEnd = pams->loopend; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
416 psmp->nC4Speed = pams->c4speed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
417 psmp->RelativeTone = pams->transpose; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
418 psmp->nVolume = pams->volume / 2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
419 packedsamples[smpmap[ismp]] = pams->flags; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
420 if (pams->flags & 0x04) psmp->uFlags |= CHN_16BIT; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
421 if (pams->flags & 0x08) psmp->uFlags |= CHN_LOOP; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
422 if (pams->flags & 0x10) psmp->uFlags |= CHN_PINGPONGLOOP; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
423 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
424 dwMemPos += sizeof(AMS2SAMPLE); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
425 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
426 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
427 if (dwMemPos + 256 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
428 // Comments |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
429 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
430 UINT composernamelen = lpStream[dwMemPos]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
431 if (composernamelen) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
432 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
433 m_lpszSongComments = new char[composernamelen+1]; // changed from CHAR |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
434 if (m_lpszSongComments) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
435 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
436 memcpy(m_lpszSongComments, lpStream+dwMemPos+1, composernamelen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
437 m_lpszSongComments[composernamelen] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
438 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
439 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
440 dwMemPos += composernamelen + 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
441 // channel names |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
442 for (UINT i=0; i<32; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
443 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
444 UINT chnnamlen = lpStream[dwMemPos]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
445 if ((chnnamlen) && (chnnamlen < MAX_CHANNELNAME)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
446 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
447 memcpy(ChnSettings[i].szName, lpStream+dwMemPos+1, chnnamlen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
448 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
449 dwMemPos += chnnamlen + 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
450 if (dwMemPos + chnnamlen + 256 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
451 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
452 // packed comments (ignored) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
453 UINT songtextlen = *((LPDWORD)(lpStream+dwMemPos)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
454 dwMemPos += songtextlen; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
455 if (dwMemPos + 256 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
456 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
457 // Order List |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
458 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
459 for (UINT i=0; i<MAX_ORDERS; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
460 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
461 Order[i] = 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
462 if (dwMemPos + 2 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
463 if (i < psh->orders) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
464 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
465 Order[i] = lpStream[dwMemPos]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
466 dwMemPos += 2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
467 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
468 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
469 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
470 // Pattern Data |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
471 for (UINT ipat=0; ipat<psh->patterns; ipat++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
472 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
473 if (dwMemPos+8 >= dwMemLength) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
474 UINT packedlen = *((LPDWORD)(lpStream+dwMemPos)); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
475 UINT numrows = 1 + (UINT)(lpStream[dwMemPos+4]); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
476 //UINT patchn = 1 + (UINT)(lpStream[dwMemPos+5] & 0x1F); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
477 //UINT patcmds = 1 + (UINT)(lpStream[dwMemPos+5] >> 5); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
478 UINT patnamlen = lpStream[dwMemPos+6]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
479 dwMemPos += 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
480 if ((ipat < MAX_PATTERNS) && (packedlen < dwMemLength-dwMemPos) && (numrows >= 8)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
481 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
482 if ((patnamlen) && (patnamlen < MAX_PATTERNNAME)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
483 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
484 char s[MAX_PATTERNNAME]; // changed from CHAR |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
485 memcpy(s, lpStream+dwMemPos+3, patnamlen); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
486 s[patnamlen] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
487 SetPatternName(ipat, s); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
488 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
489 PatternSize[ipat] = numrows; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
490 Patterns[ipat] = AllocatePattern(numrows, m_nChannels); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
491 if (!Patterns[ipat]) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
492 // Unpack Pattern Data |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
493 LPCBYTE psrc = lpStream + dwMemPos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
494 UINT pos = 3 + patnamlen; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
495 UINT row = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
496 while ((pos < packedlen) && (row < numrows)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
497 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
498 MODCOMMAND *m = Patterns[ipat] + row * m_nChannels; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
499 UINT byte1 = psrc[pos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
500 UINT ch = byte1 & 0x1F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
501 // Read Note + Instr |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
502 if (!(byte1 & 0x40)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
503 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
504 UINT byte2 = psrc[pos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
505 UINT note = byte2 & 0x7F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
506 if (note) m[ch].note = (note > 1) ? (note-1) : 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
507 m[ch].instr = psrc[pos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
508 // Read Effect |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
509 while (byte2 & 0x80) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
510 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
511 byte2 = psrc[pos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
512 if (byte2 & 0x40) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
513 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
514 m[ch].volcmd = VOLCMD_VOLUME; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
515 m[ch].vol = byte2 & 0x3F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
516 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
517 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
518 UINT command = byte2 & 0x3F; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
519 UINT param = psrc[pos++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
520 if (command == 0x0C) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
521 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
522 m[ch].volcmd = VOLCMD_VOLUME; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
523 m[ch].vol = param / 2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
524 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
525 if (command < 0x10) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
526 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
527 m[ch].command = command; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
528 m[ch].param = param; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
529 ConvertModCommand(&m[ch]); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
530 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
531 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
532 // TODO: AMS effects |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
533 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
534 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
535 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
536 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
537 if (byte1 & 0x80) row++; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
538 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
539 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
540 dwMemPos += packedlen; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
541 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
542 // Read Samples |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
543 for (UINT iSmp=1; iSmp<=m_nSamples; iSmp++) if (Ins[iSmp].nLength) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
544 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
545 if (dwMemPos >= dwMemLength - 9) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
546 UINT flags; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
547 if (packedsamples[iSmp] & 0x03) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
548 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
549 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
550 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
551 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
552 flags = (Ins[iSmp].uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
553 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
554 dwMemPos += ReadSample(&Ins[iSmp], flags, (LPSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
555 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
556 return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
557 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
558 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
559 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
560 ///////////////////////////////////////////////////////////////////// |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
561 // AMS Sample unpacking |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
562 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
563 void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char packcharacter) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
564 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
565 UINT tmplen = dmax; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
566 signed char *amstmp = new signed char[tmplen]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
567 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
568 if (!amstmp) return; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
569 // Unpack Loop |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
570 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
571 signed char *p = amstmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
572 UINT i=0, j=0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
573 while ((i < inputlen) && (j < tmplen)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
574 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
575 signed char ch = psrc[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
576 if (ch == packcharacter) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
577 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
578 BYTE ch2 = psrc[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
579 if (ch2) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
580 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
581 ch = psrc[i++]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
582 while (ch2--) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
583 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
584 p[j++] = ch; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
585 if (j >= tmplen) break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
586 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
587 } else p[j++] = packcharacter; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
588 } else p[j++] = ch; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
589 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
590 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
591 // Bit Unpack Loop |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
592 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
593 signed char *p = amstmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
594 UINT bitcount = 0x80, dh; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
595 UINT k=0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
596 for (UINT i=0; i<dmax; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
597 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
598 BYTE al = *p++; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
599 dh = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
600 for (UINT count=0; count<8; count++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
601 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
602 UINT bl = al & bitcount; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
603 bl = ((bl|(bl<<8)) >> ((dh+8-count) & 7)) & 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
604 bitcount = ((bitcount|(bitcount<<8)) >> 1) & 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
605 pdest[k++] |= bl; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
606 if (k >= dmax) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
607 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
608 k = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
609 dh++; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
610 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
611 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
612 bitcount = ((bitcount|(bitcount<<8)) >> dh) & 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
613 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
614 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
615 // Delta Unpack |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
616 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
617 signed char old = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
618 for (UINT i=0; i<dmax; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
619 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
620 int pos = ((LPBYTE)pdest)[i]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
621 if ((pos != 128) && (pos & 0x80)) pos = -(pos & 0x7F); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
622 old -= (signed char)pos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
623 pdest[i] = old; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
624 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
625 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
626 delete amstmp; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
627 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
628 |