[xiph-cvs] cvs commit: vorbis/lib bitbuffer.c bitbuffer.h

Monty xiphmont at xiph.org
Fri Nov 17 03:57:51 PST 2000



xiphmont    00/11/17 03:57:51

  Added:       lib      bitbuffer.c bitbuffer.h
  Log:
  missed adding the vorbis block-pool bitbuffer files for beta 3

Revision  Changes    Path
1.1                  vorbis/lib/bitbuffer.c

Index: bitbuffer.c
===================================================================
/********************************************************************
 *                                                                  *
 * 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 at 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]);
}

1.1                  vorbis/lib/bitbuffer.h

Index: bitbuffer.h
===================================================================
/********************************************************************
 *                                                                  *
 * 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 at 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

--- >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