Reputation: 1179
Is this correct way to create native jshortArray from C char array:
size_t s;
FILE *f = fopen(argv[4], "rb");
void *b;
fseek(f, 0, SEEK_END);
s = ftell(f);
fseek(f, 0, SEEK_SET);
b = (char *)malloc(s);
fread(b, s, 1, f);
fclose(f);
jshortArray js = env->NewShortArray(s*2);
env->SetShortArrayRegion(js, 0 , s*2, (short const *)b);
Will js contain the same content as char array?
I am working with audio library and it takes input as bytes and output will be short array (jshortArray). But I need to pass it and I assume being the right size.
Working on proprietary implementation of libspx (libspeex)
I assume that is what it takes/works:
public static native boolean nDecodeBuffer(long j12, byte[] bArr, long j13, short[] sArr);
I am also confused .... how do JNI/Java works with codecs?
I see in Java we pass by value i.e I will pass byte array as input and get my short array hopefully with output in Java Implementation (correct me if I am wrong)
In C/C++ it would be done with pointers, I would pass output to be a pointer to my short array
Can somebody explain it also
Upvotes: 0
Views: 72