我在使用Superpowered时间延长功能进行实时音高变换时遇到了问题。
为了我的目的,我使用了this solution。问题是我在输入缓冲区上应用了更改,这是一个短数组,并在处理缓冲区后得到了回音。
以下是相关代码 -
static bool audioProcessing(void * __unused clientdata, short int *audioInputOutput, int numberOfSamples, int __unused samplerate) {
SuperpoweredAudiopointerList *outputBuffers = new SuperpoweredAudiopointerList(8, 16);
// Create an input buffer for the time stretcher.
SuperpoweredAudiobufferlistElement inputBuffer;
inputBuffer.samplePosition = 0;
inputBuffer.startSample = 0;
inputBuffer.samplesUsed = 0;
inputBuffer.endSample = numberOfSamples; // <-- Important!
inputBuffer.buffers[0] = SuperpoweredAudiobufferPool::getBuffer(
(unsigned int) (numberOfSamples * 8 + 64));
inputBuffer.buffers[1] = inputBuffer.buffers[2] = inputBuffer.buffers[3] = NULL;
// Convert the decoded PCM samples from 16-bit integer to 32-bit floating point.
SuperpoweredShortIntToFloat(audioInputOutput, (float *)inputBuffer.buffers[0],
(unsigned int) numberOfSamples);
// Time stretching.
timeStretch->process(&inputBuffer, outputBuffers);
// Do we have some output?
if (outputBuffers->makeSlice(0, outputBuffers->sampleLength)) {
while (true) { // Iterate on every output slice.
// Get pointer to the output samples.
int _numSamples = 0;
float *timeStretchedAudio = (float *)outputBuffers->nextSliceItem(&_numSamples);
if (!timeStretchedAudio) break;
SuperpoweredFloatToShortInt(timeStretchedAudio, audioInputOutput,
(unsigned int) numberOfSamples);
};
// Clear the output buffer list.
outputBuffers->clear();
}
return true;
}
这是SuperpoweredAndroidAudioIO的音频处理功能。我在初始化函数中定义了timeStretch
。我现在陷入困境,需要一些帮助......
感谢。
答案 0 :(得分:0)
outputBuffers-&gt; makeSlice应该要求&#34; numberOfSamples&#34;而不是整个&#34; sampleLength&#34;。此外,当您将这些样本放入&#34; audioInputOutput&#34;在那次迭代中,确保&#34; audioInputOutput&#34;也是步进的,否则你将覆盖相同的区域(开头)。