本文整理汇总了C++中AudioBuffer::getSampleRate方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioBuffer::getSampleRate方法的具体用法?C++ AudioBuffer::getSampleRate怎么用?C++ AudioBuffer::getSampleRate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioBuffer
的用法示例。
在下文中一共展示了AudioBuffer::getSampleRate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resample
void Resampler::resample(const AudioBuffer &dataIn, AudioBuffer &dataOut)
{
const double inputFreq = dataIn.getSampleRate();
const double outputFreq = dataOut.getSampleRate();
const double sampleFactor = outputFreq / inputFreq;
if (sampleFactor == 1.0)
return;
const size_t nbFrames = dataIn.frames();
const size_t nbChans = dataIn.channels();
if (nbChans != format_.nb_channels) {
// change channel num if needed
int err;
src_delete(src_state_);
src_state_ = src_new(SRC_LINEAR, nbChans, &err);
format_.nb_channels = nbChans;
DEBUG("SRC channel number changed.");
}
if (nbChans != dataOut.channels()) {
DEBUG("Output buffer had the wrong number of channels (in: %d, out: %d).", nbChans, dataOut.channels());
dataOut.setChannelNum(nbChans);
}
size_t inSamples = nbChans * nbFrames;
size_t outSamples = inSamples * sampleFactor;
// grow buffer if needed
floatBufferIn_.resize(inSamples);
floatBufferOut_.resize(outSamples);
scratchBuffer_.resize(outSamples);
SRC_DATA src_data;
src_data.data_in = floatBufferIn_.data();
src_data.data_out = floatBufferOut_.data();
src_data.input_frames = nbFrames;
src_data.output_frames = nbFrames * sampleFactor;
src_data.src_ratio = sampleFactor;
src_data.end_of_input = 0; // More data will come
dataIn.interleaveFloat(floatBufferIn_.data());
src_process(src_state_, &src_data);
/*
TODO: one-shot deinterleave and float-to-short conversion
*/
src_float_to_short_array(floatBufferOut_.data(), scratchBuffer_.data(), outSamples);
dataOut.deinterleave(scratchBuffer_.data(), src_data.output_frames, nbChans);
}