javac++java-native-interfacesoundtouch

jni SAMPLETYPE to jbyteArray


I get an error at the return line. My code:

extern "C" DLL_PUBLIC jbyteArray Java_com_ngochoang_playerdemo_AudioNativeLib_navProcessBytes(JNIEnv *env, jobject thiz, jbyteArray data, jint size)
{
    LOGV("JNI call soundtouch.navProcessBytes");
    int bufferSize = size*5;
    SAMPLETYPE sampleBuffer[bufferSize];
    pSoundTouch.putSamples((SAMPLETYPE*)data, size);
    TotalNSamples = pSoundTouch.receiveSamples(sampleBuffer, bufferSize);
    LOGV("JNI call soundtouch.navProcessBytes END");
    return (jbyteArray)sampleBuffer;
}

Error:

Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 5980 (Thread-753)

Thanks


Solution

  • I fixed my problem.

    extern "C" DLL_PUBLIC jbyteArray Java_com_ngochoang_playerdemo_AudioNativeLib_navProcessBytes(JNIEnv *env, jobject thiz, jbyteArray data, jint size)
    {
        LOGV("JNI call soundtouch.navProcessBytes");
        int bufferSize = size*5;
        SAMPLETYPE sampleBuffer[bufferSize];
        pSoundTouch.putSamples((SAMPLETYPE*)data, size);
        TotalNSamples = pSoundTouch.receiveSamples(sampleBuffer, bufferSize);
        jbyteArray ret = env->NewByteArray(bufferSize);
        env->SetByteArrayRegion(ret, 0, bufferSize, (jbyte *)sampleBuffer);
        LOGV("JNI call soundtouch.navProcessBytes END");
        return ret;
    }
    

    it's needed copy into jbyteArray by using JNI function SetByteArrayRegion