[xiph-cvs] cvs commit: speex/libspeex bits.c cb_search.c lsp.c ltp.c misc.c misc.h modes.c nb_celp.c quant_lsp.c sb_celp.c speex_callbacks.c speex_header.c

Jean-Marc Valin jm at xiph.org
Sun Jan 5 20:18:12 PST 2003



jm          03/01/05 23:18:12

  Modified:    doc      manual.lyx
               libspeex bits.c cb_search.c lsp.c ltp.c misc.c misc.h
                        modes.c nb_celp.c quant_lsp.c sb_celp.c
                        speex_callbacks.c speex_header.c
  Log:
  cleanup: all use of libc has been moved to misc.c to make porting easier.

Revision  Changes    Path
1.43      +0 -30     speex/doc/manual.lyx

Index: manual.lyx
===================================================================
RCS file: /usr/local/cvsroot/speex/doc/manual.lyx,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- manual.lyx	5 Jan 2003 08:46:33 -0000	1.42
+++ manual.lyx	6 Jan 2003 04:18:11 -0000	1.43
@@ -45,36 +45,6 @@
  A copy of the license is included in the section entitled "GNU Free Documentati
 on License".
  
-\layout Section*
-
-Disclaimer
-\layout Standard
-
-This document is meant to provide useful information on the Speex codec
- but there is absolutely no warranty regarding usefulness or correctness
- of the information provided.
- Also, some techniques used in Speex are said to be 
-\begin_inset Quotes eld
-\end_inset 
-
-similar
-\begin_inset Quotes erd
-\end_inset 
-
- to techniques used in known codecs.
- This should not be understood as an acknowledgment that Speex is using
- any patented algorithm used in these codecs, but merely that comprehension
- of Speex can be facilitated by thinking that the principles of operation
- are the same or similar.
- Of course, there's also the obligatory 
-\begin_inset Quotes eld
-\end_inset 
-
-all trademarks are property of their respective owner
-\begin_inset Quotes erd
-\end_inset 
-
-.
 \layout Standard
 \pagebreak_top \pagebreak_bottom 
 

<p><p>1.22      +2 -5      speex/libspeex/bits.c

Index: bits.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/bits.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- bits.c	27 Oct 2002 06:01:30 -0000	1.21
+++ bits.c	6 Jan 2003 04:18:11 -0000	1.22
@@ -33,8 +33,6 @@
 */
 
 #include "speex_bits.h"
-#include <stdio.h>
-#include <stdlib.h>
 #include "misc.h"
 
 void speex_bits_init(SpeexBits *bits)
@@ -91,8 +89,7 @@
    int i;
    if (len > MAX_BYTES_PER_FRAME)
    {
-      fprintf (stderr, "Trying to init frame with too many bits");
-      exit(1);
+      speex_error ("Trying to init frame with too many bits");
    }
    for (i=0;i<len;i++)
       bits->bytes[i]=bytes[i];
@@ -162,7 +159,7 @@
       bit = (d>>(nbBits-1))&1;
       bits->bytes[bits->bytePtr] |= bit<<(7-bits->bitPtr);
       bits->bitPtr++;
