From: <sag...@us...> - 2013-06-27 21:37:15
|
Revision: 2422 http://sourceforge.net/p/modplug/code/2422 Author: saga-games Date: 2013-06-27 21:37:08 +0000 (Thu, 27 Jun 2013) Log Message: ----------- [Reg] Removed hidden setting ITCompressionVerification [Mod] Added test for IT sample compression / decompression [Ref] Don't require CModDoc for PC note serialization test anymore. Modified Paths: -------------- trunk/OpenMPT/soundlib/ITCompression.cpp trunk/OpenMPT/soundlib/ITCompression.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/soundlib/ITCompression.cpp =================================================================== --- trunk/OpenMPT/soundlib/ITCompression.cpp 2013-06-27 18:03:07 UTC (rev 2421) +++ trunk/OpenMPT/soundlib/ITCompression.cpp 2013-06-27 21:37:08 UTC (rev 2422) @@ -174,53 +174,9 @@ WriteByte(byteVal); packedData[0] = uint8((packedLength - 2) & 0xFF); packedData[1] = uint8((packedLength - 2) >> 8); - - Verify(data, sampleData, offset); } -#ifdef MODPLUG_TRACKER -#include "../mptrack/Mptrack.h" // For config filename -#endif // MODPLUG_TRACKER - -// Check integrity of compressed data -void ITCompression::Verify(const void *data, void *sampleData, SmpLength offset) -//------------------------------------------------------------------------------ -{ -#ifdef MODPLUG_TRACKER - if(::GetPrivateProfileInt("Misc", "ITCompressionVerification", 0, theApp.GetConfigFileName()) != 0) - { - int8 *newSampleData = new (std::nothrow) int8[baseLength * mptSample.GetElementarySampleSize()]; - // Load original sample data for this block again - if(mptSample.GetElementarySampleSize() > 1) - { - CopySample<int16>(sampleData, data, offset, baseLength, mptSample.GetNumChannels()); - } else - { - CopySample<int8>(sampleData, data, offset, baseLength, mptSample.GetNumChannels()); - } - - FileReader data(&packedData[0], packedLength); - ModSample sample = mptSample; - sample.uFlags.reset(CHN_STEREO); - sample.pSample = newSampleData; - sample.nLength = baseLength; - ITDecompression(data, sample, is215); - - if(memcmp(sampleData, newSampleData, baseLength * mptSample.GetElementarySampleSize())) - { - Reporting::Error("CRITICAL ERROR! Sample compression failed for some sample!\nDisable IT compression NOW, find out which sample got broken and send the original sample to the OpenMPT devs!"); - } - delete[] newSampleData; - } -#else // !MODPLUG_TRACKER - UNREFERENCED_PARAMETER(data); - UNREFERENCED_PARAMETER(sampleData); - UNREFERENCED_PARAMETER(offset); -#endif // MODPLUG_TRACKER -} - - int ITCompression::GetWidthChangeSize(int w, bool is16) //----------------------------------------------------- { Modified: trunk/OpenMPT/soundlib/ITCompression.h =================================================================== --- trunk/OpenMPT/soundlib/ITCompression.h 2013-06-27 18:03:07 UTC (rev 2421) +++ trunk/OpenMPT/soundlib/ITCompression.h 2013-06-27 21:37:08 UTC (rev 2422) @@ -52,7 +52,6 @@ template<typename Properties> void Compress(const void *data, SmpLength offset, SmpLength actualLength); - void Verify(const void *data, void *sampleData, SmpLength offset); static int GetWidthChangeSize(int w, bool is16); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-06-27 18:03:07 UTC (rev 2421) +++ trunk/OpenMPT/test/test.cpp 2013-06-27 21:37:08 UTC (rev 2422) @@ -24,6 +24,7 @@ #include "../soundlib/MIDIEvents.h" #include "../soundlib/MIDIMacros.h" #include "../soundlib/SampleFormatConverters.h" +#include "../soundlib/ITCompression.h" #ifdef MODPLUG_TRACKER #include "../mptrack/mptrack.h" #include "../mptrack/moddoc.h" @@ -303,6 +304,7 @@ void TestMIDIEvents(); void TestStringIO(); void TestSampleConversion(); +void TestITCompression(); @@ -316,6 +318,7 @@ DO_TEST(TestStringIO); DO_TEST(TestMIDIEvents); DO_TEST(TestSampleConversion); + DO_TEST(TestITCompression); // slower tests, require opening a CModDoc DO_TEST(TestPCnoteSerialization); @@ -1385,9 +1388,71 @@ DestroySoundFileContainer(sndFileContainer); } +} + +void RunITCompressionTest(const std::vector<int8> &sampleData, ChannelFlags smpFormat, bool it215) +//------------------------------------------------------------------------------------------------ +{ + std::string filename = GetTestFilenameBase() + "raw"; + + ModSample smp; + smp.uFlags = smpFormat; + smp.pSample = const_cast<int8 *>(&sampleData[0]); + smp.nLength = sampleData.size() / smp.GetBytesPerSample(); + + { + FILE *f = fopen(filename.c_str(), "wb"); + ITCompression compression(smp, it215, f); + fclose(f); + } + + { + FILE *f = fopen(filename.c_str(), "rb"); + fseek(f, 0, SEEK_END); + std::vector<int8> fileData(ftell(f), 0); + fseek(f, 0, SEEK_SET); + fread(&fileData[0], 1, fileData.size(), f); + FileReader file(&fileData[0], fileData.size()); + + std::vector<int8> sampleDataNew(sampleData.size(), 0); + smp.pSample = &sampleDataNew[0]; + + ITDecompression decompression(file, smp, it215); + for(size_t i = 0; i < sampleData.size(); i++) + { + VERIFY_EQUAL(sampleData[i], sampleDataNew[i]); + } + fclose(f); + } + remove(filename.c_str()); } + +void TestITCompression() +//---------------------- +{ + return; + // Test loading / saving of IT-compressed samples + const int sampleDataSize = 65536; + std::vector<int8> sampleData(sampleDataSize, 0); + std::srand(0); + for(int i = 0; i < sampleDataSize; i++) + { + sampleData[i] = (int8)std::rand(); + } + + // Run each compression test with IT215 compression and without. + for(int i = 0; i < 2; i++) + { + RunITCompressionTest(sampleData, ChannelFlags(0), i == 0); + RunITCompressionTest(sampleData, CHN_16BIT, i == 0); + RunITCompressionTest(sampleData, CHN_STEREO, i == 0); + RunITCompressionTest(sampleData, CHN_16BIT | CHN_STEREO, i == 0); + } +} + + double Rand01() {return rand() / double(RAND_MAX);} template <class T> @@ -1424,30 +1489,13 @@ void TestPCnoteSerialization() //---------------------------- { -#ifdef MODPLUG_TRACKER - theApp.OnFileNewMPT(); - CMainFrame* pMainFrm = CMainFrame::GetMainFrame(); - if(pMainFrm == nullptr) - throw(std::runtime_error("pMainFrm is nullptr")); - CModDoc* pModDoc = pMainFrm->GetActiveDoc(); - if(pModDoc == nullptr) - throw(std::runtime_error("pModdoc is nullptr")); - - CSoundFile &sndFile = pModDoc->GetrSoundFile(); -#else FileReader file; - std::shared_ptr<CSoundFile> pSndFile(new CSoundFile()); + MPT_SHARED_PTR<CSoundFile> pSndFile(new CSoundFile()); CSoundFile &sndFile = *pSndFile.get(); -#endif + sndFile.ChangeModTypeTo(MOD_TYPE_MPT); + sndFile.Patterns.DestroyPatterns(); + sndFile.m_nChannels = ModSpecs::mptm.channelsMax; -#ifdef MODPLUG_TRACKER - // Set maximum number of channels. - pModDoc->ReArrangeChannels(std::vector<CHANNELINDEX>(ModSpecs::mptm.channelsMax , 0)); -#else - // todo: set number of channels -#endif - - sndFile.Patterns.Remove(0); sndFile.Patterns.Insert(0, ModSpecs::mptm.patternRowsMin); sndFile.Patterns.Insert(1, 64); GenerateCommands(sndFile.Patterns[1], 0.3, 0.3); @@ -1501,11 +1549,6 @@ } VERIFY_EQUAL( bPatternDataMatch, true); } - -#ifdef MODPLUG_TRACKER - pModDoc->OnCloseDocument(); -#endif - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |