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


C++ SoundFile::getNumChannels方法代码示例

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


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

示例1: main

int main(int argc, char* argv[])
{
#ifdef TESTS
	cout << "===== RUNNING TESTS =====" << endl;
	RegressionTest::runAllTests(); 
	TestConvolver::runAllTests();
	cout << "==== TESTS COMPLETED ====" << endl;
	system("pause");
#endif
	
	/* Ensure that valid dry, IR, and output file names are provided */
	if (! checkArgs(argc, argv))
		return 1;

	/* Read wave files */
	SoundFile* dry = SoundFile::create(argv[1]);
	SoundFile* ir = SoundFile::create(argv[2]);

	/* End program if any input file is corrupted or nonexistant */
	if (dry == nullptr || ir == nullptr)
		return 1;

	int dryDataSize = dry->getDataSize();
	int irDataSize = ir->getDataSize();

	cout << "DR Size: " << dryDataSize << " IR Size: " << irDataSize << endl;

	int P;			// Length of result
	short* result;	// Resulting data of convolution to write to file
	
	/* Normalize the input data to -1 and +1 */
	double* dryNormalized = new double[dryDataSize];
	double* irNormalized = new double[irDataSize];
	Convolver::dataToSignal(dry->getData(), dryDataSize, dry->getAbsMinValue(), dryNormalized);
	Convolver::dataToSignal(ir->getData(), irDataSize, ir->getAbsMinValue(), irNormalized);
	
	if (ir->getNumChannels() == 1) {
		P = dryDataSize + irDataSize - 1;

		/* Perform time domain convolution */
		result = new short[P];

#ifndef FFT
		Convolver::convolve(dryNormalized, dryDataSize, irNormalized, irDataSize, result, P);
#else
		Convolver::fftConvolve(dryNormalized, dryDataSize, irNormalized, irDataSize, result, P);
#endif

		/* Save resulting .wav file */
		SoundFile::save(argv[3], ir->getNumChannels(), dry->getBitsPerSample(), dry->getSampleRate(), result, P);
	}
	else if (ir->getNumChannels() == 2) {
		/* Calculate half size of impulse response ONCE and store in halfM */
		int halfM = irDataSize >> 1;

		/* P = N+(M/2)-1, where P is the length of each half of this two-channel convolution */
		P = dryDataSize + halfM - 1;

		/* Split normalized stereo impulse response into left and right channels */
		double* irLeftNormalized = new double[halfM];
		double* irRightNormalized = new double[halfM];

		for (int i = 0, i2 = 0; i < halfM; i++) {
			i2 = i << 1;
			irLeftNormalized[i] = irNormalized[i2];
			irRightNormalized[i] = irNormalized[i2 + 1];
		}

		/* Perform time domain convolution */
		short* resultLeft = new short[P];
		short* resultRight = new short[P];

#ifndef FFT
		Convolver::convolve(dryNormalized, dryDataSize, irLeftNormalized, halfM, resultLeft, P);
		Convolver::convolve(dryNormalized, dryDataSize, irRightNormalized, halfM, resultRight, P);
#else
		Convolver::fftConvolve(dryNormalized, dryDataSize, irLeftNormalized, halfM, resultLeft, P);
		Convolver::fftConvolve(dryNormalized, dryDataSize, irRightNormalized, halfM, resultRight, P);
#endif

		/* Interleave left and right channel data */
		result = new short[P*2];
		for (int i = 0, halfI = 0; i < P*2; i+=2) {
			halfI = i >> 1;
			result[i] = resultLeft[halfI];
			result[i+1] = resultRight[halfI];
		}

		/* Save resulting .wav file */
		SoundFile::save(argv[3], ir->getNumChannels(), dry->getBitsPerSample(), dry->getSampleRate(), result, P*2);

		delete[] irLeftNormalized;
		delete[] irRightNormalized;
		delete[] resultLeft;
		delete[] resultRight;
	}
开发者ID:cngu,项目名称:convolution,代码行数:96,代码来源:Main.cpp


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