Fixed Ogg granulepos, added a verbose mode that allows printing bit-rate
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 31 Jul 2002 21:09:56 +0000 (21:09 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 31 Jul 2002 21:09:56 +0000 (21:09 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@3739 0101bb08-14d6-0310-b084-bc0e0c8e3800

src/speexdec.c
src/speexenc.c

index 19a85a8..34938d9 100644 (file)
@@ -210,13 +210,14 @@ int main(int argc, char **argv)
    ogg_stream_state os;
    int pf_enabled;
    int nframes=2;
+   int print_bitrate=0;
 
    pf_enabled = 0;
 
    /*Process options*/
    while(1)
    {
-      c = getopt_long (argc, argv, "hv",
+      c = getopt_long (argc, argv, "hvV",
                        long_options, &option_index);
       if (c==-1)
          break;
@@ -248,6 +249,9 @@ int main(int argc, char **argv)
          version();
          exit(0);
          break;
+      case 'V':
+         print_bitrate=1;
+         break;
       case '?':
          usage();
          exit(1);
@@ -333,19 +337,26 @@ int main(int argc, char **argv)
                   /*Decode frame*/
                   speex_decode(st, &bits, output, 0);
                
-               /*PCM saturation (just in case)*/
-               for (i=0;i<frame_size;i++)
-               {
-                  if (output[i]>32000)
-                     output[i]=32000;
-                  else if (output[i]<-32000)
-                     output[i]=-32000;
-               }
-               /*Convert to short and save to output file*/
-               for (i=0;i<frame_size;i++)
-                  out[i]=(short)le_short(output[i]);
-               fwrite(out, sizeof(short), frame_size, fout);
+                  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;i++)
+                  {
+                     if (output[i]>32000)
+                        output[i]=32000;
+                     else if (output[i]<-32000)
+                        output[i]=-32000;
+                  }
+                  /*Convert to short and save to output file*/
+                  for (i=0;i<frame_size;i++)
+                     out[i]=(short)le_short(output[i]);
+                  fwrite(out, sizeof(short), frame_size, fout);
+               }
             }
             packet_count++;
          }
index 84acae3..85a57ba 100644 (file)
@@ -105,6 +105,7 @@ int main(int argc, char **argv)
       {"version", no_argument, NULL, 0},
       {0, 0, 0, 0}
    };
+   int print_bitrate=0;
    int rate, chan, fmt, size;
    int quality=-1;
    int lbr=0;
@@ -121,7 +122,7 @@ int main(int argc, char **argv)
    /*Process command-line options*/
    while(1)
    {
-      c = getopt_long (argc, argv, "nwhv",
+      c = getopt_long (argc, argv, "nwhvV",
                        long_options, &option_index);
       if (c==-1)
          break;
@@ -167,6 +168,9 @@ int main(int argc, char **argv)
          version();
          exit(0);
          break;
+      case 'V':
+         print_bitrate=1;
+         break;
       case 'w':
          wideband=1;
          break;
@@ -322,7 +326,6 @@ int main(int argc, char **argv)
    /*Main encoding loop (one frame per iteration)*/
    while (1)
    {
-      id++;
       /*Read input audio*/
       fread(in, sizeof(short), frame_size, fin);
       if (feof(fin))
@@ -331,8 +334,15 @@ int main(int argc, char **argv)
          input[i]=(short)le_short(in[i]);
       /*Encode current frame*/
       speex_encode(st, input, &bits);
-
-      if (id%nframes!=0)
+      
+      if (print_bitrate) {
+         int tmp;
+         char ch=13;
+         speex_encoder_ctl(st, SPEEX_GET_BITRATE, &tmp);
+         fputc (ch, stderr);
+         fprintf (stderr, "Bitrate is use: %d bps     ", tmp);
+      }
+      if ((id+1)%nframes!=0)
          continue;
       nbBytes = speex_bits_write(&bits, cbits, MAX_FRAME_BYTES);
       speex_bits_reset(&bits);
@@ -356,6 +366,7 @@ int main(int argc, char **argv)
          else
             bytes_written += ret;
       }
+      id++;
    }
    
    op.packet = (unsigned char *)"END OF STREAM";