|
From: <sag...@us...> - 2013-05-17 20:36:51
|
Revision: 2090
http://sourceforge.net/p/modplug/code/2090
Author: saga-games
Date: 2013-05-17 20:36:43 +0000 (Fri, 17 May 2013)
Log Message:
-----------
[Fix] MT2 sample tuning takes finetune into account now.
[Fix] MT2 stereo samples are now loaded correctly.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_mt2.cpp
trunk/OpenMPT/soundlib/SampleIO.cpp
trunk/OpenMPT/soundlib/SampleIO.h
Modified: trunk/OpenMPT/soundlib/Load_mt2.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mt2.cpp 2013-05-17 00:18:47 UTC (rev 2089)
+++ trunk/OpenMPT/soundlib/Load_mt2.cpp 2013-05-17 20:36:43 UTC (rev 2090)
@@ -132,7 +132,7 @@
DWORD dwFrequency;
BYTE nQuality;
BYTE nChannels;
- BYTE nFlags;
+ BYTE nFlags; // 8 = no interpolation
BYTE nLoop;
DWORD dwLoopStart;
DWORD dwLoopEnd;
@@ -146,10 +146,10 @@
typedef struct PACKED _MT2GROUP
{
- BYTE nSmpNo;
- BYTE nVolume; // 0-128
- BYTE nFinePitch;
- BYTE Reserved[5];
+ uint8 nSmpNo;
+ uint8 nVolume; // 0-128
+ int8 nFinePitch;
+ int8 Reserved[5];
} MT2GROUP;
STATIC_ASSERT(sizeof(MT2GROUP) == 8);
@@ -240,7 +240,7 @@
InitializeGlobals();
InitializeChannels();
- madeWithTracker.Format("MadTracker %d.%x", pfh->wVersion >> 8, pfh->wVersion & 0xFF);
+ madeWithTracker.AppendChars(pfh->szTrackerName);
m_nType = MOD_TYPE_MT2;
m_nChannels = pfh->wChannels;
m_nRestartPos = pfh->wRestart;
@@ -564,6 +564,7 @@
if (iSmp < MAX_SAMPLES)
{
ModSample *psmp = &Samples[iSmp];
+ psmp->Initialize(MOD_TYPE_XM);
psmp->nGlobalVol = 64;
psmp->nVolume = (pms->wVolume >> 7);
psmp->nPan = (pms->nPan == 0x80) ? 128 : (pms->nPan^0x80);
@@ -571,9 +572,6 @@
psmp->nC5Speed = pms->dwFrequency;
psmp->nLoopStart = pms->dwLoopStart;
psmp->nLoopEnd = pms->dwLoopEnd;
- psmp->FrequencyToTranspose();
- psmp->RelativeTone -= pms->nBaseNote - 49;
- psmp->TransposeToFrequency();
if (pms->nQuality == 2) { psmp->uFlags |= CHN_16BIT; psmp->nLength >>= 1; }
if (pms->nChannels == 2) { psmp->nLength >>= 1; }
if (pms->nLoop == 1) psmp->uFlags |= CHN_LOOP;
@@ -611,6 +609,7 @@
Samples[nSmp].nVibSweep = pmi->bVibSweep;
Samples[nSmp].nVibDepth = pmi->bVibDepth;
Samples[nSmp].nVibRate = pmi->bVibRate;
+ Samples[nSmp].nC5Speed = Util::Round<uint32>(SampleMap[nSmp - 1]->dwFrequency * pow(2, -(SampleMap[nSmp - 1]->nBaseNote - 49 - (pmg->nFinePitch / 128.0f)) / 12.0f));
}
}
}
@@ -642,7 +641,7 @@
(sample.uFlags & CHN_16BIT) ? SampleIO::_16bit : SampleIO::_8bit,
(pms->nChannels == 2) ? SampleIO::stereoSplit : SampleIO::mono,
SampleIO::littleEndian,
- SampleIO::deltaPCM)
+ SampleIO::MT2)
.ReadSample(sample, chunk);
}
} else
Modified: trunk/OpenMPT/soundlib/SampleIO.cpp
===================================================================
--- trunk/OpenMPT/soundlib/SampleIO.cpp 2013-05-17 00:18:47 UTC (rev 2089)
+++ trunk/OpenMPT/soundlib/SampleIO.cpp 2013-05-17 20:36:43 UTC (rev 2090)
@@ -63,6 +63,7 @@
bytesRead = CopyMonoSample<ReadInt8PCM<0x80u> >(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Mono / Delta / PCM
+ case MT2:
bytesRead = CopyMonoSample<ReadInt8DeltaPCM>(sample, sourceBuf, fileSize);
break;
case PCM7to8: // 7 Bit stored as 8-Bit with highest bit unused / Mono / Signed / PCM
@@ -84,6 +85,7 @@
bytesRead = CopyStereoSplitSample<ReadInt8PCM<0x80u> >(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Stereo Split / Delta / PCM
+ case MT2:
bytesRead = CopyStereoSplitSample<ReadInt8DeltaPCM>(sample, sourceBuf, fileSize);
break;
}
@@ -120,6 +122,7 @@
bytesRead = CopyMonoSample<ReadInt16PCM<0x8000u, littleEndian16> >(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 16-Bit / Stereo Interleaved / Delta / PCM
+ case MT2:
bytesRead = CopyMonoSample<ReadInt16DeltaPCM<littleEndian16> >(sample, sourceBuf, fileSize);
break;
}
@@ -156,6 +159,7 @@
bytesRead = CopyStereoSplitSample<ReadInt16PCM<0x8000u, littleEndian16> >(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 16-Bit / Stereo Split / Delta / PCM
+ case MT2:
bytesRead = CopyStereoSplitSample<ReadInt16DeltaPCM<littleEndian16> >(sample, sourceBuf, fileSize);
break;
}
@@ -358,6 +362,24 @@
uint8 *outBuf = static_cast<uint8 *>(sample.pSample);
bytesRead = DMFUnpack(outBuf, inBuf, inBufMax, sample.GetSampleSizeInBytes());
}
+ } else if(GetEncoding() == MT2 && GetChannelFormat() == stereoSplit && GetBitDepth() <= 16)
+ {
+ // MT2 stereo samples (right channel is stored as a difference from the left channel)
+ if(GetBitDepth() == 8)
+ {
+ int8 *outBuf = static_cast<int8 *>(sample.pSample);
+ for(SmpLength i = 0; i <= sample.nLength * 2; i += 2)
+ {
+ outBuf[i + 1] += outBuf[i];
+ }
+ } else
+ {
+ int16 *outBuf = static_cast<int16 *>(sample.pSample);
+ for(SmpLength i = 0; i <= sample.nLength * 2; i += 2)
+ {
+ outBuf[i + 1] += outBuf[i];
+ }
+ }
}
if(bytesRead > 0)
Modified: trunk/OpenMPT/soundlib/SampleIO.h
===================================================================
--- trunk/OpenMPT/soundlib/SampleIO.h 2013-05-17 00:18:47 UTC (rev 2089)
+++ trunk/OpenMPT/soundlib/SampleIO.h 2013-05-17 20:36:43 UTC (rev 2090)
@@ -78,6 +78,7 @@
PTM8Dto16, // PTM 8-Bit delta value -> 16-Bit sample
PCM7to8, // 8-Bit sample data with unused high bit
ADPCM, // 4-Bit ADPCM-packed
+ MT2, // MadTracker 2 stereo delta encoding
};
SampleIO(Bitdepth bits = _8bit, Channels channels = mono, Endianness endianness = littleEndian, Encoding encoding = signedPCM)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|