当前位置: 首页>>代码示例>>C++>>正文


C++ FileReader::CanRead方法代码示例

本文整理汇总了C++中FileReader::CanRead方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::CanRead方法的具体用法?C++ FileReader::CanRead怎么用?C++ FileReader::CanRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileReader的用法示例。


在下文中一共展示了FileReader::CanRead方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IMAADPCMUnpack16

// Note: Only works for mono samples.
bool IMAADPCMUnpack16(int16 *target, SmpLength sampleLen, FileReader file, uint16 blockAlign)
//-------------------------------------------------------------------------------------------
{
	static const int32 IMAIndexTab[8] =  { -1, -1, -1, -1, 2, 4, 6, 8 };
	static const int32 IMAUnpackTable[90] =
	{
		7,     8,     9,    10,    11,    12,    13,    14,
		16,    17,    19,    21,    23,    25,    28,    31,
		34,    37,    41,    45,    50,    55,    60,    66,
		73,    80,    88,    97,   107,   118,   130,   143,
		157,   173,   190,   209,   230,   253,   279,   307,
		337,   371,   408,   449,   494,   544,   598,   658,
		724,   796,   876,   963,  1060,  1166,  1282,  1411,
		1552,  1707,  1878,  2066,  2272,  2499,  2749,  3024,
		3327,  3660,  4026,  4428,  4871,  5358,  5894,  6484,
		7132,  7845,  8630,  9493, 10442, 11487, 12635, 13899,
		15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
		32767, 0
	};

	if((sampleLen < 4) || (!target) || (blockAlign < 5) || (blockAlign > file.GetLength()))
		return false;

	SmpLength nPos = 0;
	while((nPos < sampleLen) && file.CanRead(5))
	{
		int32 value = file.ReadIntLE<int16>();
		int32 nIndex = file.ReadIntLE<uint8>();
		nIndex = Clamp(nIndex, 0, 89);
		file.Skip(1);
		target[nPos++] = (int16)value;
		for(uint32 i = 0; (i < (blockAlign - 4u) * 2u) && (nPos < sampleLen) && file.AreBytesLeft(); i++)
		{
			uint8 delta;
			if(i & 1)
			{
				delta = (file.ReadIntLE<uint8>() >> 4) & 0x0F;
			} else
			{
				delta = file.ReadIntLE<uint8>() & 0x0F;
				file.SkipBack(1);
			}
			int32 v = IMAUnpackTable[nIndex] >> 3;
			if (delta & 1) v += IMAUnpackTable[nIndex] >> 2;
			if (delta & 2) v += IMAUnpackTable[nIndex] >> 1;
			if (delta & 4) v += IMAUnpackTable[nIndex];
			if (delta & 8) value -= v; else value += v;
			nIndex += IMAIndexTab[delta & 7];
			nIndex = Clamp(nIndex, 0, 88);
			target[nPos++] = static_cast<int16>(Clamp(value, -32768, 32767));
		}
开发者ID:fgenesis,项目名称:tyrsound,代码行数:52,代码来源:Load_wav.cpp

示例2: ReadUMXNameTable

// Read complete name table.
std::vector<std::string> ReadUMXNameTable(FileReader &file, const UMXFileHeader &fileHeader)
{
	std::vector<std::string> names;
	if(!file.Seek(fileHeader.nameOffset))
	{
		return names;
	}
	names.reserve(fileHeader.nameCount);
	for(uint32 i = 0; i < fileHeader.nameCount && file.CanRead(4); i++)
	{
		names.push_back(ReadUMXNameTableEntry(file, fileHeader.packageVersion));
	}
	return names;
}
开发者ID:kode54,项目名称:Cog,代码行数:15,代码来源:UMXTools.cpp

示例3: CopyWavChannel

bool CopyWavChannel(ModSample &sample, const FileReader &file, size_t channelIndex, size_t numChannels, SampleConversion conv = SampleConversion())
{
	MPT_ASSERT(sample.GetNumChannels() == 1);
	MPT_ASSERT(sample.GetElementarySampleSize() == sizeof(typename SampleConversion::output_t));

	const size_t offset = channelIndex * sizeof(typename SampleConversion::input_t) * SampleConversion::input_inc;

	if(sample.AllocateSample() == 0 || !file.CanRead(offset))
	{
		return false;
	}

	const mpt::byte *inBuf = file.GetRawData<mpt::byte>();
	CopySample<SampleConversion>(reinterpret_cast<typename SampleConversion::output_t*>(sample.pSample), sample.nLength, 1, inBuf + offset, file.BytesLeft() - offset, numChannels, conv);
	return true;
}
开发者ID:kode54,项目名称:Cog,代码行数:16,代码来源:Load_wav.cpp

示例4: ReadITQ

bool CSoundFile::ReadITQ(FileReader &file, ModLoadingFlags loadFlags)
//------------------------------------------------------------------
{
	file.Rewind();

	ITFileHeader fileHeader;
	if(!file.ReadConvertEndianness(fileHeader)
		|| (memcmp(fileHeader.id, "ITQM", 4))
		|| fileHeader.insnum > 0xFF
		|| fileHeader.smpnum >= MAX_SAMPLES
		|| !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4))
	{
		return false;
	} else if(loadFlags == onlyVerifyHeader)
	{
		return true;
	}

	InitializeGlobals();

	bool interpretModPlugMade = false;

	// OpenMPT crap at the end of file
	file.Seek(file.GetLength() - 4);
	size_t mptStartPos = file.ReadUint32LE();
	if(mptStartPos >= file.GetLength() || mptStartPos < 0x100)
	{
		mptStartPos = file.GetLength();
	}

	if(!memcmp(fileHeader.id, "tpm.", 4))
	{
		// Legacy MPTM files (old 1.17.02.xx releases)
		ChangeModTypeTo(MOD_TYPE_MPT);
	} else
	{
		if(mptStartPos <= file.GetLength() - 3 && fileHeader.cwtv > 0x888 && fileHeader.cwtv <= 0xFFF)
		{
			file.Seek(mptStartPos);
			ChangeModTypeTo(file.ReadMagic("228") ? MOD_TYPE_MPT : MOD_TYPE_IT);
		} else
		{
			ChangeModTypeTo(MOD_TYPE_IT);
		}

		if(GetType() == MOD_TYPE_IT)
		{
			// Which tracker was used to made this?
			if((fileHeader.cwtv & 0xF000) == 0x5000)
			{
				// OpenMPT Version number (Major.Minor)
				// This will only be interpreted as "made with ModPlug" (i.e. disable compatible playback etc) if the "reserved" field is set to "OMPT" - else, compatibility was used.
				m_dwLastSavedWithVersion = (fileHeader.cwtv & 0x0FFF) << 16;
				if(!memcmp(fileHeader.reserved, "OMPT", 4))
					interpretModPlugMade = true;
			} else if(fileHeader.cmwt == 0x888 || fileHeader.cwtv == 0x888)
			{
				// OpenMPT 1.17 and 1.18 (raped IT format)
				// Exact version number will be determined later.
				interpretModPlugMade = true;
			} else if(fileHeader.cwtv == 0x0217 && fileHeader.cmwt == 0x0200 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
			{
				if(memchr(fileHeader.chnpan, 0xFF, sizeof(fileHeader.chnpan)) != NULL)
				{
					// ModPlug Tracker 1.16 (semi-raped IT format)
					m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 16, 00, 00);
					madeWithTracker = "ModPlug tracker 1.09 - 1.16";
				} else
				{
					// OpenMPT 1.17 disguised as this in compatible mode,
					// but never writes 0xFF in the pan map for unused channels (which is an invalid value).
					m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 17, 00, 00);
					madeWithTracker = "OpenMPT 1.17 (compatibility export)";
				}
				interpretModPlugMade = true;
			} else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0202 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
			{
				// ModPlug Tracker b3.3 - 1.09, instruments 557 bytes apart
				m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 09, 00, 00);
				madeWithTracker = "ModPlug tracker b3.3 - 1.09";
				interpretModPlugMade = true;
			}
		} else // case: type == MOD_TYPE_MPT
		{
			if (fileHeader.cwtv >= verMptFileVerLoadLimit)
			{
				AddToLog(str_LoadingIncompatibleVersion);
				return false;
			}
			else if (fileHeader.cwtv > verMptFileVer)
			{
				AddToLog(str_LoadingMoreRecentVersion);
			}
		}
	}

	if(GetType() == MOD_TYPE_IT) mptStartPos = file.GetLength();

	// Read row highlights
	if((fileHeader.special & ITFileHeader::embedPatternHighlights))
