missed adding the vorbis block-pool bitbuffer files for beta 3
authorMonty <xiphmont@xiph.org>
Fri, 17 Nov 2000 11:57:49 +0000 (11:57 +0000)
committerMonty <xiphmont@xiph.org>
Fri, 17 Nov 2000 11:57:49 +0000 (11:57 +0000)
svn path=/trunk/vorbis/; revision=1058

lib/bitbuffer.c [new file with mode: 0644]
lib/bitbuffer.h [new file with mode: 0644]

diff --git a/lib/bitbuffer.c b/lib/bitbuffer.c
new file mode 100644 (file)
index 0000000..6e96e1c
--- /dev/null
@@ -0,0 +1,68 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
+ * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
+ * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
+ * http://www.xiph.org/                                             *
+ *                                                                  *
+ ********************************************************************
+
+ function: flexible, delayed bitpacking abstraction
+ last mod: $Id: bitbuffer.c,v 1.1 2000/11/17 11:57:49 xiphmont Exp $
+
+ ********************************************************************/
+
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+#include "misc.h"
+#include "bitbuffer.h"
+
+/* done carefully to do two things:
+   1) no realloc
+   2) draws from our exact-size vorbis_block pool
+*/
+
+void bitbuf_init(vorbis_bitbuffer *vbb,vorbis_block *vb){
+  memset(vbb,0,sizeof(vorbis_bitbuffer));
+  vbb->vb=vb;
+  vbb->first=vbb->last=_vorbis_block_alloc(vb,sizeof(vorbis_bitbuffer_chain));
+  vbb->first->next=0; /* overengineering */
+}
+
+void bitbuf_write(vorbis_bitbuffer *vbb,unsigned long word,int length){
+  vorbis_block *vb=vbb->vb;
+  if(vbb->ptr>=_VBB_ALLOCSIZE){
+    vbb->last->next=_vorbis_block_alloc(vb,sizeof(vorbis_bitbuffer_chain));
+    vbb->last=vbb->last->next;
+    vbb->last->next=0; /* overengineering */
+    vbb->ptr=0;
+  }
+  vbb->last->words[vbb->ptr]=word;
+  vbb->last->bits[vbb->ptr++]=length;
+}
+
+void bitbuf_pack(oggpack_buffer *dest,vorbis_bitbuffer *vbb){
+  vorbis_block *vb=vbb->vb;
+  vorbis_bitbuffer_chain *vbc=vbb->first;
+  int i;
+  
+  while(vbc->next){
+    for(i=0;i<_VBB_ALLOCSIZE;i++)
+      oggpack_write(dest,vbc->words[i],vbc->bits[i]);
+    vbc=vbc->next;
+  }
+  for(i=0;i<vbb->ptr;i++)
+    oggpack_write(dest,vbc->words[i],vbc->bits[i]);
+}
+
+/* codebook variants for encoding to the bitbuffer */
+
+int vorbis_book_bufencode(codebook *book, int a, vorbis_bitbuffer *b){
+  bitbuf_write(b,book->codelist[a],book->c->lengthlist[a]);
+  return(book->c->lengthlist[a]);
+}
+
diff --git a/lib/bitbuffer.h b/lib/bitbuffer.h
new file mode 100644 (file)
index 0000000..862e0cb
--- /dev/null
@@ -0,0 +1,45 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
+ * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
+ * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
+ * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
+ * http://www.xiph.org/                                             *
+ *                                                                  *
+ ********************************************************************
+
+ function: flexible, delayed bitpacking abstraction
+ last mod: $Id: bitbuffer.h,v 1.1 2000/11/17 11:57:49 xiphmont Exp $
+
+ ********************************************************************/
+
+#ifndef _V_BITBUF_
+#define _V_BITBUF_
+
+#include "codebook.h"
+
+#define _VBB_ALLOCSIZE 128
+typedef struct vorbis_bitbuffer_chain{
+  ogg_uint32_t             words[_VBB_ALLOCSIZE];
+  int                      bits[_VBB_ALLOCSIZE];
+  struct vorbis_bitbuffer_chain *next;
+} vorbis_bitbuffer_chain;
+
+typedef struct vorbis_bitbuffer{
+  long                    ptr;
+  vorbis_bitbuffer_chain *first;
+  vorbis_bitbuffer_chain *last;
+  vorbis_block           *vb;
+} vorbis_bitbuffer;
+
+void bitbuf_init(vorbis_bitbuffer *vbb,vorbis_block *vb);
+extern void bitbuf_write(vorbis_bitbuffer *vbb,unsigned long word,int length);
+extern void bitbuf_pack(oggpack_buffer *dest,vorbis_bitbuffer *source);
+
+
+extern int vorbis_book_bufencode(codebook *book, int a, vorbis_bitbuffer *b);
+
+#endif