出于基准测试目的,我重复加载.wav文件,离线处理并使用SuperpoweredSDK保存输出。 但经过一些迭代(在我的情况下为4)我得到了错误" A / libc:传递给dlfree"的无效地址或损坏的块0x5e825000的地址。当我尝试释放shortIntBuffer时。
extern "C" JNIEXPORT void JNICALL
Java_com_example_sebas_superpoweredtest_MainActivity_testDecoderReuse(JNIEnv *env, jobject instance,
jstring apkPath_,
jlong fileOffset,
jlong fileLength,
jstring outputFileName_) {
const char *apkPath = env->GetStringUTFChars(apkPath_, 0);
const char *outputFileName = env->GetStringUTFChars(outputFileName_, 0);
SuperpoweredDecoder decoder;
short int* shortIntBuffer;
FILE* fd;
for(int i = 0; i < 100; ++i) {
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "RUN %d", i+1);
//open InputFile
const char *openError = decoder.open(apkPath, false, fileOffset, fileLength);
if (openError) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", openError);
return;
};
shortIntBuffer = new short int[decoder.samplesPerFrame * 4 + 16384] {0};
fd = createWAV(outputFileName, decoder.samplerate, 2);
if (!fd) {
__android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Failed creating File %s", outputFileName);
return;
};
//process samples
unsigned int samplesDecoded;
while (true) {
// Decode one frame. samplesDecoded will be overwritten with the actual decoded number of samples.
samplesDecoded = decoder.samplesPerFrame;
if (decoder.decode(shortIntBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Error while decoding samples.");
break;
}
if (samplesDecoded < 1) break;
// Write the audio to disk.
fwrite(shortIntBuffer, 1, samplesDecoded * 4, fd);
};
//close resources
if(fd) {
closeWAV(fd);
__android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Closed wav.");
}
delete[](shortIntBuffer); // <- SIGSEGV (signal SIGSEGV: invalid address (fault address: 0xdeadbaad))
__android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Deleted shortInBuffer");
}
env->ReleaseStringUTFChars(apkPath_, apkPath);
env->ReleaseStringUTFChars(outputFileName_, outputFileName);
}
我不明白为什么代码在第一次迭代中工作正常但不适用于所有迭代。我很高兴听到你解决这个问题。
提前致谢
当我收到消息时,这是LLDB-Frame:&#34; 0xfde0fdec(代码= 1)的致命信号11(SIGSEGV),线程9779(超级测试)&#34;