Update encoder and decoder examples. One inch away from everything
authorMonty <xiphmont@xiph.org>
Fri, 28 Jan 2000 15:25:12 +0000 (15:25 +0000)
committerMonty <xiphmont@xiph.org>
Fri, 28 Jan 2000 15:25:12 +0000 (15:25 +0000)
building clean again.

Monty

svn path=/trunk/vorbis/; revision=247

examples/decoder_example.c
examples/encoder_example.c
include/vorbis/modes.h
lib/mapping0.c
lib/psy.c
lib/psy.h
lib/window.c

index e2194b8..1a1030f 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.4 2000/01/22 13:28:08 xiphmont Exp $
+ last mod: $Id: decoder_example.c,v 1.5 2000/01/28 15:25:06 xiphmont Exp $
 
  ********************************************************************/
 
@@ -38,6 +38,7 @@ int main(){
   
   vorbis_info      vi; /* struct that stores all the static vorbis bitstream
                          settings */
+  vorbis_comment   vc; /* struct that stores all the bitstream user comments */
   vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
   vorbis_block     vb; /* local working space for packet->PCM decode */
   
@@ -85,6 +86,7 @@ int main(){
        useful to see that functionality seperated out. */
     
     vorbis_info_init(&vi);
+    vorbis_comment_init(&vc);
     if(ogg_stream_pagein(&os,&og)<0){ 
       /* error; stream version mismatch perhaps */
       fprintf(stderr,"Error reading first page of Ogg bitstream data.\n");
@@ -97,7 +99,7 @@ int main(){
       exit(1);
     }
     
-    if(vorbis_info_headerin(&vi,&op)<0){ 
+    if(vorbis_synthesis_headerin(&vi,&vc,&op)<0){ 
       /* error case; not a vorbis header */
       fprintf(stderr,"This Ogg bitstream does not contain Vorbis "
              "audio data.\n");
@@ -133,8 +135,8 @@ int main(){
                 We can't tolerate that in a header.  Die. */
              fprintf(stderr,"Corrupt secondary header.  Exiting.\n");
              exit(1);
-         }
-           vorbis_info_headerin(&vi,&op);
+           }
+           vorbis_synthesis_headerin(&vi,&vc,&op);
            i++;
          }
        }
@@ -152,13 +154,13 @@ int main(){
     /* Throw the comments plus a few lines about the bitstream we're
        decoding */
     {
-      char **ptr=vi.user_comments;
+      char **ptr=vc.user_comments;
       while(*ptr){
        fprintf(stderr,"%s\n",*ptr);
        ++ptr;
       }
       fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
-      fprintf(stderr,"Encoded by: %s\n\n",vi.vendor);
+      fprintf(stderr,"Encoded by: %s\n\n",vc.vendor);
     }
     
     convsize=4096/vi.channels;
index 85796b4..530e27f 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.5 2000/01/28 09:04:58 xiphmont Exp $
+ last mod: $Id: encoder_example.c,v 1.6 2000/01/28 15:25:07 xiphmont Exp $
 
  ********************************************************************/
 
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <math.h>
-#include "vorbis/codec.h"
+#include "vorbis/modes.h"
 
 #define READ 1024
 signed char readbuffer[READ*4+44]; /* out of the data segment, not the stack */
@@ -36,10 +36,10 @@ int main(){
   ogg_page         og; /* one Ogg bitstream page.  Vorbis packets are inside */
   ogg_packet       op; /* one raw packet of data for decode */
   
-  vorbis_info      vi; /* struct that stores all the static vorbis bitstream
+  vorbis_info     *vi; /* struct that stores all the static vorbis bitstream
                          settings */
   vorbis_comment   vc; /* struct that stores all the user comments */
-                         settings */
+
   vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
   vorbis_block     vb; /* local working space for packet->PCM decode */
 
@@ -55,13 +55,14 @@ int main(){
 
   /* choose an encoding mode */
   /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */
-  vorbis_info_modeset(&vi,0); 
+  vi=&info_A;
 
   /* add a comment */
-  vorbis_info_addcomment(&vi,"Track encoded by encoder_example.c");
+  vorbis_comment_init(&vc);
+  vorbis_comment_add(&vc,"Track encoded by encoder_example.c");
 
   /* set up the analysis state and auxiliary encoding storage */
-  vorbis_analysis_init(&vd,&vi);
+  vorbis_analysis_init(&vd,vi);
   vorbis_block_init(&vd,&vb);
   
   /* set up our packet->stream encoder */
@@ -82,7 +83,7 @@ int main(){
     ogg_packet header_comm;
     ogg_packet header_code;
 
-    vorbis_info_headerout(&vi,&header,&header_comm,&header_code);
+    vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code);
     ogg_stream_packetin(&os,&header); /* automatically placed in its own
                                         page */
     ogg_stream_packetin(&os,&header_comm);
@@ -152,7 +153,6 @@ int main(){
   ogg_stream_clear(&os);
   vorbis_block_clear(&vb);
   vorbis_dsp_clear(&vd);
-  vorbis_info_clear(&vi);
   
   /* ogg_page and ogg_packet structs always point to storage in
      libvorbis.  They're never freed or manipulated directly */
index dc6138f..5a99fd3 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: predefined encoding modes
- last mod: $Id: modes.h,v 1.3 2000/01/28 14:31:24 xiphmont Exp $
+ last mod: $Id: modes.h,v 1.4 2000/01/28 15:25:08 xiphmont Exp $
 
  ********************************************************************/
 
@@ -22,8 +22,8 @@
 #include <stdio.h>
 #include "vorbis/codec.h"
 #include "vorbis/backends.h"
-#include "vorbis/book/lsp20_0.h"
-#include "vorbis/book/lsp32_0.h"
+#include "vorbis/book/lsp20_0.vqh"
+#include "vorbis/book/lsp32_0.vqh"
 
 /*
    0      1      2      3      4     5      6     7     8     9 
@@ -43,49 +43,39 @@ static vorbis_info_psy _psy_set0={
 };
 
 /* with GNUisms, this could be short and readable. Oh well */
-static static_codebook *_book_vec0[2]={&_vq_book_lsp20_0,&_vq_book_lsp32_0};
 static vorbis_info_time0 _time_set0={0};
 static vorbis_info_floor0 _floor_set0={20, 44100,  64, 1, {0} };
 static vorbis_info_floor0 _floor_set1={32, 44100, 256, 1, {1} };
 static vorbis_info_residue0 _residue_set0={0,0};
 static vorbis_info_mapping0 _mapping_set0={1, {0,0}, {0}, {0}, {0}, {0}};
 static vorbis_info_mapping0 _mapping_set1={1, {0,0}, {0}, {1}, {0}, {0}};
-static vorbis_info mode _mode_set0={0,0,0,0};
-static vorbis_info mode _mode_set1={1,0,0,1};
-
-static vorbis_info_time *_time_A[1]={&_time_set0};
-static vorbis_info_floor *_floor_A[2]={&_floor_set0,&_floor_set1};
-static vorbis_info_residue *_res_A[1]={&_residue_set0};
-static vorbis_info_psy *_psy_A[1]={&_psy_set0};
-static vorbis_info_mode *_mode_A[2]=
-
+static vorbis_info_mode _mode_set0={0,0,0,0};
+static vorbis_info_mode _mode_set1={1,0,0,1};
 
 /* CD quality stereo, no channel coupling */
 vorbis_info info_A={
-  {
-    /* channels, sample rate, upperkbps, nominalkbps, lowerkbps */
-    2, 44100, 0,0,0,
-    /* smallblock, largeblock */
-    {256, 2048}, 
-    /* modes,maps,times,floors,residues,books,psys */
-    2,          2,    1,     2,       2,    2,   1,
-    /* modes */
-    {&_mode_set0,&mode_set1},
-    /* maps */
-    {0,0},{&_mapping_set0,&_mapping_set1},
-    /* times */
-    {0,0},{&_time_set0},
-    /* floors */
-    {0,0},{&_floor_set0,&_floor_set1},
-    /* residue */
-    {0,0},{&_residue_set0},
-    /* books */
-    {&_vq_book_lsp20_0,&_vq_book_lsp32_0},
-    /* psy */
-    {&_psy_set0},
-    /* thresh sample period, preecho clamp trigger threshhold, range */
-    64, 10, 2 
-  }
+  /* channels, sample rate, upperkbps, nominalkbps, lowerkbps */
+  0, 2, 44100, 0,0,0,
+  /* smallblock, largeblock */
+  {256, 2048}, 
+  /* modes,maps,times,floors,residues,books,psys */
+  2,          2,    1,     2,       2,    2,   1,
+  /* modes */
+  {&_mode_set0,&_mode_set1},
+  /* maps */
+  {0,0},{&_mapping_set0,&_mapping_set1},
+  /* times */
+  {0,0},{&_time_set0},
+  /* floors */
+  {0,0},{&_floor_set0,&_floor_set1},
+  /* residue */
+  {0,0},{&_residue_set0},
+  /* books */
+  {&_vq_book_lsp20_0,&_vq_book_lsp32_0},
+  /* psy */
+  {&_psy_set0},
+  /* thresh sample period, preecho clamp trigger threshhold, range */
+  64, 10, 2 
 };
 
 #define PREDEF_INFO_MAX 0
index acfb758..08f274b 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.5 2000/01/28 14:34:44 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.6 2000/01/28 15:25:09 xiphmont Exp $
 
  ********************************************************************/
 
@@ -51,14 +51,14 @@ typedef struct {
 
 } vorbis_look_mapping0;
 
-void free_info(vorbis_info_mapping *i){
+static void free_info(vorbis_info_mapping *i){
   if(i){
     memset(i,0,sizeof(vorbis_info_mapping0));
     free(i);
   }
 }
 
-void free_look(vorbis_look_mapping *look){
+static void free_look(vorbis_look_mapping *look){
   int i;
   vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look;
   if(l){
@@ -80,7 +80,7 @@ void free_look(vorbis_look_mapping *look){
   }
 }
 
-vorbis_look_mapping *look(vorbis_info *vi,vorbis_info_mode *vm,
+static vorbis_look_mapping *look(vorbis_info *vi,vorbis_info_mode *vm,
                          vorbis_info_mapping *m){
   int i;
   vorbis_look_mapping0 *ret=calloc(1,sizeof(vorbis_look_mapping0));
@@ -121,7 +121,7 @@ vorbis_look_mapping *look(vorbis_info *vi,vorbis_info_mode *vm,
   return(ret);
 }
 
-void pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
+static void pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
   int i;
   vorbis_info_mapping0 *d=(vorbis_info_mapping0 *)vm;
 
@@ -139,7 +139,7 @@ void pack(vorbis_info *vi,vorbis_info_mapping *vm,oggpack_buffer *opb){
 }
 
 /* also responsible for range checking */
-vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
+static vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
   int i;
   vorbis_info_mapping0 *d=calloc(1,sizeof(vorbis_info_mapping0));
   memset(d,0,sizeof(vorbis_info_mapping0));
@@ -179,7 +179,7 @@ vorbis_info_mapping *unpack(vorbis_info *vi,oggpack_buffer *opb){
 #include "spectrum.h"
 
 /* no time mapping implementation for now */
-int forward(vorbis_block *vb,vorbis_look_mapping *l){
+static int forward(vorbis_block *vb,vorbis_look_mapping *l){
   vorbis_dsp_state     *vd=vb->vd;
   vorbis_info          *vi=vd->vi;
   vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
@@ -261,7 +261,7 @@ int forward(vorbis_block *vb,vorbis_look_mapping *l){
   return(0);
 }
 
-int inverse(vorbis_block *vb,vorbis_look_mapping *l){
+static int inverse(vorbis_block *vb,vorbis_look_mapping *l){
   vorbis_dsp_state     *vd=vb->vd;
   vorbis_info          *vi=vd->vi;
   vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
@@ -320,4 +320,10 @@ int inverse(vorbis_block *vb,vorbis_look_mapping *l){
   return(0);
 }
 
+/* export hooks */
+vorbis_func_mapping mapping0_exportbundle={
+  &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse
+};
+
+
 
index a5170b7..e499754 100644 (file)
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.13 2000/01/28 09:05:14 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.14 2000/01/28 15:25:10 xiphmont Exp $
 
  ********************************************************************/
 
@@ -140,3 +140,9 @@ static void time_convolve(double *s,double *r,int n,int m){
   }
 }
 
+void _vi_psy_free(vorbis_info_psy *i){
+  if(i){
+    memset(i,0,sizeof(vorbis_info_psy));
+    free(i);
+  }
+}
index f41e119..f08d47c 100644 (file)
--- a/lib/psy.h
+++ b/lib/psy.h
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.7 2000/01/28 09:05:15 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.8 2000/01/28 15:25:11 xiphmont Exp $
 
  ********************************************************************/
 
@@ -31,7 +31,7 @@ typedef struct {
 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,int n,long rate);
 extern void   _vp_psy_clear(vorbis_look_psy *p);
 extern void  *_vi_psy_dup(void *source);
-extern void   _vi_psy_free(void *i);
+extern void   _vi_psy_free(vorbis_info_psy *i);
 
 extern void   _vp_mask_floor(vorbis_look_psy *p,double *pcm,
                             double *mask,double *floor);
index 499d15b..efdacf6 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.c,v 1.4 2000/01/22 13:28:36 xiphmont Exp $
+ last mod: $Id: window.c,v 1.5 2000/01/28 15:25:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -20,7 +20,7 @@
 #include <math.h>
 #include "os.h"
 
-double *vorbis_window(int type, int window,int left,int right){
+double *_vorbis_window(int type, int window,int left,int right){
   double *ret=calloc(window,sizeof(double));
 
   switch(type){