Jspeex有一个解码方法,如下所示:
public static int decode(byte[] input, int offset, int length, byte[] output) throws StreamCorruptedException {
SpeexDecoder decoder = new SpeexDecoder();
decoder.init(0, 8000, 1, true, length);
decoder.bits.read_from(input, offset, length);
int o_offset = 0;
while ( decoder.bits.getBufferSize() < length )
{
decoder.decodeToByteArray(output, o_offset);
o_offset += 320;
}
return o_offset;
}作为输入,我给出了一个长度不确定的字节数组,但方法只是适当地填充了我的输出缓冲区。换句话说,我给了一堆帧,但解码器可以处理连续的帧。但是有些机器速度很慢,所以我决定将speex与jni包装器一起使用。类似地,我们有一个如下所示的方法:
public short[] decode(byte[] frame)
{
return decode(slot, frame);
}
private native static short[] decode(int slot, byte[] frame);上面的jni封装解码方法只接受单帧。所以我的问题是,我们如何使用jni封装的speex在jspeex中做同样的事情。
PS:我试图将连续的帧分离成单独的帧,但连续帧的长度与number_of_frames X length_of_a_frame不匹配。
抱歉,我太棒了(?)英语,提前谢谢。
发布于 2015-09-10 00:18:08
对于那些面临同样问题的人来说,这就是如何做到这一点:你最好在jni内部完成。
for(int i=0;i<frames;i++) {
if(speex_decode_int(dec_state, &dbits, output_buffer+i*dec_frame_size)!=0) {
__android_log_print(ANDROID_LOG_ERROR, "Speex_jni", "Error in decoding");
return (jint)0;
}
}您需要知道framestho的数量。
https://stackoverflow.com/questions/14510251
复制相似问题