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


C++ AudioStream::Frames方法代码示例

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


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

示例1: ScanSong

std::string ScanSong(std::string fileName, bool doReplayGain)
{
	BassSource bassSource;
	AvSource avSource;
	bool bassLoaded = bassSource.Load(fileName, true);
	bool avLoaded = bassLoaded ? false : avSource.Load(fileName);

	uint32_t channels = 0;
	std::string type;
	double length = 0;
	uint32_t samplerate = 0;
	uint32_t bitrate = 0;
	Machine* decoder = 0;

	if (bassLoaded)
	{
		channels = bassSource.Channels();
		type = bassSource.CodecType();
		length = bassSource.Duration();
		samplerate = bassSource.Samplerate();
		bitrate = bassSource.Bitrate();
		decoder = static_cast<Machine*>(&bassSource);
	}

	if (avLoaded)
	{
		channels = avSource.Channels();
		type = avSource.CodecType();
		samplerate = avSource.Samplerate();
		bitrate = avSource.Bitrate();
		decoder = static_cast<Machine*>(&avSource);
	}

	if (!avLoaded && !bassLoaded)
		logror::Fatal("unknown format");
	if (samplerate == 0)
		logror::Fatal("samplerate is zero");
	if (channels < 1 || channels > 2)
		logror::Fatal("unsupported number of channels");

	uint64_t frameCounter = 0;
	RG_SampleFormat format = {samplerate, RG_FLOAT_32_BIT, channels, FALSE};
	RG_Context* context = RG_NewContext(&format);
	AudioStream stream;

	if (doReplayGain || avLoaded)
		while (!stream.endOfStream)
		{
			decoder->Process(stream, 48000);
			float* buffers[2] = {stream.Buffer(0), channels == 2 ? stream.Buffer(1) : NULL};
			if (doReplayGain)
				RG_Analyze(context, buffers, stream.Frames());
			frameCounter += stream.Frames();
		}

	double replayGain = RG_GetTitleGain(context);
	RG_FreeContext(context);
		
	if (avLoaded)
		length = static_cast<double>(frameCounter) / samplerate;
	std::string msg = "type:%1%\nlength:%2%\n";
	if (doReplayGain)
		msg.append("replay gain:%3%\n");
	if (bassSource.IsModule())
		msg.append("loopiness:%6%");
	else
		msg.append("bitrate:%4%\nsamplerate:%5%");

	boost::format formater(msg);
	formater.exceptions(boost::io::no_error_bits);
	return str(formater % type % length % replayGain % bitrate
		% samplerate % bassSource.Loopiness());
}
开发者ID:GitLaboratory,项目名称:demovibes,代码行数:73,代码来源:scan.cpp


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