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


C++ AudioBuffer::resize_frames方法代码示例

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


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

示例1: convert_rate

void AudioBuffer::convert_rate(AudioBuffer &_dest, unsigned _frames_count, SRC_STATE *_SRC)
{
	AudioSpec destspec{AUDIO_FORMAT_F32, m_spec.channels, _dest.rate()};
	if(m_spec.format != AUDIO_FORMAT_F32 || _dest.spec() != destspec) {
		throw std::logic_error("unsupported format");
	}
	_frames_count = std::min(frames(),_frames_count);
	double rate_ratio = double(destspec.rate)/double(m_spec.rate);
	unsigned out_frames = unsigned(ceil(double(_frames_count) * rate_ratio));
	if(out_frames==0) {
		return;
	}

	unsigned destpos = _dest.samples();
	unsigned destframes = _dest.frames();

	_dest.resize_frames(_dest.frames()+out_frames);

#if HAVE_LIBSAMPLERATE
	SRC_DATA srcdata;
	srcdata.data_in = &at<float>(0);
	srcdata.data_out = &_dest.at<float>(destpos);
	srcdata.input_frames = _frames_count;
	srcdata.output_frames = out_frames;
	srcdata.src_ratio = rate_ratio;
	int srcresult;
	if(_SRC != nullptr) {
		srcdata.end_of_input = 0;
		srcresult = src_process(_SRC, &srcdata);
	} else {
		srcdata.end_of_input = 1;
		srcresult = src_simple(&srcdata, SRC_SINC_BEST_QUALITY, destspec.channels) ;
	}
	if(srcresult != 0) {
		throw std::runtime_error(std::string("error resampling: ") + src_strerror(srcresult));
	}
	assert(srcdata.output_frames_gen>=0 && srcdata.output_frames_gen<=out_frames);
	if(srcdata.output_frames_gen != out_frames) {
		_dest.resize_frames(destframes + srcdata.output_frames_gen);
	}
	PDEBUGF(LOG_V2, LOG_MIXER, "convert rate: f-in: %d, f-out: %d, gen: %d\n",
			_frames_count, out_frames, srcdata.output_frames_gen);
#else
	for(unsigned i=destpos; i<_dest.samples(); ++i) {
		_dest.operator[]<float>(i) = 0.f;
	}
#endif
}
开发者ID:joncampbell123,项目名称:IBMulator,代码行数:48,代码来源:audiobuffer.cpp

示例2: convert_channels

void AudioBuffer::convert_channels(const AudioBuffer &_source, AudioBuffer &_dest,
		unsigned _frames_count)
{
	unsigned d = _dest.samples();
	_dest.resize_frames(_dest.frames()+_frames_count);
	if(_source.channels()==1 && _dest.channels()==2) {
		//from mono to stereo
		for(unsigned i=0; i<_frames_count; ++i) {
			T ch1 = _source.at<T>(i);
			_dest.operator[]<T>(d+i*2)   = ch1;
			_dest.operator[]<T>(d+i*2+1) = ch1;
		}
	} else if(_source.channels()==2 && _dest.channels()==1) {
		//from stereo to mono
		for(unsigned i=0; i<_frames_count; ++i) {
			double ch1 = double(_source.at<T>(i*2));
			double ch2 = double(_source.at<T>(i*2+1));
			_dest.operator[]<T>(d+i) = T((ch1 + ch2) / 2.0);
		}
	}
}
开发者ID:joncampbell123,项目名称:IBMulator,代码行数:21,代码来源:audiobuffer.cpp


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