dependencies/SDL_sound/libmodplug/load_far.c in gosu-1.3.0 vs dependencies/SDL_sound/libmodplug/load_far.c in gosu-1.4.0
- old
+ new
@@ -3,11 +3,11 @@
*
* Authors: Olivier Lapicque <olivierl@jps.net>
*/
////////////////////////////////////////
-// Farandole (FAR) module loader //
+// Farandole (FAR) module loader //
////////////////////////////////////////
#include "libmodplug.h"
#define FARFILEMAGIC 0xFE524146 // "FAR"
@@ -100,37 +100,35 @@
_this->m_nRestartPos = pmh2->loopto;
// Reading Patterns
dwMemPos += headerlen - (869 + stlen);
if (dwMemPos >= dwMemLength) return TRUE;
- // end byteswap of pattern data
-
WORD *patsiz = (WORD *)pmh2->patsiz;
for (UINT ipat=0; ipat<256; ipat++) if (patsiz[ipat])
{
UINT patlen = bswapLE16(patsiz[ipat]);
if ((ipat >= MAX_PATTERNS) || (patlen < 2))
{
dwMemPos += patlen;
continue;
}
if (dwMemPos + patlen >= dwMemLength) return TRUE;
+ UINT max = (patlen - 2) & ~3;
UINT rows = (patlen - 2) >> 6;
if (!rows)
{
dwMemPos += patlen;
continue;
}
if (rows > 256) rows = 256;
if (rows < 16) rows = 16;
+ if (max > rows*16*4) max = rows*16*4;
_this->PatternSize[ipat] = rows;
if ((_this->Patterns[ipat] = CSoundFile_AllocatePattern(rows, _this->m_nChannels)) == NULL) return TRUE;
MODCOMMAND *m = _this->Patterns[ipat];
UINT patbrk = lpStream[dwMemPos];
const BYTE *p = lpStream + dwMemPos + 2;
- UINT max = rows*16*4;
- if (max > patlen-2) max = patlen-2;
for (UINT len=0; len<max; len += 4, m++)
{
BYTE note = p[len];
BYTE ins = p[len+1];
BYTE vol = p[len+2];
@@ -138,15 +136,14 @@
if (note)
{
m->instr = ins + 1;
m->note = note + 36;
}
- if (vol & 0x0F)
+ if (vol >= 0x01 && vol <= 0x10)
{
m->volcmd = VOLCMD_VOLUME;
- m->vol = (vol & 0x0F) << 2;
- if (m->vol <= 4) m->vol = 0;
+ m->vol = (vol - 1) << 2;
}
switch(eff & 0xF0)
{
// 1.x: Portamento Up
case 0x10:
@@ -222,14 +219,14 @@
{
if (dwMemPos + sizeof(FARSAMPLE) > dwMemLength) return TRUE;
const FARSAMPLE *pfs = (const FARSAMPLE*)(lpStream + dwMemPos);
dwMemPos += sizeof(FARSAMPLE);
_this->m_nSamples = ismp + 1;
- const DWORD length = bswapLE32( pfs->length ) ; /* endian fix - Toad */
- pins->nLength = length ;
- pins->nLoopStart = bswapLE32(pfs->reppos) ;
- pins->nLoopEnd = bswapLE32(pfs->repend) ;
+ const DWORD length = bswapLE32(pfs->length); /* endian fix - Toad */
+ pins->nLength = length;
+ pins->nLoopStart = bswapLE32(pfs->reppos);
+ pins->nLoopEnd = bswapLE32(pfs->repend);
pins->nFineTune = 0;
pins->nC4Speed = 8363*2;
pins->nGlobalVol = 64;
pins->nVolume = pfs->volume << 4;
pins->uFlags = 0;
@@ -248,6 +245,5 @@
}
dwMemPos += length;
}
return TRUE;
}
-