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


C++ AudioChunk::channels方法代码示例

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


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

示例1: pull

void Oscillator::pull(AudioChunk &chunk, const State &a, const State &b)
{
	//Phase goes from -1 to 1.  Wierd?  Maybe.
	while (phase >= 1.0f) phase -= 2.0f;
	while (phase < -1.0f) phase += 2.0f;

	Sint32 samp;
	float v, x, sq;

	float step = (b.freq / output.rate) * 2.0f,
		amp = b.amp * 16777215.0f,
		ph = phase;

	Sint32 *i = chunk.start(0), *e = chunk.end(0);
	switch (type)
	{
	case SINE:
		while (i != e)
		{
			//Simple sine wave
			samp = amp*sin(PI * ph);
			ph += step;
			*i = samp; ++i;
			ph -= 2.0f*int(ph*.5f); //Restrict to [-1, 1]
		}
		break;

	case SQUARE:
		while (i != e)
		{
			samp = amp * ((ph>=0.0f) ? 1.0f : -1.0f);
			ph += step;
			*i = samp; ++i;
			ph -= 2.0f*int(ph*.5f); //Restrict to [-1, 1]
		}
		break;

	case TRIANGLE:
		while (i != e)
		{
			samp = amp * (2.0f*std::abs(ph) - 1.0f);
			ph += step;
			*i = samp; ++i;
			ph -= 2.0f*int(ph*.5f); //Restrict to [-1, 1]
		}
		break;

	case SAWTOOTH:
		while (i != e)
		{
			samp = amp * ph;
			ph += step;
			*i = samp; ++i;
			ph -= 2.0f*int(ph*.5f); //Restrict to [-1, 1]
		}
		break;

	case KLAXON:
	default:
	{
		const float PISQ = PI*PI;
		while (i != e)
		{
			//Sine wave approximation gone wrong
			sq = PISQ*ph*ph; x = PI*ph*amp;
			v = x * 1.02394347; //Makes the endpoints line up
			x *= sq; v -= x/6.0f;
			x *= sq; v += x/120.0f;
			x *= sq; v -= x/5040.0f;
			samp = x;
			ph += step;
			*i = samp; ++i;

			ph -= 2.0f*int(ph*.5f); //Restrict to [-1, 1]
		}
	}
		break;
	}

	phase = ph;

	//Copy signal into all other channels
	for (Uint32 c = chunk.channels()-1; c > 0; --c)
	{
		std::memcpy(chunk.start(c), chunk.start(0), 4*chunk.length());
	}
}
开发者ID:bradparks,项目名称:Plum,代码行数:87,代码来源:oscillator.cpp


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