我已经实现了一系列SuperpoweredFX类并且没有任何问题,但是,在使用SuperpoweredTimeStretching实现音高移位器时,我遇到了一些麻烦。
static bool audioProcessing(void * __unused clientdata, short int *audioInputOutput, int numberOfSamples, int __unused samplerate) {
float *floatBuffer = (float *)malloc(numberOfSamples * 2 * sizeof(float) + 1024);
SuperpoweredShortIntToFloat(audioInputOutput, floatBuffer, numberOfSamples);
if(isFX_PitchShifter_1){
__android_log_print(ANDROID_LOG_ERROR, "FrequencyDomain", "audioProcessing - isFX_PitchShifter_1 - fx_PitchShift_1");
SuperpoweredAudiopointerList *outputBuffers = new SuperpoweredAudiopointerList( 4 , 0 );//POSSIBLE MEMORY PROBLEM
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;
SuperpoweredShortIntToFloat(audioInputOutput, (float *)inputBuffer.buffers[0], (unsigned int) numberOfSamples);
if(fx_PitchShift_1!=NULL){
fx_PitchShift_1->process(&inputBuffer, outputBuffers);
if (outputBuffers->makeSlice(0, outputBuffers->sampleLength)) {
while (true) { // Iterate on every output slice.
int numSamples = 0;
float *temp_floatBuffer = (float *)outputBuffers->nextSliceItem(&numSamples);
if (!temp_floatBuffer) {
break;
}
SuperpoweredFloatToShortInt(temp_floatBuffer, audioInputOutput, numSamples);
}
outputBuffers->clear();
}
}
SuperpoweredShortIntToFloat(audioInputOutput, floatBuffer, numberOfSamples);
}
SuperpoweredFloatToShortInt(floatBuffer, audioInputOutput, numberOfSamples);
return true;
}
以上是我的处理函数,我使用的是FrequencyDomain示例中的SuperpoweredAndroidAudioIO。
我声明SuperpoweredTimeStretching类是这样的:
fx_PitchShift_1 = new SuperpoweredTimeStretching((unsigned int)thisSampleRate);
fx_PitchShift_1->setRateAndPitchShift(1.0f, (int)pitchShiftOctaves);
同样的应用程序正在使用SuperpoweredFX类,但是,当音高转换投入混音时,输出变得一团糟。可以在此处找到示例文件:https://drive.google.com/file/d/1Hy52SsgOYxlkxFq5CCsK5sCKX3Y_9G8J/view?usp=sharing
我像这样计算采样率:
samplerateString = null;
buffersizeString = null;
if (Build.VERSION.SDK_INT >= 17) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
samplerateString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
buffersizeString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
}
if (samplerateString == null) samplerateString = "44100";
if (buffersizeString == null) buffersizeString = "512";
答案 0 :(得分:0)
音调移位器在频域工作,FFT大小为2048.这与您当前的缓冲区大小不一致。
您还会在音频处理回调的每个转弯处创建一个新的输出缓冲区列表,然后丢弃音高移位器提供的所有内容。
您正确地将所有输入样本提交给音高移位器,但您需要全局处理输出列表。它将存储音高变换器的输出,如果输出列表中有可用的样本量,则可以删除输出所需的样本数。