********************************************************************
function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.3 2000/01/05 03:10:24 xiphmont Exp $
+ last mod: $Id: chaining_example.c,v 1.4 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codec.h"
#include "vorbis/vorbisfile.h"
+#include "../lib/misc.h"
int main(){
OggVorbis_File ov;
********************************************************************
function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.24 2000/02/23 09:24:21 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.25 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codec.h"
#include "bitwise.h"
#include "registry.h"
+#include "misc.h"
/* decides between modes, dispatches to the appropriate mapping. */
int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
********************************************************************
function: packing variable sized words into an octet stream
- last mod: $Id: bitwise.c,v 1.9 2000/02/23 09:24:22 xiphmont Exp $
+ last mod: $Id: bitwise.c,v 1.10 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include <string.h>
#include <stdlib.h>
#include "bitwise.h"
+#include "misc.h"
#define BUFFER_INCREMENT 256
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.27 2000/02/23 11:22:43 xiphmont Exp $
+ last mod: $Id: block.c,v 1.28 2000/03/10 13:21:18 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
#include "bitwise.h"
#include "registry.h"
#include "bookinternal.h"
+#include "misc.h"
static int ilog2(unsigned int v){
int ret=0;
if(v){
vorbis_info *vi=v->vi;
- if(v->window[0][0][0])
- for(i=0;i<VI_WINDOWB;i++){
+ if(v->window[0][0][0]){
+ for(i=0;i<VI_WINDOWB;i++)
if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
- for(j=0;j<2;j++)
- for(k=0;k<2;k++)
+ free(v->window[0][0][0]);
+
+ for(j=0;j<2;j++)
+ for(k=0;k<2;k++){
+ for(i=0;i<VI_WINDOWB;i++)
if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
- }
-
+ free(v->window[1][j][k]);
+ }
+ }
+
if(v->pcm){
for(i=0;i<vi->channels;i++)
if(v->pcm[i])free(v->pcm[i]);
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.11 2000/02/23 09:24:26 xiphmont Exp $
+ last mod: $Id: codebook.c,v 1.12 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codebook.h"
#include "bitwise.h"
#include "bookinternal.h"
+#include "misc.h"
/**** pack/unpack helpers ******************************************/
static int ilog(unsigned int v){
********************************************************************
function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.15 2000/02/07 20:03:16 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
Preecho calculation.
#include "envelope.h"
#include "bitwise.h"
#include "window.h"
+#include "misc.h"
void _ve_envelope_init(envelope_lookup *e,int samples_per){
int i;
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.11 2000/02/23 11:22:44 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.12 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "lsp.h"
#include "bookinternal.h"
#include "scales.h"
+#include "misc.h"
typedef struct {
long n;
function: code raw [Vorbis] packets into framed OggSquish stream and
decode Ogg streams back into raw packets
- last mod: $Id: framing.c,v 1.14 2000/01/12 11:34:40 xiphmont Exp $
+ last mod: $Id: framing.c,v 1.15 2000/03/10 13:21:18 xiphmont Exp $
note: The CRC code is directly derived from public domain code by
Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
#include <stdlib.h>
#include <string.h>
#include "vorbis/codec.h"
+#include "misc.h"
/* A complete description of Ogg framing exists in docs/framing.html */
********************************************************************
function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.22 2000/02/23 11:50:29 xiphmont Exp $
+ last mod: $Id: info.c,v 1.23 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "registry.h"
#include "window.h"
#include "psy.h"
+#include "misc.h"
/* helpers */
static int ilog2(unsigned int v){
********************************************************************
function: LSP (also called LSF) conversion routines
- last mod: $Id: lsp.c,v 1.4 1999/12/30 07:26:42 xiphmont Exp $
+ last mod: $Id: lsp.c,v 1.5 2000/03/10 13:21:18 xiphmont Exp $
The LSP generation code is taken (with minimal modification) from
"On the Computation of the LSP Frequencies" by Joseph Rothweiler
#include <string.h>
#include <stdlib.h>
#include "os.h"
+#include "misc.h"
void vorbis_lsp_to_lpc(double *lsp,double *lpc,int m){
int i,j,m2=m/2;
function: normalized modified discrete cosine transform
power of two length transform only [16 <= n ]
- last mod: $Id: mdct.c,v 1.15 2000/02/09 22:04:15 xiphmont Exp $
+ last mod: $Id: mdct.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
Algorithm adapted from _The use of multirate filter banks for coding
of high quality digital audio_, by T. Sporer, K. Brandenburg and
#include <math.h>
#include "mdct.h"
#include "os.h"
+#include "misc.h"
/* build lookups for trig functions; also pre-figure scaling and
some window function algebra. */
********************************************************************
function: miscellaneous prototypes
- last mod: $Id: misc.h,v 1.2 2000/02/23 09:24:30 xiphmont Exp $
+ last mod: $Id: misc.h,v 1.3 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#ifndef _V_RANDOM_H_
#define _V_RANDOM_H_
+#include "vorbis/codec.h"
extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
extern void _vorbis_block_ripcord(vorbis_block *vb);
extern void _analysis_output(char *base,int i,double *v,int n);
+#ifdef DEBUG_LEAKS
+extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
+extern void _VDBG_free(void *ptr,char *file,long line);
+
+#ifndef MISC_C
+#undef malloc
+#undef calloc
+#undef realloc
+#undef free
+
+#define malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
+#define calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
+#define realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
+#define free(x) _VDBG_free((x),__FILE__,__LINE__)
+#endif
+#endif
+
#endif
********************************************************************
function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.16 2000/02/12 08:33:07 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.17 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "lpc.h"
#include "smallft.h"
#include "scales.h"
+#include "misc.h"
/* Set up decibel threshhold slopes on a Bark frequency scale */
********************************************************************
function: registry for time, floor, res backends and channel mappings
- last mod: $Id: registry.c,v 1.2 2000/01/22 13:28:29 xiphmont Exp $
+ last mod: $Id: registry.c,v 1.3 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/codec.h"
#include "registry.h"
+#include "misc.h"
/* seems like major overkill now; the backend numbers will grow into
the infrastructure soon enough */
********************************************************************
function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.7 2000/02/09 22:04:16 xiphmont Exp $
+ last mod: $Id: smallft.c,v 1.8 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include <string.h>
#include <math.h>
#include "smallft.h"
+#include "misc.h"
static void drfti1(int n, double *wa, int *ifac){
static int ntryh[4] = { 4,2,3,5 };
********************************************************************
function: time backend 0 (dummy)
- last mod: $Id: time0.c,v 1.4 2000/02/23 09:24:32 xiphmont Exp $
+ last mod: $Id: time0.c,v 1.5 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include <string.h>
#include "vorbis/codec.h"
#include "registry.h"
+#include "misc.h"
static void pack (vorbis_info_time *i,oggpack_buffer *opb){
}
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.15 2000/02/23 11:22:47 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.16 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include "vorbis/vorbisfile.h"
#include "os.h"
+#include "misc.h"
/* A 'chained bitstream' is a Vorbis bitstream that contains more than
one logical bitstream arranged end to end (the only form of Ogg
goto bail_header;
}
}
- ogg_stream_clear(&vf->os);
return 0;
bail_header:
_seek_helper(vf,vf->offsets[i]);
if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL)==-1){
fprintf(stderr,"Error opening logical bitstream #%d.\n\n",i+1);
-
- ogg_stream_clear(&vf->os); /* clear local storage. This is not
- done in _fetch_headers, as that may
- be called in a non-seekable stream
- (in which case, we need to preserve
- the stream local storage) */
- vf->dataoffsets[i]=-1;
- }else
+ vf->dataoffsets[i]=-1;
+ }else{
vf->dataoffsets[i]=vf->offset;
+ ogg_stream_clear(&vf->os);
+ }
}
/* get the serial number and PCM length of this link. To do this,
}
}
+static int _make_decode_ready(OggVorbis_File *vf){
+ if(vf->decode_ready)exit(1);
+ vorbis_synthesis_init(&vf->vd,vf->vi);
+ vorbis_block_init(&vf->vd,&vf->vb);
+ vf->decode_ready=1;
+ return(0);
+}
+
static int _open_seekable(OggVorbis_File *vf){
vorbis_info initial_i;
vorbis_comment initial_c;
ogg_page og;
/* is this even vorbis...? */
- vorbis_info_init(&initial_i);
- vorbis_comment_init(&initial_c);
ret=_fetch_headers(vf,&initial_i,&initial_c,&serialno);
dataoffset=vf->offset;
ogg_stream_clear(&vf->os);
/* we cannot seek. Set up a 'single' (current) logical bitstream entry */
vf->links=1;
vf->vi=malloc(sizeof(vorbis_info));
+ vf->vc=malloc(sizeof(vorbis_info));
/* Try to fetch the headers, maintaining all the storage */
if(_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno)==-1)return(-1);
-
+ _make_decode_ready(vf);
+
return 0;
}
leave machine uninitialized */
vf->current_link=link;
+
+ ogg_stream_init(&vf->os,vf->current_serialno);
+ ogg_stream_reset(&vf->os,ogg_page_pageno(&og));
+
}else{
/* we're streaming */
/* fetch the three header packets, build the info struct */
link=0;
}
- /* reload */
- ogg_stream_init(&vf->os,vf->current_serialno);
- ogg_stream_reset(&vf->os,ogg_page_pageno(&og));
- vorbis_synthesis_init(&vf->vd,vf->vi+link);
- vorbis_block_init(&vf->vd,&vf->vb);
- vf->decode_ready=1;
+ _make_decode_ready(vf);
}
ogg_stream_pagein(&vf->os,&og);
}
vorbis_comment_clear(vf->vc+i);
}
free(vf->vi);
+ free(vf->vc);
}
if(vf->dataoffsets)free(vf->dataoffsets);
if(vf->pcmlengths)free(vf->pcmlengths);
if(vf->f)fclose(vf->f);
memset(vf,0,sizeof(OggVorbis_File));
}
+ _VDBG_dump();
return(0);
}
if(ret){
vf->f=NULL;
ov_clear(vf);
- }else{
- ogg_stream_init(&vf->os,vf->current_serialno);
- vorbis_synthesis_init(&vf->vd,vf->vi);
- vorbis_block_init(&vf->vd,&vf->vb);
- vf->decode_ready=1;
}
return(ret);
}
********************************************************************
function: window functions
- last mod: $Id: window.c,v 1.6 2000/02/06 13:39:48 xiphmont Exp $
+ last mod: $Id: window.c,v 1.7 2000/03/10 13:21:18 xiphmont Exp $
********************************************************************/
#include <stdlib.h>
#include <math.h>
#include "os.h"
+#include "misc.h"
double *_vorbis_window(int type, int window,int left,int right){
double *ret=calloc(window,sizeof(double));