for (i=0;i<frame_size*channels;i++) out[i]=(short)le_short((short)floor(.5+output[i]));
if (strlen(outFile)!=0) { for (i=0;i<frame_size*channels;i++) out[i]=(short)le_short((short)floor(.5+output[i])); } else { for (i=0;i<frame_size*channels;i++) out[i]=(short)floor(.5+output[i]); }
int main(int argc, char **argv){   int c;   int option_index = 0;   char *inFile, *outFile;   FILE *fin, *fout=NULL;   short out[MAX_FRAME_SIZE];   float output[MAX_FRAME_SIZE];   int frame_size=0;   void *st=NULL;   SpeexBits bits;   int packet_count=0;   int stream_init = 0;   struct option long_options[] =   {      {"help", no_argument, NULL, 0},      {"version", no_argument, NULL, 0},      {"version-short", no_argument, NULL, 0},      {"enh", no_argument, NULL, 0},      {"no-enh", no_argument, NULL, 0},      {"pf", no_argument, NULL, 0},      {"no-pf", no_argument, NULL, 0},      {"force-nb", no_argument, NULL, 0},      {"force-wb", no_argument, NULL, 0},      {"force-uwb", no_argument, NULL, 0},      {"rate", required_argument, NULL, 0},      {"mono", no_argument, NULL, 0},      {"stereo", no_argument, NULL, 0},      {"packet-loss", required_argument, NULL, 0},      {0, 0, 0, 0}   };   ogg_sync_state oy;   ogg_page       og;   ogg_packet     op;   ogg_stream_state os;   int enh_enabled;   int nframes=2;   int print_bitrate=0;   int close_in=0;   int eos=0;   int forceMode=-1;   int audio_size=0;   float loss_percent=-1;   SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT;   int channels=-1;   int rate=0;   int extra_headers;   enh_enabled = 1;   /*Process options*/   while(1)   {      c = getopt_long (argc, argv, "hvV",                       long_options, &option_index);      if (c==-1)         break;            switch(c)      {      case 0:         if (strcmp(long_options[option_index].name,"help")==0)         {            usage();            exit(0);         } else if (strcmp(long_options[option_index].name,"version")==0)         {            version();            exit(0);         } else if (strcmp(long_options[option_index].name,"version-short")==0)         {            version_short();            exit(0);         } else if (strcmp(long_options[option_index].name,"enh")==0)         {            enh_enabled=1;         } else if (strcmp(long_options[option_index].name,"no-enh")==0)         {            enh_enabled=0;         } else if (strcmp(long_options[option_index].name,"pf")==0)         {            fprintf (stderr, "--pf is deprecated, use --enh instead\n");            enh_enabled=1;         } else if (strcmp(long_options[option_index].name,"no-pf")==0)         {            fprintf (stderr, "--no-pf is deprecated, use --no-enh instead\n");            enh_enabled=0;         } else if (strcmp(long_options[option_index].name,"force-nb")==0)         {            forceMode=0;         } else if (strcmp(long_options[option_index].name,"force-wb")==0)         {            forceMode=1;         } else if (strcmp(long_options[option_index].name,"force-uwb")==0)         {            forceMode=2;         } else if (strcmp(long_options[option_index].name,"mono")==0)         {            channels=1;         } else if (strcmp(long_options[option_index].name,"stereo")==0)         {            channels=2;         } else if (strcmp(long_options[option_index].name,"rate")==0)         {            rate=atoi (optarg);         } else if (strcmp(long_options[option_index].name,"packet-loss")==0)         {            loss_percent = atof(optarg);         }         break;      case 'h':         usage();         exit(0);         break;      case 'v':         version();         exit(0);         break;      case 'V':         print_bitrate=1;         break;      case '?':         usage();         exit(1);         break;      }   }   if (argc-optind!=2 && argc-optind!=1)   {      usage();      exit(1);   }   inFile=argv[optind];   if (argc-optind==2)      outFile=argv[optind+1];   else      outFile = "";   /*Open input file*/   if (strcmp(inFile, "-")==0)   {#if defined WIN32 || defined _WIN32      _setmode(_fileno(stdin), _O_BINARY);#endif      fin=stdin;   }   else    {#if defined WIN32 || defined _WIN32      fin = fopen(inFile, "rb");#else      fin = fopen(inFile, "r");#endif      if (!fin)      {         perror(inFile);         exit(1);      }      close_in=1;   }   /*Init Ogg data struct*/   ogg_sync_init(&oy);      speex_bits_init(&bits);   /*Main decoding loop*/   while (1)   {      char *data;      int i, j, nb_read;      /*Get the ogg buffer for writing*/      data = ogg_sync_buffer(&oy, 200);      /*Read bitstream from input file*/      nb_read = fread(data, sizeof(char), 200, fin);            ogg_sync_wrote(&oy, nb_read);      /*Loop for all complete pages we got (most likely only one)*/      while (ogg_sync_pageout(&oy, &og)==1)      {         if (stream_init == 0) {            ogg_stream_init(&os, ogg_page_serialno(&og));            stream_init = 1;         }         /*Add page to the bitstream*/         ogg_stream_pagein(&os, &og);         /*Extract all available packets*/         while (!eos && ogg_stream_packetout(&os, &op)==1)         {            /*If first packet, process as Speex header*/            if (packet_count==0)            {               st = process_header(&op, enh_enabled, &frame_size, &rate, &nframes, forceMode, &channels, &stereo, &extra_headers);               if (!nframes)                  nframes=1;               if (!st)                  exit(1);               fout = out_file_open(outFile, rate, &channels);            } else if (packet_count==1)            {               print_comments((char*)op.packet, op.bytes);            } else if (packet_count<=1+extra_headers)            {               /* Ignore extra headers */            } else {                              int lost=0;               if (loss_percent>0 && 100*((float)rand())/RAND_MAX<loss_percent)                  lost=1;               /*End of stream condition*/               if (op.e_o_s)                  eos=1;               /*Copy Ogg packet to Speex bitstream*/               speex_bits_read_from(&bits, (char*)op.packet, op.bytes);               for (j=0;j!=nframes;j++)               {                  int ret;                  /*Decode frame*/                  if (!lost)                     ret = speex_decode(st, &bits, output);                  else                     ret = speex_decode(st, NULL, output);                  if (ret==-1)                     break;                  if (ret==-2)                  {                     fprintf (stderr, "Decoding error: corrupted stream?\n");                     break;                  }                  if (speex_bits_remaining(&bits)<0)                  {                     fprintf (stderr, "Decoding overflow: corrupted stream?\n");                     break;                  }                  if (channels==2)                     speex_decode_stereo(output, frame_size, &stereo);                  if (print_bitrate) {                     int tmp;                     char ch=13;                     speex_decoder_ctl(st, SPEEX_GET_BITRATE, &tmp);                     fputc (ch, stderr);                     fprintf (stderr, "Bitrate is use: %d bps     ", tmp);                  }                  /*PCM saturation (just in case)*/                  for (i=0;i<frame_size*channels;i++)                  {                     if (output[i]>32000.0)                        output[i]=32000.0;                     else if (output[i]<-32000.0)                        output[i]=-32000.0;                  }                  /*Convert to short and save to output file*/                  for (i=0;i<frame_size*channels;i++)                     out[i]=(short)le_short((short)floor(.5+output[i]));#if defined WIN32 || defined _WIN32                  if (strlen(outFile)==0)                      WIN_Play_Samples (out, sizeof(short) * frame_size*channels);                  else#endif                  fwrite(out, sizeof(short), frame_size*channels, fout);                                    audio_size+=sizeof(short)*frame_size*channels;               }            }            packet_count++;         }      }      if (feof(fin))         break;   }   if (strcmp(outFile+strlen(outFile)-4,".wav")==0 || strcmp(inFile+strlen(inFile)-4,".WAV")==0)   {      if (fseek(fout,4,SEEK_SET)==0)      {         int tmp;         tmp = le_int(audio_size+36);         fwrite(&tmp,4,1,fout);         if (fseek(fout,32,SEEK_CUR)==0)         {            tmp = le_int(audio_size);            fwrite(&tmp,4,1,fout);         } else         {            fprintf (stderr, "First seek worked, second didn't\n");         }      } else {         fprintf (stderr, "Cannot seek on wave file, size will be incorrect\n");      }   }   if (st)      speex_decoder_destroy(st);   else    {      fprintf (stderr, "This doesn't look like a Speex file\n");   }   speex_bits_destroy(&bits);   if (stream_init)      ogg_stream_clear(&os);   ogg_sync_clear(&oy);#if defined WIN32 || defined _WIN32   if (fout && strlen(outFile)==0)      WIN_Audio_close ();#endif   if (close_in)      fclose(fin);   if (fout != NULL)      fclose(fout);      return 0;}