//.........这里部分代码省略.........
开发者ID:MrEricSir,项目名称:Modipulate,代码行数:101,代码来源:Load_itq.cpp

示例5: void

OPENMPT_NAMESPACE_BEGIN


bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
//-------------------------------------------------------------------
{
	file.Rewind();

	// No valid MO3 file (magic bytes: "MO3")
	if(!file.CanRead(8) || !file.ReadMagic("MO3"))
	{
		return false;
	} else if(loadFlags == onlyVerifyHeader)
	{
		return true;
	}

#ifdef NO_MO3
	// As of November 2013, the format revision is 5; Versions > 31 are unlikely to exist in the next few years,
	// so we will just ignore those if there's no UNMO3 library to tell us if the file is valid or not
	// (avoid log entry with .MOD files that have a song name starting with "MO3".
	if(file.ReadUint8() > 31)
	{
		return false;
	}

	AddToLog(GetStrI18N("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."));
	return false;

#else

	bool result = false;	// Result of trying to load the module, false == fail.

	// Try to load unmo3 dynamically.
	mpt::Library unmo3 = mpt::Library(mpt::LibraryPath::App(MPT_PATHSTRING("unmo3")));

	if(!unmo3.IsValid())
	{
		// Didn't succeed.
		AddToLog(GetStrI18N("Loading MO3 file failed because unmo3.dll could not be loaded."));
	} else
	{
		// Library loaded successfully.
		#if MPT_OS_WINDOWS
			#define UNMO3_API __stdcall
		#else
			#define UNMO3_API 
		#endif
		typedef uint32 (UNMO3_API * UNMO3_GETVERSION)();
		// Decode a MO3 file (returns the same "exit codes" as UNMO3.EXE, eg. 0=success)
		// IN: data/len = MO3 data/len
		// OUT: data/len = decoded data/len (if successful)
		// flags & 1: Don't load samples
		typedef int32 (UNMO3_API * UNMO3_DECODE_OLD)(const void **data, uint32 *len);
		typedef int32 (UNMO3_API * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags);
		// Free the data returned by UNMO3_Decode
		typedef void (UNMO3_API * UNMO3_FREE)(const void *data);
		#undef UNMO3_API

		UNMO3_GETVERSION UNMO3_GetVersion = nullptr;
		UNMO3_DECODE_OLD UNMO3_Decode_Old = nullptr;
		UNMO3_DECODE UNMO3_Decode = nullptr;
		UNMO3_FREE UNMO3_Free = nullptr;
		unmo3.Bind(UNMO3_GetVersion, "UNMO3_GetVersion");
		if(UNMO3_GetVersion == nullptr)
		{
			// Old API version: No "flags" parameter.
			unmo3.Bind(UNMO3_Decode_Old, "UNMO3_Decode");
		} else
		{
			unmo3.Bind(UNMO3_Decode, "UNMO3_Decode");
		}
		unmo3.Bind(UNMO3_Free, "UNMO3_Free");
		if((UNMO3_Decode != nullptr || UNMO3_Decode_Old != nullptr) && UNMO3_Free != nullptr)
		{
			file.Rewind();
			const void *stream = file.GetRawData();
			uint32 length = mpt::saturate_cast<uint32>(file.GetLength());

			int32 unmo3result;
			if(UNMO3_Decode != nullptr)
			{
				unmo3result = UNMO3_Decode(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1);
			} else
			{
				// Old API version: No "flags" parameter.
				unmo3result = UNMO3_Decode_Old(&stream, &length);
			}

			if(unmo3result == 0)
			{
				// If decoding was successful, stream and length will keep the new pointers now.
				FileReader unpackedFile(stream, length);

				result = ReadXM(unpackedFile, loadFlags)
					|| ReadIT(unpackedFile, loadFlags)
					|| ReadS3M(unpackedFile, loadFlags)
					|| ReadMTM(unpackedFile, loadFlags)
					|| ReadMod(unpackedFile, loadFlags)
					|| ReadM15(unpackedFile, loadFlags);
//.........这里部分代码省略.........
开发者ID:fgenesis,项目名称:tyrsound,代码行数:101,代码来源:Load_mo3.cpp


注:本文中的FileReader::CanRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。