extra files for Bruce's recent patch
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 1 Oct 2010 00:55:20 +0000 (00:55 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 1 Oct 2010 00:55:20 +0000 (00:55 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@197 01035d8c-6547-0410-b346-abe4f91aad63

codec2/src/codebook/lsp1.txt [new file with mode: 0644]
codec2/src/codebook/lsp10.txt [new file with mode: 0644]
codec2/src/codebook/lsp2.txt [new file with mode: 0644]
codec2/src/codebook/lsp3.txt [new file with mode: 0644]
codec2/src/codebook/lsp4.txt [new file with mode: 0644]
codec2/src/codebook/lsp5.txt [new file with mode: 0644]
codec2/src/codebook/lsp6.txt [new file with mode: 0644]
codec2/src/codebook/lsp7.txt [new file with mode: 0644]
codec2/src/codebook/lsp8.txt [new file with mode: 0644]
codec2/src/codebook/lsp9.txt [new file with mode: 0644]
codec2/src/generate_codebook.c [new file with mode: 0644]

diff --git a/codec2/src/codebook/lsp1.txt b/codec2/src/codebook/lsp1.txt
new file mode 100644 (file)
index 0000000..d126be7
--- /dev/null
@@ -0,0 +1,17 @@
+1 16
+225
+250
+275
+300
+325
+350
+375
+400
+425
+450
+475
+500
+525
+550
+575
+600
diff --git a/codec2/src/codebook/lsp10.txt b/codec2/src/codebook/lsp10.txt
new file mode 100644 (file)
index 0000000..39aab7c
--- /dev/null
@@ -0,0 +1,6 @@
+1 4
+2900
+3100
+3300
+3500
+
diff --git a/codec2/src/codebook/lsp2.txt b/codec2/src/codebook/lsp2.txt
new file mode 100644 (file)
index 0000000..597f149
--- /dev/null
@@ -0,0 +1,17 @@
+1 16
+325
+350
+375
+400
+425
+450
+475
+500
+525
+550
+575
+600
+625
+650
+675
+700
diff --git a/codec2/src/codebook/lsp3.txt b/codec2/src/codebook/lsp3.txt
new file mode 100644 (file)
index 0000000..36a64b1
--- /dev/null
@@ -0,0 +1,17 @@
+1 16
+500
+550
+600
+650
+700
+750
+800
+850
+900
+950
+1000
+1050
+1100
+1150
+1200
+1250
diff --git a/codec2/src/codebook/lsp4.txt b/codec2/src/codebook/lsp4.txt
new file mode 100644 (file)
index 0000000..53a90bd
--- /dev/null
@@ -0,0 +1,17 @@
+1 16
+700
+800
+900
+1000
+1100
+1200
+1300
+1400
+1500
+1600
+1700
+1800
+1900
+2000
+2100
+2200
diff --git a/codec2/src/codebook/lsp5.txt b/codec2/src/codebook/lsp5.txt
new file mode 100644 (file)
index 0000000..94739b5
--- /dev/null
@@ -0,0 +1,19 @@
+1 16
+ 950
+1050
+1150
+1250
+1350
+1450
+1550
+1650
+1750
+1850
+1950
+2050
+2150
+2250
+2350
+2450
+
+
diff --git a/codec2/src/codebook/lsp6.txt b/codec2/src/codebook/lsp6.txt
new file mode 100644 (file)
index 0000000..992ea25
--- /dev/null
@@ -0,0 +1,19 @@
+1 16
+1100
+1200
+1300
+1400
+1500
+1600
+1700
+1800
+1900
+2000
+2100
+2200
+2300
+2400
+2500
+2600
+
+
diff --git a/codec2/src/codebook/lsp7.txt b/codec2/src/codebook/lsp7.txt
new file mode 100644 (file)
index 0000000..839cbfd
--- /dev/null
@@ -0,0 +1,19 @@
+1 16
+1500
+1600
+1700
+1800
+1900
+2000
+2100
+2200
+2300
+2400
+2500
+2600
+2700
+2800
+2900
+3000
+
+
diff --git a/codec2/src/codebook/lsp8.txt b/codec2/src/codebook/lsp8.txt
new file mode 100644 (file)
index 0000000..d9880c9
--- /dev/null
@@ -0,0 +1,11 @@
+1 8
+2300
+2400
+2500
+2600
+2700
+2800
+2900
+3000
+
+
diff --git a/codec2/src/codebook/lsp9.txt b/codec2/src/codebook/lsp9.txt
new file mode 100644 (file)
index 0000000..7e159af
--- /dev/null
@@ -0,0 +1,11 @@
+1 8
+2500
+2600
+2700
+2800
+2900
+3000
+3100
+3200
+
+
diff --git a/codec2/src/generate_codebook.c b/codec2/src/generate_codebook.c
new file mode 100644 (file)
index 0000000..de8f444
--- /dev/null
@@ -0,0 +1,151 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <math.h>
+
+static const char usage[] =
+"Usage: %s filename [filename ...]\n"
+"\tCreate C code for codebook tables.\n";
+
+static const char format[] =
+"The table format must be:\n"
+"\tTwo integers describing the dimensions of the codebook.\n"
+"\tThen, enough numbers to fill the specified dimensions.\n";
+
+static const char header[] =
+"/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */\n\n"
+"/*\n"
+" * This intermediary file and the files that used to create it are under \n"
+" * The LGPL. See the file COPYING.\n"
+" */\n\n"
+"#include \"defines.h\"\n\n";
+
+struct codebook {
+  unsigned int k;
+  unsigned int log2m;
+  unsigned int m;
+  float * cb;
+};
+
+static void
+dump_array(const struct codebook * b, int index)
+{
+  int  limit = b->k * b->m;
+  int  i;
+
+  printf("static const float codes%d[] = {\n", index);
+  for ( i = 0; i < limit; i++ ) {
+    printf("  %g", b->cb[i]);
+    if ( i < limit - 1 )
+      printf(",");
+    printf("\n");
+  }
+  printf("};\n");
+}
+
+static void
+dump_structure(const struct codebook * b, int index)
+{
+  printf("  {\n");
+  printf("    %d,\n", b->k);
+  printf("    %g,\n", log(b->m) / log(2));
+  printf("    %d,\n", b->m);
+  printf("    codes%d\n", index);
+  printf("  }");
+}
+
+float
+get_float(FILE * in, const char * name, char * * cursor, char * buffer,
+ int size)
+{
+  for ( ; ; ) {
+    char *     s = *cursor;
+    char       c;
+
+    while ( (c = *s) != '\0' && !isdigit(c) && c != '-' && c != '.' )
+      s++;
+     
+    /* Comments start with "#" and continue to the end of the line. */
+    if ( c != '\0' && c != '#' ) {
+      char *   end = 0;
+      float    f = 0;
+
+      f = strtod(s, &end);
+
+      if ( end != s )
+        *cursor = end;
+        return f;
+    }
+
+    if ( fgets(buffer, size, in) == NULL ) {
+      fprintf(stderr, "%s: Format error. %s\n", name, format);
+      exit(1);
+    }
+    *cursor = buffer;
+  }
+}
+
+static struct codebook *
+load(FILE * file, const char * name)
+{
+  char                 line[1024];
+  char *               cursor = line;
+  struct codebook *    b = malloc(sizeof(struct codebook));
+  int                  i;
+  int                  size;
+
+  *cursor = '\0';
+
+  b->k = (int)get_float(file, name, &cursor, line, sizeof(line));
+  b->m = (int)get_float(file, name ,&cursor, line, sizeof(line));
+  size = b->k * b->m;
+
+  b->cb = (float *)malloc(size * sizeof(float));
+
+  for ( i = 0; i < size; i++ )
+    b->cb[i] = get_float(file, name, &cursor, line, sizeof(line));
+
+  return b;
+}
+
+int
+main(int argc, char * * argv)
+{
+  struct codebook * *  cb = malloc(argc * sizeof(struct codebook *));
+  int                  i;
+
+  if ( argc < 2 ) {
+    fprintf(stderr, usage, argv[0]);
+    fprintf(stderr, format);
+    exit(1);
+  }
+
+  for ( i = 0; i < argc - 1; i++ ) {
+    FILE *     in = fopen(argv[i + 1], "r");
+
+    if ( in == NULL ) {
+      perror(argv[i + 1]);
+      exit(1);
+    }
+
+    cb[i] = load(in, argv[i + 1]);
+
+    fclose(in);
+  }
+
+  printf(header);
+  for ( i = 0; i < argc - 1; i++ ) {
+    printf("  /* %s */\n", argv[i + 1]);
+    dump_array(cb[i], i);
+  }
+  printf("\nconst struct lsp_codebook lsp_cb[] = {\n");
+  for ( i = 0; i < argc - 1; i++ ) {
+    printf("  /* %s */\n", argv[i + 1]);
+    dump_structure(cb[i], i);
+    printf(",\n");
+  }
+  printf("  { 0, 0, 0, 0 }\n");
+  printf("};\n");
+
+  return 0;
+}