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


C++ Sound::AddSource方法代码示例

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


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

示例1: Load

bool CarSound::Load(
	const std::string & carpath,
	const std::string & carname,
	Sound & sound,
	ContentManager & content,
	std::ostream & error_output)
{
	assert(!psound);

	// check for sound specification file
	std::string path_aud = carpath + "/" + carname + ".aud";
	std::ifstream file_aud(path_aud.c_str());
	if (file_aud.good())
	{
		PTree aud;
		read_ini(file_aud, aud);
		enginesounds.reserve(aud.size());
		for (const auto & i : aud)
		{
			const PTree & audi = i.second;

			std::string filename;
			std::shared_ptr<SoundBuffer> soundptr;
			if (!audi.get("filename", filename, error_output)) return false;

			enginesounds.push_back(EngineSoundInfo());
			EngineSoundInfo & info = enginesounds.back();

			if (!audi.get("MinimumRPM", info.minrpm, error_output)) return false;
			if (!audi.get("MaximumRPM", info.maxrpm, error_output)) return false;
			if (!audi.get("NaturalRPM", info.naturalrpm, error_output)) return false;

			bool powersetting;
			if (!audi.get("power", powersetting, error_output)) return false;
			if (powersetting)
				info.power = EngineSoundInfo::POWERON;
			else if (!powersetting)
				info.power = EngineSoundInfo::POWEROFF;
			else
				info.power = EngineSoundInfo::BOTH;

			info.sound_source = sound.AddSource(soundptr, 0, true, true);
			sound.SetSourceGain(info.sound_source, 0);
		}

		// set blend start and end locations -- requires multiple passes
		std::map <EngineSoundInfo *, EngineSoundInfo *> temporary_to_actual_map;
		std::list <EngineSoundInfo> poweron_sounds, poweroff_sounds;
		for (auto & info : enginesounds)
		{
			if (info.power == EngineSoundInfo::POWERON)
			{
				poweron_sounds.push_back(info);
				temporary_to_actual_map[&poweron_sounds.back()] = &info;
			}
			else if (info.power == EngineSoundInfo::POWEROFF)
			{
				poweroff_sounds.push_back(info);
				temporary_to_actual_map[&poweroff_sounds.back()] = &info;
			}
		}

		poweron_sounds.sort();
		poweroff_sounds.sort();

		// we only support 2 overlapping sounds at once each for poweron and poweroff; this
		// algorithm fails for other cases (undefined behavior)
		std::list <EngineSoundInfo> * cursounds = &poweron_sounds;
		for (int n = 0; n < 2; n++)
		{
			if (n == 1)
				cursounds = &poweroff_sounds;

			for (auto i = (*cursounds).begin(); i != (*cursounds).end(); ++i)
			{
				// set start blend
				if (i == (*cursounds).begin())
					i->fullgainrpmstart = i->minrpm;

				// set end blend
				auto inext = i;
				inext++;
				if (inext == (*cursounds).end())
					i->fullgainrpmend = i->maxrpm;
				else
				{
					i->fullgainrpmend = inext->minrpm;
					inext->fullgainrpmstart = i->maxrpm;
				}
			}

			// now assign back to the actual infos
			for (auto & info : *cursounds)
			{
				assert(temporary_to_actual_map.find(&info) != temporary_to_actual_map.end());
				*temporary_to_actual_map[&info] = info;
			}
		}
	}
	else
//.........这里部分代码省略.........
开发者ID:CheezeCake,项目名称:vdrift,代码行数:101,代码来源:carsound.cpp


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