如何使用Superpowered从麦克风进行实时音高转换?

时间:2017-11-10 11:50:28

标签: ios objective-c objective-c++ pitch superpowered

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

    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;
}

1 个答案:

答案 0 :(得分:2)

我做了以下事情:

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;
}

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