<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span><br></span></div><br><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;">The code i used for decoding is given below:<br><br>#include <jni.h><br>#include <stdio.h><br>#include "speex/speex.h"<br><br> #define FRAME_SIZE 160<br><br><br>void Java_com_m2_iSmartDm_ISmartDMActivity_spxDec(JNIEnv * env, jobject jobj,jstring dir1,jstring dir2)<br>{<br> const char *inFile= (*env)->GetStringUTFChars(env,dir1,0);<br> const char *outFile= (*env)->GetStringUTFChars(env,dir2,0);<br> FILE *fin;<br> FILE *fout;<br> /*Holds the audio that will be written to file (16 bits per sample)*/<br> short out[FRAME_SIZE];<br> /*Speex handle
samples as float, so we need an array of floats*/<br> float output[FRAME_SIZE];<br> char cbits[200];<br> int nbBytes;<br> /*Holds the state of the decoder*/<br> void *state;<br> /*Holds bits so they can be read and written to by the Speex routines*/<br> SpeexBits bits;<br> int i, tmp;<br><br> /*Create a new decoder state in narrowband mode*/<br> state = speex_decoder_init(&speex_nb_mode);<br><br> /*Set the perceptual enhancement on*/<br> tmp=1;<br> speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);<br><br> fin = fopen(inFile, "r");<br> fout=fopen(outFile,"w");<br><br> speex_bits_init(&bits);<br><br> while (1)<br> {<br> /*Read the size encoded by sampleenc, this part will likely be<br> different in your application*/<br> fread(&nbBytes, sizeof(int), 1, fin);<br> if
(feof(stdin))<br> break;<br><br> /*Read the "packet" encoded by sampleenc*/<br> fread(cbits, 1, nbBytes, fin);<br><br> /*Copy the data into the bit-stream struct*/<br> speex_bits_read_from(&bits, cbits, nbBytes);<br><br> /*Decode the data*/<br> speex_decode(state, &bits, output);<br><br> /*Copy from float to short (16 bits) for output*/<br> for (i=0;i<FRAME_SIZE;i++)<br> out[i]=output[i];<br><br> /*Write the decoded audio to file*/<br> fwrite(out, sizeof(short), FRAME_SIZE, fout);<br><br> }<br> /*Destroy the decoder state*/<br> speex_decoder_destroy(state);<br> /*Destroy the bit-stream truct*/<br> speex_bits_destroy(&bits);<br> fclose(fout);<br>
fclose(fin);<br><br>Please check this code and correct me. Thanks<br>} <br> </div> </div> </div></body></html>