Dmitriy Skopintsev
Dmitriy Skopintsev

Reputation: 21

Pitch shifting/Time stretching in Android with Superpowered

I need to extract audio from video and pitch shift it at real-time by changing pitch with seekbar(something like this). Performance need to be near real-time. At now at least I need to pitch shift audio(someone .aac audio file). I found an Superpowered library, but examples dont implement pitch-shifting and docs not contain info about it. Did anyone do it? Or maybe can help me with another libs?

I am found this example and at now I am trying to do it:

bool NDKAudioPlayer::process(short *output, unsigned int numberOfSamples) {
double masterBpm = player->currentBpm;

bool silence = !player->process(stereoBuffer, false, numberOfSamples, volume, masterBpm);

if (!silence){
    handler = new LiveTimeStretchingHandler();
    setupLiveTimeStretching(handler, currentSamplerate);
    liveTimeStretchingProcess(stereoBuffer, numberOfSamples, 0, handler);
    delete handler;
}

// The stereoBuffer is ready now, let's put the finished audio into the requested buffers.
if (!silence) SuperpoweredFloatToShortInt(stereoBuffer, output, numberOfSamples);
return !silence;

}

This is my NDKAudioPlayer class:

class NDKAudioPlayer {
public:

NDKAudioPlayer(unsigned int samplerate, unsigned int buffersize, const char *path, int audioFileOffset, int audioFileLength);
~NDKAudioPlayer();

bool process(short *pInt, unsigned int numberOfSamples);
void onPlayPause(bool play);
void onCentsChanged(int cents);

private:

SuperpoweredAndroidAudioIO *audioSystem;
SuperpoweredAdvancedAudioPlayer *player;
LiveTimeStretchingHandler *handler;
float *stereoBuffer;
float volume;
int currentSamplerate = 0;

};

Upvotes: 0

Views: 970

Answers (2)

Alexis R
Alexis R

Reputation: 91

You can use the PlayerExample project and add two lines at the beginning of the audioProcessing callback:

player->setTempo(1.0, true); // Needed for the pitch shifting to work
player->setPitchShift(-12); // Pitch shift one octave down

Upvotes: 0

Dmitriy Skopintsev
Dmitriy Skopintsev

Reputation: 21

Maybe this help someone with the same problem: I have implemented it with setPitchShiftCents method of SuperpoweredAdvancedAudioPlayer class. This method make pitch shifting while playing audio.

Upvotes: 2

Related Questions