#include #include /*The frame size in hardcoded for this sample code but it doesn’t have to be*/ #define FRAME_SIZE 160 void write_wav_header(FILE *file, int rate, int channels) { char ch[5]; spx_int32_t itmp; spx_int16_t stmp; ch[4]=0; fprintf (file, "RIFF"); itmp = 0x7fffffff; fwrite(&itmp, 4, 1, file); fprintf (file, "WAVEfmt "); itmp = 16; fwrite(&itmp, 4, 1, file); stmp = 1; fwrite(&stmp, 2, 1, file); stmp = channels; fwrite(&stmp, 2, 1, file); itmp = rate; fwrite(&itmp, 4, 1, file); itmp = rate*channels*2; fwrite(&itmp, 4, 1, file); stmp = 2*channels; fwrite(&stmp, 2, 1, file); stmp = 16; fwrite(&stmp, 2, 1, file); fprintf (file, "data"); itmp = 0x7fffffff; fwrite(&itmp, 4, 1, file); } int main(int argc, char **argv) { char *outFile,*inFile; FILE *fout,*fin; /*Holds the audio that will be written to file (16 bits per sample)*/ short out[FRAME_SIZE]; /*Speex handle samples as float, so we need an array of floats*/ short output[FRAME_SIZE]; char cbits[200]; int nbBytes; /*Holds the state of the decoder*/ void *state; /*Holds bits so they can be read and written to by the Speex routines*/ SpeexBits bits; int i, tmp; /*Create a new decoder state in narrowband mode*/ state = speex_decoder_init(&speex_nb_mode); /*Set the perceptual enhancement on*/ tmp=0; speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp); tmp=8; speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp); inFile = argv[1]; outFile = argv[2]; fout = fopen(outFile, "w"); fin = fopen(inFile, "r"); /*Initialization of the structure that holds the bits*/ speex_bits_init(&bits); /*******THIRU: WRITE WAV HEADER BACK******/ write_wav_header(fout,8000,01); while (1) { /*Read the size encoded by sampleenc, this part will likely be different in your application*/ fread(&nbBytes, sizeof(int), 1, fin); printf("Thiru1: Number of bytes of Read is %d\n",nbBytes); if (feof(fin)) break; /*Read the "packet" encoded by sampleenc*/ fread(cbits, 1, nbBytes, fin); //printf("Thiru2: value of nbBytes is %d\n",nbBytes); /*Copy the data into the bit-stream struct*/ speex_bits_read_from(&bits, cbits, nbBytes); //printf("Thiru3: value of nbBytes is %d\n",nbBytes); /*Decode the data*/ speex_decode_int(state, &bits, output); /*Copy from float to short (16 bits) for output*/ for (i=0;i