|
From: <rel...@us...> - 2008-07-25 20:20:22
|
Revision: 216
http://modplug.svn.sourceforge.net/modplug/?rev=216&view=rev
Author: relabsoluness
Date: 2008-07-25 20:20:15 +0000 (Fri, 25 Jul 2008)
Log Message:
-----------
./ Merged module loaders from libmodplug along with some tiny changes; should not affect functionality.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/LOAD_AMF.CPP
trunk/OpenMPT/soundlib/LOAD_DBM.CPP
trunk/OpenMPT/soundlib/LOAD_DMF.CPP
trunk/OpenMPT/soundlib/LOAD_DSM.CPP
trunk/OpenMPT/soundlib/Load_669.cpp
trunk/OpenMPT/soundlib/Load_ams.cpp
trunk/OpenMPT/soundlib/Load_far.cpp
trunk/OpenMPT/soundlib/Load_mdl.cpp
trunk/OpenMPT/soundlib/Load_med.cpp
trunk/OpenMPT/soundlib/Load_mod.cpp
trunk/OpenMPT/soundlib/Load_mt2.cpp
trunk/OpenMPT/soundlib/Load_mtm.cpp
trunk/OpenMPT/soundlib/Load_okt.cpp
trunk/OpenMPT/soundlib/Load_psm.cpp
trunk/OpenMPT/soundlib/Load_ptm.cpp
trunk/OpenMPT/soundlib/Load_s3m.cpp
trunk/OpenMPT/soundlib/Load_stm.cpp
trunk/OpenMPT/soundlib/Load_ult.cpp
trunk/OpenMPT/soundlib/Load_umx.cpp
trunk/OpenMPT/soundlib/Load_wav.cpp
trunk/OpenMPT/soundlib/Load_xm.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/load_j2b.cpp
Modified: trunk/OpenMPT/soundlib/LOAD_AMF.CPP
===================================================================
--- trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
///////////////////////////////////////////////////
@@ -21,7 +21,7 @@
//#define AMFLOG
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#pragma pack(1)
@@ -58,7 +58,7 @@
//-------------------------------------------------------------------------------
{
UINT lastinstr = 0;
- UINT nTrkSize = *(USHORT *)pTrack;
+ UINT nTrkSize = LittleEndianW(*(USHORT *)pTrack);
nTrkSize += (UINT)pTrack[2] << 16;
pTrack += 3;
while (nTrkSize--)
@@ -168,7 +168,7 @@
BOOL CSoundFile::ReadAMF(LPCBYTE lpStream, DWORD dwMemLength)
//-----------------------------------------------------------
{
- AMFFILEHEADER *pfh = (AMFFILEHEADER *)lpStream;
+ const AMFFILEHEADER *pfh = (AMFFILEHEADER *)lpStream;
DWORD dwMemPos;
if ((!lpStream) || (dwMemLength < 2048)) return FALSE;
@@ -203,9 +203,9 @@
psmp->nGlobalVol = 64;
if (psmp->nVolume > 0x40) psmp->nVolume = 0x40;
psmp->nVolume <<= 2;
- psmp->nLength = *((LPDWORD)(lpStream+dwMemPos+25));
- psmp->nLoopStart = *((LPDWORD)(lpStream+dwMemPos+29));
- psmp->nLoopEnd = psmp->nLoopStart + *((LPDWORD)(lpStream+dwMemPos+33));
+ psmp->nLength = LittleEndian(*((LPDWORD)(lpStream+dwMemPos+25)));
+ psmp->nLoopStart = LittleEndian(*((LPDWORD)(lpStream+dwMemPos+29)));
+ psmp->nLoopEnd = psmp->nLoopStart + LittleEndian(*((LPDWORD)(lpStream+dwMemPos+33)));
if ((psmp->nLoopEnd > psmp->nLoopStart) && (psmp->nLoopEnd <= psmp->nLength))
{
psmp->uFlags = CHN_LOOP;
@@ -262,7 +262,7 @@
DWORD sampleseekpos[MAX_SAMPLES];
if ((pfh->szAMF[0] != 'A') || (pfh->szAMF[1] != 'M') || (pfh->szAMF[2] != 'F')
- || (pfh->version < 10) || (pfh->version > 14) || (!pfh->numtracks)
+ || (pfh->version < 10) || (pfh->version > 14) || (!LittleEndianW(pfh->numtracks))
|| (!pfh->numorders) || (pfh->numorders > MAX_PATTERNS)
|| (!pfh->numsamples) || (pfh->numsamples > MAX_SAMPLES)
|| (pfh->numchannels < 4) || (pfh->numchannels > 32))
@@ -313,7 +313,7 @@
Patterns[iOrd].Resize(64);
if (pfh->version >= 14)
{
- Patterns[iOrd].Resize(*(USHORT *)(lpStream+dwMemPos));
+ Patterns[iOrd].Resize(LittleEndianW(*(USHORT *)(lpStream+dwMemPos)));
dwMemPos += 2;
}
ptracks[iOrd] = (USHORT *)(lpStream+dwMemPos);
@@ -331,26 +331,27 @@
dwMemPos += sizeof(AMFSAMPLE);
memcpy(m_szNames[iIns+1], psh->samplename, 32);
memcpy(pins->name, psh->filename, 13);
- pins->nLength = psh->length;
- pins->nC4Speed = psh->c2spd;
+ pins->nLength = LittleEndian(psh->length);
+ pins->nC4Speed = LittleEndianW(psh->c2spd);
pins->nGlobalVol = 64;
pins->nVolume = psh->volume * 4;
if (pfh->version >= 11)
{
- pins->nLoopStart = *(DWORD *)(lpStream+dwMemPos);
- pins->nLoopEnd = *(DWORD *)(lpStream+dwMemPos+4);
+ pins->nLoopStart = LittleEndian(*(DWORD *)(lpStream+dwMemPos));
+ pins->nLoopEnd = LittleEndian(*(DWORD *)(lpStream+dwMemPos+4));
dwMemPos += 8;
} else
{
- pins->nLoopStart = *(WORD *)(lpStream+dwMemPos);
+ pins->nLoopStart = LittleEndianW(*(WORD *)(lpStream+dwMemPos));
pins->nLoopEnd = pins->nLength;
dwMemPos += 2;
}
sampleseekpos[iIns] = 0;
- if ((psh->type) && (psh->offset < dwMemLength-1))
+ if ((psh->type) && (LittleEndian(psh->offset) < dwMemLength-1))
{
- sampleseekpos[iIns] = psh->offset;
- if (psh->offset > maxsampleseekpos) maxsampleseekpos = psh->offset;
+ sampleseekpos[iIns] = LittleEndian(psh->offset);
+ if (LittleEndian(psh->offset) > maxsampleseekpos)
+ maxsampleseekpos = LittleEndian(psh->offset);
if ((pins->nLoopEnd > pins->nLoopStart + 2)
&& (pins->nLoopEnd <= pins->nLength)) pins->uFlags |= CHN_LOOP;
}
@@ -368,7 +369,7 @@
memset(pTrackData, 0, sizeof(pTrackData));
for (UINT iTrack=0; iTrack<realtrackcnt; iTrack++) if (dwMemPos + 3 <= dwMemLength)
{
- UINT nTrkSize = *(USHORT *)(lpStream+dwMemPos);
+ UINT nTrkSize = LittleEndianW(*(USHORT *)(lpStream+dwMemPos));
nTrkSize += (UINT)lpStream[dwMemPos+2] << 16;
if (dwMemPos + nTrkSize * 3 + 3 <= dwMemLength)
{
@@ -384,10 +385,10 @@
Patterns[iPat] = p;
for (UINT iChn=0; iChn<m_nChannels; iChn++)
{
- UINT nTrack = ptracks[iPat][iChn];
+ UINT nTrack = LittleEndianW(ptracks[iPat][iChn]);
if ((nTrack) && (nTrack <= pfh->numtracks))
{
- UINT realtrk = pTrackMap[nTrack-1];
+ UINT realtrk = LittleEndianW(pTrackMap[nTrack-1]);
if (realtrk)
{
realtrk--;
Modified: trunk/OpenMPT/soundlib/LOAD_DBM.CPP
===================================================================
--- trunk/OpenMPT/soundlib/LOAD_DBM.CPP 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/LOAD_DBM.CPP 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,11 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
///////////////////////////////////////////////////////////////
@@ -18,7 +19,7 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#define DBM_FILE_MAGIC 0x304d4244
#define DBM_ID_NAME 0x454d414e
@@ -99,7 +100,7 @@
BOOL CSoundFile::ReadDBM(const BYTE *lpStream, DWORD dwMemLength)
//---------------------------------------------------------------
{
- DBMFILEHEADER *pfh = (DBMFILEHEADER *)lpStream;
+ const DBMFILEHEADER *pfh = (DBMFILEHEADER *)lpStream;
DWORD dwMemPos;
UINT nOrders, nSamples, nInstruments, nPatterns;
@@ -152,7 +153,6 @@
nsmp = BigEndianW(pih->sampleno);
psmp = ((nsmp) && (nsmp < MAX_SAMPLES)) ? &Ins[nsmp] : NULL;
memset(penv, 0, sizeof(INSTRUMENTHEADER));
- penv->pTuning = penv->s_DefaultTuning;
memcpy(penv->name, pih->name, 30);
if (psmp)
{
Modified: trunk/OpenMPT/soundlib/LOAD_DMF.CPP
===================================================================
--- trunk/OpenMPT/soundlib/LOAD_DMF.CPP 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/LOAD_DMF.CPP 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
///////////////////////////////////////////////////////
@@ -15,7 +15,7 @@
//#define DMFLOG
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#pragma pack(1)
@@ -89,7 +89,7 @@
BOOL CSoundFile::ReadDMF(const BYTE *lpStream, DWORD dwMemLength)
//---------------------------------------------------------------
{
- DMFHEADER *pfh = (DMFHEADER *)lpStream;
+ const DMFHEADER *pfh = (DMFHEADER *)lpStream;
DMFINFO *psi;
DMFSEQU *sequ;
DWORD dwMemPos;
@@ -121,7 +121,7 @@
if ((psi->infosize > dwMemLength) || (psi->infosize + dwMemPos + 8 > dwMemLength)) goto dmfexit;
if ((psi->infosize >= 8) && (!m_lpszSongComments))
{
- m_lpszSongComments = new CHAR[psi->infosize];
+ m_lpszSongComments = new char[psi->infosize];
if (m_lpszSongComments)
{
for (UINT i=0; i<psi->infosize-1; i++)
Modified: trunk/OpenMPT/soundlib/LOAD_DSM.CPP
===================================================================
--- trunk/OpenMPT/soundlib/LOAD_DSM.CPP 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/LOAD_DSM.CPP 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ *
*/
//////////////////////////////////////////////
Modified: trunk/OpenMPT/soundlib/Load_669.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_669.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_669.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,11 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
////////////////////////////////////////////////////////////
@@ -14,12 +15,12 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
typedef struct tagFILEHEADER669
{
WORD sig; // 'if' or 'JN'
- char songmessage[108]; // Song Message
+ signed char songmessage[108]; // Song Message
BYTE samples; // number of samples (1-64)
BYTE patterns; // number of patterns (1-128)
BYTE restartpos;
@@ -47,15 +48,15 @@
DWORD dwMemPos = 0;
if ((!lpStream) || (dwMemLength < sizeof(FILEHEADER669))) return FALSE;
- if ((pfh->sig != 0x6669) && (pfh->sig != 0x4E4A)) return FALSE;
- b669Ext = (pfh->sig == 0x4E4A) ? TRUE : FALSE;
+ if ((LittleEndianW(pfh->sig) != 0x6669) && (LittleEndianW(pfh->sig) != 0x4E4A)) return FALSE;
+ b669Ext = (LittleEndianW(pfh->sig) == 0x4E4A) ? TRUE : FALSE;
if ((!pfh->samples) || (pfh->samples > 64) || (pfh->restartpos >= 128)
|| (!pfh->patterns) || (pfh->patterns > 128)) return FALSE;
DWORD dontfuckwithme = 0x1F1 + pfh->samples * sizeof(SAMPLE669) + pfh->patterns * 0x600;
if (dontfuckwithme > dwMemLength) return FALSE;
for (UINT ichk=0; ichk<pfh->samples; ichk++)
{
- DWORD len = *((DWORD *)(&psmp[ichk].length));
+ DWORD len = LittleEndian(*((DWORD *)(&psmp[ichk].length)));
dontfuckwithme += len;
}
if (dontfuckwithme > dwMemLength) return FALSE;
@@ -71,9 +72,9 @@
m_nSamples = pfh->samples;
for (UINT nins=1; nins<=m_nSamples; nins++, psmp++)
{
- DWORD len = *((DWORD *)(&psmp->length));
- DWORD loopstart = *((DWORD *)(&psmp->loopstart));
- DWORD loopend = *((DWORD *)(&psmp->loopend));
+ DWORD len = LittleEndian(*((DWORD *)(&psmp->length)));
+ DWORD loopstart = LittleEndian(*((DWORD *)(&psmp->loopstart)));
+ DWORD loopend = LittleEndian(*((DWORD *)(&psmp->loopend)));
if (len > MAX_SAMPLE_LENGTH) len = MAX_SAMPLE_LENGTH;
if ((loopend > len) && (!loopstart)) loopend = 0;
if (loopend > len) loopend = len;
Modified: trunk/OpenMPT/soundlib/Load_ams.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_ams.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_ams.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
//////////////////////////////////////////////
@@ -13,13 +13,13 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#pragma pack(1)
typedef struct AMSFILEHEADER
{
- CHAR szHeader[7]; // "Extreme"
+ char szHeader[7]; // "Extreme"
BYTE verlo, verhi; // 0x??,0x01
BYTE chncfg;
BYTE samples;
@@ -107,7 +107,7 @@
dwMemPos += tmp;
}
// Read Pattern Names
- m_lpszPatternNames = new CHAR[pfh->patterns * 32];
+ m_lpszPatternNames = new char[pfh->patterns * 32];
if (!m_lpszPatternNames) return TRUE;
m_nPatternNames = pfh->patterns;
memset(m_lpszPatternNames, 0, m_nPatternNames * 32);
@@ -125,7 +125,7 @@
if (dwMemPos + tmp >= dwMemLength) return TRUE;
if (tmp)
{
- m_lpszSongComments = new CHAR[tmp+1];
+ m_lpszSongComments = new char[tmp+1];
if (!m_lpszSongComments) return TRUE;
memset(m_lpszSongComments, 0, tmp+1);
memcpy(m_lpszSongComments, lpStream + dwMemPos, tmp);
@@ -312,7 +312,7 @@
BOOL CSoundFile::ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength)
//------------------------------------------------------------
{
- AMS2FILEHEADER *pfh = (AMS2FILEHEADER *)lpStream;
+ const AMS2FILEHEADER *pfh = (AMS2FILEHEADER *)lpStream;
AMS2SONGHEADER *psh;
DWORD dwMemPos;
BYTE smpmap[16];
@@ -356,7 +356,6 @@
if (!penv) return TRUE;
memset(smpmap, 0, sizeof(smpmap));
memset(penv, 0, sizeof(INSTRUMENTHEADER));
- penv->pTuning = penv->s_DefaultTuning;
for (UINT ismpmap=0; ismpmap<pins->samples; ismpmap++)
{
if ((ismpmap >= 16) || (m_nSamples+1 >= MAX_SAMPLES)) break;
@@ -434,7 +433,7 @@
UINT composernamelen = lpStream[dwMemPos];
if (composernamelen)
{
- m_lpszSongComments = new CHAR[composernamelen+1];
+ m_lpszSongComments = new char[composernamelen+1];
if (m_lpszSongComments)
{
memcpy(m_lpszSongComments, lpStream+dwMemPos+1, composernamelen);
@@ -485,7 +484,7 @@
{
if ((patnamlen) && (patnamlen < MAX_PATTERNNAME))
{
- CHAR s[MAX_PATTERNNAME];
+ char s[MAX_PATTERNNAME];
memcpy(s, lpStream+dwMemPos+3, patnamlen);
s[patnamlen] = 0;
SetPatternName(ipat, s);
@@ -565,16 +564,16 @@
void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char packcharacter)
{
UINT tmplen = dmax;
- char *amstmp = new char[tmplen];
+ signed char *amstmp = new signed char[tmplen];
if (!amstmp) return;
// Unpack Loop
{
- char *p = amstmp;
+ signed char *p = amstmp;
UINT i=0, j=0;
while ((i < inputlen) && (j < tmplen))
{
- char ch = psrc[i++];
+ signed char ch = psrc[i++];
if (ch == packcharacter)
{
BYTE ch2 = psrc[i++];
@@ -592,7 +591,7 @@
}
// Bit Unpack Loop
{
- char *p = amstmp;
+ signed char *p = amstmp;
UINT bitcount = 0x80, dh;
UINT k=0;
for (UINT i=0; i<dmax; i++)
@@ -616,12 +615,12 @@
}
// Delta Unpack
{
- char old = 0;
+ signed char old = 0;
for (UINT i=0; i<dmax; i++)
{
int pos = ((LPBYTE)pdest)[i];
if ((pos != 128) && (pos & 0x80)) pos = -(pos & 0x7F);
- old -= (char)pos;
+ old -= (signed char)pos;
pdest[i] = old;
}
}
Modified: trunk/OpenMPT/soundlib/Load_far.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_far.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_far.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
////////////////////////////////////////
@@ -13,7 +13,7 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#define FARFILEMAGIC 0xFE524146 // "FAR"
@@ -61,15 +61,21 @@
BOOL CSoundFile::ReadFAR(const BYTE *lpStream, DWORD dwMemLength)
//---------------------------------------------------------------
{
- FARHEADER1 *pmh1 = (FARHEADER1 *)lpStream;
+ if(dwMemLength < sizeof(FARHEADER1))
+ return FALSE;
+
+ FARHEADER1 farHeader;
+ memcpy(&farHeader, lpStream, sizeof(FARHEADER1));
+ FARHEADER1 *pmh1 = &farHeader;
FARHEADER2 *pmh2;
DWORD dwMemPos = sizeof(FARHEADER1);
UINT headerlen;
BYTE samplemap[8];
- if ((!lpStream) || (dwMemLength < 1024) || (pmh1->id != FARFILEMAGIC)
+ if ((!lpStream) || (dwMemLength < 1024) || (LittleEndian(pmh1->id) != FARFILEMAGIC)
|| (pmh1->magic2[0] != 13) || (pmh1->magic2[1] != 10) || (pmh1->magic2[2] != 26)) return FALSE;
- headerlen = pmh1->headerlen;
+ headerlen = LittleEndianW(pmh1->headerlen);
+ pmh1->stlen = LittleEndianW( pmh1->stlen ); /* inplace byteswap -- Toad */
if ((headerlen >= dwMemLength) || (dwMemPos + pmh1->stlen + sizeof(FARHEADER2) >= dwMemLength)) return FALSE;
// Globals
m_nType = MOD_TYPE_FAR;
@@ -80,6 +86,7 @@
m_nDefaultSpeed = pmh1->speed;
m_nDefaultTempo = 80;
m_nDefaultGlobalVolume = 256;
+
memcpy(m_szNames[0], pmh1->songname, 32);
// Channel Setting
for (UINT nchpan=0; nchpan<16; nchpan++)
@@ -101,7 +108,10 @@
dwMemPos += pmh1->stlen;
}
// Reading orders
- pmh2 = (FARHEADER2 *)(lpStream + dwMemPos);
+ if (sizeof(FARHEADER2) > dwMemLength - dwMemPos) return TRUE;
+ FARHEADER2 farHeader2;
+ memcpy(&farHeader2, lpStream + dwMemPos, sizeof(FARHEADER2));
+ pmh2 = &farHeader2;
dwMemPos += sizeof(FARHEADER2);
if (dwMemPos >= dwMemLength) return TRUE;
for (UINT iorder=0; iorder<MAX_ORDERS; iorder++)
@@ -112,6 +122,14 @@
// Reading Patterns
dwMemPos += headerlen - (869 + pmh1->stlen);
if (dwMemPos >= dwMemLength) return TRUE;
+
+ // byteswap pattern data.
+ for(uint16 psfix = 256; psfix--;)
+ {
+ pmh2->patsiz[psfix] = LittleEndianW( pmh2->patsiz[psfix] ) ;
+ }
+ // end byteswap of pattern data
+
WORD *patsiz = (WORD *)pmh2->patsiz;
for (UINT ipat=0; ipat<256; ipat++) if (patsiz[ipat])
{
@@ -228,13 +246,14 @@
for (UINT ismp=0; ismp<64; ismp++, pins++) if (samplemap[ismp >> 3] & (1 << (ismp & 7)))
{
if (dwMemPos + sizeof(FARSAMPLE) > dwMemLength) return TRUE;
- FARSAMPLE *pfs = (FARSAMPLE *)(lpStream + dwMemPos);
+ const FARSAMPLE *pfs = reinterpret_cast<const FARSAMPLE*>(lpStream + dwMemPos);
dwMemPos += sizeof(FARSAMPLE);
m_nSamples = ismp + 1;
memcpy(m_szNames[ismp+1], pfs->samplename, 32);
- pins->nLength = pfs->length;
- pins->nLoopStart = pfs->reppos;
- pins->nLoopEnd = pfs->repend;
+ const DWORD length = LittleEndian( pfs->length );
+ pins->nLength = length;
+ pins->nLoopStart = LittleEndian(pfs->reppos) ;
+ pins->nLoopEnd = LittleEndian(pfs->repend) ;
pins->nFineTune = 0;
pins->nC4Speed = 8363*2;
pins->nGlobalVol = 64;
@@ -253,7 +272,7 @@
ReadSample(pins, (pins->uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S,
(LPSTR)(lpStream+dwMemPos), dwMemLength - dwMemPos);
}
- dwMemPos += pfs->length;
+ dwMemPos += length;
}
return TRUE;
}
Modified: trunk/OpenMPT/soundlib/Load_mdl.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mdl.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_mdl.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,9 +1,8 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
*/
@@ -15,7 +14,7 @@
//#define MDL_LOG
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
typedef struct MDLSONGHEADER
{
@@ -328,7 +327,6 @@
if ((Headers[nins] = new INSTRUMENTHEADER) == NULL) break;
INSTRUMENTHEADER *penv = Headers[nins];
memset(penv, 0, sizeof(INSTRUMENTHEADER));
- penv->pTuning = penv->s_DefaultTuning;
memcpy(penv->name, lpStream+dwPos+2, 32);
penv->nGlobalVol = 64;
penv->nPPC = 5*12;
Modified: trunk/OpenMPT/soundlib/Load_med.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_med.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_med.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
#include "stdafx.h"
@@ -493,7 +493,7 @@
// Check for 'MMDx'
DWORD dwSong = BigEndian(pmmh->song);
if ((dwSong >= dwMemLength) || (dwSong + sizeof(MMD0SONGHEADER) >= dwMemLength)) return FALSE;
- version = (char)((pmmh->id >> 24) & 0xFF);
+ version = (signed char)((pmmh->id >> 24) & 0xFF);
if ((version < '0') || (version > '3')) return FALSE;
#ifdef MED_LOG
Log("\nLoading MMD%c module (flags=0x%02X)...\n", version, BigEndian(pmmh->mmdflags));
@@ -699,7 +699,7 @@
UINT annotxt = BigEndian(pmex->annotxt);
UINT annolen = BigEndian(pmex->annolen);
annolen = min(annolen, MED_MAX_COMMENT_LENGTH); //Thanks to Luigi Auriemma for pointing out an overflow risk
- if ((annotxt) && (annolen) && (annotxt+annolen <= dwMemLength) ) {
+ if ((annotxt) && (annolen) && (annolen <= dwMemLength) && (annotxt <= dwMemLength - annolen) ) {
m_lpszSongComments = new char[annolen+1];
if (m_lpszSongComments) {
memcpy(m_lpszSongComments, lpStream+annotxt, annolen);
Modified: trunk/OpenMPT/soundlib/Load_mod.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mod.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_mod.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,16 +1,17 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
extern WORD ProTrackerPeriodTable[6*12];
@@ -98,7 +99,7 @@
command = 0x08;
if (bXM)
{
- if ((m_nType & (MOD_TYPE_IT|MOD_TYPE_MPT)) && (m_nType != MOD_TYPE_XM) && (param <= 0x80))
+ if (!(m_nType & (MOD_TYPE_IT|MOD_TYPE_MPT)) && (m_nType != MOD_TYPE_XM) && (param <= 0x80))
{
param <<= 1;
if (param > 255) param = 255;
@@ -170,7 +171,7 @@
BYTE nOrders;
BYTE nRestartPos;
BYTE Orders[128];
- CHAR Magic[4];
+ char Magic[4];
} MODMAGIC, *PMODMAGIC;
#pragma pack()
@@ -184,7 +185,7 @@
BOOL CSoundFile::ReadMod(const BYTE *lpStream, DWORD dwMemLength)
//---------------------------------------------------------------
{
- CHAR s[1024];
+ char s[1024];
DWORD dwMemPos, dwTotalSampleLen;
PMODMAGIC pMagic;
UINT nErr;
Modified: trunk/OpenMPT/soundlib/Load_mt2.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mt2.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_mt2.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -250,7 +250,7 @@
{
DWORD nTxtLen = dwLen;
if (nTxtLen > 32000) nTxtLen = 32000;
- m_lpszSongComments = new CHAR[nTxtLen];
+ m_lpszSongComments = new char[nTxtLen];
if (m_lpszSongComments)
{
memcpy(m_lpszSongComments, lpStream+dwMemPos+1, nTxtLen-1);
@@ -405,7 +405,6 @@
if (penv)
{
memset(penv, 0, sizeof(INSTRUMENTHEADER));
- penv->pTuning = penv->s_DefaultTuning;
memcpy(penv->name, pmi->szName, 32);
penv->nGlobalVol = 64;
penv->nPan = 128;
Modified: trunk/OpenMPT/soundlib/Load_mtm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mtm.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_mtm.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,16 +1,16 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ *
*/
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
//////////////////////////////////////////////////////////
// MTM file support (import only)
@@ -19,7 +19,7 @@
typedef struct tagMTMSAMPLE
{
- CHAR samplename[22];
+ char samplename[22];
DWORD length;
DWORD reppos;
DWORD repend;
@@ -31,8 +31,8 @@
typedef struct tagMTMHEADER
{
- CHAR id[4]; // MTM file marker + version
- CHAR songname[20]; // ASCIIZ songname
+ char id[4]; // MTM file marker + version
+ char songname[20]; // ASCIIZ songname
WORD numtracks; // number of tracks saved
BYTE lastpattern; // last pattern number saved
BYTE lastorder; // last order number to play (songlength-1)
Modified: trunk/OpenMPT/soundlib/Load_okt.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_okt.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_okt.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,11 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ *
*/
//////////////////////////////////////////////
@@ -13,7 +14,7 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
typedef struct OKTFILEHEADER
{
Modified: trunk/OpenMPT/soundlib/Load_psm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_psm.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_psm.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,8 +1,5 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
* Authors: Olivier Lapicque <oli...@jp...>
*/
Modified: trunk/OpenMPT/soundlib/Load_ptm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_ptm.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_ptm.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,11 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
//////////////////////////////////////////////
@@ -13,7 +14,7 @@
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#pragma pack(1)
@@ -52,7 +53,7 @@
WORD loopbeg[2]; // start of loop
WORD loopend[2]; // end of loop
WORD gusdata[8];
- CHAR samplename[28]; // name of sample, asciiz
+ char samplename[28]; // name of sample, asciiz
DWORD ptms_id; // sample identification, 'PTMS' or 0x534d5450
} PTMSAMPLE;
@@ -64,29 +65,42 @@
BOOL CSoundFile::ReadPTM(const BYTE *lpStream, DWORD dwMemLength)
//---------------------------------------------------------------
{
- LPPTMFILEHEADER pfh = (LPPTMFILEHEADER)lpStream;
+ PTMFILEHEADER pfh = *(LPPTMFILEHEADER)lpStream;
DWORD dwMemPos;
UINT nOrders;
+ pfh.norders = LittleEndianW(pfh.norders);
+ pfh.nsamples = LittleEndianW(pfh.nsamples);
+ pfh.npatterns = LittleEndianW(pfh.npatterns);
+ pfh.nchannels = LittleEndianW(pfh.nchannels);
+ pfh.fileflags = LittleEndianW(pfh.fileflags);
+ pfh.reserved2 = LittleEndianW(pfh.reserved2);
+ pfh.ptmf_id = LittleEndian(pfh.ptmf_id);
+ for (UINT j=0; j<128; j++)
+ {
+ pfh.patseg[j] = LittleEndianW(pfh.patseg[j]);
+ }
+
if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
- if ((pfh->ptmf_id != 0x464d5450) || (!pfh->nchannels) || (pfh->nchannels > 32)
- || (pfh->norders > 256) || (!pfh->norders)
- || (!pfh->nsamples) || (pfh->nsamples > 255)
- || (!pfh->npatterns) || (pfh->npatterns > 128)
- || (SIZEOF_PTMFILEHEADER+pfh->nsamples*SIZEOF_PTMSAMPLE >= (int)dwMemLength)) return FALSE;
- memcpy(m_szNames[0], pfh->songname, 28);
+ if ((pfh.ptmf_id != 0x464d5450) || (!pfh.nchannels)
+ || (pfh.nchannels > 32)
+ || (pfh.norders > 256) || (!pfh.norders)
+ || (!pfh.nsamples) || (pfh.nsamples > 255)
+ || (!pfh.npatterns) || (pfh.npatterns > 128)
+ || (SIZEOF_PTMFILEHEADER+pfh.nsamples*SIZEOF_PTMSAMPLE >= (int)dwMemLength)) return FALSE;
+ memcpy(m_szNames[0], pfh.songname, 28);
m_szNames[0][28] = 0;
m_nType = MOD_TYPE_PTM;
- m_nChannels = pfh->nchannels;
- m_nSamples = (pfh->nsamples < MAX_SAMPLES) ? pfh->nsamples : MAX_SAMPLES-1;
+ m_nChannels = pfh.nchannels;
+ m_nSamples = (pfh.nsamples < MAX_SAMPLES) ? pfh.nsamples : MAX_SAMPLES-1;
dwMemPos = SIZEOF_PTMFILEHEADER;
- nOrders = (pfh->norders < MAX_ORDERS) ? pfh->norders : MAX_ORDERS-1;
- Order.ReadAsByte(pfh->orders, nOrders, nOrders);
+ nOrders = (pfh.norders < MAX_ORDERS) ? pfh.norders : MAX_ORDERS-1;
+ Order.ReadAsByte(pfh.orders, nOrders, nOrders);
for (UINT ipan=0; ipan<m_nChannels; ipan++)
{
ChnSettings[ipan].nVolume = 64;
- ChnSettings[ipan].nPan = ((pfh->chnpan[ipan] & 0x0F) << 4) + 4;
+ ChnSettings[ipan].nPan = ((pfh.chnpan[ipan] & 0x0F) << 4) + 4;
}
for (UINT ismp=0; ismp<m_nSamples; ismp++, dwMemPos += SIZEOF_PTMSAMPLE)
{
@@ -99,16 +113,16 @@
pins->nGlobalVol = 64;
pins->nPan = 128;
pins->nVolume = psmp->volume << 2;
- pins->nC4Speed = psmp->nC4Spd << 1;
+ pins->nC4Speed = LittleEndianW(psmp->nC4Spd) << 1;
pins->uFlags = 0;
if ((psmp->sampletype & 3) == 1)
{
UINT smpflg = RS_PCM8D;
DWORD samplepos;
- pins->nLength = *(LPDWORD)(psmp->length);
- pins->nLoopStart = *(LPDWORD)(psmp->loopbeg);
- pins->nLoopEnd = *(LPDWORD)(psmp->loopend);
- samplepos = *(LPDWORD)(&psmp->fileofs);
+ pins->nLength = LittleEndian(*(LPDWORD)(psmp->length));
+ pins->nLoopStart = LittleEndian(*(LPDWORD)(psmp->loopbeg));
+ pins->nLoopEnd = LittleEndian(*(LPDWORD)(psmp->loopend));
+ samplepos = LittleEndian(*(LPDWORD)(&psmp->fileofs));
if (psmp->sampletype & 4) pins->uFlags |= CHN_LOOP;
if (psmp->sampletype & 8) pins->uFlags |= CHN_PINGPONGLOOP;
if (psmp->sampletype & 16)
@@ -126,9 +140,9 @@
}
}
// Reading Patterns
- for (UINT ipat=0; ipat<pfh->npatterns; ipat++)
+ for (UINT ipat=0; ipat<pfh.npatterns; ipat++)
{
- dwMemPos = ((UINT)pfh->patseg[ipat]) << 4;
+ dwMemPos = ((UINT)pfh.patseg[ipat]) << 4;
if ((!dwMemPos) || (dwMemPos >= dwMemLength)) continue;
if(Patterns.Insert(ipat, 64))
break;
Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_s3m.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,16 +1,17 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Copied to OpenMPT from libmodplug.
+ *
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244) //conversion from 'type1' to 'type2', possible loss of data
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
extern WORD S3MFineTuneTable[16];
@@ -207,45 +208,56 @@
BYTE s[1024];
DWORD dwMemPos;
BYTE insflags[128], inspack[128];
- S3MFILEHEADER *psfh = (S3MFILEHEADER *)lpStream;
+ S3MFILEHEADER psfh = *(S3MFILEHEADER *)lpStream;
+ psfh.reserved1 = LittleEndianW(psfh.reserved1);
+ psfh.ordnum = LittleEndianW(psfh.ordnum);
+ psfh.insnum = LittleEndianW(psfh.insnum);
+ psfh.patnum = LittleEndianW(psfh.patnum);
+ psfh.flags = LittleEndianW(psfh.flags);
+ psfh.cwtv = LittleEndianW(psfh.cwtv);
+ psfh.version = LittleEndianW(psfh.version);
+ psfh.scrm = LittleEndian(psfh.scrm);
+ psfh.special = LittleEndianW(psfh.special);
+
if ((!lpStream) || (dwMemLength <= sizeof(S3MFILEHEADER)+sizeof(S3MSAMPLESTRUCT)+64)) return FALSE;
- if (psfh->scrm != 0x4D524353) return FALSE;
+ if (psfh.scrm != 0x4D524353) return FALSE;
dwMemPos = 0x60;
m_nType = MOD_TYPE_S3M;
memset(m_szNames,0,sizeof(m_szNames));
- memcpy(m_szNames[0], psfh->name, 28);
+ memcpy(m_szNames[0], psfh.name, 28);
// Speed
- m_nDefaultSpeed = psfh->speed;
+ m_nDefaultSpeed = psfh.speed;
if (m_nDefaultSpeed < 1) m_nDefaultSpeed = 6;
if (m_nDefaultSpeed > 0x1F) m_nDefaultSpeed = 0x1F;
// Tempo
- m_nDefaultTempo = psfh->tempo;
+ m_nDefaultTempo = psfh.tempo;
if (m_nDefaultTempo < 40) m_nDefaultTempo = 40;
if (m_nDefaultTempo > 240) m_nDefaultTempo = 240;
// Global Volume
- m_nDefaultGlobalVolume = psfh->globalvol << 2;
+ m_nDefaultGlobalVolume = psfh.globalvol << 2;
if ((!m_nDefaultGlobalVolume) || (m_nDefaultGlobalVolume > 256)) m_nDefaultGlobalVolume = 256;
- m_nSamplePreAmp = psfh->mastervol & 0x7F;
+ m_nSamplePreAmp = psfh.mastervol & 0x7F;
// Channels
m_nChannels = 4;
for (UINT ich=0; ich<32; ich++)
{
ChnSettings[ich].nPan = 128;
ChnSettings[ich].nVolume = 64;
+
ChnSettings[ich].dwFlags = CHN_MUTE;
- if (psfh->channels[ich] != 0xFF)
+ if (psfh.channels[ich] != 0xFF)
{
m_nChannels = ich+1;
- UINT b = psfh->channels[ich] & 0x0F;
+ UINT b = psfh.channels[ich] & 0x0F;
ChnSettings[ich].nPan = (b & 8) ? 0xC0 : 0x40;
ChnSettings[ich].dwFlags = 0;
}
}
if (m_nChannels < 4) m_nChannels = 4;
- if ((psfh->cwtv < 0x1320) || (psfh->flags & 0x40)) m_dwSongFlags |= SONG_FASTVOLSLIDES;
+ if ((psfh.cwtv < 0x1320) || (psfh.flags & 0x40)) m_dwSongFlags |= SONG_FASTVOLSLIDES;
// Reading pattern order
- UINT iord = psfh->ordnum;
+ UINT iord = psfh.ordnum;
if (iord<1) iord = 1;
if (iord > MAX_ORDERS) iord = MAX_ORDERS;
if (iord)
@@ -255,17 +267,21 @@
}
if ((iord & 1) && (lpStream[dwMemPos] == 0xFF)) dwMemPos++;
// Reading file pointers
- insnum = nins = psfh->insnum;
+ insnum = nins = psfh.insnum;
if (insnum >= MAX_SAMPLES) insnum = MAX_SAMPLES-1;
m_nSamples = insnum;
- patnum = npat = psfh->patnum;
+ patnum = npat = psfh.patnum;
if (patnum > MAX_PATTERNS) patnum = MAX_PATTERNS;
memset(ptr, 0, sizeof(ptr));
if (nins+npat)
{
memcpy(ptr, lpStream+dwMemPos, 2*(nins+npat));
dwMemPos += 2*(nins+npat);
- if (psfh->panning_present == 252)
+ const UINT nLoopEnd = min(256, nins+npat);
+ for (UINT j = 0; j < nLoopEnd; ++j) {
+ ptr[j] = LittleEndianW(ptr[j]);
+ }
+ if (psfh.panning_present == 252)
{
const BYTE *chnpan = lpStream+dwMemPos;
for (UINT i=0; i<32; i++) if (chnpan[i] & 0x20)
@@ -289,14 +305,14 @@
lstrcpy(m_szNames[iSmp], (LPCSTR)&s[0x30]);
if ((s[0]==1) && (s[0x4E]=='R') && (s[0x4F]=='S'))
{
- UINT j = *((LPDWORD)(s+0x10));
+ UINT j = LittleEndian(*((LPDWORD)(s+0x10)));
if (j > MAX_SAMPLE_LENGTH) j = MAX_SAMPLE_LENGTH;
if (j < 4) j = 0;
Ins[iSmp].nLength = j;
- j = *((LPDWORD)(s+0x14));
+ j = LittleEndian(*((LPDWORD)(s+0x14)));
if (j >= Ins[iSmp].nLength) j = Ins[iSmp].nLength - 1;
Ins[iSmp].nLoopStart = j;
- j = *((LPDWORD)(s+0x18));
+ j = LittleEndian(*((LPDWORD)(s+0x18)));
if (j > MAX_SAMPLE_LENGTH) j = MAX_SAMPLE_LENGTH;
if (j < 4) j = 0;
if (j > Ins[iSmp].nLength) j = Ins[iSmp].nLength;
@@ -306,11 +322,11 @@
Ins[iSmp].nVolume = j << 2;
Ins[iSmp].nGlobalVol = 64;
if (s[0x1F]&1) Ins[iSmp].uFlags |= CHN_LOOP;
- j = *((LPDWORD)(s+0x20));
+ j = LittleEndian(*((LPDWORD)(s+0x20)));
if (!j) j = 8363;
if (j < 1024) j = 1024;
Ins[iSmp].nC4Speed = j;
- insfile[iSmp] = ((DWORD)*((LPWORD)(s+0x0E))) << 4;
+ insfile[iSmp] = ((DWORD)LittleEndianW(*((LPWORD)(s+0x0E)))) << 4;
insfile[iSmp] += ((DWORD)(BYTE)s[0x0D]) << 20;
if (insfile[iSmp] > dwMemLength) insfile[iSmp] &= 0xFFFF;
if ((Ins[iSmp].nLoopStart >= Ins[iSmp].nLoopEnd) || (Ins[iSmp].nLoopEnd - Ins[iSmp].nLoopStart < 8))
@@ -323,7 +339,7 @@
{
UINT nInd = ((DWORD)ptr[nins+iPat]) << 4;
if (nInd + 0x40 > dwMemLength) continue;
- WORD len = *((WORD *)(lpStream+nInd));
+ WORD len = LittleEndianW(*((WORD *)(lpStream+nInd)));
nInd += 2;
bool fail = Patterns.Insert(iPat, 64);
if ((!len) || (nInd + len > dwMemLength - 6)
@@ -385,7 +401,7 @@
// Reading samples
for (UINT iRaw=1; iRaw<=insnum; iRaw++) if ((Ins[iRaw].nLength) && (insfile[iRaw]))
{
- UINT flags = (psfh->version == 1) ? RS_PCM8S : RS_PCM8U;
+ UINT flags = (psfh.version == 1) ? RS_PCM8S : RS_PCM8U;
if (insflags[iRaw-1] & 4) flags += 5;
if (insflags[iRaw-1] & 2) flags |= RSF_STEREO;
if (inspack[iRaw-1] == 4) flags = RS_ADPCM4;
@@ -394,7 +410,7 @@
}
m_nMinPeriod = 64;
m_nMaxPeriod = 32767;
- if (psfh->flags & 0x10) m_dwSongFlags |= SONG_AMIGALIMITS;
+ if (psfh.flags & 0x10) m_dwSongFlags |= SONG_AMIGALIMITS;
return TRUE;
}
Modified: trunk/OpenMPT/soundlib/Load_stm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_stm.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_stm.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,16 +1,16 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ *
*/
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#pragma pack(1)
@@ -41,8 +41,8 @@
// Raw STM header struct:
typedef struct tagSTMHEADER
{
- CHAR songname[20];
- CHAR trackername[8]; // !SCREAM! for ST 2.xx
+ char songname[20];
+ char trackername[8]; // !SCREAM! for ST 2.xx
CHAR unused; // 0x1A
CHAR filetype; // 1=song, 2=module (only 2 is supported, of course) :)
CHAR ver_major; // Like 2
@@ -97,14 +97,14 @@
STMSAMPLE *pStm = &phdr->sample[nIns]; // STM sample data
memcpy(pIns->name, pStm->filename, 13);
memcpy(m_szNames[nIns+1], pStm->filename, 12);
- pIns->nC4Speed = pStm->c2spd;
+ pIns->nC4Speed = LittleEndianW(pStm->c2spd);
pIns->nGlobalVol = 64;
pIns->nVolume = pStm->volume << 2;
if (pIns->nVolume > 256) pIns->nVolume = 256;
- pIns->nLength = pStm->length;
+ pIns->nLength = LittleEndianW(pStm->length);
if ((pIns->nLength < 4) || (!pIns->nVolume)) pIns->nLength = 0;
- pIns->nLoopStart = pStm->loopbeg;
- pIns->nLoopEnd = pStm->loopend;
+ pIns->nLoopStart = LittleEndianW(pStm->loopbeg);
+ pIns->nLoopEnd = LittleEndianW(pStm->loopend);
if ((pIns->nLoopEnd > pIns->nLoopStart) && (pIns->nLoopEnd != 0xFFFF)) pIns->uFlags |= CHN_LOOP;
}
dwMemPos = sizeof(STMHEADER);
Modified: trunk/OpenMPT/soundlib/Load_ult.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_ult.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_ult.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,16 +1,16 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ *
*/
#include "stdafx.h"
#include "sndfile.h"
-#pragma warning(disable:4244)
+#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"
#define ULT_16BIT 0x04
#define ULT_LOOP 0x08
@@ -21,8 +21,8 @@
// Raw ULT header struct:
typedef struct tagULTHEADER
{
- CHAR id[15];
- CHAR songtitle[32];
+ char id[15];
+ char songtitle[32];
BYTE reserved;
} ULTHEADER;
@@ -135,7 +135,7 @@
// Allocating Patterns
for (UINT nAllocPat=0; nAllocPat<nop; nAllocPat++)
{
- if (nAllocPat < Patterns.Size())
+ if (nAllocPat < MAX_PATTERNS)
{
Patterns.Insert(nAllocPat, 64);
}
Modified: trunk/OpenMPT/soundlib/Load_umx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_umx.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_umx.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,9 +1,8 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
*/
@@ -18,13 +17,13 @@
{
if ((!lpStream) || (dwMemLength < 0x800)) return FALSE;
// Rip Mods from UMX
- if ((*((DWORD *)(lpStream+0x20)) < dwMemLength)
- && (*((DWORD *)(lpStream+0x18)) <= dwMemLength - 0x10)
- && (*((DWORD *)(lpStream+0x18)) >= dwMemLength - 0x200))
+ if ((LittleEndian(*((DWORD *)(lpStream+0x20))) < dwMemLength)
+ && (LittleEndian(*((DWORD *)(lpStream+0x18))) <= dwMemLength - 0x10)
+ && (LittleEndian(*((DWORD *)(lpStream+0x18))) >= dwMemLength - 0x200))
{
for (UINT uscan=0x40; uscan<0x500; uscan++)
{
- DWORD dwScan = *((DWORD *)(lpStream+uscan));
+ DWORD dwScan = LittleEndian(*((DWORD *)(lpStream+uscan)));
// IT
if (dwScan == 0x4D504D49)
{
Modified: trunk/OpenMPT/soundlib/Load_wav.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_wav.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_wav.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,10 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
+ * Copied to OpenMPT from libmodplug.
+ *
* Authors: Olivier Lapicque <oli...@jp...>
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
#include "stdafx.h"
@@ -120,7 +120,7 @@
{
int slsize = pfmt->bitspersample >> 3;
signed short *p = (signed short *)pins->pSample;
- char *psrc = (char *)(lpStream+dwMemPos+8+nChn*slsize+slsize-2);
+ signed char *psrc = (signed char *)(lpStream+dwMemPos+8+nChn*slsize+slsize-2);
for (UINT i=0; i<len; i++)
{
p[i] = *((signed short *)psrc);
@@ -133,7 +133,7 @@
signed char *psrc = (signed char *)(lpStream+dwMemPos+8+nChn);
for (UINT i=0; i<len; i++)
{
- p[i] = (char)((*psrc) + 0x80);
+ p[i] = (signed char)((*psrc) + 0x80);
psrc += samplesize;
}
p[len+1] = p[len] = p[len-1];
Modified: trunk/OpenMPT/soundlib/Load_xm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_xm.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Load_xm.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,10 +1,9 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * Copied to OpenMPT from libmodplug.
*
- * Authors: Olivier Lapicque <oli...@jp...>
+ * Authors: Olivier Lapicque <oli...@jp...>,
+ * Adam Goode <ad...@ev...> (endian and char fixes for PPC)
+ * OpenMPT dev(s) (miscellaneous modifications)
*/
#include "stdafx.h"
@@ -100,11 +99,11 @@
if ((!lpStream) || (dwMemLength < 0x200)) return FALSE;
if (_strnicmp((LPCSTR)lpStream, "Extended Module", 15)) return FALSE;
memcpy(m_szNames[0], lpStream+17, 20);
- dwHdrSize = *((DWORD *)(lpStream+60));
- norders = *((WORD *)(lpStream+64));
+ dwHdrSize = LittleEndian(*((DWORD *)(lpStream+60)));
+ norders = LittleEndianW(*((WORD *)(lpStream+64)));
if ((!norders) || (norders > MAX_ORDERS)) return FALSE;
- restartpos = *((WORD *)(lpStream+66));
- channels = *((WORD *)(lpStream+68));
+ restartpos = LittleEndianW(*((WORD *)(lpStream+66)));
+ channels = LittleEndianW(*((WORD *)(lpStream+68)));
// -> CODE#0006
// -> DESC="misc quantity changes"
// if ((!channels) || (channels > 64)) return FALSE;
@@ -115,17 +114,18 @@
m_nMaxPeriod = 54784;
m_nChannels = channels;
if (restartpos < norders) m_nRestartPos = restartpos;
- patterns = *((WORD *)(lpStream+70));
+ patterns = LittleEndianW(*((WORD *)(lpStream+70)));
if (patterns > 256) patterns = 256;
- instruments = *((WORD *)(lpStream+72));
+ instruments = LittleEndianW(*((WORD *)(lpStream+72)));
if (instruments >= MAX_INSTRUMENTS) instruments = MAX_INSTRUMENTS-1;
m_nInstruments = instruments;
m_nSamples = 0;
memcpy(&xmflags, lpStream+74, 2);
+ xmflags = LittleEndianW(xmflags);
if (xmflags & 1) m_dwSongFlags |= SONG_LINEARSLIDES;
if (xmflags & 0x1000) m_dwSongFlags |= SONG_EXFILTERRANGE;
- defspeed = *((WORD *)(lpStream+76));
- deftempo = *((WORD *)(lpStream+78));
+ defspeed = LittleEndianW(*((WORD *)(lpStream+76)));
+ deftempo = LittleEndianW(*((WORD *)(lpStream+78)));
// -> CODE#0016
// -> DESC="default tempo update"
// if ((deftempo >= 32) && (deftempo < 256)) m_nDefaultTempo = deftempo;
@@ -172,20 +172,20 @@
UINT ipatmap = pattern_map[ipat];
DWORD dwSize = 0;
WORD rows=64, packsize=0;
- dwSize = *((DWORD *)(lpStream+dwMemPos));
+ dwSize = LittleEndian(*((DWORD *)(lpStream+dwMemPos)));
while ((dwMemPos + dwSize >= dwMemLength) || (dwSize & 0xFFFFFF00))
{
if (dwMemPos + 4 >= dwMemLength) break;
dwMemPos++;
- dwSize = *((DWORD *)(lpStream+dwMemPos));
+ dwSize = LittleEndian(*((DWORD *)(lpStream+dwMemPos)));
}
- rows = *((WORD *)(lpStream+dwMemPos+5));
+ rows = LittleEndianW(*((WORD *)(lpStream+dwMemPos+5)));
// -> CODE#0008
// -> DESC="#define to set pattern size"
// if ((!rows) || (rows > 256)) rows = 64;
if ((!rows) || (rows > MAX_PATTERN_ROWS)) rows = 64;
// -> BEHAVIOUR_CHANGE#0008
- packsize = *((WORD *)(lpStream+dwMemPos+7));
+ packsize = LittleEndianW(*((WORD *)(lpStream+dwMemPos+7)));
if (dwMemPos + dwSize + 4 > dwMemLength) return TRUE;
dwMemPos += dwSize;
if (dwMemPos + packsize + 4 > dwMemLength) return TRUE;
@@ -284,7 +284,7 @@
// Wrong offset check
while (dwMemPos + 4 < dwMemLength)
{
- DWORD d = *((DWORD *)(lpStream+dwMemPos));
+ DWORD d = LittleEndian(*((DWORD *)(lpStream+dwMemPos)));
if (d < 0x300) break;
dwMemPos++;
}
@@ -301,7 +301,7 @@
if (dwMemPos + sizeof(XMINSTRUMENTHEADER) >= dwMemLength) return TRUE;
pih = (XMINSTRUMENTHEADER *)(lpStream+dwMemPos);
- if (dwMemPos + pih->size > dwMemLength) return TRUE;
+ if (dwMemPos + LittleEndian(pih->size) > dwMemLength) return TRUE;
if ((Headers[iIns] = new INSTRUMENTHEADER) == NULL) continue;
memset(Headers[iIns], 0, sizeof(INSTRUMENTHEADER));
Headers[iIns]->pTuning = m_defaultInstrument.pTuning;
@@ -313,10 +313,17 @@
{
if (dwMemPos + sizeof(XMSAMPLEHEADER) > dwMemLength) return TRUE;
memcpy(&xmsh, lpStream+dwMemPos+sizeof(XMINSTRUMENTHEADER), sizeof(XMSAMPLEHEADER));
- dwMemPos += pih->size;
+ xmsh.shsize = LittleEndian(xmsh.shsize);
+ for (int i = 0; i < 24; ++i) {
+ xmsh.venv[i] = LittleEndianW(xmsh.venv[i]);
+ xmsh.penv[i] = LittleEndianW(xmsh.penv[i]);
+ }
+ xmsh.volfade = LittleEndianW(xmsh.volfade);
+ xmsh.res = LittleEndianW(xmsh.res);
+ dwMemPos += LittleEndian(pih->size);
} else
{
- if (pih->size) dwMemPos += pih->size;
+ if (LittleEndian(pih->size)) dwMemPos += LittleEndian(pih->size);
else dwMemPos += sizeof(XMINSTRUMENTHEADER);
continue;
}
@@ -456,6 +463,9 @@
if ((dwMemPos + sizeof(xmss) > dwMemLength)
|| (dwMemPos + xmsh.shsize > dwMemLength)) return TRUE;
memcpy(&xmss, lpStream+dwMemPos, sizeof(xmss));
+ xmss.samplen = LittleEndian(xmss.samplen);
+ xmss.loopstart = LittleEndian(xmss.loopstart);
+ xmss.looplen = LittleEndian(xmss.looplen);
dwMemPos += xmsh.shsize;
flags[ins] = (xmss.type & 0x10) ? RS_PCM16D : RS_PCM8D;
if (xmss.type & 0x20) flags[ins] = (xmss.type & 0x10) ? RS_STPCM16D : RS_STPCM8D;
@@ -528,7 +538,7 @@
}
}
// Read song comments: "TEXT"
- if ((dwMemPos + 8 < dwMemLength) && (*((DWORD *)(lpStream+dwMemPos)) == 0x74786574))
+ if ((dwMemPos + 8 < dwMemLength) && (LittleEndian(*((DWORD *)(lpStream+dwMemPos))) == 0x74786574))
{
UINT len = *((DWORD *)(lpStream+dwMemPos+4));
dwMemPos += 8;
@@ -544,7 +554,7 @@
}
}
// Read midi config: "MIDI"
- if ((dwMemPos + 8 < dwMemLength) && (*((DWORD *)(lpStream+dwMemPos)) == 0x4944494D))
+ if ((dwMemPos + 8 < dwMemLength) && (LittleEndian(*((DWORD *)(lpStream+dwMemPos))) == 0x4944494D))
{
UINT len = *((DWORD *)(lpStream+dwMemPos+4));
dwMemPos += 8;
@@ -556,7 +566,7 @@
}
}
// Read pattern names: "PNAM"
- if ((dwMemPos + 8 < dwMemLength) && (*((DWORD *)(lpStream+dwMemPos)) == 0x4d414e50))
+ if ((dwMemPos + 8 < dwMemLength) && (LittleEndian(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e50))
{
UINT len = *((DWORD *)(lpStream+dwMemPos+4));
dwMemPos += 8;
@@ -572,7 +582,7 @@
}
}
// Read channel names: "CNAM"
- if ((dwMemPos + 8 < dwMemLength) && (*((DWORD *)(lpStream+dwMemPos)) == 0x4d414e43))
+ if ((dwMemPos + 8 < dwMemLength) && (LittleEndian(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e43))
{
UINT len = *((DWORD *)(lpStream+dwMemPos+4));
dwMemPos += 8;
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2008-07-25 20:20:15 UTC (rev 216)
@@ -1300,7 +1300,14 @@
return NULL;
}
-
+// Ending swaps:
+// BigEndian(x) may be used either to:
+// -Convert DWORD x, which is in big endian format(for example read from file),
+// to endian format of current architecture.
+// -Convert value x from endian format of current architecture to big endian format.
+// Similarly LittleEndian(x) converts known little endian format to format of current
+// endian architecture or value x in format of current architecture to little endian
+// format.
#ifdef PLATFORM_BIG_ENDIAN
// PPC
inline DWORD LittleEndian(DWORD x) { return ((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | ((x & 0xFF000000) >> 24); }
@@ -1315,6 +1322,8 @@
#define LittleEndianW(x) (x)
#endif
+
+
//////////////////////////////////////////////////////////
// WAVE format information
Modified: trunk/OpenMPT/soundlib/load_j2b.cpp
===================================================================
--- trunk/OpenMPT/soundlib/load_j2b.cpp 2008-07-11 16:17:21 UTC (rev 215)
+++ trunk/OpenMPT/soundlib/load_j2b.cpp 2008-07-25 20:20:15 UTC (rev 216)
@@ -1,8 +1,5 @@
/*
- * This program is free software; you can redistribute it and modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the license or (at your
- * option) any later version.
+ * This source code is public domain.
*
* Authors: Olivier Lapicque <oli...@jp...>
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|