From: <sag...@us...> - 2013-02-19 02:26:16
|
Revision: 1538 http://sourceforge.net/p/modplug/code/1538 Author: saga-games Date: 2013-02-19 02:25:59 +0000 (Tue, 19 Feb 2013) Log Message: ----------- [Ref] Small changes. Modified Paths: -------------- trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/FileReader.h trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/SampleFormatConverters.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/WAVTools.h Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/common/typedefs.h 2013-02-19 02:25:59 UTC (rev 1538) @@ -56,3 +56,9 @@ const uint64 uint64_max = 18446744073709551615; typedef float float32; + +union FloatInt32 +{ + float32 f; + uint32 i; +}; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-19 02:25:59 UTC (rev 1538) @@ -1720,8 +1720,7 @@ if(f.Open(files.first_file.c_str())) { size_t len = f.GetLength(); - const char *data = reinterpret_cast<const char *>(f.Lock(len)); - FileReader file(data, len); + FileReader file(f.Lock(len), len); errorStr = VSTPresets::GetErrorMessage(VSTPresets::LoadFile(file, *this)); f.Close(); Modified: trunk/OpenMPT/soundlib/FileReader.h =================================================================== --- trunk/OpenMPT/soundlib/FileReader.h 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/FileReader.h 2013-02-19 02:25:59 UTC (rev 1538) @@ -34,7 +34,7 @@ // Initialize invalid file reader object. FileReader() : streamData(nullptr), streamLength(0), streamPos(0) { } // Initialize file reader object with pointer to data and data length. - FileReader(const char *data, off_t length) : streamData(data), streamLength(length), streamPos(0) { } + FileReader(const void *data, off_t length) : streamData(static_cast<const char *>(data)), streamLength(length), streamPos(0) { } // Initialize file reader object based on an existing file reader object. The other object's stream position is copied. FileReader(const FileReader &other) : streamData(other.streamData), streamLength(other.streamLength), streamPos(other.streamPos) { } @@ -285,12 +285,11 @@ // If successful, the file cursor is advanced by the size of the float. float ReadFloatLE() { - float target; + FloatInt32 target; if(Read(target)) { - uint32 temp = *reinterpret_cast<uint32 *>(&target); - SwapBytesLE(temp); - return *reinterpret_cast<float *>(&temp); + SwapBytesLE(target.i); + return target.f; } else { return 0.0f; @@ -301,12 +300,11 @@ // If successful, the file cursor is advanced by the size of the float. float ReadFloatBE() { - float target; + FloatInt32 target; if(Read(target)) { - uint32 temp = *reinterpret_cast<uint32 *>(&target); - SwapBytesBE(temp); - return *reinterpret_cast<float *>(&temp); + SwapBytesBE(target.i); + return target.f; } else { return 0.0f; @@ -394,7 +392,7 @@ // Read destSize elements of type T into a vector. // If successful, the file cursor is advanced by the size of the vector. - // Otherwise, the vector is cleared. + // Otherwise, the vector is resized to destSize, but possibly existing contents are not cleared. template<typename T> bool ReadVector(std::vector<T> &destVector, size_t destSize) { Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-02-19 02:25:59 UTC (rev 1538) @@ -81,7 +81,7 @@ // If decoding was successful, stream and length will keep the new pointers now. if(length > 0) { - FileReader unpackedFile(static_cast<const char *>(stream), length); + FileReader unpackedFile(stream, length); result = ReadXM(unpackedFile) || ReadIT(unpackedFile) Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-02-19 02:25:59 UTC (rev 1538) @@ -568,9 +568,7 @@ return false; } - //BYTE s[64*64*5]; - vector<BYTE> s(64*64*5, 0); - BYTE xmph[9]; + vector<uint8> s(64 * 64 * 5, 0); bool addChannel = false; // avoid odd channel count for FT2 compatibility XMFileHeader fileHeader; @@ -631,7 +629,7 @@ fileHeader.ConvertEndianness(); fwrite(&fileHeader, 1, sizeof(fileHeader), f); - // write order list (wihout +++ and ---, explained above) + // write order list (without +++ and ---, explained above) for(ORDERINDEX ord = 0; ord < Order.GetLengthTailTrimmed(); ord++) { if(Patterns.IsValidIndex(Order[ord]) || !compatibilityExport) @@ -642,19 +640,27 @@ } // Writing patterns - for(PATTERNINDEX pat = 0; pat < nPatterns; pat++) if (Patterns[pat]) + for(PATTERNINDEX pat = 0; pat < nPatterns; pat++) { - ModCommand *p = Patterns[pat]; + uint8 patHead[9]; + MemsetZero(patHead); + patHead[0] = 9; + patHead[5] = static_cast<uint8>(Patterns[pat].GetNumRows() & 0xFF); + patHead[6] = static_cast<uint8>(Patterns[pat].GetNumRows() >> 8); + + if(!Patterns.IsValidPat(pat)) + { + // There's nothing to write... chicken out. + fwrite(patHead, 1, 9, f); + continue; + } + + const ModCommand *p = Patterns[pat]; size_t len = 0; // Empty patterns are always loaded as 64-row patterns in FT2, regardless of their real size... bool emptyPattern = true; - MemsetZero(xmph); - xmph[0] = 9; - xmph[5] = (BYTE)(Patterns[pat].GetNumRows() & 0xFF); - xmph[6] = (BYTE)(Patterns[pat].GetNumRows() >> 8); - - for (size_t j = m_nChannels * Patterns[pat].GetNumRows(); j > 0; j--, p++) + for(size_t j = m_nChannels * Patterns[pat].GetNumRows(); j > 0; j--, p++) { // Don't write more than 32 channels if(compatibilityExport && m_nChannels - ((j - 1) % m_nChannels) > 32) continue; @@ -722,7 +728,7 @@ s[len++] = param; } else { - BYTE b = 0x80; + uint8 b = 0x80; if (note) b |= 0x01; if (p->instr) b |= 0x02; if (vol >= 0x10) b |= 0x04; @@ -751,17 +757,10 @@ len = 0; } - xmph[7] = (BYTE)(len & 0xFF); - xmph[8] = (BYTE)(len >> 8); - fwrite(xmph, 1, 9, f); + patHead[7] = static_cast<uint8>(len & 0xFF); + patHead[8] = static_cast<uint8>(len >> 8); + fwrite(patHead, 1, 9, f); if(len) fwrite(&s[0], 1, len, f); - } else - { - MemsetZero(xmph); - xmph[0] = 9; - xmph[5] = (BYTE)(Patterns[pat].GetNumRows() & 0xFF); - xmph[6] = (BYTE)(Patterns[pat].GetNumRows() >> 8); - fwrite(xmph, 1, 9, f); } // Check which samples are referenced by which instruments (for assigning unreferenced samples to instruments) Modified: trunk/OpenMPT/soundlib/SampleFormatConverters.h =================================================================== --- trunk/OpenMPT/soundlib/SampleFormatConverters.h 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/SampleFormatConverters.h 2013-02-19 02:25:59 UTC (rev 1538) @@ -254,11 +254,7 @@ template <size_t loLoByteIndex, size_t loHiByteIndex, size_t hiLoByteIndex, size_t hiHiByteIndex> struct ReadFloat32to16PCMandNormalize : SampleConversionFunctor<float, int16, conversionHasNoState> { - union - { - float f; - uint32 i; - } maxVal; + FloatInt32 maxVal; ReadFloat32to16PCMandNormalize() { maxVal.i = 0; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-02-19 02:25:59 UTC (rev 1538) @@ -541,7 +541,7 @@ } if (lpStream) { - FileReader file(reinterpret_cast<const char*>(lpStream), dwMemLength); + FileReader file(lpStream, dwMemLength); const std::vector<const char *> modExtensions = GetSupportedExtensions(true); @@ -562,7 +562,7 @@ { lpStream = unrar.GetOutputFile(); dwMemLength = unrar.GetOutputFileLength(); - file = FileReader((char *)lpStream, dwMemLength); + file = FileReader(lpStream, dwMemLength); } } #endif @@ -574,7 +574,7 @@ { lpStream = unlha.GetOutputFile(); dwMemLength = unlha.GetOutputFileLength(); - file = FileReader((char *)lpStream, dwMemLength); + file = FileReader(lpStream, dwMemLength); } } #endif @@ -592,7 +592,7 @@ BOOL bMMCmp = MMCMP_Unpack(&lpStream, &dwMemLength); if(bMMCmp) { - file = FileReader(reinterpret_cast<const char*>(lpStream), dwMemLength); + file = FileReader(lpStream, dwMemLength); } #endif Modified: trunk/OpenMPT/soundlib/WAVTools.h =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.h 2013-02-17 21:51:24 UTC (rev 1537) +++ trunk/OpenMPT/soundlib/WAVTools.h 2013-02-19 02:25:59 UTC (rev 1538) @@ -98,6 +98,7 @@ fmtPCM = 1, fmtFloat = 3, fmtIMA_ADPCM = 17, + fmtMP3 = 85, fmtExtensible = 0xFFFE, }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |