|
From: <sag...@us...> - 2010-05-15 20:27:02
|
Revision: 597
http://modplug.svn.sourceforge.net/modplug/?rev=597&view=rev
Author: saga-games
Date: 2010-05-15 20:26:56 +0000 (Sat, 15 May 2010)
Log Message:
-----------
[Ref] J2B Loader: Removed AM pattern loader from CSoundFile.
[Imp] J2B Loader: Added some security checks for possible malicious files where the patterns could be the first chunks, so that m_nChannels is not set yet.
[Imp] MOD/XM Loader: Don't load effect 37 as DelayCut anymore, since we cannot save it in MOD/XM files anyway...
[Ref] A bit more refactoring.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_mod.cpp
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/load_j2b.cpp
Modified: trunk/OpenMPT/soundlib/Load_mod.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mod.cpp 2010-05-14 16:37:15 UTC (rev 596)
+++ trunk/OpenMPT/soundlib/Load_mod.cpp 2010-05-15 20:26:56 UTC (rev 597)
@@ -56,7 +56,7 @@
case 'Y' - 55: command = CMD_PANBRELLO; break; //34
case 'Z' - 55: command = CMD_MIDI; break; //35
case '\\' - 56: command = CMD_SMOOTHMIDI; break; //rewbs.smoothVST: 36
- case ':' - 21: command = CMD_DELAYCUT; break; //37
+ //case ':' - 21: command = CMD_DELAYCUT; break; //37
case '#' + 3: command = CMD_XPARAM; break; //rewbs.XMfixes - XParam is 38
default: command = 0;
}
@@ -450,7 +450,6 @@
#ifndef MODPLUG_NO_FILESAVE
-#pragma warning(disable:4100)
bool CSoundFile::SaveMod(LPCSTR lpszFileName, UINT nPacking, const bool bCompatibilityExport)
//-------------------------------------------------------------------------------------------
@@ -581,8 +580,10 @@
} //end for all patterns
//Check for unsaved patterns
- for (UINT ipat=nbp; ipat<MAX_PATTERNS; ipat++) {
- if (Patterns[ipat]) {
+ for (UINT ipat=nbp; ipat<MAX_PATTERNS; ipat++)
+ {
+ if (Patterns[ipat])
+ {
AfxMessageBox("Warning: this track contains at least 1 pattern after the highest pattern number referred to in the sequence.\r\nSuch patterns will not be saved in the .mod format.");
break;
}
@@ -620,5 +621,4 @@
return true;
}
-#pragma warning(default:4100)
#endif // MODPLUG_NO_FILESAVE
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2010-05-14 16:37:15 UTC (rev 596)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2010-05-15 20:26:56 UTC (rev 597)
@@ -3134,14 +3134,15 @@
return *p;
}
-/* Try to write an (volume) effect in a given channel or any channel of a pattern in a specific row.
+
+/* Try to write an (volume column) effect in a given channel or any channel of a pattern in a specific row.
Usage: nPat - Pattern that should be modified
nRow - Row that should be modified
nEffect - (Volume) Effect that should be written
nParam - Effect that should be written
- bIsVolumeEffect - Indicates whether the given effect is a volume effect or not
+ bIsVolumeEffect - Indicates whether the given effect is a volume column effect or not
nChn - Channel that should be modified - use CHANNELINDEX_INVALID to allow all channels of the given row
- bAllowMultipleEffects - If false, No effect will be written if an effect of the same type is already present in the channel(s)
+ bAllowMultipleEffects - If false, No effect will be written if an effect of the same type is already present in the channel(s). Useful for f.e. tempo effects.
bAllowNextRow - Indicates whether it is allowed to use the next row if there's no space for the effect
bRetry - For internal use only. Indicates whether an effect "rewrite" has already taken place (for recursive calls)
*/
@@ -3160,7 +3161,7 @@
}
// Scan channel(s) for same effect type - if an effect of the same type is already present, exit.
- if(bAllowMultipleEffects == false)
+ if(!bAllowMultipleEffects)
{
for(CHANNELINDEX i = nScanChnMin; i <= nScanChnMax; i++)
{
@@ -3191,7 +3192,8 @@
}
// Ok, apparently there's no space. If we haven't tried already, try to map it to the volume column or effect column instead.
- if(bRetry == true) {
+ if(bRetry)
+ {
// Move some effects that also work in the volume column, so there's place for our new effect.
if(!bIsVolumeEffect)
{
@@ -3285,22 +3287,24 @@
}
+// Set up channel panning and volume suitable for MOD + similar files. If the current mod type is not MOD, bForceSetup has to be set to true.
void CSoundFile::SetupMODPanning(bool bForceSetup)
//------------------------------------------------
{
// Setup LRRL panning, max channel volume
if((m_nType & MOD_TYPE_MOD) == 0 && bForceSetup == false) return;
- for (CHANNELINDEX nChn = 0; nChn < MAX_BASECHANNELS; nChn++)
+ for(CHANNELINDEX nChn = 0; nChn < MAX_BASECHANNELS; nChn++)
{
ChnSettings[nChn].nVolume = 64;
- if (gdwSoundSetup & SNDMIX_MAXDEFAULTPAN)
+ if(gdwSoundSetup & SNDMIX_MAXDEFAULTPAN)
ChnSettings[nChn].nPan = (((nChn & 3) == 1) || ((nChn & 3) == 2)) ? 256 : 0;
else
ChnSettings[nChn].nPan = (((nChn & 3) == 1) || ((nChn & 3) == 2)) ? 0xC0 : 0x40;
}
}
+
// Convert an Exx command (MOD) to Sxx command (S3M)
void CSoundFile::MODExx2S3MSxx(MODCOMMAND *m)
//-------------------------------------------
@@ -3323,6 +3327,7 @@
}
}
+
// Convert an Sxx command (S3M) to Exx command (MOD)
void CSoundFile::S3MSxx2MODExx(MODCOMMAND *m)
//-------------------------------------------
@@ -3345,6 +3350,7 @@
}
}
+
// Convert a mod command from one format to another.
void CSoundFile::ConvertCommand(MODCOMMAND *m, MODTYPE nOldType, MODTYPE nNewType)
//--------------------------------------------------------------------------------
@@ -3545,7 +3551,7 @@
///////////////////////
// Convert IT to S3M
- else if (oldTypeIsIT_MPT && newTypeIsS3M)
+ else if(oldTypeIsIT_MPT && newTypeIsS3M)
{
if(m->note == NOTE_KEYOFF || m->note == NOTE_FADE)
m->note = NOTE_NOTECUT;
@@ -3631,68 +3637,68 @@
if(m->command) switch(m->command)
{
- case CMD_RETRIG: // MOD only has E9x
- m->command = CMD_MODCMDEX;
- m->param = 0x90 | (m->param & 0x0F);
- break;
- case CMD_MODCMDEX: // This would turn into "Invert Loop", so let's better remove it
- if((m->param & 0xF0) == 0xF0) m->command = CMD_NONE;
- break;
+ case CMD_RETRIG: // MOD only has E9x
+ m->command = CMD_MODCMDEX;
+ m->param = 0x90 | (m->param & 0x0F);
+ break;
+ case CMD_MODCMDEX: // This would turn into "Invert Loop", so let's better remove it
+ if((m->param & 0xF0) == 0xF0) m->command = CMD_NONE;
+ break;
}
else switch(m->volcmd)
{
- case VOLCMD_VOLUME:
- m->command = CMD_VOLUME;
- m->param = m->vol;
- break;
- case VOLCMD_PANNING:
- m->command = CMD_PANNING8;
- m->param = CLAMP(m->vol << 2, 0, 0xFF);
- break;
- case VOLCMD_VOLSLIDEDOWN:
- m->command = CMD_VOLUMESLIDE;
- m->param = m->vol;
- break;
- case VOLCMD_VOLSLIDEUP:
- m->command = CMD_VOLUMESLIDE;
- m->param = m->vol << 4;
- break;
- case VOLCMD_FINEVOLDOWN:
- m->command = CMD_MODCMDEX;
- m->param = 0xB0 | m->vol;
- break;
- case VOLCMD_FINEVOLUP:
- m->command = CMD_MODCMDEX;
- m->param = 0xA0 | m->vol;
- break;
- case VOLCMD_PORTADOWN:
- m->command = CMD_PORTAMENTODOWN;
- m->param = m->vol << 2;
- break;
- case VOLCMD_PORTAUP:
- m->command = CMD_PORTAMENTOUP;
- m->param = m->vol << 2;
- break;
- case VOLCMD_TONEPORTAMENTO:
- m->command = CMD_TONEPORTAMENTO;
- m->param = m->vol << 2;
- break;
- case VOLCMD_VIBRATODEPTH:
- m->command = CMD_VIBRATO;
- m->param = m->vol;
- break;
- case VOLCMD_VIBRATOSPEED:
- m->command = CMD_VIBRATO;
- m->param = m->vol << 4;
- break;
- // OpenMPT-specific commands
- case VOLCMD_OFFSET:
- m->command = CMD_OFFSET;
- m->param = m->vol << 3;
- break;
- default:
- break;
+ case VOLCMD_VOLUME:
+ m->command = CMD_VOLUME;
+ m->param = m->vol;
+ break;
+ case VOLCMD_PANNING:
+ m->command = CMD_PANNING8;
+ m->param = CLAMP(m->vol << 2, 0, 0xFF);
+ break;
+ case VOLCMD_VOLSLIDEDOWN:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = m->vol;
+ break;
+ case VOLCMD_VOLSLIDEUP:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = m->vol << 4;
+ break;
+ case VOLCMD_FINEVOLDOWN:
+ m->command = CMD_MODCMDEX;
+ m->param = 0xB0 | m->vol;
+ break;
+ case VOLCMD_FINEVOLUP:
+ m->command = CMD_MODCMDEX;
+ m->param = 0xA0 | m->vol;
+ break;
+ case VOLCMD_PORTADOWN:
+ m->command = CMD_PORTAMENTODOWN;
+ m->param = m->vol << 2;
+ break;
+ case VOLCMD_PORTAUP:
+ m->command = CMD_PORTAMENTOUP;
+ m->param = m->vol << 2;
+ break;
+ case VOLCMD_TONEPORTAMENTO:
+ m->command = CMD_TONEPORTAMENTO;
+ m->param = m->vol << 2;
+ break;
+ case VOLCMD_VIBRATODEPTH:
+ m->command = CMD_VIBRATO;
+ m->param = m->vol;
+ break;
+ case VOLCMD_VIBRATOSPEED:
+ m->command = CMD_VIBRATO;
+ m->param = m->vol << 4;
+ break;
+ // OpenMPT-specific commands
+ case VOLCMD_OFFSET:
+ m->command = CMD_OFFSET;
+ m->param = m->vol << 3;
+ break;
+ default:
+ break;
}
m->volcmd = CMD_NONE;
} // End if (newTypeIsMOD)
@@ -3703,69 +3709,69 @@
{
if(!m->command) switch(m->volcmd)
{
- case VOLCMD_VOLSLIDEDOWN:
- m->command = CMD_VOLUMESLIDE;
- m->param = m->vol;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_VOLSLIDEUP:
- m->command = CMD_VOLUMESLIDE;
- m->param = m->vol << 4;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_FINEVOLDOWN:
- m->command = CMD_VOLUMESLIDE;
- m->param = 0xF0 | m->vol;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_FINEVOLUP:
- m->command = CMD_VOLUMESLIDE;
- m->param = (m->vol << 4) | 0x0F;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PORTADOWN:
- m->command = CMD_PORTAMENTODOWN;
- m->param = m->vol << 2;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PORTAUP:
- m->command = CMD_PORTAMENTOUP;
- m->param = m->vol << 2;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_TONEPORTAMENTO:
- m->command = CMD_TONEPORTAMENTO;
- m->param = m->vol << 2;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_VIBRATODEPTH:
- m->command = CMD_VIBRATO;
- m->param = m->vol;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_VIBRATOSPEED:
- m->command = CMD_VIBRATO;
- m->param = m->vol << 4;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PANSLIDELEFT:
- m->command = CMD_PANNINGSLIDE;
- m->param = m->vol << 4;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PANSLIDERIGHT:
- m->command = CMD_PANNINGSLIDE;
- m->param = m->vol;
- m->volcmd = CMD_NONE;
- break;
- // OpenMPT-specific commands
- case VOLCMD_OFFSET:
- m->command = CMD_OFFSET;
- m->param = m->vol << 3;
- m->volcmd = CMD_NONE;
- break;
- default:
- break;
+ case VOLCMD_VOLSLIDEDOWN:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = m->vol;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_VOLSLIDEUP:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = m->vol << 4;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_FINEVOLDOWN:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = 0xF0 | m->vol;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_FINEVOLUP:
+ m->command = CMD_VOLUMESLIDE;
+ m->param = (m->vol << 4) | 0x0F;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PORTADOWN:
+ m->command = CMD_PORTAMENTODOWN;
+ m->param = m->vol << 2;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PORTAUP:
+ m->command = CMD_PORTAMENTOUP;
+ m->param = m->vol << 2;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_TONEPORTAMENTO:
+ m->command = CMD_TONEPORTAMENTO;
+ m->param = m->vol << 2;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_VIBRATODEPTH:
+ m->command = CMD_VIBRATO;
+ m->param = m->vol;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_VIBRATOSPEED:
+ m->command = CMD_VIBRATO;
+ m->param = m->vol << 4;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PANSLIDELEFT:
+ m->command = CMD_PANNINGSLIDE;
+ m->param = m->vol << 4;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PANSLIDERIGHT:
+ m->command = CMD_PANNINGSLIDE;
+ m->param = m->vol;
+ m->volcmd = CMD_NONE;
+ break;
+ // OpenMPT-specific commands
+ case VOLCMD_OFFSET:
+ m->command = CMD_OFFSET;
+ m->param = m->vol << 3;
+ m->volcmd = CMD_NONE;
+ break;
+ default:
+ break;
}
} // End if (newTypeIsS3M)
@@ -3775,24 +3781,24 @@
{
if(!m->command) switch(m->volcmd)
{
- case VOLCMD_PORTADOWN:
- m->command = CMD_PORTAMENTODOWN;
- m->param = m->vol << 2;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PORTAUP:
- m->command = CMD_PORTAMENTOUP;
- m->param = m->vol << 2;
- m->volcmd = CMD_NONE;
- break;
- // OpenMPT-specific commands
- case VOLCMD_OFFSET:
- m->command = CMD_OFFSET;
- m->param = m->vol << 3;
- m->volcmd = CMD_NONE;
- break;
- default:
- break;
+ case VOLCMD_PORTADOWN:
+ m->command = CMD_PORTAMENTODOWN;
+ m->param = m->vol << 2;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PORTAUP:
+ m->command = CMD_PORTAMENTOUP;
+ m->param = m->vol << 2;
+ m->volcmd = CMD_NONE;
+ break;
+ // OpenMPT-specific commands
+ case VOLCMD_OFFSET:
+ m->command = CMD_OFFSET;
+ m->param = m->vol << 3;
+ m->volcmd = CMD_NONE;
+ break;
+ default:
+ break;
}
} // End if (newTypeIsXM)
@@ -3802,35 +3808,35 @@
{
if(!m->command) switch(m->volcmd)
{
- case VOLCMD_VOLSLIDEDOWN:
- case VOLCMD_VOLSLIDEUP:
- case VOLCMD_FINEVOLDOWN:
- case VOLCMD_FINEVOLUP:
- case VOLCMD_PORTADOWN:
- case VOLCMD_PORTAUP:
- case VOLCMD_TONEPORTAMENTO:
- case VOLCMD_VIBRATODEPTH:
- // OpenMPT-specific commands
- case VOLCMD_OFFSET:
- m->vol = min(m->vol, 9);
- break;
- case VOLCMD_PANSLIDELEFT:
- m->command = CMD_PANNINGSLIDE;
- m->param = m->vol << 4;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_PANSLIDERIGHT:
- m->command = CMD_PANNINGSLIDE;
- m->param = m->vol;
- m->volcmd = CMD_NONE;
- break;
- case VOLCMD_VIBRATOSPEED:
- m->command = CMD_VIBRATO;
- m->param = m->vol << 4;
- m->volcmd = CMD_NONE;
- break;
- default:
- break;
+ case VOLCMD_VOLSLIDEDOWN:
+ case VOLCMD_VOLSLIDEUP:
+ case VOLCMD_FINEVOLDOWN:
+ case VOLCMD_FINEVOLUP:
+ case VOLCMD_PORTADOWN:
+ case VOLCMD_PORTAUP:
+ case VOLCMD_TONEPORTAMENTO:
+ case VOLCMD_VIBRATODEPTH:
+ // OpenMPT-specific commands
+ case VOLCMD_OFFSET:
+ m->vol = min(m->vol, 9);
+ break;
+ case VOLCMD_PANSLIDELEFT:
+ m->command = CMD_PANNINGSLIDE;
+ m->param = m->vol << 4;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_PANSLIDERIGHT:
+ m->command = CMD_PANNINGSLIDE;
+ m->param = m->vol;
+ m->volcmd = CMD_NONE;
+ break;
+ case VOLCMD_VIBRATOSPEED:
+ m->command = CMD_VIBRATO;
+ m->param = m->vol << 4;
+ m->volcmd = CMD_NONE;
+ break;
+ default:
+ break;
}
} // End if (newTypeIsIT)
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2010-05-14 16:37:15 UTC (rev 596)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2010-05-15 20:26:56 UTC (rev 597)
@@ -719,9 +719,6 @@
bool ReadJ2B(const LPCBYTE lpStream, const DWORD dwMemLength);
bool ReadMID(LPCBYTE lpStream, DWORD dwMemLength);
- void SetupMODPanning(bool bForceSetup = false); // Setup LRRL panning, max channel volume
- bool Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM); // used by ReadAM(...) to convert AM(FF) patterns
-
// Save Functions
#ifndef MODPLUG_NO_FILESAVE
UINT WriteSample(FILE *f, MODSAMPLE *pSmp, UINT nFlags, UINT nMaxLen=0);
@@ -754,6 +751,7 @@
static void ConvertCommand(MODCOMMAND *m, MODTYPE nOldType, MODTYPE nNewType); // Convert a complete MODCOMMAND item from one format to another
static void MODExx2S3MSxx(MODCOMMAND *m); // Convert Exx to Sxx
static void S3MSxx2MODExx(MODCOMMAND *m); // Convert Sxx to Exx
+ void SetupMODPanning(bool bForceSetup = false); // Setup LRRL panning, max channel volume
public:
// Real-time sound functions
Modified: trunk/OpenMPT/soundlib/load_j2b.cpp
===================================================================
--- trunk/OpenMPT/soundlib/load_j2b.cpp 2010-05-14 16:37:15 UTC (rev 596)
+++ trunk/OpenMPT/soundlib/load_j2b.cpp 2010-05-15 20:26:56 UTC (rev 597)
@@ -1,6 +1,8 @@
/*
+ * load_j2b.cpp
+ * ------------
* Purpose: Load RIFF AM and RIFF AMFF modules (Galaxy Sound System).
- * Note: J2B is a compressed variant of RIFF AM and RIFF AMFF files used in Jazz Jackrabbit 2.
+ * Notes : J2B is a compressed variant of RIFF AM and RIFF AMFF files used in Jazz Jackrabbit 2.
* It seems like no other game used the AM(FF) format.
* Authors: Johannes Schultz (OpenMPT port)
* Chris Moeller (foo_dumb - this is almost a complete port of his code, thanks)
@@ -107,8 +109,8 @@
CMD_TREMOR, CMD_XFINEPORTAUPDOWN,
};
-bool CSoundFile::Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM)
-//----------------------------------------------------------------------------------------------------------------
+bool Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM, CSoundFile *pSndFile)
+//--------------------------------------------------------------------------------------------------------------------------
{
// version false = AMFF, true = AM
#define ASSERT_CAN_READ(x) \
@@ -120,12 +122,16 @@
ROWINDEX nRows = lpStream[0] + 1;
- if(Patterns.Insert(nPat, nRows))
+ if(pSndFile == nullptr || pSndFile->Patterns.Insert(nPat, nRows))
return false;
dwMemPos++;
- MODCOMMAND *mrow = Patterns[nPat];
+ const CHANNELINDEX nChannels = pSndFile->GetNumChannels();
+ if(nChannels == 0)
+ return false;
+
+ MODCOMMAND *mrow = pSndFile->Patterns[nPat];
MODCOMMAND *m = mrow;
ROWINDEX nRow = 0;
uint8 flags;
@@ -138,11 +144,11 @@
if (flags == 0)
{
nRow++;
- m = mrow = Patterns[nPat] + nRow * m_nChannels;
+ m = mrow = pSndFile->Patterns[nPat] + nRow * nChannels;
continue;
}
- m = mrow + min((flags & 0x1F), m_nChannels - 1);
+ m = mrow + min((flags & 0x1F), nChannels - 1);
if(flags & 0xE0)
{
@@ -179,7 +185,7 @@
m->param = ((m->param >> 4) * 10) + (m->param & 0x0F);
break;
case CMD_MODCMDEX:
- MODExx2S3MSxx(m);
+ pSndFile->MODExx2S3MSxx(m);
break;
case CMD_TEMPO:
if(m->param <= 0x1F) m->command = CMD_SPEED;
@@ -205,7 +211,7 @@
wsprintf(s, "J2B: Unknown command: 0x%X, param 0x%X", m->command, m->param);
Log(s);
}
-#endif
+#endif // DEBUG
m->command = CMD_NONE;
}
}
@@ -263,6 +269,7 @@
else if(LittleEndian(*(uint32 *)(lpStream + dwMemPos)) == 0x20204D41) bIsAM = true; // "AM "
else return false;
dwMemPos += 4;
+ m_nChannels = 0;
// go through all chunks now
while(dwMemPos < dwMemLength)
@@ -330,7 +337,7 @@
case 0x54544150: // "PATT" - Pattern data for one pattern
ASSERT_CAN_READ_CHUNK(5);
- Convert_RIFF_AM_Pattern(lpStream[dwMemPos], (LPCBYTE)(lpStream + dwMemPos + 5), LittleEndian(*(DWORD *)(lpStream + dwMemPos + 1)), bIsAM);
+ Convert_RIFF_AM_Pattern(lpStream[dwMemPos], (LPCBYTE)(lpStream + dwMemPos + 5), LittleEndian(*(DWORD *)(lpStream + dwMemPos + 1)), bIsAM, this);
break;
case 0x54534E49: // "INST" - Instrument (only in RIFF AMFF)
@@ -365,16 +372,17 @@
Samples[nSmp].nLoopEnd = LittleEndian(smpchunk->loopend);
Samples[nSmp].nC5Speed = LittleEndian(smpchunk->samplerate);
- if(LittleEndianW(smpchunk->flags) & 0x04)
+ uint16 flags = LittleEndianW(smpchunk->flags);
+ if(flags & 0x04)
Samples[nSmp].uFlags |= CHN_16BIT;
- if(LittleEndianW(smpchunk->flags) & 0x08)
+ if(flags & 0x08)
Samples[nSmp].uFlags |= CHN_LOOP;
- if(LittleEndianW(smpchunk->flags) & 0x10)
+ if(flags & 0x10)
Samples[nSmp].uFlags |= CHN_PINGPONGLOOP;
- if(LittleEndianW(smpchunk->flags) & 0x20)
+ if(flags & 0x20)
Samples[nSmp].uFlags |= CHN_PANNING;
- dwMemPos += ReadSample(&Samples[nSmp], (LittleEndianW(smpchunk->flags) & 0x04) ? RS_PCM16S : RS_PCM8S, (LPCSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
+ dwMemPos += ReadSample(&Samples[nSmp], (flags & 0x04) ? RS_PCM16S : RS_PCM8S, (LPCSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
}
break;
@@ -436,24 +444,26 @@
Samples[nSmp].nLoopEnd = LittleEndian(smpchunk->loopend);
Samples[nSmp].nC5Speed = LittleEndian(smpchunk->samplerate);
- if(LittleEndianW(smpchunk->flags) & 0x04)
+ uint16 flags = LittleEndianW(smpchunk->flags);
+ if(flags & 0x04)
Samples[nSmp].uFlags |= CHN_16BIT;
- if(LittleEndianW(smpchunk->flags) & 0x08)
+ if(flags & 0x08)
Samples[nSmp].uFlags |= CHN_LOOP;
- if(LittleEndianW(smpchunk->flags) & 0x10)
+ if(flags & 0x10)
Samples[nSmp].uFlags |= CHN_PINGPONGLOOP;
- if(LittleEndianW(smpchunk->flags) & 0x20)
+ if(flags & 0x20)
Samples[nSmp].uFlags |= CHN_PANNING;
dwMemPos += LittleEndian(smpchunk->headsize) + 12; // doesn't include the 3 first DWORDs
- dwMemPos += ReadSample(&Samples[nSmp], (LittleEndianW(smpchunk->flags) & 0x04) ? RS_PCM16S : RS_PCM8S, (LPCSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
+ dwMemPos += ReadSample(&Samples[nSmp], (flags & 0x04) ? RS_PCM16S : RS_PCM8S, (LPCSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
}
break;
}
dwMemPos = dwChunkEnd;
- // RIFF AM has a padding byte
- if(bIsAM && (LittleEndian(chunkheader->chunksize) & 1)) dwMemPos++;
+ // RIFF AM has a padding byte so that all chunks have an even size.
+ if(bIsAM && (LittleEndian(chunkheader->chunksize) & 1))
+ dwMemPos++;
}
return true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|