如何使用 Superpowered 从麦克风进行实时变调?

How to do real-time pitch shifting from mic with Superpowered?

我正在尝试使用超级功率从麦克风实时进行音高转换。我查看了文件的示例。也试图适应它。我设法改变了声音,但结果却因干扰而失真。我究竟做错了什么?在哪里可以找到有关超能力和时间拉伸的更多信息?

    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;

    float tempBuffer[numberOfSamples * 2 + 16];
    SuperpoweredInterleave(buffers[0], buffers[1], tempBuffer, numberOfSamples);
    float *outputBuffer = tempBuffer;

    SuperpoweredAudiobufferlistElement inputBuffer;

    inputBuffer.samplePosition = 0;

    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;

    memcpy((float *)inputBuffer.buffers[0], outputBuffer, numberOfSamples * 2 + 16);

    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 sampleCount = 0;
            float *timeStretchedAudio = (float *)self->outputBuffers->nextSliceItem(&sampleCount);
            if (!timeStretchedAudio) break;
            SuperpoweredDeInterleave(timeStretchedAudio, buffers[0], buffers[1], numberOfSamples);
        };

        // Clear the output buffer list.
        self->outputBuffers->clear();
    };

    return true;
}

我做了以下事情:

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 = numberOfSamples;
    inputBuffer.buffers[0] = SuperpoweredAudiobufferPool::getBuffer((unsigned int) (numberOfSamples * 8 + 64));
    inputBuffer.buffers[1] = inputBuffer.buffers[2] = inputBuffer.buffers[3] = NULL;

    SuperpoweredInterleave(buffers[0], buffers[1], (float *)inputBuffer.buffers[0], 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;
            }

            SuperpoweredDeInterleave(timeStretchedAudio, buffers[0], buffers[1], numSamples);
        }
        // Clear the output buffer list.
        self->outputBuffers->clear();
    }

    return true;
}

这在改变速度时也可能无法正常工作,但我只想要实时音高变换。人们应该能够自己说得更慢或更快。