我有一个函数audioReceived(float * input, int bufferSize, int nChannels)
,我想在其中调用一个需要const float *const *inputBuffers
的库函数。
显然,强制转换const float *const *inputBuffers = (const float* const*)input;
虽然可以编译通过,但是这样做是个坏主意,会导致程序崩溃、杀死小猫等问题。没有人需要修改原始的float* input
,它是正在处理的音频数据。
我该如何正确地实现呢?
编辑:这里有更多的代码。 audioReceived
是:
void testApp::audioReceived (float * input, int bufferSize, int nChannels){
Vamp::RealTime rt = Vamp::RealTime::fromMilliseconds(ofGetSystemTime());
float const *const tmp[] = { input, 0 };
Vamp::Plugin::FeatureSet fs = myPlugin->process(tmp, rt);
}
库函数process
在基类中被定义:
/**
* Process a single block of input data.
*
* If the plugin's inputDomain is TimeDomain, inputBuffers will
* point to one array of floats per input channel, and each of
* these arrays will contain blockSize consecutive audio samples
* (the host will zero-pad as necessary). The timestamp in this
* case will be the real time in seconds of the start of the
* supplied block of samples.
*
* If the plugin's inputDomain is FrequencyDomain, inputBuffers
* will point to one array of floats per input channel, and each
* of these arrays will contain blockSize/2+1 consecutive pairs of
* real and imaginary component floats corresponding to bins
* 0..(blockSize/2) of the FFT output. That is, bin 0 (the first
* pair of floats) contains the DC output, up to bin blockSize/2
* which contains the Nyquist-frequency output. There will
* therefore be blockSize+2 floats per channel in total. The
* timestamp will be the real time in seconds of the centre of the
* FFT input window (i.e. the very first block passed to process
* might contain the FFT of half a block of zero samples and the
* first half-block of the actual data, with a timestamp of zero).
*
* Return any features that have become available after this
* process call. (These do not necessarily have to fall within
* the process block, except for OneSamplePerStep outputs.)
*/
virtual FeatureSet process(const float *const *inputBuffers,
RealTime timestamp) = 0;
在实际的标题中:
FeatureSet process(const float *const *inputBuffers, Vamp::RealTime timestamp);
我认为
EXC_BAD_ACCESS
可能来自于库函数需要一个零填充数组,而我没有提供(a)这听起来合理吗?(b)如果是这样,是时候在SO上问一个不同的问题了吗?感谢大家迄今为止的帮助,它非常启发性/澄清/教育/有趣。
c++
的标签呢?它不是纯粹的 C 问题吗? - sbiconst
时,我也会问“啥?”--但这是特征提取库所需的,我试图首先按照它的要求开始,然后再尝试重写库。 (这可能只会导致更多的混乱;我的工作假设是编写该代码的人比我知道得多--尽管可能不比你们中的一些人知道得多。) - buildsucceededfloat * input
)解释为包含该数组的数组(float const *const tmp[] = { &input
, 0 }`,如下所示)。从概念上讲是有意义的,但是后者会导致编译错误。 - buildsucceeded