2013-01-24 71 views
1

Jspeex具有解碼的方法,如下所示:的Speex和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; 
} 

作爲輸入我給字節的數組,其長度並不確定,但方法簡單地適當填充了我的輸出緩衝器。換句話說,我給了一堆彼此相鄰的幀,但是解碼器對於連續的幀很好。但是有些機器很慢,所以我決定用jni wrapper來使用speex。同樣我們有一個方法如下:

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不匹配。

對不起,我的真棒(?)英語,在此先感謝。

回答

0

對於那些面臨同樣問題的人,這是你如何做到的: 你最好在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; 
    } 
} 

您需要知道frames tho的編號。