-      /*fprintf(stderr, "%d %d\n", nbBits, bit);*/
+
       if (bits->bitPtr==8)
       {
          bits->bitPtr=0;

<p><p>1.81      +2 -6      speex/libspeex/cb_search.c

Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- cb_search.c	2 Nov 2002 06:08:00 -0000	1.80
+++ cb_search.c	6 Jan 2003 04:18:11 -0000	1.81
@@ -30,12 +30,11 @@
 */
 
 
-#include <stdlib.h>
 #include "cb_search.h"
 #include "filters.h"
 #include "stack_alloc.h"
 #include "vq.h"
-
+#include "misc.h"
 
 void split_cb_search_shape_sign(
 float target[],			/* target vector */
@@ -384,8 +383,5 @@
 void *stack
 )
 {
-   int i;
-
-   for (i=0;i<nsf;i++)
-      exc[i]+=3*((((float)rand())/RAND_MAX)-.5);
+   speex_rand_vec(1, exc, nsf);
 }

<p><p>1.21      +3 -2      speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- lsp.c	19 Dec 2002 04:07:08 -0000	1.20
+++ lsp.c	6 Jan 2003 04:18:11 -0000	1.21
@@ -44,8 +44,6 @@
 */
 
 #include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include "lsp.h"
 #include "stack_alloc.h"
 
@@ -54,6 +52,9 @@
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
 
+#ifndef NULL
+#define NULL 0
+#endif
 
 /*---------------------------------------------------------------------------*\
 

<p><p>1.67      +0 -1      speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- ltp.c	28 Nov 2002 06:32:50 -0000	1.66
+++ ltp.c	6 Jan 2003 04:18:11 -0000	1.67
@@ -31,7 +31,6 @@
 */
 
 #include <math.h>
-#include <stdio.h>
 #include "ltp.h"
 #include "stack_alloc.h"
 #include "filters.h"

<p><p>1.6       +35 -0     speex/libspeex/misc.c

Index: misc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- misc.c	27 Oct 2002 06:01:30 -0000	1.5
+++ misc.c	6 Jan 2003 04:18:11 -0000	1.6
@@ -104,3 +104,38 @@
 {
    return memmove(dest,src,n);
 }
+
+void speex_error(char *str)
+{
+   fprintf (stderr, "Fatal error: %s\n", str);
+   exit(1);
+}
+
+void speex_warning(char *str)
+{
+   fprintf (stderr, "warning: %s\n", str);
+}
+
+void speex_warning_int(char *str, int val)
+{
+   fprintf (stderr, "warning: %s %d\n", str, val);
+}
+
+void speex_rand_vec(float std, float *data, int len)
+{
+   int i;
+   for (i=0;i<len;i++)
+      data[i]+=3*std*((((float)rand())/RAND_MAX)-.5);
+}
+
+float speex_rand(float std)
+{
+   return 3*std*((((float)rand())/RAND_MAX)-.5);
+}
+
+float _speex_putc(int ch, void *file)
+{
+   FILE *f = (FILE *)file;
+   fputc(ch, f);
+
+}

<p><p>1.12      +12 -0     speex/libspeex/misc.h

Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- misc.h	31 Dec 2002 06:07:33 -0000	1.11
+++ misc.h	6 Jan 2003 04:18:11 -0000	1.12
@@ -59,4 +59,16 @@
 /** Speex wrapper for mem_move */
 void *speex_move (void *dest, void *src, int n);
 
+void speex_error(char *str);
+
+void speex_warning(char *str);
+
+void speex_warning_int(char *str, int val);
+
+void speex_rand_vec(float std, float *data, int len);
+
+float speex_rand(float std);
+
+float _speex_putc(int ch, void *file);
+
 #endif

<p><p>1.94      +7 -4      speex/libspeex/modes.c

Index: modes.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.c,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- modes.c	20 Dec 2002 08:24:46 -0000	1.93
+++ modes.c	6 Jan 2003 04:18:11 -0000	1.94
@@ -32,8 +32,6 @@
 
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include "modes.h"
 #include "ltp.h"
 #include "quant_lsp.h"
@@ -41,6 +39,11 @@
 #include "sb_celp.h"
 #include "nb_celp.h"
 #include "vbr.h"
+#include "misc.h"
+
+#ifndef NULL
+#define NULL 0
+#endif
 
 SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
 
@@ -571,7 +574,7 @@
       *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
       break;
    default:
-      fprintf(stderr, "Unknown wb_mode_query request: %d\n", request);
+      speex_warning_int("Unknown nb_mode_query request: ", request);
    }
 
 }
@@ -589,7 +592,7 @@
       *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
       break;
    default:
-      fprintf(stderr, "Unknown wb_mode_query request: %d\n", request);
+      speex_warning_int("Unknown wb_mode_query request: ", request);
    }
 }
 

<p><p>1.104     +18 -16    speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -r1.103 -r1.104
--- nb_celp.c	5 Jan 2003 08:46:33 -0000	1.103
+++ nb_celp.c	6 Jan 2003 04:18:11 -0000	1.104
@@ -29,8 +29,6 @@
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <math.h>
 #include "nb_celp.h"
 #include "lpc.h"
@@ -55,6 +53,10 @@
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
 
