Rearranged chaining example into a library interface (vorbisfile.a)
authorMonty <xiphmont@xiph.org>
Tue, 2 Nov 1999 23:27:34 +0000 (23:27 +0000)
committerMonty <xiphmont@xiph.org>
Tue, 2 Nov 1999 23:27:34 +0000 (23:27 +0000)
and a main() file (chaining_example.c).

Need to flesh out vorbisfile.a a bit more.

Monty

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

lib/Makefile.in
lib/vorbisfile.c [moved from lib/chaining_example.c with 86% similarity]
lib/vorbisfile.h [new file with mode: 0644]

index aee6429..660eb89 100644 (file)
@@ -1,6 +1,6 @@
 # vorbis makefile configured for use with gcc on any platform
 
-# $Id: Makefile.in,v 1.13 1999/11/02 11:17:34 xiphmont Exp $
+# $Id: Makefile.in,v 1.14 1999/11/02 23:27:32 xiphmont Exp $
 
 ###############################################################################
 #                                                                             #
@@ -34,6 +34,8 @@ LFILES =      framing.o mdct.o smallft.o block.o envelope.o window.o\
                lsp.o lpc.o analysis.o synthesis.o psy.o info.o bitwise.o\
                spectrum.o
 
+FFILES =       vorbisfile.o
+
 EFILES =       encoder_example.o decoder_example.o chaining_example.o
 
 all:
@@ -48,7 +50,8 @@ analysis:
 profile: 
        $(MAKE) target CFLAGS="$(PROFILE)"
 
-target:        libvorbis.a encoder_example decoder_example chaining_example
+target:        libvorbis.a vorbisfile.a \
+       encoder_example decoder_example chaining_example
 
 selftest:      
        $(MAKE) clean
@@ -67,15 +70,22 @@ decoder_example:    $(EFILES) libvorbis.a
        $(CC) $(CFLAGS) $(LDFLAGS) decoder_example.o libvorbis.a -o \
                        decoder_example -lm
 
-chaining_example:      $(EFILES) libvorbis.a
-       $(CC) $(CFLAGS) $(LDFLAGS) chaining_example.o libvorbis.a -o \
-                       chaining_example -lm
+chaining_example:      $(EFILES) libvorbis.a vorbisfile.a
+       $(CC) $(CFLAGS) $(LDFLAGS) chaining_example.o \
+                       vorbisfile.a libvorbis.a -o chaining_example -lm
 
 libvorbis.a:   $(LFILES)       
-               $(AR) -r libvorbis.a $(LFILES)
+               $(AR) -r libvorbis.a $^
                $(RANLIB) libvorbis.a
 
+vorbisfile.a:  $(FFILES)
+               $(AR) -r vorbisfile.a $^
+               $(RANLIB) vorbisfile.a
+
+
 $(LFILES):     $(HFILES)
+$(FFILES):     $(HFILES) vorbisfile.h
+$(EFILES):     $(HFILES) vorbisfile.h
 
 info.o:                modes.h
 
similarity index 86%
rename from lib/chaining_example.c
rename to lib/vorbisfile.c
index df48835..cc3e5bd 100644 (file)
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- function: simple example of opening/seeking chained bitstreams
+ function: stdio-based convenience library for opening/seeking/decoding
  author: Monty <xiphmont@mit.edu>
  modifications by: Monty
  last modification date: Nov 02 1999
  ********************************************************************/
 
 #include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <stdio.h>
-#include <math.h>
 #include "codec.h"
+#include "vorbisfile.h"
 
 /* A 'chained bitstream' is a Vorbis bitstream that contains more than
    one logical bitstream arranged end to end (the only form of Ogg
@@ -40,7 +38,7 @@
    bitstream structure right off the bat, or find pieces on demand.
    This example determines and caches structure for the entire
    bitstream, but builds a virtual decoder on the fly when moving
-   between links in the chain */
+   between links in the chain. */
 
 /* There are also different ways to implement seeking.  Enough
    information exists in an Ogg bitstream to seek to
    picking some portion of the stream roughtly in the area if we only
    want course navigation through the stream. */
 
