使用Superpowered在Android中进行音高变换/时间延长

时间:2017-11-06 21:55:33

标签: android audio superpowered pitch-shifting

我需要从视频中提取音频,并通过使用搜索栏(something like this)改变音高来实时调整音高。 性能需要接近实时。 现在至少我需要音调移位音频(有人.aac音频文件)。 我发现了一个Superpowered库,但是实例并没有实现音高变换,而且docs不包含有关它的信息。 有没有人这样做?或者也许可以帮助我使用另一个库?

我发现这是example和 现在我正在尝试这样做:

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;

}

这是我的NDKAudioPlayer类:

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;

};

2 个答案:

答案 0 :(得分:0)

也许这会帮助有同样问题的人: 我用SuperpoweredAdvancedAudioPlayer类的setPitchShiftCents方法实现了它。 这种方法在播放音频时进行音高变换。

答案 1 :(得分:0)

您可以使用PlayerExample项目并在audioProcessing回调的开头添加两行:

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