+#ifndef NULL
+#define NULL 0
+#endif
+
 #define SUBMODE(x) st->submodes[st->submodeID]->x
 
 float exc_gain_quant_scal3[8]={-2.794750, -1.810660, -1.169850, -0.848119, -0.587190, -0.329818, -0.063266, 0.282826};
@@ -687,7 +689,7 @@
 
          st->pitch[sub]=pitch;
       } else {
-         fprintf (stderr, "No pitch prediction, what's wrong\n");
+         speex_error ("No pitch prediction, what's wrong");
       }
 
       /* Update target for adaptive codebook contribution */
@@ -741,14 +743,15 @@
 
          ener_1 = 1/ener;
 
-         if (0) {
+#if 0
+         {
             int start=rand()%35;
             printf ("norm_exc: ");
             for (i=start;i<start+5;i++)
                printf ("%f ", ener_1*st->buf2[i]);
             printf ("\n");
          }
-         
+#endif    
          /* Normalize innovation */
          for (i=0;i<st->subframeSize;i++)
             target[i]*=ener_1;
@@ -767,7 +770,7 @@
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov[i];
          } else {
-            fprintf(stderr, "No fixed codebook\n");
+            speex_error("No fixed codebook");
          }
 
          /* In some (rare) modes, we do a second search (more bits) to reduce noise even more */
@@ -1013,7 +1016,7 @@
 #else
          /*exc[i]=pitch_gain*exc[i-st->last_pitch] +  fact*st->innov[i+offset];*/
          exc[i]=pitch_gain*exc[i-st->last_pitch] + 
-         fact*sqrt(1-pitch_gain)*3*innov_gain*((((float)rand())/RAND_MAX)-.5);
+         fact*sqrt(1-pitch_gain)*speex_rand(innov_gain);
 #endif
       }
       }
@@ -1094,7 +1097,7 @@
             wideband = speex_bits_unpack_unsigned(bits, 1);
             if (wideband)
             {
-               fprintf (stderr, "Corrupted stream?\n");
+               speex_error ("Corrupted stream?");
             }
          }
 
@@ -1143,11 +1146,10 @@
             pitch_gain=.6;
          for (i=0;i<st->frameSize;i++)
             innov_gain += st->innov[i]*st->innov[i];
-         innov_gain=sqrt(innov_gain/160);
+         innov_gain=sqrt(innov_gain/st->frameSize);
          for (i=0;i<st->frameSize;i++)
-         {
-            st->exc[i]=3*innov_gain*((((float)rand())/RAND_MAX)-.5);
-         }
+            st->exc[i]=0;
+         speex_rand_vec(innov_gain, st->exc, st->frameSize);
       }
 
 
@@ -1340,7 +1342,7 @@
                         best_pitch_gain=.85;*/
          }
       } else {
-         fprintf (stderr, "No pitch prediction, what's wrong\n");
+         speex_error("No pitch prediction, what's wrong");
       }
       
       /* Unquantize the innovation */
@@ -1373,7 +1375,7 @@
             /*Fixed codebook contribution*/
             SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, stack);
          } else {
-            fprintf(stderr, "No fixed codebook\n");
+            speex_error("No fixed codebook");
          }
 
          /* De-normalize innovation and update excitation */
@@ -1638,7 +1640,7 @@
       (*(float*)ptr)=st->relative_quality;
       break;
    default:
-      fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
+      speex_warning_int("Unknown nb_ctl request: ", request);
    }
 }
 
@@ -1723,6 +1725,6 @@
       }
       break;
    default:
-      fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
+      speex_warning_int("Unknown nb_ctl request: ", request);
    }
 }

<p><p>1.18      +0 -1      speex/libspeex/quant_lsp.c

Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- quant_lsp.c	11 Oct 2002 03:39:34 -0000	1.17
+++ quant_lsp.c	6 Jan 2003 04:18:12 -0000	1.18
@@ -32,7 +32,6 @@
 
 #include "quant_lsp.h"
 #include <math.h>
-#include <stdio.h>
 
 extern int lsp_nb_vqid[64];
 static float quant_weight[MAX_LSP_SIZE];

<p><p>1.108     +7 -9      speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- sb_celp.c	31 Dec 2002 03:25:34 -0000	1.107
+++ sb_celp.c	6 Jan 2003 04:18:12 -0000	1.108
@@ -30,10 +30,7 @@
 */
 
 
