From: <sag...@us...> - 2010-04-07 15:19:42
|
Revision: 565 http://modplug.svn.sourceforge.net/modplug/?rev=565&view=rev Author: saga-games Date: 2010-04-07 15:19:36 +0000 (Wed, 07 Apr 2010) Log Message: ----------- [Fix] MOD Saving: Samples were shifted badly if the sample size was odd. (wow, this is an OLD bug!) [Fix] Sample Editor: It was not possible to create the last sample slot (i.e. pressing "new sample" with a MOD file that had 30 samples would result in an error, although MOD supports 31 samples). Modified Paths: -------------- trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/soundlib/Load_mod.cpp Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2010-03-30 19:13:11 UTC (rev 564) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2010-04-07 15:19:36 UTC (rev 565) @@ -742,7 +742,7 @@ } } if (((bLimit) && (i >= 200) && (!m_SndFile.m_nInstruments)) - || (i >= m_SndFile.GetModSpecifications().samplesMax)) + || (i > m_SndFile.GetModSpecifications().samplesMax)) { ErrorBox(IDS_ERR_TOOMANYSMP, CMainFrame::GetMainFrame()); return SAMPLEINDEX_INVALID; Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2010-03-30 19:13:11 UTC (rev 564) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2010-04-07 15:19:36 UTC (rev 565) @@ -487,6 +487,9 @@ MODSAMPLE *pSmp = &Samples[insmap[iins]]; memcpy(bTab, m_szNames[iins],22); inslen[iins] = pSmp->nLength; + // if the sample size is odd, we have to add a padding byte, as all sample sizes in MODs are even. + if(inslen[iins] & 1) + inslen[iins]++; if (inslen[iins] > 0x1fff0) inslen[iins] = 0x1fff0; bTab[22] = inslen[iins] >> 9; bTab[23] = inslen[iins] >> 1; @@ -509,7 +512,7 @@ fwrite(bTab, 30, 1, f); } // Writing number of patterns - UINT nbp=0, norders=128; + UINT nbp = 0, norders = 128; for (UINT iord=0; iord<128; iord++) { if (Order[iord] == Order.GetInvalidPatIndex()) @@ -535,7 +538,8 @@ // Writing patterns for (UINT ipat=0; ipat<nbp; ipat++) { //for all patterns BYTE s[64*4]; - if (Patterns[ipat]) { //if pattern exists + if (Patterns[ipat]) //if pattern exists + { MODCOMMAND *m = Patterns[ipat]; for (UINT i=0; i<64; i++) { //for all rows if (i < PatternSize[ipat]) { //if row exists @@ -584,7 +588,7 @@ } // Writing instruments - for (UINT ismpd=1; ismpd<=31; ismpd++) if (inslen[ismpd]) + for (UINT ismpd = 1; ismpd <= 31; ismpd++) if (inslen[ismpd]) { MODSAMPLE *pSmp = &Samples[insmap[ismpd]]; if(bCompatibilityExport == true) // first two bytes have to be 0 due to PT's one-shot loop ("no loop") @@ -604,6 +608,12 @@ } #endif WriteSample(f, pSmp, flags, inslen[ismpd]); + // write padding byte if the sample size is odd. + if((pSmp->nLength & 1) && !nPacking) + { + int8 padding = 0; + fwrite(&padding, 1, 1, f); + } } fclose(f); return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |