4 /*The frame size in hardcoded for this sample code but it doesn't have to be*/
6 int main(int argc, char **argv)
10 /*Holds the audio that will be written to file (16 bits per sample)*/
11 short out[FRAME_SIZE];
12 /*Speex handle samples as float, so we need an array of floats*/
13 float output[FRAME_SIZE];
16 /*Holds the state of the decoder*/
18 /*Holds bits so they can be read and written to by the Speex routines*/
22 /*Create a new decoder state in narrowband mode*/
23 state = speex_decoder_init(&speex_nb_mode);
25 /*Set the perceptual enhancement on*/
27 speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);
30 fout = fopen(outFile, "w");
32 /*Initialization of the structure that holds the bits*/
33 speex_bits_init(&bits);
36 /*Read the size encoded by sampleenc, this part will likely be
37 different in your application*/
38 fread(&nbBytes, sizeof(int), 1, stdin);
39 fprintf (stderr, "nbBytes: %d\n", nbBytes);
43 /*Read the "packet" encoded by sampleenc*/
44 fread(cbits, 1, nbBytes, stdin);
45 /*Copy the data into the bit-stream struct*/
46 speex_bits_read_from(&bits, cbits, nbBytes);
49 speex_decode(state, &bits, output);
51 /*Copy from float to short (16 bits) for output*/
52 for (i=0;i<FRAME_SIZE;i++)
55 /*Write the decoded audio to file*/
56 fwrite(out, sizeof(short), FRAME_SIZE, fout);
59 /*Destroy the decoder state*/
60 speex_encoder_destroy(state);
61 /*Destroy the bit-stream truct*/
62 speex_bits_destroy(&bits);