I am developing encode mechanics using sppex in JNI. I call Encode method from java,
Following c code which is working fine.
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);
}
This C code is doing encoding fine.
when i Implement this using JNI ,read file as short array in java and call JNI encode,encoded data is not right.
Here is JNI code
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;
}`
pls,.Can u found any mistake in above code,.. Thanks in advance.