|
From: <sag...@us...> - 2015-03-02 00:25:55
|
Revision: 4805
http://sourceforge.net/p/modplug/code/4805
Author: saga-games
Date: 2015-03-02 00:25:42 +0000 (Mon, 02 Mar 2015)
Log Message:
-----------
[Fix] PLM: 16 bit samples didn't load correclty.
[Mod] Load PLM files as IT instead of S3M again because of increased channel count and sample global volume.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_plm.cpp
trunk/OpenMPT/soundlib/Sndfile.cpp
Modified: trunk/OpenMPT/soundlib/Load_plm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_plm.cpp 2015-03-01 22:01:31 UTC (rev 4804)
+++ trunk/OpenMPT/soundlib/Load_plm.cpp 2015-03-02 00:25:42 UTC (rev 4805)
@@ -185,6 +185,14 @@
sample.nLoopStart = sampleHeader.loopStart;
sample.nLoopEnd = sampleHeader.loopEnd;
sample.nLength = sampleHeader.length;
+ if(sampleHeader.flags & PLMSampleHeader::smp16Bit)
+ {
+ sample.nLoopStart /= 2;
+ sample.nLoopEnd /= 2;
+ sample.nLength /= 2;
+ // Apparently there is a bug in DT2 which adds an extra byte before the sample data.
+ sampleHeader.headerSize++;
+ }
if(sample.nLoopEnd > sample.nLoopStart) sample.uFlags.set(CHN_LOOP);
sample.SanitizeLoops();
file.Seek(samplePos[smp] + sampleHeader.headerSize);
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-03-01 22:01:31 UTC (rev 4804)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-03-02 00:25:42 UTC (rev 4805)
@@ -1331,7 +1331,6 @@
case MOD_TYPE_DSM:
case MOD_TYPE_AMF:
case MOD_TYPE_MTM:
- case MOD_TYPE_PLM:
return MOD_TYPE_S3M;
case MOD_TYPE_AMS:
case MOD_TYPE_AMS2:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-02 19:58:36
|
Revision: 4808
http://sourceforge.net/p/modplug/code/4808
Author: saga-games
Date: 2015-03-02 19:58:29 +0000 (Mon, 02 Mar 2015)
Log Message:
-----------
[Fix] PLM: Portamento-related improvements.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_plm.cpp
trunk/OpenMPT/soundlib/Snd_fx.cpp
Modified: trunk/OpenMPT/soundlib/Load_plm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_plm.cpp 2015-03-02 15:47:16 UTC (rev 4807)
+++ trunk/OpenMPT/soundlib/Load_plm.cpp 2015-03-02 19:58:29 UTC (rev 4808)
@@ -138,6 +138,7 @@
InitializeGlobals();
InitializeChannels();
+ SetModFlag(MSF_COMPATIBLE_PLAY, true);
m_nType = MOD_TYPE_PLM;
madeWithTracker = "Disorder Tracker 2";
mpt::String::Read<mpt::String::maybeNullTerminated>(songName, fileHeader.songName);
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-02 15:47:16 UTC (rev 4807)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-02 19:58:29 UTC (rev 4808)
@@ -951,7 +951,7 @@
// Special XM hack (also applies to MOD / S3M)
// Test case: PortaSmpChange.mod, PortaSmpChange.s3m
if((!instrumentChanged && (GetType() & (MOD_TYPE_XM | MOD_TYPE_MT2)) && pIns)
- || (GetType() & (MOD_TYPE_MOD | MOD_TYPE_S3M)))
+ || (GetType() & (MOD_TYPE_MOD | MOD_TYPE_S3M | MOD_TYPE_PLM)))
{
// FT2 doesn't change the sample in this case,
// but still uses the sample info from the old one (bug?)
@@ -3351,8 +3351,8 @@
{
pChn->dwFlags.set(CHN_PORTAMENTO);
- //IT compatibility 03
- if(!m_SongFlags[SONG_ITCOMPATGXX] && IsCompatibleMode(TRK_IMPULSETRACKER))
+ //IT compatibility 03: Share effect memory with portamento up/down
+ if((!m_SongFlags[SONG_ITCOMPATGXX] && IsCompatibleMode(TRK_IMPULSETRACKER)) || GetType() == MOD_TYPE_PLM)
{
if(param == 0) param = pChn->nOldPortaUpDown;
pChn->nOldPortaUpDown = param;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-04 02:08:40
|
Revision: 4818
http://sourceforge.net/p/modplug/code/4818
Author: saga-games
Date: 2015-03-04 02:08:26 +0000 (Wed, 04 Mar 2015)
Log Message:
-----------
[Imp] MOD Loader: Do not use VBlank timing if it actually results in a longer tune (http://bugs.openmpt.org/view.php?id=654)
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_mod.cpp
trunk/OpenMPT/soundlib/Snd_defs.h
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/mod_specifications.cpp
Modified: trunk/OpenMPT/soundlib/Load_mod.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mod.cpp 2015-03-03 22:41:35 UTC (rev 4817)
+++ trunk/OpenMPT/soundlib/Load_mod.cpp 2015-03-04 02:08:26 UTC (rev 4818)
@@ -338,23 +338,13 @@
// Functor for fixing VBlank MODs and MODs with 7-bit panning
-struct FixMODPatterns
+struct Fix7BitPanning
//===================
{
- FixMODPatterns(bool fixVBlank, bool fixPanning)
- {
- this->fixVBlank = fixVBlank;
- this->fixPanning = fixPanning;
- }
-
void operator()(ModCommand &m)
{
- if(m.command == CMD_TEMPO && this->fixVBlank)
+ if(m.command == CMD_PANNING8)
{
- // Fix VBlank MODs
- m.command = CMD_SPEED;
- } else if(m.command == CMD_PANNING8 && this->fixPanning)
- {
// Fix MODs with 7-bit + surround panning
if(m.param == 0xA4)
{
@@ -366,8 +356,6 @@
}
}
}
-
- bool fixVBlank, fixPanning;
};
@@ -762,12 +750,27 @@
// In the pattern loader above, a second condition is used: Only tempo commands
// below 100 BPM are taken into account. Furthermore, only M.K. (ProTracker)
// modules are checked.
- const bool fixVBlank = isMdKd && hasTempoCommands && GetSongTime() >= 600.0;
- const bool fix7BitPanning = leftPanning && !extendedPanning;
- if(fixVBlank || fix7BitPanning)
+ if(isMdKd && hasTempoCommands)
{
- Patterns.ForEachModCommand(FixMODPatterns(fixVBlank, fix7BitPanning));
+ const double songTime = GetSongTime();
+ if(songTime >= 600.0)
+ {
+ m_SongFlags.set(SONG_VBLANK_TIMING);
+ if(GetLength(eNoAdjust, GetLengthTarget(songTime)).front().targetReached)
+ {
+ // This just makes things worse, song is at least as long asi n CIA mode (e.g. in "Stary Hallway" by Neurodancer)
+ // Obviously we should keep using CIA timing then...
+ m_SongFlags.reset(SONG_VBLANK_TIMING);
+ } else
+ {
+ madeWithTracker = "ProTracker (VBlank)";
+ }
+ }
}
+ if(leftPanning && !extendedPanning)
+ {
+ Patterns.ForEachModCommand(Fix7BitPanning());
+ }
return true;
}
Modified: trunk/OpenMPT/soundlib/Snd_defs.h
===================================================================
--- trunk/OpenMPT/soundlib/Snd_defs.h 2015-03-03 22:41:35 UTC (rev 4817)
+++ trunk/OpenMPT/soundlib/Snd_defs.h 2015-03-04 02:08:26 UTC (rev 4818)
@@ -40,7 +40,6 @@
typedef uintptr_t SmpLength;
-#define MOD_AMIGAC2 0x1AB // Period of Amiga middle-c
const SmpLength MAX_SAMPLE_LENGTH = 0x10000000; // Sample length in *samples*
// Note: Sample size in bytes can be more than this (= 256 MB).
@@ -53,8 +52,8 @@
const SEQUENCEINDEX MAX_SEQUENCES = 50;
-const CHANNELINDEX MAX_BASECHANNELS = 127; // Max pattern channels.
-const CHANNELINDEX MAX_CHANNELS = 256; //200 // Maximum number of mixing channels.
+const CHANNELINDEX MAX_BASECHANNELS = 127; // Maximum pattern channels.
+const CHANNELINDEX MAX_CHANNELS = 256; // Maximum number of mixing channels.
#define FREQ_FRACBITS 4 // Number of fractional bits in return value of CSoundFile::GetFreqFromPeriod()
@@ -276,10 +275,11 @@
SONG_POSJUMP = 0x100000, // Position jump encountered (internal flag, do not touch)
SONG_PT1XMODE = 0x200000, // ProTracker 1/2 playback mode
SONG_PLAYALLSONGS = 0x400000, // Play all subsongs consecutively (libopenmpt)
+ SONG_VBLANK_TIMING = 0x800000, // Use MOD VBlank timing (F21 and higher set speed instead of tempo)
};
DECLARE_FLAGSET(SongFlags)
-#define SONG_FILE_FLAGS (SONG_EMBEDMIDICFG|SONG_FASTVOLSLIDES|SONG_ITOLDEFFECTS|SONG_ITCOMPATGXX|SONG_LINEARSLIDES|SONG_EXFILTERRANGE|SONG_AMIGALIMITS|SONG_PT1XMODE)
+#define SONG_FILE_FLAGS (SONG_EMBEDMIDICFG|SONG_FASTVOLSLIDES|SONG_ITOLDEFFECTS|SONG_ITCOMPATGXX|SONG_LINEARSLIDES|SONG_EXFILTERRANGE|SONG_AMIGALIMITS|SONG_PT1XMODE|SONG_VBLANK_TIMING)
#define SONG_PLAY_FLAGS (~SONG_FILE_FLAGS)
// Global Options (Renderer)
@@ -362,14 +362,6 @@
PLUGIN_VOLUMEHANDLING_MAX,
};
-// filtermodes
-/*enum {
- INST_FILTERMODE_DEFAULT=0,
- INST_FILTERMODE_HIGHPASS,
- INST_FILTERMODE_LOWPASS,
- INST_NUMFILTERMODES
-};*/
-
enum MidiChannel
{
MidiNoChannel = 0,
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-03 22:41:35 UTC (rev 4817)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-04 02:08:26 UTC (rev 4818)
@@ -379,14 +379,19 @@
}
#endif // MODPLUG_TRACKER
if (!param) break;
- // Allow high speed values here for VBlank MODs. (Maybe it would be better to have a "VBlank MOD" flag somewhere? Is it worth the effort?)
- if ((param <= GetModSpecifications().speedMax) || GetType() == MOD_TYPE_MOD)
+ if (param <= GetModSpecifications().speedMax)
{
memory.state.m_nMusicSpeed = param;
}
break;
// Set Tempo
case CMD_TEMPO:
+ if(m_SongFlags[SONG_VBLANK_TIMING])
+ {
+ // ProTracker MODs with VBlank timing: All Fxx parameters set the tick count.
+ if(param != 0) memory.state.m_nMusicSpeed = param;
+ break;
+ }
if ((adjustMode & eAdjust) && (GetType() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)))
{
if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
@@ -2229,7 +2234,7 @@
if(retrigEnv) //Case: instrument with no note data.
{
//IT compatibility: Instrument with no note.
- if(IsCompatibleMode(TRK_IMPULSETRACKER))
+ if(IsCompatibleMode(TRK_IMPULSETRACKER) || GetType() == MOD_TYPE_PLM)
{
if(GetNumInstruments())
{
@@ -2586,28 +2591,34 @@
// Set Tempo
case CMD_TEMPO:
+ if(m_SongFlags[SONG_VBLANK_TIMING])
+ {
+ // ProTracker MODs with VBlank timing: All Fxx parameters set the tick count.
+ if(m_SongFlags[SONG_FIRSTTICK] && param != 0) SetSpeed(param);
+ break;
+ }
// -> CODE#0010
// -> DESC="add extended parameter mechanism to pattern effects"
- m = nullptr;
- if (m_PlayState.m_nRow < Patterns[m_PlayState.m_nPattern].GetNumRows()-1)
+ m = nullptr;
+ if (m_PlayState.m_nRow < Patterns[m_PlayState.m_nPattern].GetNumRows()-1)
+ {
+ m = Patterns[m_PlayState.m_nPattern].GetpModCommand(m_PlayState.m_nRow + 1, nChn);
+ }
+ if (m && m->command == CMD_XPARAM)
+ {
+ if ((GetType() & MOD_TYPE_XM))
{
- m = Patterns[m_PlayState.m_nPattern].GetpModCommand(m_PlayState.m_nRow + 1, nChn);
+ param -= 0x20; //with XM, 0x20 is the lowest tempo. Anything below changes ticks per row.
}
- if (m && m->command == CMD_XPARAM)
- {
- if ((GetType() & MOD_TYPE_XM))
- {
- param -= 0x20; //with XM, 0x20 is the lowest tempo. Anything below changes ticks per row.
- }
- param = (param << 8) + m->param;
- }
+ param = (param << 8) + m->param;
+ }
// -! NEW_FEATURE#0010
- if (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT))
- {
- if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
- }
- if (param > GetModSpecifications().tempoMax) param = GetModSpecifications().tempoMax; // rewbs.merge: added check to avoid hyperspaced tempo!
- SetTempo(param);
+ if (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT))
+ {
+ if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
+ }
+ if (param > GetModSpecifications().tempoMax) param = GetModSpecifications().tempoMax; // rewbs.merge: added check to avoid hyperspaced tempo!
+ SetTempo(param);
break;
// Set Offset
Modified: trunk/OpenMPT/soundlib/mod_specifications.cpp
===================================================================
--- trunk/OpenMPT/soundlib/mod_specifications.cpp 2015-03-03 22:41:35 UTC (rev 4817)
+++ trunk/OpenMPT/soundlib/mod_specifications.cpp 2015-03-04 02:08:26 UTC (rev 4818)
@@ -115,7 +115,7 @@
false, // Doesn't support plugins
false, // No custom pattern time signatures
false, // No pattern names
- SongFlag(0) | SONG_PT1XMODE | SONG_AMIGALIMITS, // Supported song flags
+ SongFlag(0) | SONG_PT1XMODE | SONG_AMIGALIMITS | SONG_VBLANK_TIMING, // Supported song flags
};
@@ -159,7 +159,7 @@
false, // Doesn't support plugins
false, // No custom pattern time signatures
false, // No pattern names
- SongFlag(0) | SONG_LINEARSLIDES, // Supported song flags
+ SongFlag(0) | SONG_LINEARSLIDES, // Supported song flags
};
// XM with MPT extensions
@@ -246,7 +246,7 @@
false, // Doesn't support plugins
false, // No custom pattern time signatures
false, // No pattern names
- SongFlag(0) | SONG_FASTVOLSLIDES | SONG_AMIGALIMITS, // Supported song flags
+ SongFlag(0) | SONG_FASTVOLSLIDES | SONG_AMIGALIMITS, // Supported song flags
};
// S3M with MPT extensions
@@ -290,7 +290,7 @@
false, // Doesn't support plugins
false, // No custom pattern time signatures
false, // No pattern names
- SongFlag(0) | SONG_FASTVOLSLIDES | SONG_AMIGALIMITS, // Supported song flags
+ SongFlag(0) | SONG_FASTVOLSLIDES | SONG_AMIGALIMITS, // Supported song flags
};
const CModSpecifications it =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <man...@us...> - 2015-03-04 12:42:10
|
Revision: 4822
http://sourceforge.net/p/modplug/code/4822
Author: manxorist
Date: 2015-03-04 12:41:57 +0000 (Wed, 04 Mar 2015)
Log Message:
-----------
[Ref] Convert SampleIO::WriteSample to std::ostream and mpt::IO.
[Ref] Use mpt::oftsream to write wav and raw samples.
[Ref] Remove FILE* support in class WavWriter, which is now unsed. (fixes a 64bit warning)
Modified Paths:
--------------
trunk/OpenMPT/soundlib/SampleFormats.cpp
trunk/OpenMPT/soundlib/SampleIO.cpp
trunk/OpenMPT/soundlib/SampleIO.h
trunk/OpenMPT/soundlib/WAVTools.cpp
trunk/OpenMPT/soundlib/WAVTools.h
Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp
===================================================================
--- trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-03-04 12:19:20 UTC (rev 4821)
+++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-03-04 12:41:57 UTC (rev 4822)
@@ -463,8 +463,14 @@
bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const
//----------------------------------------------------------------------------------------
{
- WAVWriter file(filename);
+ mpt::ofstream f(filename, std::ios::binary);
+ if(!f)
+ {
+ return false;
+ }
+ WAVWriter file(&f);
+
if(!file.IsValid())
{
return false;
@@ -480,7 +486,7 @@
sample.uFlags[CHN_STEREO] ? SampleIO::stereoInterleaved : SampleIO::mono,
SampleIO::littleEndian,
sample.uFlags[CHN_16BIT] ? SampleIO::signedPCM : SampleIO::unsignedPCM)
- .WriteSample(file.GetFile(), sample));
+ .WriteSample(f, sample));
file.WriteLoopInformation(sample);
file.WriteExtraInformation(sample, GetType());
@@ -504,8 +510,11 @@
bool CSoundFile::SaveRAWSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const
//----------------------------------------------------------------------------------------
{
- FILE *f;
- if((f = mpt_fopen(filename, "wb")) == NULL) return false;
+ mpt::ofstream f(filename, std::ios::binary);
+ if(!f)
+ {
+ return false;
+ }
const ModSample &sample = Samples[nSample];
SampleIO(
@@ -515,7 +524,6 @@
SampleIO::signedPCM)
.WriteSample(f, sample);
- fclose(f);
return true;
}
Modified: trunk/OpenMPT/soundlib/SampleIO.cpp
===================================================================
--- trunk/OpenMPT/soundlib/SampleIO.cpp 2015-03-04 12:19:20 UTC (rev 4821)
+++ trunk/OpenMPT/soundlib/SampleIO.cpp 2015-03-04 12:41:57 UTC (rev 4822)
@@ -592,9 +592,10 @@
#ifndef MODPLUG_NO_FILESAVE
+
// Write a sample to file
-size_t SampleIO::WriteSample(FILE *f, const ModSample &sample, SmpLength maxSamples) const
-//----------------------------------------------------------------------------------------
+size_t SampleIO::WriteSample(std::ostream *f, const ModSample &sample, SmpLength maxSamples) const
+//------------------------------------------------------------------------------------------------
{
if(!sample.HasSampleData()) return 0;
@@ -640,11 +641,11 @@
bufcount++;
if(bufcount >= CountOf(buffer16))
{
- if(f) fwrite(buffer16, 1, bufcount * 2, f);
+ if(f) mpt::IO::WriteRaw(*f, buffer16, bufcount * 2);
bufcount = 0;
}
}
- if (bufcount) if(f) fwrite(buffer16, 1, bufcount * 2, f);
+ if (bufcount) if(f) mpt::IO::WriteRaw(*f, buffer16, bufcount * 2);
}
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoSplit &&
@@ -672,11 +673,11 @@
}
if(bufcount >= CountOf(buffer8))
{
- if(f) fwrite(buffer8, 1, bufcount, f);
+ if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
bufcount = 0;
}
}
- if (bufcount) if(f) fwrite(buffer8, 1, bufcount, f);
+ if (bufcount) if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
}
len = numSamples * 2;
}
@@ -707,11 +708,11 @@
bufcount++;
if(bufcount >= CountOf(buffer16))
{
- if(f) fwrite(buffer16, 1, bufcount * 2, f);
+ if(f) mpt::IO::WriteRaw(*f, buffer16, bufcount * 2);
bufcount = 0;
}
}
- if (bufcount) if(f) fwrite(buffer16, 1, bufcount * 2, f);
+ if (bufcount) if(f) mpt::IO::WriteRaw(*f, buffer16, bufcount * 2);
}
len = numSamples * 4;
}
@@ -720,7 +721,7 @@
{
// Stereo signed interleaved
len = sample.GetSampleSizeInBytes();
- if(f) fwrite(pSampleVoid, 1, len, f);
+ if(f) mpt::IO::WriteRaw(*f, pSampleVoid, len);
}
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoInterleaved && GetEncoding() == unsignedPCM)
@@ -733,18 +734,17 @@
bufcount++;
if(bufcount >= CountOf(buffer8))
{
- if(f) fwrite(buffer8, 1, bufcount, f);
+ if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
bufcount = 0;
}
}
- if (bufcount) if(f) fwrite(buffer8, 1, bufcount, f);
+ if (bufcount) if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
}
else if(GetEncoding() == IT214 || GetEncoding() == IT215)
{
// IT2.14-encoded samples
- mpt::FILE_ostream s(f);
- ITCompression its(sample, GetEncoding() == IT215, f ? &s : nullptr);
+ ITCompression its(sample, GetEncoding() == IT215, f);
len = its.GetCompressedSize();
}
@@ -777,15 +777,33 @@
}
if(bufcount >= CountOf(buffer8))
{
- if(f) fwrite(buffer8, 1, bufcount, f);
+ if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
bufcount = 0;
}
}
- if (bufcount) if(f) fwrite(buffer8, 1, bufcount, f);
+ if (bufcount) if(f) mpt::IO::WriteRaw(*f, buffer8, bufcount);
}
return len;
}
+
+// Write a sample to file
+size_t SampleIO::WriteSample(std::ostream &f, const ModSample &sample, SmpLength maxSamples) const
+//------------------------------------------------------------------------------------------------
+{
+ return WriteSample(&f, sample, maxSamples);
+}
+
+
+// Write a sample to file
+size_t SampleIO::WriteSample(FILE *f, const ModSample &sample, SmpLength maxSamples) const
+//----------------------------------------------------------------------------------------
+{
+ mpt::FILE_ostream s(f);
+ return WriteSample(f ? &s : nullptr, sample, maxSamples);
+}
+
+
#endif // MODPLUG_NO_FILESAVE
Modified: trunk/OpenMPT/soundlib/SampleIO.h
===================================================================
--- trunk/OpenMPT/soundlib/SampleIO.h 2015-03-04 12:19:20 UTC (rev 4821)
+++ trunk/OpenMPT/soundlib/SampleIO.h 2015-03-04 12:41:57 UTC (rev 4822)
@@ -169,7 +169,11 @@
size_t ReadSample(ModSample &sample, FileReader &file) const;
#ifndef MODPLUG_NO_FILESAVE
+ // Optionally write a sample to file
+ size_t WriteSample(std::ostream *f, const ModSample &sample, SmpLength maxSamples = 0) const;
// Write a sample to file
+ size_t WriteSample(std::ostream &f, const ModSample &sample, SmpLength maxSamples = 0) const;
+ // Write a sample to file
size_t WriteSample(FILE *f, const ModSample &sample, SmpLength maxSamples = 0) const;
#endif // MODPLUG_NO_FILESAVE
};
Modified: trunk/OpenMPT/soundlib/WAVTools.cpp
===================================================================
--- trunk/OpenMPT/soundlib/WAVTools.cpp 2015-03-04 12:19:20 UTC (rev 4821)
+++ trunk/OpenMPT/soundlib/WAVTools.cpp 2015-03-04 12:41:57 UTC (rev 4822)
@@ -257,29 +257,9 @@
// WAV Writing
-// Output to file: Initialize with filename.
-WAVWriter::WAVWriter(const mpt::PathString &filename) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0)
-//---------------------------------------------------------------------------------------------------------------------------
-{
- f = mpt_fopen(filename, "w+b");
- fileOwned = true;
- Init();
-}
-
-
-// Output to file: Initialize with FILE*.
-WAVWriter::WAVWriter(FILE *file) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0)
-//------------------------------------------------------------------------------------------------------
-{
- f = file;
- fileOwned = false;
- Init();
-}
-
-
// Output to stream: Initialize with std::ostream*.
-WAVWriter::WAVWriter(std::ostream *stream) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0)
-//----------------------------------------------------------------------------------------------------------------
+WAVWriter::WAVWriter(std::ostream *stream) : s(nullptr), memory(nullptr), memSize(0)
+//----------------------------------------------------------------------------------
{
s = stream;
Init();
@@ -287,8 +267,8 @@
// Output to clipboard: Initialize with pointer to memory and size of reserved memory.
-WAVWriter::WAVWriter(void *mem, size_t size) : f(nullptr), fileOwned(false), s(nullptr), memory(static_cast<uint8 *>(mem)), memSize(size)
-//---------------------------------------------------------------------------------------------------------------------------------------
+WAVWriter::WAVWriter(void *mem, size_t size) : s(nullptr), memory(static_cast<uint8 *>(mem)), memSize(size)
+//----------------------------------------------------------------------------------------------------------
{
Init();
}
@@ -329,21 +309,6 @@
Seek(0);
Write(fileHeader);
- if(f != nullptr)
- {
-#ifdef _DEBUG
- fseek(f, 0, SEEK_END);
- size_t realSize = static_cast<size_t>(ftell(f));
- MPT_ASSERT(totalSize == realSize);
-#endif
- if(fileOwned)
- {
- fclose(f);
- fileOwned = false;
- }
- }
-
- f = nullptr;
s = nullptr;
memory = nullptr;
@@ -397,11 +362,8 @@
position = pos;
totalSize = std::max(totalSize, position);
- if(f != nullptr)
+ if(s != nullptr)
{
- fseek(f, position, SEEK_SET);
- } else if(s != nullptr)
- {
s->seekp(position);
}
}
@@ -411,11 +373,8 @@
void WAVWriter::Write(const void *data, size_t numBytes)
//------------------------------------------------------
{
- if(f != nullptr)
+ if(s != nullptr)
{
- fwrite(data, numBytes, 1, f);
- } else if(s != nullptr)
- {
s->write(static_cast<const char*>(data), numBytes);
} else if(memory != nullptr)
{
Modified: trunk/OpenMPT/soundlib/WAVTools.h
===================================================================
--- trunk/OpenMPT/soundlib/WAVTools.h 2015-03-04 12:19:20 UTC (rev 4821)
+++ trunk/OpenMPT/soundlib/WAVTools.h 2015-03-04 12:41:57 UTC (rev 4822)
@@ -386,9 +386,6 @@
//=============
{
protected:
- // When writing to file: File handle
- FILE *f;
- bool fileOwned;
// When writing to a stream: Stream pointer
std::ostream *s;
// When writing to memory: Memory address + length
@@ -405,10 +402,6 @@
RIFFChunk chunkHeader;
public:
- // Output to file: Initialize with filename. The created FILE* is owned by this instance.
- WAVWriter(const mpt::PathString &filename);
- // Output to file: Initialize with FILE*.
- WAVWriter(FILE *file);
// Output to stream: Initialize with std::ostream*.
WAVWriter(std::ostream *stream);
// Output to clipboard: Initialize with pointer to memory and size of reserved memory.
@@ -417,7 +410,7 @@
~WAVWriter();
// Check if anything can be written to the file.
- bool IsValid() const { return f != nullptr || s != nullptr || memory != nullptr; }
+ bool IsValid() const { return s != nullptr || memory != nullptr; }
// Finalize the file by closing the last open chunk and updating the file header. Returns total size of file.
size_t Finalize();
@@ -426,8 +419,6 @@
// Skip some bytes... For example after writing sample data.
void Skip(size_t numBytes) { Seek(position + numBytes); }
- // Get file handle
- FILE *GetFile() { return f; }
// Get position in file (not counting any changes done to the file from outside this class, i.e. through GetFile())
size_t GetPosition() const { return position; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-07 16:02:28
|
Revision: 4831
http://sourceforge.net/p/modplug/code/4831
Author: saga-games
Date: 2015-03-07 16:02:15 +0000 (Sat, 07 Mar 2015)
Log Message:
-----------
[Mod] Use FileReader at least for verifying files in the last three remaining loaders (MDL, MED, MID). The actual file loading is still done with raw memory access.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_mdl.cpp
trunk/OpenMPT/soundlib/Load_med.cpp
trunk/OpenMPT/soundlib/Load_mid.cpp
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/Load_mdl.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mdl.cpp 2015-03-06 22:16:16 UTC (rev 4830)
+++ trunk/OpenMPT/soundlib/Load_mdl.cpp 2015-03-07 16:02:15 UTC (rev 4831)
@@ -288,11 +288,27 @@
-bool CSoundFile::ReadMDL(const uint8 *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags)
-//-------------------------------------------------------------------------------------------------
+bool CSoundFile::ReadMDL(FileReader &file, ModLoadingFlags loadFlags)
+//-------------------------------------------------------------------
{
+ file.Rewind();
+ MDLFileHeader pmsh;
+ if(!file.ReadStruct(pmsh)
+ || !file.CanRead(1024)
+ || pmsh.id != LittleEndian(0x4C444D44)
+ || (pmsh.version & 0xF0) > 0x10)
+ {
+ return false;
+ } else if(loadFlags == onlyVerifyHeader)
+ {
+ return true;
+ }
+
+ file.Rewind();
+ const FileReader::off_t dwMemLength = file.GetLength();
+ const uint8 *lpStream = reinterpret_cast<const uint8 *>(file.GetRawData());
+
DWORD dwMemPos, dwPos, blocklen, dwTrackPos;
- const MDLFileHeader *pmsh = (const MDLFileHeader *)lpStream;
MDLInfoBlock *pmib;
UINT i,j, norders = 0, npatterns = 0, ntracks = 0;
UINT ninstruments = 0, nsamples = 0;
@@ -305,11 +321,8 @@
UINT nvolenv, npanenv, npitchenv;
std::vector<ROWINDEX> patternLength;
- if ((!lpStream) || (dwMemLength < 1024)) return false;
- if ((pmsh->id != 0x4C444D44) || ((pmsh->version & 0xF0) > 0x10)) return false;
- else if(loadFlags == onlyVerifyHeader) return true;
#ifdef MDL_LOG
- Log("MDL v%d.%d\n", pmsh->version>>4, pmsh->version&0x0f);
+ Log("MDL v%d.%d\n", pmsh.version>>4, pmsh.version&0x0f);
#endif
MemsetZero(patterntracks);
MemsetZero(smpinfo);
@@ -388,7 +401,7 @@
UINT ch;
if (dwPos+18 >= dwMemLength) break;
- if (pmsh->version > 0)
+ if (pmsh.version > 0)
{
const MDLPatternHeader *pmpd = (const MDLPatternHeader *)(lpStream + dwPos);
if (pmpd->channels > 32) break;
@@ -520,7 +533,7 @@
#endif
nsamples = lpStream[dwMemPos];
dwPos = dwMemPos + 1;
- for (i = 0; i < nsamples; i++, dwPos += (pmsh->version > 0) ? sizeof(MDLSampleHeader) : sizeof(MDLSampleHeaderv0))
+ for (i = 0; i < nsamples; i++, dwPos += (pmsh.version > 0) ? sizeof(MDLSampleHeader) : sizeof(MDLSampleHeaderv0))
{
const MDLSampleHeaderCommon *info = reinterpret_cast<const MDLSampleHeaderCommon *>(lpStream + dwPos);
if(!IsInRange(info->sampleIndex, 1, MAX_SAMPLES-1))
@@ -537,7 +550,7 @@
mpt::String::Read<mpt::String::maybeNullTerminated>(m_szNames[info->sampleIndex], info->name);
mpt::String::Read<mpt::String::maybeNullTerminated>(sample.filename, info->filename);
- if(pmsh->version > 0)
+ if(pmsh.version > 0)
{
const MDLSampleHeader *sampleHeader = reinterpret_cast<const MDLSampleHeader *>(lpStream + dwPos);
Modified: trunk/OpenMPT/soundlib/Load_med.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_med.cpp 2015-03-06 22:16:16 UTC (rev 4830)
+++ trunk/OpenMPT/soundlib/Load_med.cpp 2015-03-07 16:02:15 UTC (rev 4831)
@@ -66,7 +66,7 @@
typedef struct PACKED tagMEDMODULEHEADER
{
- DWORD id; // MMD1-MMD3
+ char id[4]; // MMD1-MMD3
DWORD modlen; // Size of file
DWORD song; // Position in file for this song
WORD psecnum;
@@ -502,47 +502,57 @@
}
-bool CSoundFile::ReadMed(const uint8 *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags)
-//-------------------------------------------------------------------------------------------------
+bool CSoundFile::ReadMed(FileReader &file, ModLoadingFlags loadFlags)
+//------------------------------------------------------------------
{
- const MEDMODULEHEADER *pmmh;
+ file.Rewind();
+ MEDMODULEHEADER pmmh;
+ DWORD dwSong;
+ if(!file.CanRead(512)
+ || !file.ReadStruct(pmmh)
+ || memcmp(pmmh.id, "MMD", 3)
+ || pmmh.id[3] < '0' || pmmh.id[3] > '3'
+ || (dwSong = BigEndian(pmmh.song)) == 0
+ || !file.LengthIsAtLeast(dwSong)
+ || !file.LengthIsAtLeast(dwSong + sizeof(MMD0SONGHEADER)))
+ {
+ return false;
+ } else if(loadFlags == onlyVerifyHeader)
+ {
+ return true;
+ }
+
+ file.Rewind();
+ const FileReader::off_t dwMemLength = file.GetLength();
+ const uint8 *lpStream = reinterpret_cast<const uint8 *>(file.GetRawData());
const MMD0SONGHEADER *pmsh;
const MMD2SONGHEADER *pmsh2;
const MMD0EXP *pmex;
DWORD dwBlockArr, dwSmplArr, dwExpData, wNumBlocks;
const_unaligned_ptr_le<DWORD> pdwTable;
- int8 version;
+ int8 version = pmmh.id[3];
UINT deftempo;
int playtransp = 0;
- if ((!lpStream) || (dwMemLength < 0x200)) return false;
- pmmh = (MEDMODULEHEADER *)lpStream;
- if (((pmmh->id & 0x00FFFFFF) != 0x444D4D) || (!pmmh->song)) return false;
- // Check for 'MMDx'
- DWORD dwSong = BigEndian(pmmh->song);
- if ((dwSong >= dwMemLength) || (dwSong + sizeof(MMD0SONGHEADER) >= dwMemLength)) return false;
- version = (signed char)((pmmh->id >> 24) & 0xFF);
- if ((version < '0') || (version > '3')) return false;
- else if(loadFlags == onlyVerifyHeader) return true;
#ifdef MED_LOG
- Log("\nLoading MMD%c module (flags=0x%02X)...\n", version, BigEndian(pmmh->mmdflags));
- Log(" modlen = %d\n", BigEndian(pmmh->modlen));
- Log(" song = 0x%08X\n", BigEndian(pmmh->song));
- Log(" psecnum = %d\n", BigEndianW(pmmh->psecnum));
- Log(" pseq = %d\n", BigEndianW(pmmh->pseq));
- Log(" blockarr = 0x%08X\n", BigEndian(pmmh->blockarr));
- Log(" mmdflags = 0x%08X\n", BigEndian(pmmh->mmdflags));
- Log(" smplarr = 0x%08X\n", BigEndian(pmmh->smplarr));
- Log(" reserved = 0x%08X\n", BigEndian(pmmh->reserved));
- Log(" expdata = 0x%08X\n", BigEndian(pmmh->expdata));
- Log(" reserved2= 0x%08X\n", BigEndian(pmmh->reserved2));
- Log(" pstate = %d\n", BigEndianW(pmmh->pstate));
- Log(" pblock = %d\n", BigEndianW(pmmh->pblock));
- Log(" pline = %d\n", BigEndianW(pmmh->pline));
- Log(" pseqnum = %d\n", BigEndianW(pmmh->pseqnum));
- Log(" actplayline=%d\n", BigEndianW(pmmh->actplayline));
- Log(" counter = %d\n", pmmh->counter);
- Log(" extra_songs = %d\n", pmmh->extra_songs);
+ Log("\nLoading MMD%c module (flags=0x%02X)...\n", version, BigEndian(pmmh.mmdflags));
+ Log(" modlen = %d\n", BigEndian(pmmh.modlen));
+ Log(" song = 0x%08X\n", BigEndian(pmmh.song));
+ Log(" psecnum = %d\n", BigEndianW(pmmh.psecnum));
+ Log(" pseq = %d\n", BigEndianW(pmmh.pseq));
+ Log(" blockarr = 0x%08X\n", BigEndian(pmmh.blockarr));
+ Log(" mmdflags = 0x%08X\n", BigEndian(pmmh.mmdflags));
+ Log(" smplarr = 0x%08X\n", BigEndian(pmmh.smplarr));
+ Log(" reserved = 0x%08X\n", BigEndian(pmmh.reserved));
+ Log(" expdata = 0x%08X\n", BigEndian(pmmh.expdata));
+ Log(" reserved2= 0x%08X\n", BigEndian(pmmh.reserved2));
+ Log(" pstate = %d\n", BigEndianW(pmmh.pstate));
+ Log(" pblock = %d\n", BigEndianW(pmmh.pblock));
+ Log(" pline = %d\n", BigEndianW(pmmh.pline));
+ Log(" pseqnum = %d\n", BigEndianW(pmmh.pseqnum));
+ Log(" actplayline=%d\n", BigEndianW(pmmh.actplayline));
+ Log(" counter = %d\n", pmmh.counter);
+ Log(" extra_songs = %d\n", pmmh.extra_songs);
Log("\n");
#endif
@@ -554,9 +564,9 @@
m_nType = MOD_TYPE_MED;
m_nSamplePreAmp = 32;
- dwBlockArr = BigEndian(pmmh->blockarr);
- dwSmplArr = BigEndian(pmmh->smplarr);
- dwExpData = BigEndian(pmmh->expdata);
+ dwBlockArr = BigEndian(pmmh.blockarr);
+ dwSmplArr = BigEndian(pmmh.smplarr);
+ dwExpData = BigEndian(pmmh.expdata);
if ((dwExpData) && (dwExpData < dwMemLength - sizeof(MMD0EXP)))
pmex = (MMD0EXP *)(lpStream+dwExpData);
else
Modified: trunk/OpenMPT/soundlib/Load_mid.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mid.cpp 2015-03-06 22:16:16 UTC (rev 4830)
+++ trunk/OpenMPT/soundlib/Load_mid.cpp 2015-03-07 16:02:15 UTC (rev 4831)
@@ -39,7 +39,7 @@
typedef struct PACKED MIDIFILEHEADER
{
- DWORD id; // "MThd" = 0x6468544D
+ char id[4]; // "MThd" = 0x6468544D
DWORD len; // 6
WORD w1; // 1?
WORD wTrks; // 2?
@@ -468,15 +468,56 @@
#define MIDIGLOBAL_XGSYSTEMON 0x0200
-bool CSoundFile::ReadMID(const uint8 *lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags)
-//-------------------------------------------------------------------------------------------
+bool CSoundFile::ReadMID(FileReader &file, ModLoadingFlags loadFlags)
+//-------------------------------------------------------------------
{
- const MIDIFILEHEADER *pmfh = (const MIDIFILEHEADER *)lpStream;
+ file.Rewind();
+
+ // Microsoft MIDI files
+ if(file.ReadMagic("RIFF"))
+ {
+ file.Skip(4);
+ if(!file.ReadMagic("RMID"))
+ {
+ return false;
+ } else if(loadFlags == onlyVerifyHeader)
+ {
+ return true;
+ }
+ do
+ {
+ uint32 id = file.ReadUint32LE();
+ uint32 length = file.ReadUint32LE();
+ if(memcmp(&id, "data", 4))
+ {
+ file.Skip(length);
+ } else
+ {
+ break;
+ }
+ } while(file.BytesLeft());
+ }
+
+ MIDIFILEHEADER pmfh;
+ if(!file.ReadStruct(pmfh)
+ || memcmp(pmfh.id, "MThd", 4)
+ || !file.Seek(8 + BigEndian(pmfh.len)))
+ {
+ return false;
+ } else if(loadFlags == onlyVerifyHeader)
+ {
+ return true;
+ }
+
+ const FileReader::off_t dwMemLength = file.BytesLeft();
+ const uint8 *lpStream = reinterpret_cast<const uint8 *>(file.GetRawData());
+
const MIDITRACKHEADER *pmth;
MODCHANNELSTATE chnstate[MAX_BASECHANNELS];
MIDICHANNELSTATE midichstate[16];
std::vector<MIDITRACK> miditracks;
- DWORD dwMemPos, dwGlobalFlags, tracks, tempo;
+ FileReader::off_t dwMemPos = 0;
+ DWORD dwGlobalFlags, tracks, tempo;
UINT row, pat, midimastervol;
short int division;
int midi_clock, nTempoUsec, nPPQN, nTickMultiplier;
@@ -493,36 +534,8 @@
Limit(importSpeed, 2, 6);
Limit(importPatternLen, ROWINDEX(1), MAX_PATTERN_ROWS);
- // Detect RMI files
- if ((dwMemLength > 12)
- && (*(DWORD *)(lpStream) == IFFID_RIFF)
- && (*(DWORD *)(lpStream+8) == 0x44494D52))
- {
- lpStream += 12;
- dwMemLength -= 12;
- while (dwMemLength > 8)
- {
- DWORD id = *(DWORD *)lpStream;
- DWORD len = *(DWORD *)(lpStream+4);
- lpStream += 8;
- dwMemLength -= 8;
- if ((id == IFFID_data) && (len < dwMemLength))
- {
- dwMemLength = len;
- pmfh = (const MIDIFILEHEADER *)lpStream;
- break;
- }
- if (len >= dwMemLength) return false;
- lpStream += len;
- dwMemLength -= len;
- }
- }
- // MIDI File Header
- if ((dwMemLength < sizeof(MIDIFILEHEADER)+8) || (pmfh->id != 0x6468544D)) return false;
- dwMemPos = 8 + BigEndian(pmfh->len);
- if (dwMemPos >= dwMemLength - 8) return false;
pmth = (MIDITRACKHEADER *)(lpStream+dwMemPos);
- tracks = BigEndianW(pmfh->wTrks);
+ tracks = BigEndianW(pmfh.wTrks);
if ((pmth->id != 0x6B72544D) || (!tracks)) return false;
else if(loadFlags == onlyVerifyHeader) return true;
miditracks.resize(tracks);
@@ -535,7 +548,7 @@
songName = "";
// MIDI->MOD Tempo Conversion
- division = BigEndianW(pmfh->wDivision);
+ division = BigEndianW(pmfh.wDivision);
if (division < 0)
{
int nFrames = -(division>>8);
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-03-06 22:16:16 UTC (rev 4830)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-03-07 16:02:15 UTC (rev 4831)
@@ -739,9 +739,9 @@
&& !ReadWav(file, loadFlags)
#endif // MODPLUG_TRACKER
&& !ReadSTM(file, loadFlags)
- && !ReadMed(lpStream, dwMemLength, loadFlags)
+ && !ReadMed(file, loadFlags)
&& !ReadMTM(file, loadFlags)
- && !ReadMDL(lpStream, dwMemLength, loadFlags)
+ && !ReadMDL(file, loadFlags)
&& !ReadDBM(file, loadFlags)
&& !Read669(file, loadFlags)
&& !ReadFAR(file, loadFlags)
@@ -759,7 +759,7 @@
&& !ReadPSM16(file, loadFlags)
&& !ReadMT2(file, loadFlags)
#ifdef MODPLUG_TRACKER
- && !ReadMID(lpStream, dwMemLength, loadFlags)
+ && !ReadMID(file, loadFlags)
#endif // MODPLUG_TRACKER
&& !ReadGDM(file, loadFlags)
&& !ReadIMF(file, loadFlags)
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-03-06 22:16:16 UTC (rev 4830)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-03-07 16:02:15 UTC (rev 4831)
@@ -666,7 +666,7 @@
bool ReadMod(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadM15(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadICE(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
- bool ReadMed(const uint8 *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags = loadCompleteModule);
+ bool ReadMed(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadMTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadSTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadIT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
@@ -678,7 +678,7 @@
bool ReadFAR(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadAMS(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadAMS2(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
- bool ReadMDL(const uint8 *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags = loadCompleteModule);
+ bool ReadMDL(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadOKT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadDMF(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadPTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
@@ -696,7 +696,7 @@
bool ReadJ2B(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadDIGI(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
bool ReadPLM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
- bool ReadMID(const uint8 *lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags = loadCompleteModule);
+ bool ReadMID(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
static std::vector<const char *> GetSupportedExtensions(bool otherFormats);
static mpt::Charset GetCharsetFromModType(MODTYPE modtype);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-11 15:23:43
|
Revision: 4864
http://sourceforge.net/p/modplug/code/4864
Author: saga-games
Date: 2015-03-11 15:23:30 +0000 (Wed, 11 Mar 2015)
Log Message:
-----------
[Fix] XParam + Oxx was no longer able to create offsets < 256.
[Ref] Make tempo code also use CalculateXParam.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 14:23:08 UTC (rev 4863)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 15:23:30 UTC (rev 4864)
@@ -378,34 +378,13 @@
if(param != 0) memory.state.m_nMusicSpeed = param;
break;
}
+ param = CalculateXParam(memory.state.m_nPattern, memory.state.m_nRow, nChn);
if ((adjustMode & eAdjust) && (GetType() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)))
{
if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
}
- if (param >= 0x20) memory.state.m_nMusicTempo = param; else
- {
- // Tempo Slide
- uint32 tempoDiff = (param & 0x0F) * (memory.state.m_nMusicSpeed - 1);
- if ((param & 0xF0) == 0x10)
- {
- memory.state.m_nMusicTempo += tempoDiff;
- } else
- {
- if(tempoDiff < memory.state.m_nMusicTempo)
- memory.state.m_nMusicTempo -= tempoDiff;
- else
- memory.state.m_nMusicTempo = 32;
- }
- }
-// -> CODE#0010
-// -> DESC="add extended parameter mechanism to pattern effects"
- if(IsCompatibleMode(TRK_ALLTRACKERS)) // clamp tempo correctly in compatible mode
- memory.state.m_nMusicTempo = Clamp(memory.state.m_nMusicTempo, 32u, 255u);
- else
- memory.state.m_nMusicTempo = Clamp(memory.state.m_nMusicTempo, GetModSpecifications().tempoMin, GetModSpecifications().tempoMax);
-// -! NEW_FEATURE#0010
+ SetTempo(param);
break;
-
case CMD_S3MCMDEX:
if((param & 0xF0) == 0x60)
{
@@ -641,8 +620,9 @@
if(p->command == CMD_OFFSET)
{
- SmpLength offset = CalculateXParam(memory.state.m_nPattern, memory.state.m_nRow, nChn);
- if(offset < 256)
+ bool isExtended = false;
+ SmpLength offset = CalculateXParam(memory.state.m_nPattern, memory.state.m_nRow, nChn, &isExtended);
+ if(!isExtended)
{
offset <<= 8;
if(offset == 0) offset = pChn->oldOffset;
@@ -2600,27 +2580,12 @@
if(m_SongFlags[SONG_FIRSTTICK] && param != 0) SetSpeed(param);
break;
}
-// -> CODE#0010
-// -> DESC="add extended parameter mechanism to pattern effects"
- m = nullptr;
- if (m_PlayState.m_nRow < Patterns[m_PlayState.m_nPattern].GetNumRows()-1)
- {
- m = Patterns[m_PlayState.m_nPattern].GetpModCommand(m_PlayState.m_nRow + 1, nChn);
- }
- if (m && m->command == CMD_XPARAM)
- {
- if ((GetType() & MOD_TYPE_XM))
- {
- param -= 0x20; //with XM, 0x20 is the lowest tempo. Anything below changes ticks per row.
- }
- param = (param << 8) + m->param;
- }
-// -! NEW_FEATURE#0010
+
+ param = CalculateXParam(m_PlayState.m_nPattern, m_PlayState.m_nRow, nChn);
if (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT))
{
if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
}
- if (param > GetModSpecifications().tempoMax) param = GetModSpecifications().tempoMax; // rewbs.merge: added check to avoid hyperspaced tempo!
SetTempo(param);
break;
@@ -2634,8 +2599,9 @@
{
break;
}
- SmpLength offset = CalculateXParam(m_PlayState.m_nPattern, m_PlayState.m_nRow, nChn);
- if(offset < 256)
+ bool isExtended = false;
+ SmpLength offset = CalculateXParam(m_PlayState.m_nPattern, m_PlayState.m_nRow, nChn, &isExtended);
+ if(!isExtended)
{
// No X-param (normal behaviour)
offset <<= 8;
@@ -3020,9 +2986,11 @@
// Calculate full parameter for effects that support parameter extension at the given pattern location.
// maxCommands sets the maximum number of XParam commands to look at for this effect
-uint32_t CSoundFile::CalculateXParam(PATTERNINDEX pat, ROWINDEX row, CHANNELINDEX chn) const
-//------------------------------------------------------------------------------------------
+// isExtended returns if the command is actually using any XParam extensions.
+uint32_t CSoundFile::CalculateXParam(PATTERNINDEX pat, ROWINDEX row, CHANNELINDEX chn, bool *isExtended) const
+//------------------------------------------------------------------------------------------------------------
{
+ if(isExtended != nullptr) *isExtended = false;
ROWINDEX maxCommands = 4;
const ModCommand *m = Patterns[pat].GetpModCommand(chn, row);
uint32_t val = m->param;
@@ -3042,6 +3010,7 @@
return val;
}
+ const bool xmTempoFix = m->command == CMD_TEMPO && GetType() == MOD_TYPE_XM;
ROWINDEX numRows = std::min(Patterns[pat].GetNumRows() - row - 1, maxCommands);
while(numRows > 0)
{
@@ -3050,8 +3019,14 @@
{
break;
}
+ if(xmTempoFix && val < 256)
+ {
+ // With XM, 0x20 is the lowest tempo. Anything below changes ticks per row.
+ val -= 0x20;
+ }
val = (val << 8) | m->param;
numRows--;
+ if(isExtended != nullptr) *isExtended = true;
}
return val;
}
@@ -4916,22 +4891,19 @@
if (param >= 0x20 && m_SongFlags[SONG_FIRSTTICK]) //rewbs.tempoSlideFix: only set if not (T0x or T1x) and tick is 0
{
m_PlayState.m_nMusicTempo = param;
- }
- // Tempo Slide
- else if (param < 0x20 && !m_SongFlags[SONG_FIRSTTICK]) //rewbs.tempoSlideFix: only slide if (T0x or T1x) and tick is not 0
+ if (param > GetModSpecifications().tempoMax) param = GetModSpecifications().tempoMax;
+ } else if (param < 0x20 && !m_SongFlags[SONG_FIRSTTICK]) //rewbs.tempoSlideFix: only slide if (T0x or T1x) and tick is not 0
{
+ // Tempo Slide
if ((param & 0xF0) == 0x10)
m_PlayState.m_nMusicTempo += (param & 0x0F); //rewbs.tempoSlideFix: no *2
else
m_PlayState.m_nMusicTempo -= (param & 0x0F); //rewbs.tempoSlideFix: no *2
- // -> CODE#0016
- // -> DESC="default tempo update"
if(IsCompatibleMode(TRK_ALLTRACKERS)) // clamp tempo correctly in compatible mode
m_PlayState.m_nMusicTempo = Clamp(m_PlayState.m_nMusicTempo, 32u, 255u);
else
m_PlayState.m_nMusicTempo = Clamp(m_PlayState.m_nMusicTempo, specs.tempoMin, specs.tempoMax);
- // -! BEHAVIOUR_CHANGE#0016
}
}
}
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-03-11 14:23:08 UTC (rev 4863)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-03-11 15:23:30 UTC (rev 4864)
@@ -781,7 +781,7 @@
void NoteChange(ModChannel *pChn, int note, bool bPorta = false, bool bResetEnv = true, bool bManual = false) const;
void InstrumentChange(ModChannel *pChn, UINT instr, bool bPorta = false, bool bUpdVol = true, bool bResetEnv = true) const;
void ApplyInstrumentPanning(ModChannel *pChn, const ModInstrument *instr, const ModSample *smp) const;
- uint32_t CalculateXParam(PATTERNINDEX pat, ROWINDEX row, CHANNELINDEX chn) const;
+ uint32_t CalculateXParam(PATTERNINDEX pat, ROWINDEX row, CHANNELINDEX chn, bool *isExtended = nullptr) const;
// Channel Effects
void KeyOff(ModChannel *pChn) const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <man...@us...> - 2015-03-11 15:36:09
|
Revision: 4865
http://sourceforge.net/p/modplug/code/4865
Author: manxorist
Date: 2015-03-11 15:35:56 +0000 (Wed, 11 Mar 2015)
Log Message:
-----------
[Ref] Silence signed/unsigned comparison warnings.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_it.cpp
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/modsmp_ctrl.cpp
Modified: trunk/OpenMPT/soundlib/Load_it.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_it.cpp 2015-03-11 15:23:30 UTC (rev 4864)
+++ trunk/OpenMPT/soundlib/Load_it.cpp 2015-03-11 15:35:56 UTC (rev 4865)
@@ -2091,7 +2091,7 @@
// with the amount of samples that OpenMPT supports.
WRITEMODULARHEADER('S','E','U','C', 2 + CountOf(sample.cues) * 4);
mpt::IO::WriteIntLE<uint16_t>(f, smp);
- for(int i = 0; i < CountOf(sample.cues); i++)
+ for(std::size_t i = 0; i < CountOf(sample.cues); i++)
{
mpt::IO::WriteIntLE<uint32_t>(f, sample.cues[i]);
}
@@ -2266,7 +2266,7 @@
if(smp > 0 && smp <= GetNumSamples())
{
ModSample &sample = Samples[smp];
- for(int i = 0; i < CountOf(sample.cues); i++)
+ for(std::size_t i = 0; i < CountOf(sample.cues); i++)
{
sample.cues[i] = chunk.ReadUint32LE();
}
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 15:23:30 UTC (rev 4864)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 15:35:56 UTC (rev 4865)
@@ -4711,7 +4711,7 @@
chn.nLength = chn.pModSample->nLength;
offset--;
if(offset == 0) offset = chn.oldOffset;
- else if(offset <= CountOf(chn.pModSample->cues)) offset = chn.oldOffset = chn.pModSample->cues[offset - 1];
+ else if(offset <= static_cast<int>(CountOf(chn.pModSample->cues))) offset = chn.oldOffset = chn.pModSample->cues[offset - 1];
SampleOffset(nChn, offset);
}
}
Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.cpp
===================================================================
--- trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2015-03-11 15:23:30 UTC (rev 4864)
+++ trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2015-03-11 15:35:56 UTC (rev 4865)
@@ -73,7 +73,7 @@
// Update loop points if necessary.
if(smp.nLoopStart >= nStartFrom) smp.nLoopStart += nSilenceLength;
if(smp.nLoopEnd >= nStartFrom) smp.nLoopEnd += nSilenceLength;
- for(int i = 0; i < CountOf(smp.cues); i++)
+ for(std::size_t i = 0; i < CountOf(smp.cues); i++)
{
if(smp.cues[i] >= nStartFrom) smp.cues[i] += nSilenceLength;
}
@@ -126,7 +126,7 @@
if(smp.nLoopEnd == 0) smp.uFlags.reset(CHN_LOOP | CHN_PINGPONGLOOP);
if(smp.nSustainEnd == 0) smp.uFlags.reset(CHN_SUSTAINLOOP | CHN_PINGPONGSUSTAIN);
- for(int i = 0; i < CountOf(smp.cues); i++)
+ for(std::size_t i = 0; i < CountOf(smp.cues); i++)
{
Util::DeleteItem(selStart, selEnd - 1, smp.cues[i]);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-11 16:59:49
|
Revision: 4874
http://sourceforge.net/p/modplug/code/4874
Author: saga-games
Date: 2015-03-11 16:59:34 +0000 (Wed, 11 Mar 2015)
Log Message:
-----------
[Ref] Kill all type conversion warnings in Snd_fx.cpp
Modified Paths:
--------------
trunk/OpenMPT/soundlib/ModChannel.h
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/ModChannel.h
===================================================================
--- trunk/OpenMPT/soundlib/ModChannel.h 2015-03-11 16:33:48 UTC (rev 4873)
+++ trunk/OpenMPT/soundlib/ModChannel.h 2015-03-11 16:59:34 UTC (rev 4874)
@@ -21,8 +21,8 @@
struct EnvInfo
{
FlagSet<EnvelopeFlags> flags;
- uint32 nEnvPosition;
- int32 nEnvValueAtReleaseJump;
+ uint32_t nEnvPosition;
+ int32_t nEnvValueAtReleaseJump;
void Reset()
{
@@ -34,16 +34,16 @@
// Information used in the mixer (should be kept tight for better caching)
// Byte sizes are for 32-bit builds and 32-bit integer / float mixer
const void *pCurrentSample; // Currently playing sample (nullptr if no sample is playing)
- uint32 nPos; // Current play position
- uint32 nPosLo; // 16-bit fractional part of play position
- int32 nInc; // 16.16 fixed point sample speed relative to mixing frequency (0x10000 = one sample per output sample, 0x20000 = two samples per output sample, etc...)
- int32 leftVol; // 0...4096 (12 bits, since 16 bits + 12 bits = 28 bits = 0dB in integer mixer, see MIXING_ATTENUATION)
- int32 rightVol; // Ditto
- int32 leftRamp; // Ramping delta, 20.12 fixed point (see VOLUMERAMPPRECISION)
- int32 rightRamp; // Ditto
+ uint32_t nPos; // Current play position
+ uint32_t nPosLo; // 16-bit fractional part of play position
+ int32_t nInc; // 16.16 fixed point sample speed relative to mixing frequency (0x10000 = one sample per output sample, 0x20000 = two samples per output sample, etc...)
+ int32_t leftVol; // 0...4096 (12 bits, since 16 bits + 12 bits = 28 bits = 0dB in integer mixer, see MIXING_ATTENUATION)
+ int32_t rightVol; // Ditto
+ int32_t leftRamp; // Ramping delta, 20.12 fixed point (see VOLUMERAMPPRECISION)
+ int32_t rightRamp; // Ditto
// Up to here: 32 bytes
- int32 rampLeftVol; // Current ramping volume, 20.12 fixed point (see VOLUMERAMPPRECISION)
- int32 rampRightVol; // Ditto
+ int32_t rampLeftVol; // Current ramping volume, 20.12 fixed point (see VOLUMERAMPPRECISION)
+ int32_t rampRightVol; // Ditto
mixsample_t nFilter_Y[2][2]; // Filter memory - two history items per sample channel
mixsample_t nFilter_A0, nFilter_B0, nFilter_B1; // Filter coeffs
mixsample_t nFilter_HP;
@@ -54,7 +54,7 @@
SmpLength nLoopEnd;
FlagSet<ChannelFlags> dwFlags;
mixsample_t nROfs, nLOfs;
- uint32 nRampLength;
+ uint32_t nRampLength;
// Up to here: 100 bytes
const ModSample *pModSample; // Currently assigned sample slot (can already be stopped)
@@ -64,52 +64,52 @@
SmpLength proTrackerOffset; // Offset for instrument-less notes in ProTracker mode
SmpLength oldOffset;
FlagSet<ChannelFlags> dwOldFlags; // Flags from previous tick
- int32 newLeftVol, newRightVol;
- int32 nRealVolume, nRealPan;
- int32 nVolume, nPan, nFadeOutVol;
- int32 nPeriod, nC5Speed, nPortamentoDest;
- int32 cachedPeriod, glissandoPeriod;
- int32 nCalcVolume; // Calculated channel volume, 14-Bit (without global volume, pre-amp etc applied) - for MIDI macros
+ int32_t newLeftVol, newRightVol;
+ int32_t nRealVolume, nRealPan;
+ int32_t nVolume, nPan, nFadeOutVol;
+ int32_t nPeriod, nC5Speed, nPortamentoDest;
+ int32_t cachedPeriod, glissandoPeriod;
+ int32_t nCalcVolume; // Calculated channel volume, 14-Bit (without global volume, pre-amp etc applied) - for MIDI macros
EnvInfo VolEnv, PanEnv, PitchEnv; // Envelope playback info
- int32 nGlobalVol; // Channel volume (CV in ITTECH.TXT)
- int32 nInsVol; // Sample / Instrument volume (SV * IV in ITTECH.TXT)
- int32 nFineTune, nTranspose;
- int32 nPortamentoSlide, nAutoVibDepth;
- uint32 nAutoVibPos, nVibratoPos, nTremoloPos, nPanbrelloPos;
- int32 nVolSwing, nPanSwing;
- int32 nCutSwing, nResSwing;
- int32 nRestorePanOnNewNote; //If > 0, nPan should be set to nRestorePanOnNewNote - 1 on new note. Used to recover from panswing.
- uint32 nOldGlobalVolSlide;
- uint32 nEFxOffset; // offset memory for Invert Loop (EFx, .MOD only)
- int32 nRetrigCount, nRetrigParam;
+ int32_t nGlobalVol; // Channel volume (CV in ITTECH.TXT)
+ int32_t nInsVol; // Sample / Instrument volume (SV * IV in ITTECH.TXT)
+ int32_t nFineTune, nTranspose;
+ int32_t nPortamentoSlide, nAutoVibDepth;
+ uint32_t nAutoVibPos, nVibratoPos, nTremoloPos, nPanbrelloPos;
+ int32_t nVolSwing, nPanSwing;
+ int32_t nCutSwing, nResSwing;
+ int32_t nRestorePanOnNewNote; //If > 0, nPan should be set to nRestorePanOnNewNote - 1 on new note. Used to recover from panswing.
+ uint32_t nEFxOffset; // offset memory for Invert Loop (EFx, .MOD only)
+ int32_t nRetrigCount, nRetrigParam;
ROWINDEX nPatternLoop;
CHANNELINDEX nMasterChn;
ModCommand rowCommand;
// 8-bit members
- uint8 resamplingMode;
- uint8 nRestoreResonanceOnNewNote; // See nRestorePanOnNewNote
- uint8 nRestoreCutoffOnNewNote; // ditto
- uint8 nNote, nNNA;
- uint8 nLastNote; // Last note, ignoring note offs and cuts - for MIDI macros
- uint8 nArpeggioLastNote, nArpeggioBaseNote; // For plugin arpeggio
- uint8 nNewNote, nNewIns, nOldIns, nCommand, nArpeggio;
- uint8 nOldVolumeSlide, nOldFineVolUpDown;
- uint8 nOldPortaUpDown, nOldFinePortaUpDown, nOldExtraFinePortaUpDown;
- uint8 nOldPanSlide, nOldChnVolSlide;
- uint8 nVibratoType, nVibratoSpeed, nVibratoDepth;
- uint8 nTremoloType, nTremoloSpeed, nTremoloDepth;
- uint8 nPanbrelloType, nPanbrelloSpeed, nPanbrelloDepth;
- int8 nPanbrelloOffset, nPanbrelloRandomMemory;
- uint8 nOldCmdEx, nOldVolParam, nOldTempo;
- uint8 nOldHiOffset;
- uint8 nCutOff, nResonance;
- uint8 nTremorCount, nTremorParam;
- uint8 nPatternLoopCount;
- uint8 nLeftVU, nRightVU;
- uint8 nActiveMacro, nFilterMode;
- uint8 nEFxSpeed, nEFxDelay; // memory for Invert Loop (EFx, .MOD only)
- uint8 nNoteSlideCounter, nNoteSlideSpeed, nNoteSlideStep; // IMF / PTM Note Slide
- uint8 lastZxxParam; // Memory for \xx slides
+ uint8_t resamplingMode;
+ uint8_t nRestoreResonanceOnNewNote; // See nRestorePanOnNewNote
+ uint8_t nRestoreCutoffOnNewNote; // ditto
+ uint8_t nNote, nNNA;
+ uint8_t nLastNote; // Last note, ignoring note offs and cuts - for MIDI macros
+ uint8_t nArpeggioLastNote, nArpeggioBaseNote; // For plugin arpeggio
+ uint8_t nNewNote, nNewIns, nOldIns, nCommand, nArpeggio;
+ uint8_t nOldVolumeSlide, nOldFineVolUpDown;
+ uint8_t nOldPortaUpDown, nOldFinePortaUpDown, nOldExtraFinePortaUpDown;
+ uint8_t nOldPanSlide, nOldChnVolSlide;
+ uint8_t nOldGlobalVolSlide;
+ uint8_t nVibratoType, nVibratoSpeed, nVibratoDepth;
+ uint8_t nTremoloType, nTremoloSpeed, nTremoloDepth;
+ uint8_t nPanbrelloType, nPanbrelloSpeed, nPanbrelloDepth;
+ int8_t nPanbrelloOffset, nPanbrelloRandomMemory;
+ uint8_t nOldCmdEx, nOldVolParam, nOldTempo;
+ uint8_t nOldHiOffset;
+ uint8_t nCutOff, nResonance;
+ uint8_t nTremorCount, nTremorParam;
+ uint8_t nPatternLoopCount;
+ uint8_t nLeftVU, nRightVU;
+ uint8_t nActiveMacro, nFilterMode;
+ uint8_t nEFxSpeed, nEFxDelay; // memory for Invert Loop (EFx, .MOD only)
+ uint8_t nNoteSlideCounter, nNoteSlideSpeed, nNoteSlideStep; // IMF / PTM Note Slide
+ uint8_t lastZxxParam; // Memory for \xx slides
bool isFirstTick : 1;
//-->Variables used to make user-definable tuning modes work with pattern effects.
@@ -121,15 +121,15 @@
//To tell whether to calculate frequency.
bool m_CalculateFreq : 1;
- int32 m_PortamentoFineSteps, m_PortamentoTickSlide;
+ int32_t m_PortamentoFineSteps, m_PortamentoTickSlide;
- uint32 m_Freq;
+ uint32_t m_Freq;
float m_VibratoDepth;
//<----
//NOTE_PCs memory.
float m_plugParamValueStep, m_plugParamTargetValue;
- uint16 m_RowPlugParam;
+ uint16_t m_RowPlugParam;
PLUGINDEX m_RowPlug;
void ClearRowCmd() { rowCommand = ModCommand::Empty(); }
@@ -172,7 +172,7 @@
void Reset(ResetFlags resetMask, const CSoundFile &sndFile, CHANNELINDEX sourceChannel);
- typedef uint32 volume_t;
+ typedef uint32_t volume_t;
volume_t GetVSTVolume() { return (pModInstrument) ? pModInstrument->nGlobalVol * 4 : nVolume; }
// Check if the channel has a valid MIDI output. This function guarantees that pModInstrument != nullptr.
@@ -193,8 +193,8 @@
struct ModChannelSettings
{
FlagSet<ChannelFlags> dwFlags; // Channel flags
- uint16 nPan; // Initial pan (0...256)
- uint16 nVolume; // Initial channel volume (0...64)
+ uint16_t nPan; // Initial pan (0...256)
+ uint16_t nVolume; // Initial channel volume (0...64)
PLUGINDEX nMixPlugin; // Assigned plugin
char szName[MAX_CHANNELNAME]; // Channel name
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 16:33:48 UTC (rev 4873)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-11 16:59:34 UTC (rev 4874)
@@ -25,11 +25,6 @@
OPENMPT_NAMESPACE_BEGIN
-#if MPT_COMPILER_MSVC
-#pragma warning(disable:4244)
-#endif
-
-
// Formats which have 7-bit (0...128) instead of 6-bit (0...64) global volume commands, or which are imported to this range (mostly formats which are converted to IT internally)
#ifdef MODPLUG_TRACKER
#define GLOBALVOL_7BIT_FORMATS_EXT (MOD_TYPE_MT2)
@@ -382,7 +377,7 @@
uint32_t tempo = CalculateXParam(memory.state.m_nPattern, memory.state.m_nRow, nChn);
if ((adjustMode & eAdjust) && (GetType() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)))
{
- if (tempo) pChn->nOldTempo = tempo; else tempo = pChn->nOldTempo;
+ if (tempo) pChn->nOldTempo = static_cast<uint8_t>(tempo); else tempo = pChn->nOldTempo;
}
if (tempo >= 0x20) memory.state.m_nMusicTempo = tempo;
@@ -563,23 +558,20 @@
if (param <= 64) pChn->nGlobalVol = param;
break;
case CMD_CHANNELVOLSLIDE:
- if (param) pChn->nOldChnVolSlide = param; else param = pChn->nOldChnVolSlide;
- if (((param & 0x0F) == 0x0F) && (param & 0xF0))
{
- param = (param >> 4) + pChn->nGlobalVol;
- } else
- if (((param & 0xF0) == 0xF0) && (param & 0x0F))
- {
- if (pChn->nGlobalVol > (param & 0x0F)) param = pChn->nGlobalVol - (param & 0x0F);
- else param = 0;
- } else
- if (param & 0x0F)
- {
- param = (param & 0x0F) * (memory.state.m_nMusicSpeed - 1);
- param = (pChn->nGlobalVol > param) ? pChn->nGlobalVol - param : 0;
- } else param = ((param & 0xF0) >> 4) * (memory.state.m_nMusicSpeed - 1) + pChn->nGlobalVol;
- param = MIN(param, 64);
- pChn->nGlobalVol = param;
+ if (param) pChn->nOldChnVolSlide = param; else param = pChn->nOldChnVolSlide;
+ int32_t volume = pChn->nGlobalVol;
+ if((param & 0x0F) == 0x0F && (param & 0xF0))
+ volume += (param >> 4); // Fine Up
+ else if((param & 0xF0) == 0xF0 && (param & 0x0F))
+ volume -= (param & 0x0F); // Fine Down
+ else if(param & 0x0F) // Down
+ volume -= (param & 0x0F) * (memory.state.m_nMusicSpeed - 1);
+ else // Up
+ volume += ((param & 0xF0) >> 4) * (memory.state.m_nMusicSpeed - 1);
+ Limit(volume, 0, 64);
+ pChn->nGlobalVol = volume;
+ }
break;
}
}
@@ -897,7 +889,7 @@
if(instr >= MAX_INSTRUMENTS) return;
const ModInstrument *pIns = (instr < MAX_INSTRUMENTS) ? Instruments[instr] : nullptr;
const ModSample *pSmp = &Samples[instr];
- UINT note = pChn->nNewNote;
+ ModCommand::NOTE note = pChn->nNewNote;
if(note == NOTE_NONE && IsCompatibleMode(TRK_IMPULSETRACKER)) return;
@@ -1272,7 +1264,7 @@
pChn->nPortamentoDest = 0;
else
{
- pChn->nPortamentoDest = pIns->pTuning->GetStepDistance(pChn->nNote, pChn->m_PortamentoFineSteps, note, 0);
+ pChn->nPortamentoDest = pIns->pTuning->GetStepDistance(pChn->nNote, pChn->m_PortamentoFineSteps, static_cast<CTuningBase::NOTEINDEXTYPE>(note), 0);
//Here pChn->nPortamentoDest means 'steps to slide'.
pChn->m_PortamentoFineSteps = -pChn->nPortamentoDest;
}
@@ -1318,10 +1310,10 @@
if(IsCompatibleMode(TRK_IMPULSETRACKER))
{
// need to memorize the original note for various effects (e.g. PPS)
- pChn->nNote = Clamp(realnote, NOTE_MIN, NOTE_MAX);
+ pChn->nNote = static_cast<ModCommand::NOTE>(Clamp(realnote, NOTE_MIN, NOTE_MAX));
} else
{
- pChn->nNote = note;
+ pChn->nNote = static_cast<ModCommand::NOTE>(note);
}
pChn->m_CalculateFreq = true;
@@ -1622,7 +1614,7 @@
CHANNELINDEX nnaChn = CHANNELINDEX_INVALID;
ModChannel *pChn = &m_PlayState.Chn[nChn];
const ModInstrument *pIns = nullptr;
- if(!ModCommand::IsNote(note))
+ if(!ModCommand::IsNote(static_cast<ModCommand::NOTE>(note)))
{
return nnaChn;
}
@@ -1954,7 +1946,11 @@
NoteCut(nChn, cutAtTick, IsCompatibleMode(TRK_IMPULSETRACKER) || GetType() == MOD_TYPE_S3M);
} else if ((cmd == CMD_MODCMDEX) || (cmd == CMD_S3MCMDEX))
{
- if ((!param) && (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT))) param = pChn->nOldCmdEx; else pChn->nOldCmdEx = param;
+ if ((!param) && (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT)))
+ param = pChn->nOldCmdEx;
+ else
+ pChn->nOldCmdEx = static_cast<ModCommand::PARAM>(param);
+
// Note Delay ?
if ((param & 0xF0) == 0xD0)
{
@@ -2084,8 +2080,8 @@
// Handles note/instrument/volume changes
if(triggerNote)
{
- UINT note = pChn->rowCommand.note;
- if(instr) pChn->nNewIns = instr;
+ ModCommand::NOTE note = pChn->rowCommand.note;
+ if(instr) pChn->nNewIns = static_cast<ModCommand::INSTR>(instr);
if(ModCommand::IsNote(note) && IsCompatibleMode(TRK_FASTTRACKER2))
{
@@ -2107,7 +2103,7 @@
} else
{
// Sample mode
- sample = instr;
+ sample = static_cast<SAMPLEINDEX>(instr);
}
if(sample <= GetNumSamples())
{
@@ -2120,11 +2116,11 @@
{
note = NOTE_NONE;
}
- } else if((GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT)) && GetNumInstruments() != 0 && ModCommand::IsNoteOrEmpty(note))
+ } else if((GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT)) && GetNumInstruments() != 0 && ModCommand::IsNoteOrEmpty(static_cast<ModCommand::NOTE>(note)))
{
// IT compatibility: Invalid instrument numbers do nothing, but they are remembered for upcoming notes and do not trigger a note in that case.
// Test case: InstrumentNumberChange.it
- INSTRUMENTINDEX instrToCheck = (instr != 0 ? instr : pChn->nOldIns);
+ INSTRUMENTINDEX instrToCheck = static_cast<INSTRUMENTINDEX>((instr != 0) ? instr : pChn->nOldIns);
if(instrToCheck != 0 && (instrToCheck > GetNumInstruments() || Instruments[instrToCheck] == nullptr))
{
note = NOTE_NONE;
@@ -2176,7 +2172,7 @@
{
// If there's a note delay but no real note, retrig the last note.
// Test case: delay2.xm, delay3.xm
- note = pChn->nNote - pChn->nTranspose;
+ note = static_cast<ModCommand::NOTE>(pChn->nNote - pChn->nTranspose);
} else if(note >= NOTE_MIN_SPECIAL)
{
// Gah! Even Note Off + Note Delay will cause envelopes to *retrigger*! How stupid is that?
@@ -2446,7 +2442,7 @@
{
// IT Compatibility: Effects in the volume column don't have an unified memory.
// Test case: VolColMemory.it
- if(vol) pChn->nOldVolParam = vol; else vol = pChn->nOldVolParam;
+ if(vol) pChn->nOldVolParam = static_cast<ModCommand::PARAM>(vol); else vol = pChn->nOldVolParam;
}
switch(volcmd)
@@ -2462,9 +2458,9 @@
break;
} else
{
- pChn->nOldVolParam = vol;
+ pChn->nOldVolParam = static_cast<ModCommand::PARAM>(vol);
}
- VolumeSlide(pChn, volcmd == VOLCMD_VOLSLIDEUP ? (vol << 4) : vol);
+ VolumeSlide(pChn, static_cast<ModCommand::PARAM>(volcmd == VOLCMD_VOLSLIDEUP ? (vol << 4) : vol));
break;
case VOLCMD_FINEVOLUP:
@@ -2474,7 +2470,7 @@
{
// IT Compatibility: Volume column volume slides have their own memory
// Test case: VolColMemory.it
- FineVolumeUp(pChn, vol, IsCompatibleMode(TRK_IMPULSETRACKER));
+ FineVolumeUp(pChn, static_cast<ModCommand::PARAM>(vol), IsCompatibleMode(TRK_IMPULSETRACKER));
}
break;
@@ -2485,7 +2481,7 @@
{
// IT Compatibility: Volume column volume slides have their own memory
// Test case: VolColMemory.it
- FineVolumeDown(pChn, vol, IsCompatibleMode(TRK_IMPULSETRACKER));
+ FineVolumeDown(pChn, static_cast<ModCommand::PARAM>(vol), IsCompatibleMode(TRK_IMPULSETRACKER));
}
break;
@@ -2502,21 +2498,21 @@
break;
case VOLCMD_PANSLIDELEFT:
- PanningSlide(pChn, vol, !IsCompatibleMode(TRK_FASTTRACKER2));
+ PanningSlide(pChn, static_cast<ModCommand::PARAM>(vol), !IsCompatibleMode(TRK_FASTTRACKER2));
break;
case VOLCMD_PANSLIDERIGHT:
- PanningSlide(pChn, vol << 4, !IsCompatibleMode(TRK_FASTTRACKER2));
+ PanningSlide(pChn, static_cast<ModCommand::PARAM>(vol << 4), !IsCompatibleMode(TRK_FASTTRACKER2));
break;
case VOLCMD_PORTAUP:
// IT compatibility (one of the first testcases - link effect memory)
- PortamentoUp(nChn, vol << 2, IsCompatibleMode(TRK_IMPULSETRACKER));
+ PortamentoUp(nChn, static_cast<ModCommand::PARAM>(vol << 2), IsCompatibleMode(TRK_IMPULSETRACKER));
break;
case VOLCMD_PORTADOWN:
// IT compatibility (one of the first testcases - link effect memory)
- PortamentoDown(nChn, vol << 2, IsCompatibleMode(TRK_IMPULSETRACKER));
+ PortamentoDown(nChn, static_cast<ModCommand::PARAM>(vol << 2), IsCompatibleMode(TRK_IMPULSETRACKER));
break;
case VOLCMD_OFFSET:
@@ -2549,18 +2545,18 @@
// Portamento Up
case CMD_PORTAMENTOUP:
if ((!param) && (GetType() & MOD_TYPE_MOD)) break;
- PortamentoUp(nChn, param);
+ PortamentoUp(nChn, static_cast<ModCommand::PARAM>(param));
break;
// Portamento Down
case CMD_PORTAMENTODOWN:
if ((!param) && (GetType() & MOD_TYPE_MOD)) break;
- PortamentoDown(nChn, param);
+ PortamentoDown(nChn, static_cast<ModCommand::PARAM>(param));
break;
// Volume Slide
case CMD_VOLUMESLIDE:
- if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, param);
+ if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, static_cast<ModCommand::PARAM>(param));
break;
// Tone-Portamento
@@ -2570,7 +2566,7 @@
// Tone-Portamento + Volume Slide
case CMD_TONEPORTAVOL:
- if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, param);
+ if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, static_cast<ModCommand::PARAM>(param));
TonePortamento(pChn, 0);
break;
@@ -2581,7 +2577,7 @@
// Vibrato + Volume Slide
case CMD_VIBRATOVOL:
- if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, param);
+ if ((param) || (GetType() != MOD_TYPE_MOD)) VolumeSlide(pChn, static_cast<ModCommand::PARAM>(param));
Vibrato(pChn, 0);
break;
@@ -2603,7 +2599,7 @@
param = CalculateXParam(m_PlayState.m_nPattern, m_PlayState.m_nRow, nChn);
if (GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT))
{
- if (param) pChn->nOldTempo = param; else param = pChn->nOldTempo;
+ if (param) pChn->nOldTempo = static_cast<ModCommand::PARAM>(param); else param = pChn->nOldTempo;
}
SetTempo(param);
break;
@@ -2640,7 +2636,7 @@
&& !IsCompatibleMode(TRK_IMPULSETRACKER) && GetType() != MOD_TYPE_S3M) break;
if (!param && (GetType() & (MOD_TYPE_XM | MOD_TYPE_MOD))) break; // Only important when editing MOD/XM files (000 effects are removed when loading files where this means "no effect")
pChn->nCommand = CMD_ARPEGGIO;
- if (param) pChn->nArpeggio = param;
+ if (param) pChn->nArpeggio = static_cast<ModCommand::PARAM>(param);
break;
// Retrig
@@ -2688,7 +2684,7 @@
}
pChn->nCommand = CMD_TREMOR;
- if (param) pChn->nTremorParam = param;
+ if (param) pChn->nTremorParam = static_cast<ModCommand::PARAM>(param);
break;
@@ -2727,9 +2723,9 @@
case CMD_GLOBALVOLSLIDE:
//IT compatibility 16. Saving last global volume slide param per channel (FT2/IT)
if(IsCompatibleMode(TRK_IMPULSETRACKER | TRK_FASTTRACKER2))
- GlobalVolSlide(param, pChn->nOldGlobalVolSlide);
+ GlobalVolSlide(static_cast<ModCommand::PARAM>(param), pChn->nOldGlobalVolSlide);
else
- GlobalVolSlide(param, m_PlayState.Chn[0].nOldGlobalVolSlide);
+ GlobalVolSlide(static_cast<ModCommand::PARAM>(param), m_PlayState.Chn[0].nOldGlobalVolSlide);
break;
// Set 8-bit Panning
@@ -2744,7 +2740,7 @@
// Panning Slide
case CMD_PANNINGSLIDE:
- PanningSlide(pChn, param);
+ PanningSlide(pChn, static_cast<ModCommand::PARAM>(param));
break;
// Tremolo
@@ -2759,7 +2755,7 @@
// MOD/XM Exx Extended Commands
case CMD_MODCMDEX:
- ExtendedMODCommands(nChn, param);
+ ExtendedMODCommands(nChn, static_cast<ModCommand::PARAM>(param));
break;
// S3M/IT Sxx Extended Commands
@@ -2768,7 +2764,7 @@
{
param = pChn->nArpeggio; // S00 uses the last non-zero effect parameter as memory, like other effects including Arpeggio, so we "borrow" our memory there.
}
- ExtendedS3MCommands(nChn, param);
+ ExtendedS3MCommands(nChn, static_cast<ModCommand::PARAM>(param));
break;
// Key Off
@@ -2814,7 +2810,7 @@
case 0x70:
case 0x90:
case 0xA0:
- if(!IsCompatibleMode(TRK_FASTTRACKER2)) ExtendedS3MCommands(nChn, param);
+ if(!IsCompatibleMode(TRK_FASTTRACKER2)) ExtendedS3MCommands(nChn, static_cast<ModCommand::PARAM>(param));
break;
}
break;
@@ -2831,7 +2827,7 @@
// Channel volume slide
case CMD_CHANNELVOLSLIDE:
- ChannelVolSlide(pChn, param);
+ ChannelVolSlide(pChn, static_cast<ModCommand::PARAM>(param));
break;
// Panbrello (IT)
@@ -2859,10 +2855,10 @@
// Position Jump
case CMD_POSITIONJUMP:
m_PlayState.m_nNextPatStartRow = 0; // FT2 E60 bug
- nPosJump = param;
+ nPosJump = static_cast<ORDERINDEX>(param);
if(m_SongFlags[SONG_PATTERNLOOP] && m_PlayState.m_nSeqOverride == ORDERINDEX_INVALID)
{
- m_PlayState.m_nSeqOverride = param;
+ m_PlayState.m_nSeqOverride = static_cast<ORDERINDEX>(param);
//Releasing pattern loop after position jump could cause
//instant jumps - modifying behavior so that now position jumps
//occurs also when pattern loop is enabled.
@@ -2879,7 +2875,7 @@
// Pattern Break
case CMD_PATTERNBREAK:
{
- ROWINDEX row = PatternBreak(m_PlayState, nChn, param);
+ ROWINDEX row = PatternBreak(m_PlayState, nChn, static_cast<ModCommand::PARAM>(param));
if(row != ROWINDEX_INVALID)
{
nBreakRow = row;
@@ -2919,7 +2915,7 @@
if(IsCompatibleMode(TRK_SCREAMTRACKER) && param != 0)
{
- UpdateS3MEffectMemory(pChn, param);
+ UpdateS3MEffectMemory(pChn, static_cast<ModCommand::PARAM>(param));
}
if(pChn->rowCommand.instr)
@@ -2989,8 +2985,8 @@
// Update the effect memory of all S3M effects that use the last non-zero effect parameter as memory (Dxy, Exx, Fxx, Ixy, Jxy, Kxy, Lxy, Qxy, Rxy, Sxy)
// Test case: ParamMemory.s3m
-void CSoundFile::UpdateS3MEffectMemory(ModChannel *pChn, UINT param) const
-//------------------------------------------------------------------------
+void CSoundFile::UpdateS3MEffectMemory(ModChannel *pChn, ModCommand::PARAM param) const
+//-------------------------------------------------------------------------------------
{
pChn->nOldVolumeSlide = param; // Dxy / Kxy / Lxy
pChn->nOldPortaUpDown = param; // Exx / Fxx
@@ -3066,8 +3062,8 @@
}
-void CSoundFile::PortamentoUp(CHANNELINDEX nChn, UINT param, const bool doFinePortamentoAsRegular)
-//------------------------------------------------------------------------------------------------
+void CSoundFile::PortamentoUp(CHANNELINDEX nChn, ModCommand::PARAM param, const bool doFinePortamentoAsRegular)
+//-------------------------------------------------------------------------------------------------------------
{
ModChannel *pChn = &m_PlayState.Chn[nChn];
@@ -3123,8 +3119,8 @@
}
-void CSoundFile::PortamentoDown(CHANNELINDEX nChn, UINT param, const bool doFinePortamentoAsRegular)
-//--------------------------------------------------------------------------------------------------
+void CSoundFile::PortamentoDown(CHANNELINDEX nChn, ModCommand::PARAM param, const bool doFinePortamentoAsRegular)
+//---------------------------------------------------------------------------------------------------------------
{
ModChannel *pChn = &m_PlayState.Chn[nChn];
@@ -3227,8 +3223,8 @@
}
-void CSoundFile::FinePortamentoUp(ModChannel *pChn, UINT param)
-//-------------------------------------------------------------
+void CSoundFile::FinePortamentoUp(ModChannel *pChn, ModCommand::PARAM param) const
+//--------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3267,8 +3263,8 @@
}
-void CSoundFile::FinePortamentoDown(ModChannel *pChn, UINT param)
-//---------------------------------------------------------------
+void CSoundFile::FinePortamentoDown(ModChannel *pChn, ModCommand::PARAM param) const
+//----------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3299,8 +3295,8 @@
}
-void CSoundFile::ExtraFinePortamentoUp(ModChannel *pChn, UINT param)
-//------------------------------------------------------------------
+void CSoundFile::ExtraFinePortamentoUp(ModChannel *pChn, ModCommand::PARAM param) const
+//-------------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3339,8 +3335,8 @@
}
-void CSoundFile::ExtraFinePortamentoDown(ModChannel *pChn, UINT param)
-//--------------------------------------------------------------------
+void CSoundFile::ExtraFinePortamentoDown(ModChannel *pChn, ModCommand::PARAM param) const
+//---------------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3372,8 +3368,8 @@
// Implemented for IMF compatibility, can't actually save this in any formats
// Slide up / down every x ticks by y semitones
-void CSoundFile::NoteSlide(ModChannel *pChn, UINT param, bool slideUp, bool retrig)
-//---------------------------------------------------------------------------------
+void CSoundFile::NoteSlide(ModChannel *pChn, UINT param, bool slideUp, bool retrig) const
+//---------------------------------------------------------------------------------------
{
uint8 x, y;
if(m_SongFlags[SONG_FIRSTTICK])
@@ -3403,8 +3399,8 @@
}
// Portamento Slide
-void CSoundFile::TonePortamento(ModChannel *pChn, UINT param)
-//-----------------------------------------------------------
+void CSoundFile::TonePortamento(ModChannel *pChn, UINT param) const
+//-----------------------------------------------------------------
{
pChn->dwFlags.set(CHN_PORTAMENTO);
@@ -3412,7 +3408,7 @@
if((!m_SongFlags[SONG_ITCOMPATGXX] && IsCompatibleMode(TRK_IMPULSETRACKER)) || GetType() == MOD_TYPE_PLM)
{
if(param == 0) param = pChn->nOldPortaUpDown;
- pChn->nOldPortaUpDown = param;
+ pChn->nOldPortaUpDown = static_cast<uint8_t>(param);
}
if(GetType() == MOD_TYPE_MPT && pChn->pModInstrument && pChn->pModInstrument->pTuning)
@@ -3432,7 +3428,7 @@
(pChn->nPortamentoDest < 0 && pChn->nPortamentoSlide > 0))
pChn->nPortamentoSlide = -pChn->nPortamentoSlide;
- pChn->m_PortamentoTickSlide = (m_PlayState.m_nTickCount + 1.0) * pChn->nPortamentoSlide / m_PlayState.m_nMusicSpeed;
+ pChn->m_PortamentoTickSlide = static_cast<int32_t>((m_PlayState.m_nTickCount + 1.0) * pChn->nPortamentoSlide / m_PlayState.m_nMusicSpeed);
if(pChn->dwFlags[CHN_GLISSANDO])
{
@@ -3575,8 +3571,8 @@
}
-void CSoundFile::VolumeSlide(ModChannel *pChn, UINT param)
-//--------------------------------------------------------
+void CSoundFile::VolumeSlide(ModChannel *pChn, ModCommand::PARAM param)
+//---------------------------------------------------------------------
{
if (param)
pChn->nOldVolumeSlide = param;
@@ -3647,8 +3643,8 @@
}
-void CSoundFile::PanningSlide(ModChannel *pChn, UINT param, bool memory)
-//----------------------------------------------------------------------
+void CSoundFile::PanningSlide(ModChannel *pChn, ModCommand::PARAM param, bool memory)
+//-----------------------------------------------------------------------------------
{
if(memory)
{
@@ -3727,8 +3723,8 @@
}
-void CSoundFile::FineVolumeUp(ModChannel *pChn, UINT param, bool volCol)
-//----------------------------------------------------------------------
+void CSoundFile::FineVolumeUp(ModChannel *pChn, ModCommand::PARAM param, bool volCol) const
+//-----------------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3752,8 +3748,8 @@
}
-void CSoundFile::FineVolumeDown(ModChannel *pChn, UINT param, bool volCol)
-//------------------------------------------------------------------------
+void CSoundFile::FineVolumeDown(ModChannel *pChn, ModCommand::PARAM param, bool volCol) const
+//-------------------------------------------------------------------------------------------
{
if(GetType() == MOD_TYPE_XM)
{
@@ -3786,8 +3782,8 @@
}
-void CSoundFile::ChannelVolSlide(ModChannel *pChn, UINT param)
-//------------------------------------------------------------
+void CSoundFile::ChannelVolSlide(ModChannel *pChn, ModCommand::PARAM param) const
+//-------------------------------------------------------------------------------
{
LONG nChnSlide = 0;
if (param) pChn->nOldChnVolSlide = param; else param = pChn->nOldChnVolSlide;
@@ -3821,11 +3817,11 @@
}
-void CSoundFile::ExtendedMODCommands(CHANNELINDEX nChn, UINT param)
-//-----------------------------------------------------------------
+void CSoundFile::ExtendedMODCommands(CHANNELINDEX nChn, ModCommand::PARAM param)
+//------------------------------------------------------------------------------
{
ModChannel *pChn = &m_PlayState.Chn[nChn];
- UINT command = param & 0xF0;
+ uint8_t command = param & 0xF0;
param &= 0x0F;
switch(command)
{
@@ -3894,11 +3890,11...
[truncated message content] |
|
From: <sag...@us...> - 2015-03-19 04:37:04
|
Revision: 4897
http://sourceforge.net/p/modplug/code/4897
Author: saga-games
Date: 2015-03-19 04:36:50 +0000 (Thu, 19 Mar 2015)
Log Message:
-----------
[Imp] Improve seek + sample sync performance greatly by minimizing the number of rendered notes. If there are no tempo changes or portamentos, only the very last triggered note on every channel needs to be "rendered" now in theory.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/ModChannel.cpp
trunk/OpenMPT/soundlib/ModChannel.h
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/ModChannel.cpp
===================================================================
--- trunk/OpenMPT/soundlib/ModChannel.cpp 2015-03-18 17:24:25 UTC (rev 4896)
+++ trunk/OpenMPT/soundlib/ModChannel.cpp 2015-03-19 04:36:50 UTC (rev 4897)
@@ -94,4 +94,17 @@
}
+void ModChannel::Stop()
+//---------------------
+{
+ nPeriod = 0;
+ nInc = 0;
+ nPos = nPosLo = 0;
+ nLeftVU = nRightVU = 0;
+ nVolume = 0;
+ pCurrentSample = nullptr;
+ nInc = 0;
+}
+
+
OPENMPT_NAMESPACE_END
Modified: trunk/OpenMPT/soundlib/ModChannel.h
===================================================================
--- trunk/OpenMPT/soundlib/ModChannel.h 2015-03-18 17:24:25 UTC (rev 4896)
+++ trunk/OpenMPT/soundlib/ModChannel.h 2015-03-19 04:36:50 UTC (rev 4897)
@@ -57,7 +57,7 @@
uint32 nRampLength;
// Up to here: 100 bytes
- const ModSample *pModSample; // Currently assigned sample slot (can already be stopped)
+ const ModSample *pModSample; // Currently assigned sample slot (may already be stopped)
// Information not used in the mixer
const ModInstrument *pModInstrument; // Currently assigned instrument slot
@@ -171,6 +171,7 @@
};
void Reset(ResetFlags resetMask, const CSoundFile &sndFile, CHANNELINDEX sourceChannel);
+ void Stop();
typedef uint32 volume_t;
volume_t GetVSTVolume() { return (pModInstrument) ? pModInstrument->nGlobalVol * 4 : nVolume; }
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-18 17:24:25 UTC (rev 4896)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-19 04:36:50 UTC (rev 4897)
@@ -48,9 +48,11 @@
{
double patLoop;
ROWINDEX patLoopStart;
+ uint32 ticksToRender; // When using sample sync, we still need to render this many ticks
+ bool incChanged; // When using sample sync, note frequency has changed
BYTE vol;
- ChnSettings()
+ void Reset()
{
patLoop = 0.0;
patLoopStart = 0;
@@ -60,17 +62,20 @@
std::vector<ChnSettings> chnSettings;
double elapsedTime;
+ static const uint32 IGNORE_CHANNEL = uint32_max;
protected:
const CSoundFile &sndFile;
public:
- GetLengthMemory(const CSoundFile &sf) : sndFile(sf)
+ GetLengthMemory(const CSoundFile &sf)
+ : sndFile(sf)
+ , chnSettings(sf.GetNumChannels())
+ , state(sf.m_PlayState)
{
- state = sf.m_PlayState;
Reset();
- };
+ }
void Reset()
{
@@ -79,15 +84,100 @@
state.m_nMusicSpeed = sndFile.m_nDefaultSpeed;
state.m_nMusicTempo = sndFile.m_nDefaultTempo;
state.m_nGlobalVolume = sndFile.m_nDefaultGlobalVolume;
- chnSettings.assign(sndFile.GetNumChannels(), ChnSettings());
for(CHANNELINDEX chn = 0; chn < sndFile.GetNumChannels(); chn++)
{
+ chnSettings[chn].Reset();
state.Chn[chn].Reset(ModChannel::resetTotal, sndFile, chn);
state.Chn[chn].nOldGlobalVolSlide = 0;
state.Chn[chn].nOldChnVolSlide = 0;
state.Chn[chn].nNote = state.Chn[chn].nNewNote = state.Chn[chn].nLastNote = NOTE_NONE;
}
}
+
+ // Increment playback position of sample and envelopes on a channel
+ void RenderChannel(CHANNELINDEX channel, uint32 tickDuration, uint32 portaStart = 0)
+ {
+ ModChannel &chn = state.Chn[channel];
+ uint32 numTicks = chnSettings[channel].ticksToRender;
+ if(numTicks == IGNORE_CHANNEL || numTicks == 0 || (chn.nInc == 0 && !chnSettings[channel].incChanged) || chn.pModSample == nullptr)
+ {
+ return;
+ }
+
+ bool stopNote = false;
+ for(uint32 i = 0; i < numTicks; i++)
+ {
+ bool updateInc = (chn.PitchEnv.flags & (ENV_ENABLED | ENV_FILTER)) == ENV_ENABLED;
+ if(i >= portaStart)
+ {
+ const ModCommand *p = sndFile.Patterns[state.m_nPattern].GetpModCommand(state.m_nRow, channel);
+ if(p->command == CMD_TONEPORTAMENTO) sndFile.TonePortamento(&chn, p->param);
+ //else if(p->command == CMD_TONEPORTAVOL) TonePortamento(pChn, 0);
+ if(p->volcmd == VOLCMD_TONEPORTAMENTO)
+ {
+ uint32 param = p->vol;
+ if(sndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT | MOD_TYPE_AMS | MOD_TYPE_AMS2 | MOD_TYPE_DMF | MOD_TYPE_DBM | MOD_TYPE_IMF | MOD_TYPE_PSM | MOD_TYPE_J2B | MOD_TYPE_ULT | MOD_TYPE_OKT | MOD_TYPE_MT2 | MOD_TYPE_MDL))
+ {
+ param = ImpulseTrackerPortaVolCmd[param & 0x0F];
+ } else
+ {
+ // Close enough. Do not bother with idiosyncratic FT2 behaviour here.
+ param <<= 4;
+ }
+ sndFile.TonePortamento(&chn, param);
+ }
+ updateInc = true;
+ }
+
+ sndFile.IncrementEnvelopePositions(&chn);
+ int vol = 0;
+ sndFile.ProcessInstrumentFade(&chn, vol);
+
+ if(updateInc || chnSettings[channel].incChanged)
+ {
+ chn.nInc = sndFile.GetChannelIncrement(&chn, chn.nPeriod, 0);
+ chnSettings[channel].incChanged = false;
+ }
+
+ int32 inc = chn.nInc;
+ if(chn.dwFlags[CHN_PINGPONGFLAG]) inc = -inc;
+ chn.nPosLo += inc * tickDuration;
+ chn.nPos += ((int32)chn.nPosLo >> 16);
+ chn.nPosLo &= 0xFFFF;
+ }
+ if(chn.pModSample->uFlags[CHN_SUSTAINLOOP | CHN_LOOP])
+ {
+ // Check if we exceeded the sample loop.
+ if(chn.dwFlags[CHN_PINGPONGLOOP] && chn.nPos >= chn.nLoopEnd)
+ {
+ // Ping-pong loops are not supported for now.
+ stopNote = true;
+ } else
+ {
+ const SmpLength loopLength = chn.nLoopEnd - chn.nLoopStart;
+ if(chn.nPos >= chn.nLoopEnd + loopLength)
+ {
+ const SmpLength overshoot = chn.nPos - chn.nLoopEnd;
+ chn.nPos -= (overshoot / loopLength) * loopLength;
+ }
+ while(chn.nPos >= chn.nLoopEnd)
+ {
+ chn.nPos -= loopLength;
+ }
+ }
+ } else if(chn.nPos >= chn.nLength)
+ {
+ // Past sample end.
+ stopNote = true;
+ }
+
+ if(stopNote)
+ {
+ // Stop channel.
+ chn.Stop();
+ }
+ chnSettings[channel].ticksToRender = 0;
+ }
};
@@ -119,7 +209,6 @@
memory.state.m_nNextOrder = memory.state.m_nCurrentOrder = target.startOrder;
// Optimize away channels for which it's pointless to adjust sample positions
- std::vector<bool> adjustSampleChn(GetNumChannels(), true);
if(adjustSamplePos && target.mode == GetLengthTarget::SeekPosition)
{
PATTERNINDEX seekPat = PATTERNINDEX_INVALID;
@@ -130,7 +219,7 @@
{
if(ChnSettings[i].dwFlags[CHN_MUTE])
{
- adjustSampleChn[i] = false;
+ memory.chnSettings[i].ticksToRender = GetLengthMemory::IGNORE_CHANNEL;
continue;
}
if(seekPat != PATTERNINDEX_INVALID)
@@ -139,7 +228,7 @@
if(m.note == NOTE_NOTECUT || m.note == NOTE_KEYOFF || (m.note == NOTE_FADE && GetNumInstruments())
|| (m.IsNote() && !m.IsPortamento()))
{
- adjustSampleChn[i] = false;
+ memory.chnSettings[i].ticksToRender = GetLengthMemory::IGNORE_CHANNEL;
}
}
}
@@ -157,11 +246,13 @@
forbiddenCommands.set(CMD_NOTESLIDEUPRETRIG); forbiddenCommands.set(CMD_NOTESLIDEDOWN);
forbiddenCommands.set(CMD_NOTESLIDEDOWNRETRIG);
forbiddenVolCommands.set(VOLCMD_PORTAUP); forbiddenVolCommands.set(VOLCMD_PORTADOWN);
- forbiddenVolCommands.set(VOLCMD_TONEPORTAMENTO); forbiddenVolCommands.set(VOLCMD_VOLSLIDEUP);
- forbiddenVolCommands.set(VOLCMD_VOLSLIDEDOWN); forbiddenVolCommands.set(VOLCMD_FINEVOLUP);
- forbiddenVolCommands.set(VOLCMD_FINEVOLDOWN);
+ forbiddenVolCommands.set(VOLCMD_VOLSLIDEUP); forbiddenVolCommands.set(VOLCMD_VOLSLIDEDOWN);
+ forbiddenVolCommands.set(VOLCMD_FINEVOLUP); forbiddenVolCommands.set(VOLCMD_FINEVOLDOWN);
}
+ // If samples are being synced , force them to resync if tick duration changes
+ uint32 oldTickDuration = 0;
+
for (;;)
{
// Time target reached.
@@ -294,7 +385,25 @@
}
ModChannel *pChn = memory.state.Chn;
- ModCommand *p = Patterns[memory.state.m_nPattern].GetRow(memory.state.m_nRow);
+ const ModCommand *p = Patterns[memory.state.m_nPattern].GetRow(memory.state.m_nRow);
+
+ // For various effects, we need to know first how many ticks there are in this row.
+ for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++)
+ {
+ if(p[nChn].command == CMD_SPEED)
+ {
+#ifdef MODPLUG_TRACKER
+ // FT2 appears to be decrementing the tick count before checking for zero,
+ // so it effectively counts down 65536 ticks with speed = 0 (song speed is a 16-bit variable in FT2)
+ if(GetType() == MOD_TYPE_XM && !p[nChn].param)
+ {
+ memory.state.m_nMusicSpeed = uint16_max;
+ }
+#endif // MODPLUG_TRACKER
+ if(p[nChn].param > 0) memory.state.m_nMusicSpeed = p[nChn].param;
+ }
+ }
+
for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); p++, pChn++, nChn++) if(!p->IsEmpty())
{
if(IsCompatibleMode(TRK_SCREAMTRACKER) && ChnSettings[nChn].dwFlags[CHN_MUTE]) // not even effects are processed on muted S3M channels
@@ -349,22 +458,6 @@
}
}
break;
- // Set Speed
- case CMD_SPEED:
-#ifdef MODPLUG_TRACKER
- // FT2 appears to be decrementing the tick count before checking for zero,
- // so it effectively counts down 65536 ticks with speed = 0 (song speed is a 16-bit variable in FT2)
- if(GetType() == MOD_TYPE_XM && !param)
- {
- memory.state.m_nMusicSpeed = uint16_max;
- }
-#endif // MODPLUG_TRACKER
- if (!param) break;
- if (param <= GetModSpecifications().speedMax)
- {
- memory.state.m_nMusicSpeed = param;
- }
- break;
// Set Tempo
case CMD_TEMPO:
if(m_SongFlags[SONG_VBLANK_TIMING])
@@ -401,7 +494,6 @@
memory.state.m_nMusicTempo = Clamp(memory.state.m_nMusicTempo, 32u, 255u);
else
memory.state.m_nMusicTempo = Clamp(memory.state.m_nMusicTempo, GetModSpecifications().tempoMin, GetModSpecifications().tempoMax);
-
break;
case CMD_S3MCMDEX:
if((param & 0xF0) == 0x60)
@@ -533,14 +625,12 @@
param >>= 4;
if (!(GetType() & GLOBALVOL_7BIT_FORMATS)) param <<= 1;
memory.state.m_nGlobalVolume += param << 1;
- } else
- if (((param & 0xF0) == 0xF0) && (param & 0x0F))
+ } else if (((param & 0xF0) == 0xF0) && (param & 0x0F))
{
param = (param & 0x0F) << 1;
if (!(GetType() & GLOBALVOL_7BIT_FORMATS)) param <<= 1;
memory.state.m_nGlobalVolume -= param;
- } else
- if (param & 0xF0)
+ } else if (param & 0xF0)
{
param >>= 4;
param <<= 1;
@@ -552,7 +642,7 @@
if (!(GetType() & GLOBALVOL_7BIT_FORMATS)) param <<= 1;
memory.state.m_nGlobalVolume -= param * (memory.state.m_nMusicSpeed - 1);
}
- memory.state.m_nGlobalVolume = Clamp(memory.state.m_nGlobalVolume, 0, 256);
+ Limit(memory.state.m_nGlobalVolume, 0, 256);
break;
case CMD_CHANNELVOLUME:
if (param <= 64) pChn->nGlobalVol = param;
@@ -609,12 +699,12 @@
p = Patterns[memory.state.m_nPattern].GetRow(memory.state.m_nRow);
for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); p++, pChn++, nChn++)
{
- if(!adjustSampleChn[nChn])
+ if(memory.chnSettings[nChn].ticksToRender == GetLengthMemory::IGNORE_CHANNEL)
continue;
uint32 startTick = 0;
uint32 paramHi = p->param >> 4, paramLo = p->param & 0x0F;
- bool porta = p->command == CMD_TONEPORTAMENTO /*|| p->command CMD_TONEPORTAVOL || p->volcmd == VOLCMD_TONEPORTAMENTO*/; // Volume column tone portamento can be crazy, and CMD_TONEPORTAVOL requires volume slides which we don't emulate right now.
+ bool porta = p->command == CMD_TONEPORTAMENTO /*|| p->command CMD_TONEPORTAVOL*/ || p->volcmd == VOLCMD_TONEPORTAMENTO; // CMD_TONEPORTAVOL requires volume slides which we don't emulate right now.
bool stopNote = patternLoopStartedOnThisRow; // It's too much trouble to keep those pattern loops in sync...
if(p->instr) pChn->proTrackerOffset = 0;
@@ -623,7 +713,7 @@
pChn->nNewNote = pChn->nLastNote;
if(pChn->nNewIns != 0) InstrumentChange(pChn, pChn->nNewIns, porta);
NoteChange(pChn, p->note, porta);
- pChn->nInc = GetChannelIncrement(pChn, pChn->nPeriod, 0);
+ memory.chnSettings[nChn].incChanged = true;
if((p->command == CMD_MODCMDEX || p->command == CMD_S3MCMDEX) && (p->param & 0xF0) == 0xD0 && paramLo < numTicks)
{
@@ -632,6 +722,7 @@
{
startTick = paramHi;
}
+ if(!porta) memory.chnSettings[nChn].ticksToRender = 0;
if(p->command == CMD_OFFSET)
{
@@ -682,26 +773,9 @@
{
pChn->nPan = p->vol * 4;
}
- if(p->command == CMD_S3MCMDEX)
+
+ if(pChn->pModSample && !stopNote)
{
- if(p->param == 0x9E)
- {
- // Play forward
- pChn->dwFlags.reset(CHN_PINGPONGFLAG);
- } else if(p->param == 0x9F)
- {
- // Reverse
- pChn->dwFlags.set(CHN_PINGPONGFLAG);
- if(!pChn->nPos && pChn->nLength && (p->IsNote() || !pChn->dwFlags[CHN_LOOP]))
- {
- pChn->nPos = pChn->nLength - 1;
- pChn->nPosLo = 0xFFFF;
- }
- }
- }
-
- if(pChn->nInc != 0 && pChn->pModSample && !stopNote)
- {
// Check if we don't want to emulate some effect and thus stop processing.
if(p->command < MAX_EFFECTS)
{
@@ -728,71 +802,51 @@
}
}
- if(pChn->nInc != 0 && pChn->pModSample && !stopNote)
+ if(stopNote)
{
- // Increment playback position of sample and envelopes
- for(uint32 i = 0; i < (numTicks - startTick); i++)
+ pChn->Stop();
+ memory.chnSettings[nChn].ticksToRender = 0;
+ } else
+ {
+ if(oldTickDuration != tickDuration && oldTickDuration != 0)
{
- bool updateInc = (pChn->PitchEnv.flags & (ENV_ENABLED | ENV_FILTER)) == ENV_ENABLED;
- if(porta && i != startTick)
- {
- if(p->command == CMD_TONEPORTAMENTO) TonePortamento(pChn, p->param);
- //else if(p->command == CMD_TONEPORTAVOL) TonePortamento(pChn, 0);
- updateInc = true;
- }
+ memory.RenderChannel(nChn, oldTickDuration); // Re-sync what we've got so far
+ }
- IncrementEnvelopePositions(pChn);
- int vol = 0;
- ProcessInstrumentFade(pChn, vol);
-
- if(updateInc) pChn->nInc = GetChannelIncrement(pChn, pChn->nPeriod, 0);
-
- int32 inc = pChn->nInc;
- if(pChn->dwFlags[CHN_PINGPONGFLAG]) inc = -inc;
- pChn->nPosLo += inc * tickDuration;
- pChn->nPos += ((int32)pChn->nPosLo >> 16);
- pChn->nPosLo &= 0xFFFF;
- }
- if(pChn->pModSample->uFlags[CHN_SUSTAINLOOP | CHN_LOOP])
+ if(p->command == CMD_S3MCMDEX)
{
- // Check if we exceeded the sample loop.
- if(pChn->dwFlags[CHN_PINGPONGLOOP] && pChn->nPos >= pChn->nLoopEnd)
+ if(p->param == 0x9E)
{
- // Ping-pong loops are not supported for now.
- stopNote = true;
- } else
+ // Play forward
+ memory.RenderChannel(nChn, oldTickDuration); // Re-sync what we've got so far
+ pChn->dwFlags.reset(CHN_PINGPONGFLAG);
+ } else if(p->param == 0x9F)
{
- const SmpLength loopLength = pChn->nLoopEnd - pChn->nLoopStart;
- if(pChn->nPos >= pChn->nLoopEnd + loopLength)
+ // Reverse
+ memory.RenderChannel(nChn, oldTickDuration); // Re-sync what we've got so far
+ pChn->dwFlags.set(CHN_PINGPONGFLAG);
+ if(!pChn->nPos && pChn->nLength && (p->IsNote() || !pChn->dwFlags[CHN_LOOP]))
{
- const SmpLength overshoot = pChn->nPos - pChn->nLoopEnd;
- pChn->nPos -= (overshoot / loopLength) * loopLength;
+ pChn->nPos = pChn->nLength - 1;
+ pChn->nPosLo = 0xFFFF;
}
- while(pChn->nPos >= pChn->nLoopEnd)
- {
- pChn->nPos -= loopLength;
- }
}
- } else if(pChn->nPos >= pChn->nLength)
+ }
+
+ if(porta)
{
- // Past sample end.
- stopNote = true;
+ // Portamento needs immediate syncing
+ uint32 portaTick = memory.chnSettings[nChn].ticksToRender + startTick + 1;
+ memory.chnSettings[nChn].ticksToRender += numTicks;
+ memory.RenderChannel(nChn, tickDuration, portaTick);
+ } else
+ {
+ memory.chnSettings[nChn].ticksToRender += (numTicks - startTick);
}
}
-
- if(stopNote)
- {
- // Stop channel.
- pChn->nPeriod = 0;
- pChn->nInc = 0;
- pChn->nPos = pChn->nPosLo = 0;
- pChn->nLeftVU = pChn->nRightVU = 0;
- pChn->nVolume = 0;
- pChn->pCurrentSample = nullptr;
- pChn->nInc = 0;
- }
}
}
+ oldTickDuration = tickDuration;
if(patternLoopEndedOnThisRow)
{
@@ -830,6 +884,19 @@
}
}
+ // Now advance the sample positions for sample seeking on channels that are still playing
+ if(adjustSamplePos)
+ {
+ ModCommand *p = Patterns[memory.state.m_nPattern].GetRow(memory.state.m_nRow);
+ for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++, p++)
+ {
+ if(memory.chnSettings[nChn].ticksToRender != GetLengthMemory::IGNORE_CHANNEL)
+ {
+ memory.RenderChannel(nChn, oldTickDuration);
+ }
+ }
+ }
+
if(retval.targetReached || target.mode == GetLengthTarget::NoTarget)
{
retval.lastOrder = memory.state.m_nCurrentOrder;
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-03-18 17:24:25 UTC (rev 4896)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-03-19 04:36:50 UTC (rev 4897)
@@ -277,6 +277,7 @@
class CSoundFile
//==============
{
+ friend class GetLengthMemory;
public: //Misc
void ChangeModTypeTo(const MODTYPE& newType);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-03-21 22:48:29
|
Revision: 4903
http://sourceforge.net/p/modplug/code/4903
Author: saga-games
Date: 2015-03-21 22:48:16 +0000 (Sat, 21 Mar 2015)
Log Message:
-----------
[Fix] GetLength: Offset was not applied correctly in sample sync mode.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-21 14:18:38 UTC (rev 4902)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-03-21 22:48:16 UTC (rev 4903)
@@ -17,7 +17,7 @@
#include "stdafx.h"
#include "Sndfile.h"
#ifdef MODPLUG_TRACKER
-#include "../mptrack/moddoc.h"
+#include "../mptrack/Moddoc.h"
#endif // MODPLUG_TRACKER
#include "tuning.h"
#include "Tables.h"
@@ -792,7 +792,7 @@
if(offset == 0) offset = pChn->oldOffset;
offset += static_cast<SmpLength>(pChn->nOldHiOffset) << 16;
}
- SampleOffset(nChn, offset);
+ SampleOffset(*pChn, offset);
} else if(p->volcmd == VOLCMD_OFFSET)
{
if(p->vol <= CountOf(pChn->pModSample->cues) && pChn->pModSample != nullptr)
@@ -802,7 +802,7 @@
offset = pChn->oldOffset;
else
offset = pChn->oldOffset = pChn->pModSample->cues[p->vol - 1];
- SampleOffset(nChn, offset);
+ SampleOffset(*pChn, offset);
}
}
}
@@ -2639,7 +2639,7 @@
offset = pChn->oldOffset;
else
offset = pChn->oldOffset = pChn->pModSample->cues[vol - 1];
- SampleOffset(nChn, offset);
+ SampleOffset(*pChn, offset);
}
break;
}
@@ -2739,7 +2739,7 @@
if (offset) pChn->oldOffset = offset; else offset = pChn->oldOffset;
offset += static_cast<SmpLength>(pChn->nOldHiOffset) << 16;
}
- SampleOffset(nChn, offset);
+ SampleOffset(*pChn, offset);
}
break;
@@ -4641,28 +4641,26 @@
}
-void CSoundFile::SampleOffset(CHANNELINDEX nChn, SmpLength param)
-//---------------------------------------------------------------
+void CSoundFile::SampleOffset(ModChannel &chn, SmpLength param) const
+//-------------------------------------------------------------------
{
+ chn.proTrackerOffset += param;
- ModChannel *pChn = &m_PlayState.Chn[nChn];
- pChn->proTrackerOffset += param;
-
- if(pChn->rowCommand.IsNote())
+ if(chn.rowCommand.IsNote())
{
if(m_SongFlags[SONG_PT1XMODE])
{
// ProTracker compatbility: PT1/2-style funky 9xx offset command
// Test case: ptoffset.mod
- pChn->nPos = pChn->proTrackerOffset;
- pChn->proTrackerOffset += param;
+ chn.nPos = chn.proTrackerOffset;
+ chn.proTrackerOffset += param;
} else
{
- pChn->nPos = param;
+ chn.nPos = param;
}
- pChn->nPosLo = 0;
+ chn.nPosLo = 0;
- if (pChn->nPos >= pChn->nLength || (pChn->dwFlags[CHN_LOOP] && pChn->nPos >= pChn->nLoopEnd))
+ if (chn.nPos >= chn.nLength || (chn.dwFlags[CHN_LOOP] && chn.nPos >= chn.nLoopEnd))
{
// Offset beyond sample size
if (!(GetType() & (MOD_TYPE_XM|MOD_TYPE_MT2|MOD_TYPE_MOD)))
@@ -4671,30 +4669,30 @@
if(IsCompatibleMode(TRK_IMPULSETRACKER))
{
if(m_SongFlags[SONG_ITOLDEFFECTS])
- pChn->nPos = pChn->nLength; // Old FX: Clip to end of sample
+ chn.nPos = chn.nLength; // Old FX: Clip to end of sample
else
- pChn->nPos = 0; // Reset to beginning of sample
+ chn.nPos = 0; // Reset to beginning of sample
} else
{
- pChn->nPos = pChn->nLoopStart;
- if(m_SongFlags[SONG_ITOLDEFFECTS] && pChn->nLength > 4)
+ chn.nPos = chn.nLoopStart;
+ if(m_SongFlags[SONG_ITOLDEFFECTS] && chn.nLength > 4)
{
- pChn->nPos = pChn->nLength - 2;
+ chn.nPos = chn.nLength - 2;
}
}
} else if(IsCompatibleMode(TRK_FASTTRACKER2))
{
// FT2 Compatibility: Don't play note if offset is beyond sample length
// Test case: 3xx-no-old-samp.xm
- pChn->dwFlags.set(CHN_FASTVOLRAMP);
- pChn->nVolume = pChn->nPeriod = 0;
+ chn.dwFlags.set(CHN_FASTVOLRAMP);
+ chn.nVolume = chn.nPeriod = 0;
}
}
- } else if ((param < pChn->nLength) && (GetType() & (MOD_TYPE_MTM | MOD_TYPE_DMF | MOD_TYPE_MDL | MOD_TYPE_PLM)))
+ } else if ((param < chn.nLength) && (GetType() & (MOD_TYPE_MTM | MOD_TYPE_DMF | MOD_TYPE_MDL | MOD_TYPE_PLM)))
{
// Some trackers can also call offset effects without notes next to them...
- pChn->nPos = param;
- pChn->nPosLo = 0;
+ chn.nPos = param;
+ chn.nPosLo = 0;
}
}
@@ -4836,7 +4834,7 @@
offset--;
if(offset == 0) offset = chn.oldOffset;
else if(offset <= static_cast<int>(CountOf(chn.pModSample->cues))) offset = chn.oldOffset = chn.pModSample->cues[offset - 1];
- SampleOffset(nChn, offset);
+ SampleOffset(chn, offset);
}
}
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-03-21 14:18:38 UTC (rev 4902)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-03-21 22:48:16 UTC (rev 4903)
@@ -850,7 +850,7 @@
void Panbrello(ModChannel *pChn, UINT param) const;
void Panning(ModChannel *pChn, uint32 param, PanningType panBits) const;
void RetrigNote(CHANNELINDEX nChn, int param, int offset = 0);
- void SampleOffset(CHANNELINDEX nChn, SmpLength param);
+ void SampleOffset(ModChannel &chn, SmpLength param) const;
void NoteCut(CHANNELINDEX nChn, UINT nTick, bool cutSample);
ROWINDEX PatternLoop(ModChannel *, UINT param);
void ExtendedMODCommands(CHANNELINDEX nChn, ModCommand::PARAM param);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-04-11 12:49:01
|
Revision: 4922
http://sourceforge.net/p/modplug/code/4922
Author: saga-games
Date: 2015-04-11 12:48:48 +0000 (Sat, 11 Apr 2015)
Log Message:
-----------
[Mod] MPTM Saving: Only write out full envelope information for those envelope types that need it.
[Mod] PLM Loader: Improve Note-less offset command in OpenMPT (already works as intended in libopenmpt)
[Ref] Small changes
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_669.cpp
trunk/OpenMPT/soundlib/Load_it.cpp
trunk/OpenMPT/soundlib/Load_itp.cpp
trunk/OpenMPT/soundlib/Load_plm.cpp
trunk/OpenMPT/soundlib/MIDIMacros.h
Modified: trunk/OpenMPT/soundlib/Load_669.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_669.cpp 2015-04-10 10:56:00 UTC (rev 4921)
+++ trunk/OpenMPT/soundlib/Load_669.cpp 2015-04-11 12:48:48 UTC (rev 4922)
@@ -66,6 +66,7 @@
{
mptSmp.Initialize();
+ mptSmp.nC5Speed = 8363;
mptSmp.nLength = length;
mptSmp.nLoopStart = loopStart;
mptSmp.nLoopEnd = loopEnd;
@@ -161,7 +162,13 @@
continue;
}
- std::vector<uint8> effect(8, 0xFF);
+ const ModCommand::COMMAND effTrans[] =
+ {
+ CMD_PORTAMENTOUP, CMD_PORTAMENTODOWN, CMD_TONEPORTAMENTO, CMD_PORTAMENTOUP,
+ CMD_ARPEGGIO, CMD_SPEED, CMD_PANNINGSLIDE, CMD_RETRIG,
+ };
+
+ uint8 effect[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
for(ROWINDEX row = 0; row < 64; row++)
{
PatternRow m = Patterns[pat].GetRow(row);
@@ -202,14 +209,8 @@
m->param = effect[chn] & 0x0F;
- static const ModCommand::COMMAND effTrans[] =
+ if((effect[chn] >> 4) < CountOf(effTrans))
{
- CMD_PORTAMENTOUP, CMD_PORTAMENTODOWN, CMD_TONEPORTAMENTO, CMD_PORTAMENTOUP,
- CMD_ARPEGGIO, CMD_SPEED, CMD_PANNINGSLIDE, CMD_RETRIG,
- };
-
- if(static_cast<uint8>(effect[chn] >> 4) < CountOf(effTrans))
- {
m->command = effTrans[effect[chn] >> 4];
} else
{
@@ -242,7 +243,7 @@
case 5:
// F - set tempo
- // TODO: param 0 is a "super fast tempo" in extended mode (?)
+ // TODO: param 0 is a "super fast tempo" in extended mode (?)
effect[chn] = 0xFF;
break;
Modified: trunk/OpenMPT/soundlib/Load_it.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_it.cpp 2015-04-10 10:56:00 UTC (rev 4921)
+++ trunk/OpenMPT/soundlib/Load_it.cpp 2015-04-11 12:48:48 UTC (rev 4922)
@@ -943,7 +943,7 @@
{
// ModPlug Tracker 1.00a5, instruments 560 bytes apart
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 00, 00, A5);
- madeWithTracker = "ModPlug tracker 1.00a5";
+ madeWithTracker = "ModPlug Tracker 1.00a5";
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0214 && !memcmp(fileHeader.reserved, "CHBI", 4))
{
@@ -1000,6 +1000,9 @@
case 7:
madeWithTracker = mpt::String::Print("ITMCK %1.%2.%3", (fileHeader.cwtv >> 8) & 0x0F, (fileHeader.cwtv >> 4) & 0x0F, fileHeader.cwtv & 0x0F);
break;
+ case 0xD:
+ madeWithTracker = "spc2it";
+ break;
}
}
@@ -1957,24 +1960,28 @@
if(GetType() & MOD_TYPE_MPT)
{
- uint32 maxNodes = 0;
+ uint32 maxNodes[3] = { 0 };
for(INSTRUMENTINDEX nIns = 1; nIns <= m_nInstruments; nIns++) if(Instruments[nIns] != nullptr)
{
- maxNodes = std::max(maxNodes, Instruments[nIns]->VolEnv.nNodes);
- maxNodes = std::max(maxNodes, Instruments[nIns]->PanEnv.nNodes);
- maxNodes = std::max(maxNodes, Instruments[nIns]->PitchEnv.nNodes);
+ maxNodes[0] = std::max(maxNodes[0], Instruments[nIns]->VolEnv.nNodes);
+ maxNodes[1] = std::max(maxNodes[1], Instruments[nIns]->PanEnv.nNodes);
+ maxNodes[2] = std::max(maxNodes[2], Instruments[nIns]->PitchEnv.nNodes);
}
// write full envelope information for MPTM files (more env points)
- if(maxNodes > 25)
+ if(maxNodes[0] > 25)
{
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('V','E','.','.'), sizeof(ModInstrument().VolEnv.nNodes), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('V','P','[','.'), sizeof(ModInstrument().VolEnv.Ticks), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('V','E','[','.'), sizeof(ModInstrument().VolEnv.Values), f, nInstruments);
-
+ }
+ if(maxNodes[1] > 25)
+ {
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','E','.','.'), sizeof(ModInstrument().PanEnv.nNodes), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','P','[','.'), sizeof(ModInstrument().PanEnv.Ticks), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','E','[','.'), sizeof(ModInstrument().PanEnv.Values), f, nInstruments);
-
+ }
+ if(maxNodes[2] > 25)
+ {
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','i','E','.'), sizeof(ModInstrument().PitchEnv.nNodes), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','i','P','['), sizeof(ModInstrument().PitchEnv.Ticks), f, nInstruments);
WriteInstrumentPropertyForAllInstruments(MAGIC4BE('P','i','E','['), sizeof(ModInstrument().PitchEnv.Values), f, nInstruments);
Modified: trunk/OpenMPT/soundlib/Load_itp.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_itp.cpp 2015-04-10 10:56:00 UTC (rev 4921)
+++ trunk/OpenMPT/soundlib/Load_itp.cpp 2015-04-11 12:48:48 UTC (rev 4922)
@@ -110,7 +110,10 @@
for(CHANNELINDEX chn = 0; chn < m_nChannels; chn++)
{
ChnSettings[chn].nPan = static_cast<uint16>(file.ReadUint32LE());
- ChnSettings[chn].dwFlags = static_cast<ChannelFlags>(file.ReadUint32LE());
+ ChnSettings[chn].dwFlags.reset();
+ uint32 flags = file.ReadUint32LE();
+ if(flags & 0x100) ChnSettings[chn].dwFlags.set(CHN_MUTE);
+ if(flags & 0x800) ChnSettings[chn].dwFlags.set(CHN_SURROUND);
ChnSettings[chn].nVolume = static_cast<uint16>(file.ReadUint32LE());
file.ReadString<mpt::String::maybeNullTerminated>(ChnSettings[chn].szName, size);
}
@@ -186,7 +189,7 @@
if(pat < numNamedPats)
{
- char patName[MAX_PATTERNNAME];
+ char patName[32];
pattNames.ReadString<mpt::String::maybeNullTerminated>(patName, patNameLen);
Patterns[pat].SetName(patName);
}
@@ -210,13 +213,13 @@
}
}
- // Load embeded samples
+ // Load embedded samples
// Read original number of samples
m_nSamples = static_cast<SAMPLEINDEX>(file.ReadUint32LE());
LimitMax(m_nSamples, SAMPLEINDEX(MAX_SAMPLES - 1));
- // Read number of embeded samples
+ // Read number of embedded samples
uint32 embeddedSamples = file.ReadUint32LE();
// Read samples
Modified: trunk/OpenMPT/soundlib/Load_plm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_plm.cpp 2015-04-10 10:56:00 UTC (rev 4921)
+++ trunk/OpenMPT/soundlib/Load_plm.cpp 2015-04-11 12:48:48 UTC (rev 4922)
@@ -268,6 +268,7 @@
const uint32 patternEnd = ord.x + patHeader.numRows;
maxPos = std::max(maxPos, patternEnd);
+ ModCommand::NOTE lastNote[32]= { 0 };
for(ROWINDEX r = 0; r < patHeader.numRows; r++, curRow++)
{
if(curRow >= rowsPerPat)
@@ -290,7 +291,7 @@
uint8 data[5];
file.ReadArray(data);
if(data[0])
- m->note = (data[0] >> 4) * 12 + (data[0] & 0x0F) + 12 + NOTE_MIN;
+ lastNote[c] = m->note = (data[0] >> 4) * 12 + (data[0] & 0x0F) + 12 + NOTE_MIN;
else
m->note = NOTE_NONE;
m->instr = data[1];
@@ -358,6 +359,10 @@
m->param = mpt::saturate_cast<ModCommand::PARAM>(((m->param * Samples[m->instr].nLength) / 255) >> 8);
}
}
+ if((data[3] == 0x13 || data[3] == 0x16) && m->note == NOTE_NONE)
+ {
+ m->note = lastNote[c];
+ }
}
}
if(patHeader.numChannels > numChannels)
Modified: trunk/OpenMPT/soundlib/MIDIMacros.h
===================================================================
--- trunk/OpenMPT/soundlib/MIDIMacros.h 2015-04-10 10:56:00 UTC (rev 4921)
+++ trunk/OpenMPT/soundlib/MIDIMacros.h 2015-04-11 12:48:48 UTC (rev 4922)
@@ -10,6 +10,12 @@
#pragma once
+enum
+{
+ NUM_MACROS = 16, // number of parametered macros
+ MACRO_LENGTH = 32, // max number of chars per macro
+};
+
#ifdef MODPLUG_TRACKER
OPENMPT_NAMESPACE_BEGIN
class CSoundFile;
@@ -70,10 +76,7 @@
};
-#define NUM_MACROS 16 // number of parametered macros
-#define MACRO_LENGTH 32 // max number of chars per macro
-
#ifdef NEEDS_PRAGMA_PACK
#pragma pack(push, 1)
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-05-24 17:23:35
|
Revision: 5153
http://sourceforge.net/p/modplug/code/5153
Author: saga-games
Date: 2015-05-24 17:23:30 +0000 (Sun, 24 May 2015)
Log Message:
-----------
[Fix] Previewing samples from UAX files in the tree view played them at the wrong frequency.
[Ref] Small non-functional changes in Load_it.cpp
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_it.cpp
trunk/OpenMPT/soundlib/Snd_fx.cpp
Modified: trunk/OpenMPT/soundlib/Load_it.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_it.cpp 2015-05-24 09:45:49 UTC (rev 5152)
+++ trunk/OpenMPT/soundlib/Load_it.cpp 2015-05-24 17:23:30 UTC (rev 5153)
@@ -25,7 +25,6 @@
#include "../common/mptFileIO.h"
#endif
#include <sstream>
-#include <list>
#include "../common/version.h"
#include "ITTools.h"
#include <time.h>
@@ -92,7 +91,7 @@
TNTS_MAP tNameToShort_Map;
unsigned short figMap = 0;
- for(UINT i = 1; i <= sf.GetNumInstruments(); i++) if (sf.Instruments[i] != nullptr)
+ for(INSTRUMENTINDEX i = 1; i <= sf.GetNumInstruments(); i++) if (sf.Instruments[i] != nullptr)
{
TNTS_MAP_ITER iter = tNameToShort_Map.find(sf.Instruments[i]->pTuning);
if(iter != tNameToShort_Map.end())
@@ -170,7 +169,7 @@
ReadTuningMapTemplate<uint16, uint8>(iStrm, shortToTNameMap);
//Read & set tunings for instruments
- std::list<std::string> notFoundTunings;
+ std::vector<std::string> notFoundTunings;
for(UINT i = 1; i<=csf.GetNumInstruments(); i++)
{
uint16 ui;
@@ -180,7 +179,7 @@
{
const std::string str = iter->second;
- if(str == std::string("->MPT_ORIGINAL_IT<-"))
+ if(str == "->MPT_ORIGINAL_IT<-")
{
csf.Instruments[i]->pTuning = nullptr;
continue;
@@ -207,8 +206,8 @@
continue;
//Checking if not found tuning already noticed.
- std::list<std::string>::iterator iter;
- iter = find(notFoundTunings.begin(), notFoundTunings.end(), str);
+ std::vector<std::string>::iterator iter;
+ iter = std::find(notFoundTunings.begin(), notFoundTunings.end(), str);
if(iter == notFoundTunings.end())
{
notFoundTunings.push_back(str);
@@ -224,9 +223,9 @@
}
csf.Instruments[i]->pTuning = csf.GetDefaultTuning();
- }
- else //This 'else' happens probably only in case of corrupted file.
+ } else
{
+ //This 'else' happens probably only in case of corrupted file.
if(csf.Instruments[i])
csf.Instruments[i]->pTuning = csf.GetDefaultTuning();
}
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-24 09:45:49 UTC (rev 5152)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-24 17:23:30 UTC (rev 5153)
@@ -5185,7 +5185,7 @@
if (note == NOTE_NONE || (note >= NOTE_MIN_SPECIAL)) return 0;
note -= NOTE_MIN;
if (GetType() & (MOD_TYPE_IT|MOD_TYPE_MPT|MOD_TYPE_MT2|MOD_TYPE_S3M|MOD_TYPE_STM|MOD_TYPE_MDL|MOD_TYPE_ULT|MOD_TYPE_WAV|MOD_TYPE_669|MOD_TYPE_PLM
- |MOD_TYPE_FAR|MOD_TYPE_DMF|MOD_TYPE_PTM|MOD_TYPE_AMS|MOD_TYPE_AMS2|MOD_TYPE_DBM|MOD_TYPE_AMF|MOD_TYPE_PSM|MOD_TYPE_J2B|MOD_TYPE_IMF))
+ |MOD_TYPE_FAR|MOD_TYPE_DMF|MOD_TYPE_PTM|MOD_TYPE_AMS|MOD_TYPE_AMS2|MOD_TYPE_DBM|MOD_TYPE_AMF|MOD_TYPE_PSM|MOD_TYPE_J2B|MOD_TYPE_IMF|MOD_TYPE_UAX))
{
if(m_SongFlags[SONG_LINEARSLIDES])
{
@@ -5198,8 +5198,7 @@
return Util::muldiv_unsigned(8363, (FreqS3MTable[note % 12] << 5), nC5Speed << (note / 12));
//8363 * freq[note%12] / nC5Speed * 2^(5-note/12)
}
- } else
- if (GetType() == MOD_TYPE_XM)
+ } else if (GetType() == MOD_TYPE_XM)
{
if (note < 12) note = 12;
note -= 12;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <man...@us...> - 2015-05-25 10:13:46
|
Revision: 5165
http://sourceforge.net/p/modplug/code/5165
Author: manxorist
Date: 2015-05-25 10:13:40 +0000 (Mon, 25 May 2015)
Log Message:
-----------
[Ref] Small simplification in tuning code.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/tuning.cpp
trunk/OpenMPT/soundlib/tuning.h
Modified: trunk/OpenMPT/soundlib/tuning.cpp
===================================================================
--- trunk/OpenMPT/soundlib/tuning.cpp 2015-05-25 09:26:54 UTC (rev 5164)
+++ trunk/OpenMPT/soundlib/tuning.cpp 2015-05-25 10:13:40 UTC (rev 5165)
@@ -89,7 +89,6 @@
m_GroupSize = 0;
m_GroupRatio = 0;
m_RatioTableFine.clear();
- BelowRatios = AboveRatios = DefaultBARFUNC;
}
}
@@ -102,7 +101,6 @@
m_StepMin = vr.first;
ProSetGroupSize(static_cast<UNOTEINDEXTYPE>(v.size()));
ProSetGroupRatio(r);
- BelowRatios = AboveRatios = DefaultBARFUNC;
m_RatioTable.resize(vr.second-vr.first+1);
std::copy(v.begin(), v.end(), m_RatioTable.begin() + (ratiostartpos - vr.first));
@@ -138,7 +136,6 @@
m_StepMin = vr.first;
ProSetGroupSize(s);
ProSetGroupRatio(r);
- BelowRatios = AboveRatios = DefaultBARFUNC;
const RATIOTYPE stepRatio = pow(r, static_cast<RATIOTYPE>(1)/s);
m_RatioTable.resize(vr.second - vr.first + 1);
@@ -183,18 +180,15 @@
}
-CTuningRTI::RATIOTYPE CTuningRTI::DefaultBARFUNC(const NOTEINDEXTYPE&, const STEPINDEXTYPE&)
-//---------------------------------------------------------------
-{
- return 1;
-}
+const RATIOTYPE CTuningRTI::s_DefaultFallbackRatio = 1.0f;
+
//Without finetune
CTuning::RATIOTYPE CTuningRTI::GetRatio(const NOTEINDEXTYPE& stepsFromCentre) const
//-------------------------------------------------------------------------------------
{
- if(stepsFromCentre < m_StepMin) return BelowRatios(stepsFromCentre,0);
- if(stepsFromCentre >= m_StepMin + static_cast<NOTEINDEXTYPE>(m_RatioTable.size())) return AboveRatios(stepsFromCentre,0);
+ if(stepsFromCentre < m_StepMin) return s_DefaultFallbackRatio;
+ if(stepsFromCentre >= m_StepMin + static_cast<NOTEINDEXTYPE>(m_RatioTable.size())) return s_DefaultFallbackRatio;
return m_RatioTable[stepsFromCentre - m_StepMin];
}
@@ -228,8 +222,8 @@
fineStep = ((fsCount + 1) - (abs(baseStepDiff) % (fsCount+1))) % (fsCount+1);
}
- if(note < m_StepMin) return BelowRatios(note, fineStep);
- if(note >= m_StepMin + static_cast<NOTEINDEXTYPE>(m_RatioTable.size())) return AboveRatios(note, fineStep);
+ if(note < m_StepMin) return s_DefaultFallbackRatio;
+ if(note >= m_StepMin + static_cast<NOTEINDEXTYPE>(m_RatioTable.size())) return s_DefaultFallbackRatio;
if(fineStep) return m_RatioTable[note - m_StepMin] * GetRatioFine(note, fineStep);
else return m_RatioTable[note - m_StepMin];
Modified: trunk/OpenMPT/soundlib/tuning.h
===================================================================
--- trunk/OpenMPT/soundlib/tuning.h 2015-05-25 09:26:54 UTC (rev 5164)
+++ trunk/OpenMPT/soundlib/tuning.h 2015-05-25 10:13:40 UTC (rev 5165)
@@ -24,15 +24,10 @@
class CTuningRTI : public CTuning //RTI <-> Ratio Table Implementation
//================================
{
-public:
-//BEGIN TYPEDEFS:
- typedef RATIOTYPE (BARFUNC)(const NOTEINDEXTYPE&, const STEPINDEXTYPE&);
- //BARFUNC <-> Beyond Array Range FUNCtion.
-//END TYPEDEFS
public:
//BEGIN STATIC CONST MEMBERS:
- static RATIOTYPE DefaultBARFUNC(const NOTEINDEXTYPE&, const STEPINDEXTYPE&);
+ static const RATIOTYPE s_DefaultFallbackRatio;
static const NOTEINDEXTYPE s_StepMinDefault = -64;
static const UNOTEINDEXTYPE s_RatioTableSizeDefault = 128;
static const USTEPINDEXTYPE s_RatioTableFineSizeMaxDefault = 1000;
@@ -168,11 +163,6 @@
//m_GroupSize should always be >= 0.
NOTEINDEXTYPE m_GroupSize;
RATIOTYPE m_GroupRatio;
-
-
- BARFUNC* BelowRatios;
- BARFUNC* AboveRatios;
- //Defines the ratio to return if the ratio table runs out.
//<----Actual data members
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-05-25 15:35:59
|
Revision: 5176
http://sourceforge.net/p/modplug/code/5176
Author: saga-games
Date: 2015-05-25 15:35:54 +0000 (Mon, 25 May 2015)
Log Message:
-----------
[New] Add support for song-specific resampling mode (not usable form GUI yet)
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_it.cpp
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/Load_it.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_it.cpp 2015-05-25 15:33:30 UTC (rev 5175)
+++ trunk/OpenMPT/soundlib/Load_it.cpp 2015-05-25 15:35:54 UTC (rev 5176)
@@ -2080,6 +2080,11 @@
WRITEMODULAR(MAGIC4BE('R','P','.','.'), m_nRestartPos);
}
+ if(m_nResampling != SRCMODE_DEFAULT)
+ {
+ WRITEMODULAR(MAGIC4LE('R','S','M','P'), m_nResampling);
+ }
+
// Sample cues
if(GetType() == MOD_TYPE_MPT)
{
@@ -2242,6 +2247,10 @@
case MAGIC4BE('D','G','V','.'): ReadField(chunk, size, m_nDefaultGlobalVolume); break;
case MAGIC4BE('R','P','.','.'): if(modtype != MOD_TYPE_XM) ReadField(chunk, size, m_nRestartPos); break;
case MAGIC4BE('M','S','F','.'): ReadFieldFlagSet(chunk, size, m_ModFlags); break;
+ case MAGIC4LE('R','S','M','P'):
+ ReadField(chunk, size, m_nResampling);
+ if(!IsKnownResamplingMode(m_nResampling)) m_nResampling = SRCMODE_DEFAULT;
+ break;
#ifdef MODPLUG_TRACKER
case MAGIC4BE('M','I','M','A'): GetMIDIMapper().Deserialize(chunk); break;
#endif
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-05-25 15:33:30 UTC (rev 5175)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-05-25 15:35:54 UTC (rev 5176)
@@ -644,6 +644,7 @@
m_SongFlags.reset();
m_nMinPeriod = 16;
m_nMaxPeriod = 32767;
+ m_nResampling = SRCMODE_DEFAULT;
m_dwLastSavedWithVersion = m_dwCreatedWithVersion = 0;
SetMixLevels(mixLevels_compatible);
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-05-25 15:33:30 UTC (rev 5175)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-05-25 15:35:54 UTC (rev 5176)
@@ -434,6 +434,7 @@
// Periods in MPT are 4 times as fine as Amiga periods because of extra fine frequency slides (introduced in the S3M format).
int32 m_nMinPeriod, m_nMaxPeriod;
+ uint32 m_nResampling; // Resampling mode (if overriding the globally set resampling)
int32 m_nRepeatCount; // -1 means repeat infinitely.
ORDERINDEX m_nMaxOrderPosition;
ModChannelSettings ChnSettings[MAX_BASECHANNELS]; // Initial channels settings
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2015-05-25 15:33:30 UTC (rev 5175)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2015-05-25 15:35:54 UTC (rev 5176)
@@ -2119,6 +2119,9 @@
{
// for defined resampling modes, use per-instrument resampling mode if set
pChn->resamplingMode = static_cast<uint8>(pChn->pModInstrument->nResampling);
+ } else if(IsKnownResamplingMode(m_nResampling))
+ {
+ pChn->resamplingMode = static_cast<uint8>(m_nResampling);
} else
{
// default to global mixer settings
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-05-29 21:29:04
|
Revision: 5206
http://sourceforge.net/p/modplug/code/5206
Author: saga-games
Date: 2015-05-29 21:28:57 +0000 (Fri, 29 May 2015)
Log Message:
-----------
[Fix] Song estimation should not affect modern tempo tick compensation of potentially parallel playback
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-29 20:26:17 UTC (rev 5205)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-29 21:28:57 UTC (rev 5206)
@@ -738,13 +738,13 @@
break;
}
- ROWINDEX rowsPerBeat = m_nDefaultRowsPerBeat;
+ m_PlayState.m_nCurrentRowsPerBeat = m_nDefaultRowsPerBeat;
if(Patterns[memory.state.m_nPattern].GetOverrideSignature())
{
- rowsPerBeat = Patterns[memory.state.m_nPattern].GetRowsPerBeat();
+ m_PlayState.m_nCurrentRowsPerBeat = Patterns[memory.state.m_nPattern].GetRowsPerBeat();
}
- const uint32 tickDuration = GetTickDuration(memory.state.m_nMusicTempo, memory.state.m_nMusicSpeed, rowsPerBeat);
+ const uint32 tickDuration = GetTickDuration(memory.state);
const uint32 rowDuration = tickDuration * numTicks;
memory.elapsedTime += static_cast<double>(rowDuration) / static_cast<double>(m_MixerSettings.gdwMixingFreq);
memory.state.m_lTotalSampleCount += rowDuration;
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-05-29 20:26:17 UTC (rev 5205)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-05-29 21:28:57 UTC (rev 5206)
@@ -1811,38 +1811,38 @@
// Get length of a tick in sample, with tick-to-tick tempo correction in modern tempo mode.
// This has to be called exactly once per tick because otherwise the error accumulation
// goes wrong.
-uint32 CSoundFile::GetTickDuration(uint32 tempo, uint32 speed, ROWINDEX rowsPerBeat)
-//----------------------------------------------------------------------------------
+uint32 CSoundFile::GetTickDuration(PlayState &playState) const
+//------------------------------------------------------------
{
- UINT retval = 0;
+ uint32 retval = 0;
switch(m_nTempoMode)
{
case tempo_mode_classic:
default:
- retval = (m_MixerSettings.gdwMixingFreq * 5) / (tempo << 1);
+ retval = (m_MixerSettings.gdwMixingFreq * 5) / (playState.m_nMusicTempo << 1);
break;
case tempo_mode_alternative:
- retval = m_MixerSettings.gdwMixingFreq / tempo;
+ retval = m_MixerSettings.gdwMixingFreq / playState.m_nMusicTempo;
break;
case tempo_mode_modern:
{
- double accurateBufferCount = static_cast<double>(m_MixerSettings.gdwMixingFreq) * (60.0 / static_cast<double>(tempo) / (static_cast<double>(speed * rowsPerBeat)));
- UINT bufferCount = static_cast<int>(accurateBufferCount);
- m_PlayState.m_dBufferDiff += accurateBufferCount - bufferCount;
+ double accurateBufferCount = static_cast<double>(m_MixerSettings.gdwMixingFreq) * (60.0 / static_cast<double>(playState.m_nMusicTempo) / (static_cast<double>(playState.m_nMusicSpeed * playState.m_nCurrentRowsPerBeat)));
+ uint32 bufferCount = static_cast<int>(accurateBufferCount);
+ playState.m_dBufferDiff += accurateBufferCount - bufferCount;
//tick-to-tick tempo correction:
- if(m_PlayState.m_dBufferDiff >= 1)
+ if(playState.m_dBufferDiff >= 1)
{
bufferCount++;
- m_PlayState.m_dBufferDiff--;
+ playState.m_dBufferDiff--;
} else if(m_PlayState.m_dBufferDiff <= -1)
{
bufferCount--;
- m_PlayState.m_dBufferDiff++;
+ playState.m_dBufferDiff++;
}
- MPT_ASSERT(fabs(m_PlayState.m_dBufferDiff) < 1);
+ MPT_ASSERT(fabs(playState.m_dBufferDiff) < 1);
retval = bufferCount;
}
break;
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-05-29 20:26:17 UTC (rev 5205)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-05-29 21:28:57 UTC (rev 5206)
@@ -650,7 +650,7 @@
void RecalculateSamplesPerTick();
double GetRowDuration(UINT tempo, UINT speed) const;
- uint32 GetTickDuration(uint32 tempo, uint32 speed, ROWINDEX rowsPerBeat);
+ uint32 GetTickDuration(PlayState &playState) const;
// A repeat count value of -1 means infinite loop
void SetRepeatCount(int n) { m_nRepeatCount = n; }
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2015-05-29 20:26:17 UTC (rev 5205)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2015-05-29 21:28:57 UTC (rev 5206)
@@ -1769,7 +1769,7 @@
////////////////////////////////////////////////////////////////////////////////////
if (!m_PlayState.m_nMusicTempo) return false;
- m_PlayState.m_nSamplesPerTick = GetTickDuration(m_PlayState.m_nMusicTempo, m_PlayState.m_nMusicSpeed, m_PlayState.m_nCurrentRowsPerBeat);
+ m_PlayState.m_nSamplesPerTick = GetTickDuration(m_PlayState);
m_PlayState.m_nBufferCount = m_PlayState.m_nSamplesPerTick;
// Master Volume + Pre-Amplification / Attenuation setup
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sag...@us...> - 2015-05-29 23:41:26
|
Revision: 5209
http://sourceforge.net/p/modplug/code/5209
Author: saga-games
Date: 2015-05-29 23:41:20 +0000 (Fri, 29 May 2015)
Log Message:
-----------
[Fix] Panning commands were still applied when seeking even if PT1/2 mode was enabled.
[Mod] MOD Loader: Heuristically enable PT1/2 mode if 8xx commands seem likely to be used as sync markers rather than panning
[Mod] MOD Loader: Treat EXO8 modules to have paired patterns like FLT8 modules (I don't have any such files to test, and it probably doesn't even matter since they should contain synthesized samples which we don't support)
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Load_mod.cpp
trunk/OpenMPT/soundlib/Snd_fx.cpp
Modified: trunk/OpenMPT/soundlib/Load_mod.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_mod.cpp 2015-05-29 23:10:31 UTC (rev 5208)
+++ trunk/OpenMPT/soundlib/Load_mod.cpp 2015-05-29 23:41:20 UTC (rev 5209)
@@ -543,7 +543,7 @@
LimitMax(m_nChannels, MAX_BASECHANNELS);
// Startrekker 8 channel mod (needs special treatment, see below)
- const bool isFLT8 = IsMagic(magic, "FLT8");
+ const bool isFLT8 = IsMagic(magic, "FLT8") || IsMagic(magic, "EXO8");
// Only apply VBlank tests to M.K. (ProTracker) modules.
const bool isMdKd = IsMagic(magic, "M.K.");
@@ -626,7 +626,7 @@
m_nMaxPeriod = 3424 * 4;
// Prevent clipping based on number of channels... If all channels are playing at full volume, "256 / #channels"
// is the maximum possible sample pre-amp without getting distortion (Compatible mix levels given).
- // The more channels we have, the less likely it is that all of them are used at the same time, though, so clip at 32...
+ // The more channels we have, the less likely it is that all of them are used at the same time, though, so cap at 32...
m_nSamplePreAmp = std::max(32, 256 / m_nChannels);
m_SongFlags.reset();
@@ -635,6 +635,7 @@
const CHANNELINDEX readChannels = (isFLT8 ? 4 : m_nChannels); // 4 channels per pattern in FLT8 format.
if(isFLT8) numPatterns++; // as one logical pattern consists of two real patterns in FLT8 format, the highest pattern number has to be increased by one.
+ uint8 maxPanning = 0; // For detecting 8xx-as-sync
bool hasTempoCommands = false; // for detecting VBlank MODs
bool leftPanning = false, extendedPanning = false; // for detecting 800-880 panning
bool onlyAmigaNotes = true;
@@ -689,15 +690,19 @@
// Perform some checks for our heuristics...
if(m.command == CMD_TEMPO && m.param < 100)
hasTempoCommands = true;
- if(m.command == CMD_PANNING8 && m.param < 0x80)
- leftPanning = true;
- if(m.command == CMD_PANNING8 && m.param > 0x8F && m.param != 0xA4)
- extendedPanning = true;
+ else if(m.command == CMD_PANNING8)
+ {
+ maxPanning = std::max(maxPanning, m.param);
+ if(m.param < 0x80)
+ leftPanning = true;
+ else if(m.param > 0x8F && m.param != 0xA4)
+ extendedPanning = true;
+ }
if(m.note == NOTE_NONE && m.instr > 0 && !isFLT8)
{
if(lastInstrument[chn] > 0 && lastInstrument[chn] != m.instr)
{
- // Arbitrary threshold for going into PT1x mode: 4 consecutive "sample swaps" in one pattern.
+ // Arbitrary threshold for going into PT1/2 mode: 4 consecutive "sample swaps" in one pattern.
if(++instrWithoutNoteCount[chn] >= 4)
{
m_SongFlags.set(SONG_PT1XMODE);
@@ -724,6 +729,11 @@
{
// M.K. files that don't exceed the Amiga note limit (fixes mod.mothergoose)
m_SongFlags.set(SONG_AMIGALIMITS);
+ // Arbitrary threshold for deciding that 8xx effects are only used as sync markers
+ if(maxPanning < 0x20)
+ {
+ m_SongFlags.set(SONG_PT1XMODE);
+ }
}
// Reading samples
@@ -758,7 +768,7 @@
m_SongFlags.set(SONG_VBLANK_TIMING);
if(GetLength(eNoAdjust, GetLengthTarget(songTime)).front().targetReached)
{
- // This just makes things worse, song is at least as long asi n CIA mode (e.g. in "Stary Hallway" by Neurodancer)
+ // This just makes things worse, song is at least as long as in CIA mode (e.g. in "Stary Hallway" by Neurodancer)
// Obviously we should keep using CIA timing then...
m_SongFlags.reset(SONG_VBLANK_TIMING);
} else
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-29 23:10:31 UTC (rev 5208)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-29 23:41:20 UTC (rev 5209)
@@ -2485,21 +2485,7 @@
} else
if (volcmd == VOLCMD_PANNING)
{
- // IT Compatibility (and other trackers as well): panning disables surround (unless panning in rear channels is enabled, which is not supported by the original trackers anyway)
- if(IsCompatibleMode(TRK_ALLTRACKERS) && !m_SongFlags[SONG_SURROUNDPAN])
- {
- pChn->dwFlags.reset(CHN_SURROUND);
- }
- if(vol > 64) vol = 64;
- pChn->nPan = vol * 4;
- pChn->dwFlags.set(CHN_FASTVOLRAMP);
- pChn->nRestorePanOnNewNote = 0;
- //IT compatibility 20. Set pan overrides random pan
- if(IsCompatibleMode(TRK_IMPULSETRACKER))
- {
- pChn->nPanSwing = 0;
- pChn->nPanbrelloOffset = 0;
- }
+ Panning(pChn, vol, Pan6bit);
}
#ifdef MODPLUG_TRACKER
@@ -2874,12 +2860,10 @@
// Set 8-bit Panning
case CMD_PANNING8:
- if(!m_SongFlags[SONG_FIRSTTICK]
- || m_SongFlags[SONG_PT1XMODE]) // No panning in ProTracker mode
+ if(m_SongFlags[SONG_FIRSTTICK])
{
- break;
+ Panning(pChn, param, Pan8bit);
}
- Panning(pChn, param, Pan8bit);
break;
// Panning Slide
@@ -3683,8 +3667,14 @@
void CSoundFile::Panning(ModChannel *pChn, uint32 param, PanningType panBits) const
//---------------------------------------------------------------------------------
{
- if (!m_SongFlags[SONG_SURROUNDPAN] && (panBits == 8 || IsCompatibleMode(TRK_ALLTRACKERS)))
+ // No panning in ProTracker mode
+ if(m_SongFlags[SONG_PT1XMODE])
{
+ return;
+ }
+ // IT Compatibility (and other trackers as well): panning disables surround (unless panning in rear channels is enabled, which is not supported by the original trackers anyway)
+ if (!m_SongFlags[SONG_SURROUNDPAN] && (panBits == Pan8bit || IsCompatibleMode(TRK_ALLTRACKERS)))
+ {
pChn->dwFlags.reset(CHN_SURROUND);
}
if(panBits == Pan4bit)
@@ -4011,7 +4001,7 @@
case 0x70: pChn->nTremoloType = param & 0x07; break;
// E8x: Set 4-bit Panning
case 0x80:
- if(m_SongFlags[SONG_FIRSTTICK] && !m_SongFlags[SONG_PT1XMODE])
+ if(m_SongFlags[SONG_FIRSTTICK])
{
Panning(pChn, param, Pan4bit);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <man...@us...> - 2015-06-11 19:58:57
|
Revision: 5291
http://sourceforge.net/p/modplug/code/5291
Author: manxorist
Date: 2015-06-11 19:58:50 +0000 (Thu, 11 Jun 2015)
Log Message:
-----------
[Fix] No new-line at end of file is malformed source code in C++98. Any conforming C++98 compiler will loudly and rightfully warn. Quote ?\194?\1672.1.1.2: "If a source file that is not empty does not end in a new-line character, or ends in a new-line character immediately preceded by a backslash character before any such splicing takes place, the behavior is undefined."
Modified Paths:
--------------
trunk/OpenMPT/soundlib/tuning.cpp
trunk/OpenMPT/soundlib/tuning.h
trunk/OpenMPT/soundlib/tuningbase.cpp
trunk/OpenMPT/soundlib/tuningbase.h
Modified: trunk/OpenMPT/soundlib/tuning.cpp
===================================================================
--- trunk/OpenMPT/soundlib/tuning.cpp 2015-06-11 19:18:07 UTC (rev 5290)
+++ trunk/OpenMPT/soundlib/tuning.cpp 2015-06-11 19:58:50 UTC (rev 5291)
@@ -595,4 +595,4 @@
} // namespace CTuningS11n.
-OPENMPT_NAMESPACE_END
\ No newline at end of file
+OPENMPT_NAMESPACE_END
Modified: trunk/OpenMPT/soundlib/tuning.h
===================================================================
--- trunk/OpenMPT/soundlib/tuning.h 2015-06-11 19:18:07 UTC (rev 5290)
+++ trunk/OpenMPT/soundlib/tuning.h 2015-06-11 19:58:50 UTC (rev 5291)
@@ -174,4 +174,4 @@
}; //End: CTuningRTI declaration.
-OPENMPT_NAMESPACE_END
\ No newline at end of file
+OPENMPT_NAMESPACE_END
Modified: trunk/OpenMPT/soundlib/tuningbase.cpp
===================================================================
--- trunk/OpenMPT/soundlib/tuningbase.cpp 2015-06-11 19:18:07 UTC (rev 5290)
+++ trunk/OpenMPT/soundlib/tuningbase.cpp 2015-06-11 19:58:50 UTC (rev 5291)
@@ -476,4 +476,4 @@
}
-OPENMPT_NAMESPACE_END
\ No newline at end of file
+OPENMPT_NAMESPACE_END
Modified: trunk/OpenMPT/soundlib/tuningbase.h
===================================================================
--- trunk/OpenMPT/soundlib/tuningbase.h 2015-06-11 19:18:07 UTC (rev 5290)
+++ trunk/OpenMPT/soundlib/tuningbase.h 2015-06-11 19:58:50 UTC (rev 5291)
@@ -325,4 +325,4 @@
}
-OPENMPT_NAMESPACE_END
\ No newline at end of file
+OPENMPT_NAMESPACE_END
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <man...@us...> - 2015-06-19 19:08:02
|
Revision: 5347
http://sourceforge.net/p/modplug/code/5347
Author: manxorist
Date: 2015-06-19 19:07:56 +0000 (Fri, 19 Jun 2015)
Log Message:
-----------
[Fix] When loading the sample in ReadSampleAsInstrument ultimately failed, the old instrument had been destroyed and cleared already and no failure code was returned after that. Properly handle this error case and avoid clearing the old instrument unless we successfully loaded the new sample.
[Ref] Add an optional keepSample (default SAMPLEINDEX_INVALID) parameter to RemoveInstrumentSamples which is used in ReadSampleAsInstrument in order to avoid removing the just loaded sample, as the sample index returned from GetNextFreeSample may point to a sample index used by the old instrument. Deleting has to be done after loading the new sample in order to be able to bail out without destroying old data in the case when sample loading fails.
[Ref] Checking actual file magic of all known sample formats in ReadSampleAsInstrument makes it infeasable to delegate reading sample formats to any multi-format third-party library that does its own internal format detection. Do not duplicate our known sample format file magic checks in ReadSampleAsInstrument. In order to avoid trying to read actual instrument formats again as a sample (in case parsing as an instrument already had failed), add an explicit parameter to ReadSampleFromFile which tells it to skip instrument formats.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/SampleFormats.cpp
trunk/OpenMPT/soundlib/Sndfile.h
Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp
===================================================================
--- trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-06-19 18:43:50 UTC (rev 5346)
+++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2015-06-19 19:07:56 UTC (rev 5347)
@@ -76,16 +76,16 @@
#endif // NO_MP3_SAMPLES
-bool CSoundFile::ReadSampleFromFile(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize)
-//-------------------------------------------------------------------------------------------
+bool CSoundFile::ReadSampleFromFile(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize, bool includeInstrumentFormats)
+//--------------------------------------------------------------------------------------------------------------------------
{
if(!nSample || nSample >= MAX_SAMPLES) return false;
if(!ReadWAVSample(nSample, file, mayNormalize)
- && !ReadXISample(nSample, file)
- && !ReadITISample(nSample, file)
+ && !(includeInstrumentFormats && ReadXISample(nSample, file))
+ && !(includeInstrumentFormats && ReadITISample(nSample, file))
&& !ReadAIFFSample(nSample, file, mayNormalize)
&& !ReadITSSample(nSample, file)
- && !ReadPATSample(nSample, file)
+ && !(includeInstrumentFormats && ReadPATSample(nSample, file))
&& !ReadIFFSample(nSample, file)
&& !ReadS3ISample(nSample, file)
&& !ReadFLACSample(nSample, file)
@@ -131,56 +131,37 @@
bool CSoundFile::ReadSampleAsInstrument(INSTRUMENTINDEX nInstr, FileReader &file, bool mayNormalize)
//--------------------------------------------------------------------------------------------------
{
- file.Rewind();
+ // Scanning free sample
+ SAMPLEINDEX nSample = GetNextFreeSample(nInstr); // may also return samples which are only referenced by the current instrument
+ if(nSample == SAMPLEINDEX_INVALID)
+ {
+ return false;
+ }
- if(!file.CanRead(80))
+ // Loading Instrument
+ ModInstrument *pIns = new (std::nothrow) ModInstrument(nSample);
+ if(pIns == nullptr)
+ {
return false;
- char psig[80];
- file.ReadArray(psig);
- file.SkipBack(80);
- if( (!memcmp(&psig[0], "RIFF", 4) && !memcmp(&psig[8], "WAVE", 4)) // RIFF....WAVE signature
- || (!memcmp(&psig[0], "LIST", 4) && !memcmp(&psig[8], "wave", 4)) // LIST....wave
- || !memcmp(&psig[76], "SCRS", 4) // S3I signature
- || (!memcmp(&psig[0], "FORM", 4) &&
- (!memcmp(&psig[8], "AIFF", 4) // AIFF signature
- || !memcmp(&psig[8], "AIFC", 4) // AIFF-C signature
- || !memcmp(&psig[8], "8SVX", 4))) // 8SVX signature
- || !memcmp(&psig[0], "IMPS", 4) // ITS signature
-#ifndef NO_FLAC
- || !memcmp(&psig[0], "fLaC", 4) // FLAC signature
- || (!memcmp(&psig[0], "OggS", 4) && !memcmp(&psig[29], "FLAC", 4)) // FLAC in OGG signature
-#endif // NO_FLAC
-#ifndef NO_MP3_SAMPLES
- || IsMPEG(file) // MPEG signature
- || IsID3(file) // MP3 signature
-#endif // NO_MP3_SAMPLES
- )
+ }
+ if(!ReadSampleFromFile(nSample, file, mayNormalize, false))
{
- // Scanning free sample
- SAMPLEINDEX nSample = GetNextFreeSample(nInstr);
- if(nSample == SAMPLEINDEX_INVALID)
- {
- return false;
- }
-
- // Loading Instrument
+ delete pIns;
+ return false;
+ }
- ModInstrument *pIns = new (std::nothrow) ModInstrument(nSample);
- if(pIns == nullptr)
- {
- return false;
- }
-
- DestroyInstrument(nInstr, deleteAssociatedSamples);
- Instruments[nInstr] = pIns;
+ // Remove all samples which are only referenced by the old instrument, except for the one we just loaded our new sample into.
+ RemoveInstrumentSamples(nInstr, nSample);
- ReadSampleFromFile(nSample, file, mayNormalize);
+ // Replace the instrument
+ DestroyInstrument(nInstr, doNoDeleteAssociatedSamples);
+ Instruments[nInstr] = pIns;
+
#if defined(MPT_WITH_FILEIO) && defined(MPT_EXTERNAL_SAMPLES)
- SetSamplePath(nSample, file.GetFileName());
+ SetSamplePath(nSample, file.GetFileName());
#endif
- return true;
- }
- return false;
+
+ return true;
}
@@ -210,9 +191,9 @@
}
-// Removing all unused samples
-bool CSoundFile::RemoveInstrumentSamples(INSTRUMENTINDEX nInstr)
-//--------------------------------------------------------------
+// Remove all unused samples from the given nInstr and keep keepSample if provided
+bool CSoundFile::RemoveInstrumentSamples(INSTRUMENTINDEX nInstr, SAMPLEINDEX keepSample)
+//--------------------------------------------------------------------------------------
{
if(Instruments[nInstr] == nullptr)
{
@@ -226,9 +207,20 @@
for(std::set<SAMPLEINDEX>::const_iterator sample = referencedSamples.begin(); sample != referencedSamples.end(); sample++)
{
if((*sample) <= GetNumSamples())
+ {
keepSamples[*sample] = false;
+ }
}
+ // If we want to keep a specific sample, do so.
+ if(keepSample != SAMPLEINDEX_INVALID)
+ {
+ if(keepSample <= GetNumSamples())
+ {
+ keepSamples[keepSample] = true;
+ }
+ }
+
// Check if any of those samples are referenced by other instruments as well, in which case we want to keep them of course.
for(INSTRUMENTINDEX nIns = 1; nIns <= GetNumInstruments(); nIns++) if (Instruments[nIns] != nullptr && nIns != nInstr)
{
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2015-06-19 18:43:50 UTC (rev 5346)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2015-06-19 19:07:56 UTC (rev 5347)
@@ -894,12 +894,12 @@
bool DestroyInstrument(INSTRUMENTINDEX nInstr, deleteInstrumentSamples removeSamples);
bool IsSampleUsed(SAMPLEINDEX nSample) const;
bool IsInstrumentUsed(INSTRUMENTINDEX nInstr) const;
- bool RemoveInstrumentSamples(INSTRUMENTINDEX nInstr);
+ bool RemoveInstrumentSamples(INSTRUMENTINDEX nInstr, SAMPLEINDEX keepSample = SAMPLEINDEX_INVALID);
SAMPLEINDEX DetectUnusedSamples(std::vector<bool> &sampleUsed) const;
SAMPLEINDEX RemoveSelectedSamples(const std::vector<bool> &keepSamples);
// Samples file I/O
- bool ReadSampleFromFile(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize=false);
+ bool ReadSampleFromFile(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize=false, bool includeInstrumentFormats=true);
bool ReadWAVSample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize=false, FileReader *wsmpChunk = nullptr);
bool ReadPATSample(SAMPLEINDEX nSample, FileReader &file);
bool ReadS3ISample(SAMPLEINDEX nSample, FileReader &file);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|