gpt4 book ai didi

c++ - super 强大:实时音高转换,时间拉伸(stretch)器不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:07:50 24 4
gpt4 key购买 nike

我将 Superpowered 用于各种实时 FX,它们都非常简单。然而,音高变换是另一回事,我认为事实上是因为它基于时间拉伸(stretch)算法,当然必须处理随时间变化的输出,这比应用 EQ 或混响等 FX 复杂得多。但是,我只对更改麦克风输入的音调感兴趣。

我看了the only example I could find on GitHub我稍微调整了一下以适应我的工作:

static bool audioProcessing(void *clientdata,
float **buffers,
unsigned int inputChannels,
unsigned int outputChannels,
unsigned int numberOfSamples,
unsigned int samplerate,
uint64_t hostTime) {
__unsafe_unretained Superpowered *self = (__bridge Superpowered *)clientdata;

SuperpoweredAudiobufferlistElement inputBuffer;

inputBuffer.startSample = 0;
inputBuffer.samplesUsed = 0;
inputBuffer.endSample = self->timeStretcher->numberOfInputSamplesNeeded;
inputBuffer.buffers[0] = SuperpoweredAudiobufferPool::getBuffer(self->timeStretcher->numberOfInputSamplesNeeded * 8 + 64);
inputBuffer.buffers[1] = inputBuffer.buffers[2] = inputBuffer.buffers[3] = NULL;

self->outputBuffers->clear();
self->timeStretcher->process(&inputBuffer, self->outputBuffers);
int samples = self->timeStretcher->numberOfInputSamplesNeeded;
float *timeStretchedAudio = (float *)self->outputBuffers->nextSliceItem(&samples);
if (timeStretchedAudio != 0) {
SuperpoweredDeInterleave(timeStretchedAudio, buffers[0], buffers[1], numberOfSamples);
}

//self->outputBuffers->rewindSlice();

return true;
}

我删除了大部分我认为不必要的代码。例如,有一个 while 循环似乎可以处理时间延长的情况,我只是在输入的同时输出。

一些观察:

  • 如果我不清除 outputBuffers,我的内存使用量就会飙升
  • 如果我使用 self->outputBuffers->rewindSlice(); 应用程序会变得安静,这可能意味着缓冲区正在被安静覆盖
  • 如果我不使用 self->outputBuffers->rewindSlice(); 我可以听到自己的声音回来,但是 timeStretchedAudio 总是 0 除了第一次

最佳答案

我终于让它工作了:

static bool audioProcessing(void *clientdata,
float **buffers,
unsigned int inputChannels,
unsigned int outputChannels,
unsigned int numberOfSamples,
unsigned int samplerate,
uint64_t hostTime) {
__unsafe_unretained Superpowered *self = (__bridge Superpowered *)clientdata;

//timeStretching->setRateAndPitchShift(realTimeRate, realTimePitch);
SuperpoweredAudiobufferlistElement inputBuffer;
inputBuffer.startSample = 0;
inputBuffer.samplesUsed = 0;
inputBuffer.endSample = numberOfSamples;
inputBuffer.buffers[0] = SuperpoweredAudiobufferPool::getBuffer((unsigned int) (numberOfSamples * 8 + 64));
inputBuffer.buffers[1] = inputBuffer.buffers[2] = inputBuffer.buffers[3] = NULL;

// Converting the 16-bit integer samples to 32-bit floating point.
SuperpoweredInterleave(buffers[0], buffers[1], (float *)inputBuffer.buffers[0], numberOfSamples);
//SuperpoweredShortIntToFloat(audioInputOutput, (float *)inputBuffer.buffers[0], (unsigned int) numberOfSamples);

self->timeStretcher->process(&inputBuffer, self->outputBuffers);

// Do we have some output?
if (self->outputBuffers->makeSlice(0, self->outputBuffers->sampleLength)) {
while (true) { // Iterate on every output slice.
// Get pointer to the output samples.
int numSamples = 0;
float *timeStretchedAudio = (float *)self->outputBuffers->nextSliceItem(&numSamples);
if (!timeStretchedAudio || *timeStretchedAudio == 0) {
break;
}

// Convert the time stretched PCM samples from 32-bit floating point to 16-bit integer.
//SuperpoweredFloatToShortInt(timeStretchedAudio, audioInputOutput,
// (unsigned int) numSamples);
SuperpoweredDeInterleave(timeStretchedAudio, buffers[0], buffers[1], numSamples);
self->recorder->process(timeStretchedAudio, numSamples);

// Write the audio to disk.
//fwrite(audioInputOutput, 1, numSamples * 4, fd);
}
// Clear the output buffer list.
self->outputBuffers->clear();
// If we have enough samples in the fifo output buffer, pass them to the audio output.
//SuperpoweredFloatToShortInt((float *)inputBuffer.buffers[0], audioInputOutput, (unsigned int) numberOfSamples);
}

return true;
}

我不确定更改费率是否也有效,但我不关心这个应用程序。 YMMV.

关于c++ - super 强大:实时音高转换,时间拉伸(stretch)器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46889430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com