Pergunta

Jspeex has a method to decode as seen below:

 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;
}

as input I am giving an array of byte whose length is not certain, but method simply fills my output buffer properly. In other words I am giving a bunch of frames next to each other, but decoder is fine with successive frames. However some machines are slow, so I decided to use speex with jni wrapper. similarly we have a method seen below:

public short[] decode(byte[] frame)
{
    return decode(slot, frame);
}

private native static short[] decode(int slot, byte[] frame);

above jni wrapped decode method only accepts single frame. so my question is how can we do exactly same thing with jspeex using jni wrapped speex.

PS: I tried to separate successive frames into individual frames but length of successive frames did not match with number_of_frames X length_of_a_frame.

sorry for my awesome(?) English, thanks in advance.

Foi útil?

Solução

For those who face the same problem this is how you do it: You better do it inside the 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;
    }
}

You need to know number of framestho.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top