-#include <stdlib.h>
 #include <math.h>
-#include <stdio.h>
-/*#include "nb_celp.h"*/
 #include "sb_celp.h"
 #include "stdlib.h"
 #include "filters.h"
@@ -600,6 +597,7 @@
 
          scale = gc*sqrt(1+el)/filter_ratio;
          scale_1 = 1/scale;
+#if 0
          if (0 && rand()%5==0)
          {
             float sc = 1/sqrt(.1+eh/st->subframeSize);
@@ -613,7 +611,7 @@
                printf (" %f", tmp);
             }
          }
-
+#endif
          for (i=0;i<st->subframeSize;i++)
             exc[i]=0;
          exc[0]=1;
@@ -677,8 +675,8 @@
                exc[i] += innov2[i];
          }
 
-
-         if (0) {
+#if 0
+         {
             float en=0;
             for (i=0;i<st->subframeSize;i++)
                en+=exc[i]*exc[i];
@@ -687,7 +685,7 @@
                exc[i]*=en;
             printf ("correction high: %f\n", en);
          }
-
+#endif
       }
 
          /*Keep the previous memory*/
@@ -1317,7 +1315,7 @@
       (*(float*)ptr)=st->relative_quality;
       break;
    default:
-      fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
+      speex_warning_int("Unknown nb_ctl request: ", request);
    }
 
 }
@@ -1400,7 +1398,7 @@
       }
       break;
    default:
-      fprintf(stderr, "Unknown sb_ctl request: %d\n", request);
+      speex_warning_int("Unknown nb_ctl request: ", request);
    }
 
 }

<p><p>1.6       +2 -3      speex/libspeex/speex_callbacks.c

Index: speex_callbacks.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_callbacks.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- speex_callbacks.c	27 Oct 2002 06:01:30 -0000	1.5
+++ speex_callbacks.c	6 Jan 2003 04:18:12 -0000	1.6
@@ -33,7 +33,7 @@
 */
 
 #include "speex_callbacks.h"
-#include <stdio.h>
+#include "misc.h"
 
 int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state)
 {
@@ -119,9 +119,8 @@
 int speex_std_char_handler(SpeexBits *bits, void *state, void *data)
 {
    unsigned char ch;
-   FILE *f = (FILE *)data;
    ch = speex_bits_unpack_unsigned(bits, 8);
-   fputc(ch, f);
+   _speex_putc(ch, data);
    return 0;
 }
 

<p><p>1.10      +12 -9     speex/libspeex/speex_header.c

Index: speex_header.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_header.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- speex_header.c	27 Oct 2002 06:01:30 -0000	1.9
+++ speex_header.c	6 Jan 2003 04:18:12 -0000	1.10
@@ -33,9 +33,11 @@
 
 #include "speex_header.h"
 #include "misc.h"
-#include <stdio.h>
 #include "speex.h"
-#include <stdlib.h>
+
+#ifndef NULL
+#define NULL 0
+#endif
 
 #define ENDIAN_SWITCH(x) {x=le_int(x);}
 
@@ -83,7 +85,7 @@
    header->mode = m->modeID;
    header->mode_bitstream_version = m->bitstream_version;
    if (m->modeID<0)
-      fprintf (stderr, "This mode is meant to be used alone\n");
+      speex_warning("This mode is meant to be used alone");
    header->nb_channels = nb_channels;
    header->bitrate = -1;
    speex_mode_query(m, SPEEX_MODE_FRAME_SIZE, &header->frame_size);
@@ -125,14 +127,15 @@
    char *h = "Speex   ";
    for (i=0;i<8;i++)
       if (packet[i]!=h[i])
-   {
-      fprintf (stderr, "This doesn't look like a Speex file\n");
-      return NULL;
-   }
-
+      {
+         speex_warning ("This doesn't look like a Speex file");
+         return NULL;
+      }
+   
+   /*FIXME: Do we allow larger headers?*/
    if (sizeof(SpeexHeader) != size)
    {
-      fprintf (stderr, "Speex header size mismarch\n");
+      speex_warning("Speex header size mismarch");
       return NULL;
    }
    

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list