class="cpp">[code="c++"] /****************************************************************** iLBC Speech Coder ANSI-C Source Code anaFilter.h Copyright (C) The Internet Society (2004). All Rights Reserved. ******************************************************************/ #ifndef __iLBC_ANAFILTER_H #define __iLBC_ANAFILTER_H void anaFilter( float *In, /* (i) Signal to be filtered */ float *a, /* (i) LP parameters */ int len,/* (i) Length of signal */ float *Out, /* (o) Filtered signal */ float *mem /* (i/o) Filter state */ ); #endif [/code] 就是试一下代码效果。
?
/****************************************************************** iLBC Speech Coder ANSI-C Source Code anaFilter.c Copyright (C) The Internet Society (2004). All Rights Reserved. ******************************************************************/ #include <string.h> #include "iLBC_define.h" /*----------------------------------------------------------------* * LP analysis filter. *---------------------------------------------------------------*/ void anaFilter( float *In, /* (i) Signal to be filtered */ float *a, /* (i) LP parameters */ int len,/* (i) Length of signal */ float *Out, /* (o) Filtered signal */ float *mem /* (i/o) Filter state */ ){ int i, j; float *po, *pi, *pm, *pa; po = Out; /* Filter first part using memory from past */ for (i=0; i<LPC_FILTERORDER; i++) { pi = &In[i]; pm = &mem[LPC_FILTERORDER-1]; pa = a; *po=0.0; for (j=0; j<=i; j++) { *po+=(*pa++)*(*pi--); } for (j=i+1; j<LPC_FILTERORDER+1; j++) { *po+=(*pa++)*(*pm--); } po++; } /* Filter last part where the state is entirely in the input vector */ for (i=LPC_FILTERORDER; i<len; i++) { pi = &In[i]; pa = a; *po=0.0; for (j=0; j<LPC_FILTERORDER+1; j++) { *po+=(*pa++)*(*pi--); } po++; } /* Update state vector */ memcpy(mem, &In[len-LPC_FILTERORDER], LPC_FILTERORDER*sizeof(float)); }
?
package com.googlecode.androidilbc; import android.util.Log; public class Codec { static final private String TAG = "Codec"; static final private Codec INSTANCE = new Codec(); public native int encode(byte[] data, int dataOffset, int dataLength, byte[] samples, int samplesOffset); public native int decode(byte[] samples, int samplesOffset, int samplesLength, byte[] data, int dataOffset); private native int init(int mode); private Codec() { System.loadLibrary("ilbc-codec"); init(30); } static public Codec instance() { return INSTANCE; } public byte[] encode(byte[] samples, int offset, int len) { byte[] data = new byte[4096 * 10]; int bytesEncoded = 0; bytesEncoded += encode(samples, offset, len, data, 0); Log.e(TAG, "Encode " + bytesEncoded); return data; } public byte[] decode(byte[] data, int offset, int len) { return null; } }
?