pR0
pR0

Reputation: 1

Real time pitch shift using Superpowered Android

I am having problem in using the Superpowered time stretching function for real time pitch shift.

I have used this solution for my purpose. The problem is I am applying the change on the input buffer which is a short array and getting back noise after processing the buffer.

Here's the relevant code--

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

This is the audio processing function of the SuperpoweredAndroidAudioIO. I have defined the timeStretch in the initializing function.I am stuck at this point and need some help...

Thanks.

Upvotes: 0

Views: 1005

Answers (1)

Gabor Szanto
Gabor Szanto

Reputation: 1329

outputBuffers->makeSlice should ask for "numberOfSamples", not the entire "sampleLength". Also, when you put those samples into "audioInputOutput" in that iteration, make sure that "audioInputOutput" is also stepped, otherwise you will overwrite the same region (the beginning).

Upvotes: 0

Related Questions