Повторно использовать SuperpoweredDecoder для загрузки аудио файлов

В целях тестирования я повторяю загрузку .wav-файла, обрабатываю его в автономном режиме и сохраняю вывод с помощью SuperpoweredSDK.
Но после некоторых итераций (в моем случае 4) я получаю ошибку «A / libc: неверный адрес или адрес поврежденного блока 0x5e825000, переданный dlfree», когда я пытаюсь освободить 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-кадр, когда я получаю сообщение: «Фатальный сигнал 11 (SIGSEGV) в 0xfde0fdec (код = 1), поток 9779 (uperpoweredtest)»

LLDB Frame

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector