Mercurial > audlegacy-plugins
comparison src/modplug/load_mtm.cxx @ 2216:3673c7ec4ea2
Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 07 Dec 2007 12:08:47 -0600 |
parents | 6b5a52635b3b |
children | 6907fc39b53f |
comparison
equal
deleted
inserted
replaced
2198:32f9f1e4a9ec | 2216:3673c7ec4ea2 |
---|---|
57 || (pmh->numsamples >= MAX_SAMPLES) || (!pmh->numsamples) | 57 || (pmh->numsamples >= MAX_SAMPLES) || (!pmh->numsamples) |
58 || (!pmh->numtracks) || (!pmh->numchannels) | 58 || (!pmh->numtracks) || (!pmh->numchannels) |
59 || (!pmh->lastpattern) || (pmh->lastpattern > MAX_PATTERNS)) return FALSE; | 59 || (!pmh->lastpattern) || (pmh->lastpattern > MAX_PATTERNS)) return FALSE; |
60 strncpy(m_szNames[0], pmh->songname, 20); | 60 strncpy(m_szNames[0], pmh->songname, 20); |
61 m_szNames[0][20] = 0; | 61 m_szNames[0][20] = 0; |
62 if (dwMemPos + 37*pmh->numsamples + 128 + 192*pmh->numtracks | 62 if (dwMemPos + 37*pmh->numsamples + 128 + 192*bswapLE16(pmh->numtracks) |
63 + 64 * (pmh->lastpattern+1) + pmh->commentsize >= dwMemLength) return FALSE; | 63 + 64 * (pmh->lastpattern+1) + bswapLE16(pmh->commentsize) >= dwMemLength) return FALSE; |
64 m_nType = MOD_TYPE_MTM; | 64 m_nType = MOD_TYPE_MTM; |
65 m_nSamples = pmh->numsamples; | 65 m_nSamples = pmh->numsamples; |
66 m_nChannels = pmh->numchannels; | 66 m_nChannels = pmh->numchannels; |
67 // Reading instruments | 67 // Reading instruments |
68 for (UINT i=1; i<=m_nSamples; i++) | 68 for (UINT i=1; i<=m_nSamples; i++) |
70 MTMSAMPLE *pms = (MTMSAMPLE *)(lpStream + dwMemPos); | 70 MTMSAMPLE *pms = (MTMSAMPLE *)(lpStream + dwMemPos); |
71 strncpy(m_szNames[i], pms->samplename, 22); | 71 strncpy(m_szNames[i], pms->samplename, 22); |
72 m_szNames[i][22] = 0; | 72 m_szNames[i][22] = 0; |
73 Ins[i].nVolume = pms->volume << 2; | 73 Ins[i].nVolume = pms->volume << 2; |
74 Ins[i].nGlobalVol = 64; | 74 Ins[i].nGlobalVol = 64; |
75 DWORD len = pms->length; | 75 DWORD len = bswapLE32(pms->length); |
76 if ((len > 4) && (len <= MAX_SAMPLE_LENGTH)) | 76 if ((len > 4) && (len <= MAX_SAMPLE_LENGTH)) |
77 { | 77 { |
78 Ins[i].nLength = len; | 78 Ins[i].nLength = len; |
79 Ins[i].nLoopStart = pms->reppos; | 79 Ins[i].nLoopStart = bswapLE32(pms->reppos); |
80 Ins[i].nLoopEnd = pms->repend; | 80 Ins[i].nLoopEnd = bswapLE32(pms->repend); |
81 if (Ins[i].nLoopEnd > Ins[i].nLength) Ins[i].nLoopEnd = Ins[i].nLength; | 81 if (Ins[i].nLoopEnd > Ins[i].nLength) Ins[i].nLoopEnd = Ins[i].nLength; |
82 if (Ins[i].nLoopStart + 4 >= Ins[i].nLoopEnd) Ins[i].nLoopStart = Ins[i].nLoopEnd = 0; | 82 if (Ins[i].nLoopStart + 4 >= Ins[i].nLoopEnd) Ins[i].nLoopStart = Ins[i].nLoopEnd = 0; |
83 if (Ins[i].nLoopEnd) Ins[i].uFlags |= CHN_LOOP; | 83 if (Ins[i].nLoopEnd) Ins[i].uFlags |= CHN_LOOP; |
84 Ins[i].nFineTune = MOD2XMFineTune(pms->finetune); | 84 Ins[i].nFineTune = MOD2XMFineTune(pms->finetune); |
85 if (pms->attribute & 0x01) | 85 if (pms->attribute & 0x01) |
102 // Reading pattern order | 102 // Reading pattern order |
103 memcpy(Order, lpStream + dwMemPos, pmh->lastorder+1); | 103 memcpy(Order, lpStream + dwMemPos, pmh->lastorder+1); |
104 dwMemPos += 128; | 104 dwMemPos += 128; |
105 // Reading Patterns | 105 // Reading Patterns |
106 LPCBYTE pTracks = lpStream + dwMemPos; | 106 LPCBYTE pTracks = lpStream + dwMemPos; |
107 dwMemPos += 192 * pmh->numtracks; | 107 dwMemPos += 192 * bswapLE16(pmh->numtracks); |
108 LPWORD pSeq = (LPWORD)(lpStream + dwMemPos); | 108 LPWORD pSeq = (LPWORD)(lpStream + dwMemPos); |
109 for (UINT pat=0; pat<=pmh->lastpattern; pat++) | 109 for (UINT pat=0; pat<=pmh->lastpattern; pat++) |
110 { | 110 { |
111 PatternSize[pat] = 64; | 111 PatternSize[pat] = 64; |
112 PatternAllocSize[pat] = 64; | |
112 if ((Patterns[pat] = AllocatePattern(64, m_nChannels)) == NULL) break; | 113 if ((Patterns[pat] = AllocatePattern(64, m_nChannels)) == NULL) break; |
113 for (UINT n=0; n<32; n++) if ((pSeq[n]) && (pSeq[n] <= pmh->numtracks) && (n < m_nChannels)) | 114 for (UINT n=0; n<32; n++) if ((pSeq[n]) && (pSeq[n] <= bswapLE16(pmh->numtracks)) && (n < m_nChannels)) |
114 { | 115 { |
115 LPCBYTE p = pTracks + 192 * (pSeq[n]-1); | 116 LPCBYTE p = pTracks + 192 * (pSeq[n]-1); |
116 MODCOMMAND *m = Patterns[pat] + n; | 117 MODCOMMAND *m = Patterns[pat] + n; |
117 for (UINT i=0; i<64; i++, m+=m_nChannels, p+=3) | 118 for (UINT i=0; i<64; i++, m+=m_nChannels, p+=3) |
118 { | 119 { |
130 } | 131 } |
131 } | 132 } |
132 pSeq += 32; | 133 pSeq += 32; |
133 } | 134 } |
134 dwMemPos += 64*(pmh->lastpattern+1); | 135 dwMemPos += 64*(pmh->lastpattern+1); |
135 if ((pmh->commentsize) && (dwMemPos + pmh->commentsize < dwMemLength)) | 136 if (bswapLE16(pmh->commentsize) && (dwMemPos + bswapLE16(pmh->commentsize) < dwMemLength)) |
136 { | 137 { |
137 UINT n = pmh->commentsize; | 138 UINT n = bswapLE16(pmh->commentsize); |
138 m_lpszSongComments = new char[n+1]; | 139 m_lpszSongComments = new char[n+1]; |
139 if (m_lpszSongComments) | 140 if (m_lpszSongComments) |
140 { | 141 { |
141 memcpy(m_lpszSongComments, lpStream+dwMemPos, n); | 142 memcpy(m_lpszSongComments, lpStream+dwMemPos, n); |
142 m_lpszSongComments[n] = 0; | 143 m_lpszSongComments[n] = 0; |
147 m_lpszSongComments[i] = ((i+1) % 40) ? 0x20 : 0x0D; | 148 m_lpszSongComments[i] = ((i+1) % 40) ? 0x20 : 0x0D; |
148 } | 149 } |
149 } | 150 } |
150 } | 151 } |
151 } | 152 } |
152 dwMemPos += pmh->commentsize; | 153 dwMemPos += bswapLE16(pmh->commentsize); |
153 // Reading Samples | 154 // Reading Samples |
154 for (UINT ismp=1; ismp<=m_nSamples; ismp++) | 155 for (UINT ismp=1; ismp<=m_nSamples; ismp++) |
155 { | 156 { |
156 if (dwMemPos >= dwMemLength) break; | 157 if (dwMemPos >= dwMemLength) break; |
157 dwMemPos += ReadSample(&Ins[ismp], (Ins[ismp].uFlags & CHN_16BIT) ? RS_PCM16U : RS_PCM8U, | 158 dwMemPos += ReadSample(&Ins[ismp], (Ins[ismp].uFlags & CHN_16BIT) ? RS_PCM16U : RS_PCM8U, |