本文介绍了超级动力:时间延长器不起作用的实时音调转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我将Superpowered用于各种实时FX,它们都非常简单。但是,音调转换完全是另外一回事了,我认为实际上是因为它基于时间拉伸算法,所以当然必须处理随时间变化的输出,这比应用诸如EQ或混响的FX复杂得多。但是我只对更改麦克风输入的音高感兴趣。I am using Superpowered for various real-time FX and they all work very straightforward. However the pitch shifting is a whole other story, I think in fact because it's based on the time-stretching algorithm that of course has to deal with output that changes in time which is a lot more complex than applying FX like EQ or reverb. However I'm only interested in change the pitch of my mic input.我看着我可以在GitHub上找到的唯一示例,我对其进行了一些调整以适应我的工作:I looked at the only example I could find on GitHub and I slightly adapted it to fit my work: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循环似乎处理时间延展的情况,我只是在输入时输出相同的时间。I have removed most of the code that I thought wasn't necessary. For example there was a while loop that seemed to deal with time-stretch scenarios, I'm just outputting the same time as I input.一些观察结果: 如果我不清除 outputBuffers 我的内存使用量达到顶峰 如果我使用 self-> outputBuffers-> rewindSlice(); 应用程序变得安静,这可能意味着缓冲区将被静音覆盖 如果我不使用 self-> outputBuffers-> rewindSlice(); 我可以听到自己的声音回来,但是 timeStretchedAudio 总是 0 ,除了第一次If I don't clear the outputBuffers my memory usage goes through the roofIf I use self->outputBuffers->rewindSlice(); the app becomes silent, probably meaning the buffers are getting overwritten with silenceIf I do not use self->outputBuffers->rewindSlice(); I can hear my own voice coming back, but timeStretchedAudio is always 0 except the very first time推荐答案我终于成功了: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。I am not sure if changing the rate also works, but I don't care for this application. YMMV. 这篇关于超级动力:时间延长器不起作用的实时音调转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-26 00:22