-typedef struct {
-  FILE             *f;
-  int              seekable;
-  long             offset;
-  long             end;
-  ogg_sync_state   oy; 
-
-  /* If the FILE handle isn't seekable (eg, a pipe), only the current
-     stream appears */
-  int              links;
-  long             *offsets;
-  long             *serialnos;
-  size64           *pcmlengths;
-  vorbis_info      *vi;
-
-  /* Decoding working state local storage */
-  int ready;
-  ogg_stream_state os; /* take physical pages, weld into a logical
-                          stream of packets */
-  vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
-  vorbis_block     vb; /* local working space for packet->PCM decode */
-
-} OggVorbis_File;
-
-
 /*************************************************************************
  * Many, many internal helpers.  The intention is not to be confusing; 
  * rampant duplication and monolithic function implementation would be 
@@ -455,7 +428,7 @@ double ov_lbtime(OggVorbis_File *vf,int i){
   return(0);
 }
 
-long ov_totaltime(OggVorbis_File *vf){
+double ov_totaltime(OggVorbis_File *vf){
   double acc=0;
   int i;
   for(i=0;i<vf->links;i++)
@@ -464,51 +437,37 @@ long ov_totaltime(OggVorbis_File *vf){
 }
 
 /* seek to an offset relative to the *compressed* data */
-int ov_seek_stream;
+int ov_seek_stream(OggVorbis_File *vf,long pos){
+
+
+
+
+}
+
+/* seek to the beginning of the next logical bitstream within the
+   physical bitstream */
+int ov_seek_bitstream(OggVorbis_File *vf,long pos){
+
+
+
 
+}
 
 /* seek to an offset relative to the decompressed *output* stream */
-int ov_seek_pcm;
+int ov_seek_pcm(OggVorbis_File *vf,long pos){
 
 
-int main(){
-  OggVorbis_File ov;
-  int i;
 
-  /* open the file/pipe on stdin */
-  if(ov_open(stdin,&ov,NULL,-1)==-1){
-    printf("Could not open input as an OggVorbis file.\n\n");
-    exit(1);
-  }
-  
-  /* print details about each logical bitstream in the input */
-  if(ov.seekable){
-    printf("Input bitstream contained %d logical bitstream section(s).\n",
-          ov.links);
-    printf("Total bitstream playing time: %ld seconds\n\n",
-          (long)ov_totaltime(&ov));
+}
+
+int ov_seek_time(OggVorbis_File *vf,double seconds){
+
 
-  }else{
-    printf("Standard input was not seekable.\n"
-          "First logical bitstream information:\n\n");
-  }
 
-  for(i=0;i<ov.links;i++){
-    printf("\tlogical bitstream section %d information:\n",i+1);
-    printf("\t\tsample rate: %ldHz\n",ov.vi[i].rate);
-    printf("\t\tchannels: %d\n",ov.vi[i].channels);
-    printf("\t\tserial number: %ld\n",ov.serialnos[i]);
-    printf("\t\traw length: %ldbytes\n",(ov.offsets?
-                                    ov.offsets[i+1]-ov.offsets[i]:
-                                    -1));
-    printf("\t\tplay time: %lds\n\n",(long)ov_lbtime(&ov,i));
-  }
-  
-  ov_clear(&ov);
-  return 0;
 }
 
 
 
 
 
+
diff --git a/lib/vorbisfile.h b/lib/vorbisfile.h
new file mode 100644 (file)
index 0000000..3bdb14a
--- /dev/null
@@ -0,0 +1,65 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
+ * PLEASE READ THESE TERMS DISTRIBUTING.                            *
+ *                                                                  *
+ * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999             *
+ * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company       *
+ * http://www.xiph.org/                                             *
+ *                                                                  *
+ ********************************************************************
+
+ function: stdio-based convenience library for opening/seeking/decoding
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ last modification date: Nov 02 1999
+
+ ********************************************************************/
+
+#ifndef _VO_FILE_H_
+#define _VO_FILE_H_
+
+#include <stdio.h>
+#include "codec.h"
+
+typedef struct {
+  FILE             *f;
+  int              seekable;
+  long             offset;
+  long             end;
+  ogg_sync_state   oy; 
+
+  /* If the FILE handle isn't seekable (eg, a pipe), only the current
+     stream appears */
+  int              links;
+  long             *offsets;
+  long             *serialnos;
+  size64           *pcmlengths;
+  vorbis_info      *vi;
+
+  /* Decoding working state local storage */
+  int ready;
+  ogg_stream_state os; /* take physical pages, weld into a logical
+                          stream of packets */
+  vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+  vorbis_block     vb; /* local working space for packet->PCM decode */
+
+} OggVorbis_File;
+
+extern int ov_clear(OggVorbis_File *vf);
+extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
+
+extern double ov_lbtime(OggVorbis_File *vf,int i);
+extern double ov_totaltime(OggVorbis_File *vf);
+
+
+#endif
+
+
+
+
+
+
+