Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JNI:speex编码数据错误_Java_C_Java Native Interface_Speex - Fatal编程技术网

Java JNI:speex编码数据错误

Java JNI:speex编码数据错误,java,c,java-native-interface,speex,Java,C,Java Native Interface,Speex,我正在JNI中使用sppex开发编码机制。 我从java调用Encode方法 下面是工作正常的c代码 short in_short[FRAME_SIZE]; short out_short[FRAME_SIZE]; short out[FRAME_SIZE]; char cbits[200]; int nbBits; int i; void *st; SpeexBits bits; /*read file as short array and

我正在JNI中使用sppex开发编码机制。 我从java调用Encode方法

下面是工作正常的c代码

   short in_short[FRAME_SIZE];
   short out_short[FRAME_SIZE];
   short out[FRAME_SIZE];
   char cbits[200];
   int nbBits;
   int i;
   void *st;
   SpeexBits bits;
   /*read file as short array and encode that fram and store in file */
   while (!feof(fin))
   {
     fread(in_short, sizeof(short), frame_size, fin);
       if (feof(fin))
         break; 
      speex_bits_reset(&bits);
      speex_encode_int(st, in_short, &bits);
      nbBits = speex_bits_write(&bits, cbits, 200);
fwrite(&cbits,sizeof(char),nbBits,fout);
}
这个C代码编码很好

当我使用JNI实现此功能时,在java中将文件读取为短数组并调用JNI encode,编码的数据是不正确的

下面是JNI代码

jbyteArray Java_com_argusoft_JNIActivity_encode(JNIEnv *env, jobject obj, jshortArray lin){

jbyteArray  returnVal;
    jshort buffer[enc_frame_size]; // enc_frame_size =160
    jbyte output_buffer[enc_frame_size];
    int i, tot_bytes = 0;
    speex_bits_reset(&ebits);
    (*env)->GetShortArrayRegion(env,lin,  0,enc_frame_size, buffer);
    speex_encode_int(enc_state1, buffer, &ebits);
    tot_bytes = speex_bits_write(&ebits,output_buffer,enc_frame_size);
    returnVal =  ((*env)->NewByteArray(env, tot_bytes));
    (*env)->SetByteArrayRegion(env,returnVal, 0, tot_bytes,output_buffer);
    return returnVal;
}`
请问,你能在上面的代码中发现任何错误吗,。。 提前谢谢