# vorbis makefile configured for use with gcc on any platform
-# $Id: Makefile.in,v 1.14 1999/11/02 23:27:32 xiphmont Exp $
+# $Id: Makefile.in,v 1.15 1999/11/17 03:52:56 xiphmont Exp $
###############################################################################
# #
# (unless, of course, you know what you are doing :) ##########################
@SET_MAKE@
-FLAGS=-I. @TYPESIZES@ @CFLAGS@
+FLAGS=-I. @TYPESIZES@ @CFLAGS@
OPT=@OPT@ $(FLAGS)
DEBUG=@DEBUG@ $(FLAGS)
PROFILE=@PROFILE@ $(FLAGS)
LIBS=@LIBS@ -lm
HFILES = mdct.h codec.h bitwise.h envelope.h lpc.h lsp.h \
- psy.h smallft.h window.h xlogmap.h
-
+ psy.h smallft.h window.h xlogmap.h os.h
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
+BINFILES = encoder_example decoder_example chaining_example
all:
$(MAKE) target CFLAGS="$(OPT)"
profile:
$(MAKE) target CFLAGS="$(PROFILE)"
-target: libvorbis.a vorbisfile.a \
- encoder_example decoder_example chaining_example
+target: libvorbis.a vorbisfile.a $(BINFILES)
selftest:
$(MAKE) clean
$(CC) $(CFLAGS) -c $<
clean:
- -rm -f *.o *.a test* *~ *.out ogg config.* dsptest
+ -rm -f *.o *.a test* *~ *.out ogg config.* $(BINFILES) tone
+
+distclean: clean
+ -rf -f Makefile
+
function: single-block PCM analysis
author: Monty <xiphmont@mit.edu>
modifications by: Monty
- last modification date: Oct 21 1999
+ last modification date: Nov 16 1999
********************************************************************/
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include "os.h"
+#include "codec.h"
#include "lpc.h"
#include "lsp.h"
-#include "codec.h"
#include "envelope.h"
#include "mdct.h"
#include "psy.h"
for(i=0;i<vi->channels;i++){
static int frameno=0;
int j;
- double floor[n/2];
- double curve[n/2];
+ double *floor=alloca(n/2*sizeof(double));
+ double *curve=alloca(n/2*sizeof(double));
double *lpc=vb->lpc[i];
double *lsp=vb->lsp[i];
things crystallize */
lpc_init(&v->vl[0],vi->blocksize[0]/2,vi->blocksize[0]/2,
vi->floororder[0],vi->flooroctaves[0],0);
- lpc_init(&v->vl[1],vi->blocksize[1]/2,vi->blocksize[1]/2,
+ lpc_init(&v->vl[1],vi->blocksize[1]/2,vi->blocksize[1]/4,
vi->floororder[1],vi->flooroctaves[1],0);
/*lpc_init(&v->vbal[0],vi->blocksize[0]/2,256,
vi->balanceorder,vi->balanceoctaves,0);
/* print details about each logical bitstream in the input */
if(ov_seekable(&ov)){
- printf("Input bitstream contained %d logical bitstream section(s).\n",
+ printf("Input bitstream contained %ld logical bitstream section(s).\n",
ov_streams(&ov));
printf("Total bitstream playing time: %ld seconds\n\n",
(long)ov_time_total(&ov,-1));
for(i=0;i<ov_streams(&ov);i++){
vorbis_info *vi=ov_info(&ov,i);
printf("\tlogical bitstream section %d information:\n",i+1);
- printf("\t\t%ldHz %d channels bitrate %dkbps serial number=%ld\n",
+ printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
ov_serialnumber(&ov,i));
printf("\t\tcompressed length: %ld bytes ",ov_raw_total(&ov,i));
drft_lookup fft;
/* en/decode lookups */
+ long *dscale;
int *iscale;
double *ifrac;
double *norm;
+++ /dev/null
-/********************************************************************
- * *
- * 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: coder backend; handles encoding into and decoding from
- codewords, codebook generation, and codebook transmission
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- last modification date: Oct 13 1999
-
- ********************************************************************/
-
-#include <stdlib.h>
-
-#include "codec.h"
-
-/* several basic functions:
-
- create codebooks from representation
- create codebooks from data
- encode codebooks
- decode codebooks
-
- encode using codebook
- decode using codebook
- map an entry to a sparse codebook's (eg, VQ) codeword index
-*/
-
-typedef struct vorbis_codebook{
-
- int entries;
-
- /*** codebook side ****************************************************/
-
- /* encode side tree structure (indice->codeword) */
- int *codewords; /* null if indice==codeword (ie fixed len codeword) */
- int *codelengths; /* null if indice==codeword */
- int len; /* -1 if varlength */
-
- /* decode side tree structure (codeword->indice) */
-
- int *tree; /* null if codeword==indice */
-
- /*** mapping side *****************************************************/
-
- int wordsper;
-
- /* decode is easy */
- int remaining;
- int *mapping;
-
- /* encode in the VQ case is what's hard. We need to find the
- 'closest match' out of a large n-dimentional space */
-
-
-} vorbis_codebook;
function: simple example decoder
author: Monty <xiphmont@mit.edu>
modifications by: Monty
- last modification date: Oct 29 1999
+ last modification date: Nov 16 1999
********************************************************************/
/* Takes a vorbis bitstream from stdin and writes raw stereo PCM to
- stdout. Decodes simple and chained OggVorbis files from beginning to
- end.
-*/
+ stdout. Decodes simple and chained OggVorbis files from beginning
+ to end. Vorbisfile.a is somewhat more complex than the code below. */
+
+/* Note that this is POSIX, not ANSI code */
#include <stdio.h>
#include <math.h>
fprintf(stderr,"%s\n",*ptr);
++ptr;
}
- fprintf(stderr,"\nBitstream is %d channel, %dHz\n",vi.channels,vi.rate);
+ fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
fprintf(stderr,"Encoded by: %s\n\n",vi.vendor);
}
int16_t *ptr=convbuffer+i;
double *mono=pcm[i];
for(j=0;j<out;j++){
- int val=rint(mono[j]*32767.);
+ int val=mono[j]*32767.;
/* might as well guard against clipping */
if(val>32767){
val=32767;
function: simple example encoder
author: Monty <xiphmont@mit.edu>
modifications by: Monty
- last modification date: Oct 29 1999
+ last modification date: Nov 16 1999
********************************************************************/
/* takes a stereo 16bit 44.1kHz WAV file from stdin and encodes it into
a Vorbis bitstream */
+/* Note that this is POSIX, not ANSI, code */
+
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
+#include "os.h"
#include "codec.h"
#include "mdct.h"
#include "envelope.h"
static void _ve_deltas(double *deltas,double *pcm,int n,double *window,
int winsize,mdct_lookup *m){
int i,j;
- double out[winsize/2];
+ double *out=alloca(sizeof(double)*winsize/2);
for(j=0;j<n;j++){
double acc=0.;
-
+
mdct_forward(m,pcm+j*winsize,out,window);
for(i=winsize/10;i<winsize/2;i++)
acc+=fabs(out[i]);
void _ve_envelope_deltas(vorbis_dsp_state *v){
vorbis_info *vi=v->vi;
int step=vi->envelopesa;
-
+
int dtotal=v->pcm_current/vi->envelopesa;
int dcurr=v->envelope_current;
int pch;
}
/* expose a segment at least as large as requested at the fill mark */
- return(oy->data+oy->fill);
+ return((char *)oy->data+oy->fill);
}
int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
function: LPC low level routines
author: Monty <monty@xiph.org>
modifications by: Monty
- last modification date: Oct 18 1999
+ last modification date: Nov 16 1999
********************************************************************/
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include "os.h"
#include "smallft.h"
#include "lpc.h"
#include "xlogmap.h"
double vorbis_lpc_from_data(double *data,double *lpc,int n,int m){
- double aut[m+1],error;
+ double *aut=alloca(sizeof(double)*(m+1));
+ double error;
int i,j;
/* autocorrelation, p+1 lag coefficients */
double vorbis_lpc_from_spectrum(double *curve,double *lpc,lpc_lookup *l){
int n=l->ln;
int m=l->m;
- double work[n+n];
+ double *work=alloca(sizeof(double)*(n+n));
double fscale=.5/n;
int i,j;
slightly if mapped != n */
int mapped=l->ln;
- double work[mapped];
+ double *work=alloca(sizeof(double)*mapped);
int i;
/* fairly correct for low frequencies, naieve for high frequencies
/* One can do this the long way by generating the transfer function in
the time domain and taking the forward FFT of the result. The
- results from direct calculation are cleaner and faster. If one
- looks at the below in the context of the calling function, there's
- lots of redundant trig, but at least it's clear */
+ results from direct calculation are cleaner and faster.
-/* This version does a linear curve generation and then later
+ This version does a linear curve generation and then later
interpolates the log curve from the linear curve. This could stand
optimization; it could both be more precise as well as not compute
quite a few unused values */
/* generate the whole freq response curve on an LPC IIR filter */
void vorbis_lpc_to_curve(double *curve,double *lpc,double amp,lpc_lookup *l){
- double lcurve[l->ln*2];
+ double *lcurve=alloca(sizeof(double)*(l->ln*2));
int i;
_vlpc_de_helper(lcurve,lpc,amp,l);
}
void vorbis_lpc_apply(double *residue,double *lpc,double amp,lpc_lookup *l){
- double lcurve[l->ln*2];
+ double *lcurve=alloca(sizeof(double)*((l->ln+l->n)*2));
int i;
if(amp==0){
}
}
-/* subtract or add an lpc filter to data */
+/* subtract or add an lpc filter to data. Vorbis doesn't actually use this. */
void vorbis_lpc_residue(double *coeff,double *prime,int m,
double *data,long n){
out: data[0...n-1] residuals from LPC prediction */
long i,j;
- double work[m+n],y;
+ double *work=alloca(sizeof(double)*(m+n));
+ double y;
if(!prime)
for(i=0;i<m;i++)
long i,j,o,p;
double y;
- double work[n+m];
+ double *work=alloca(sizeof(double)*(m+n));
if(!prime)
for(i=0;i<m;i++)
function: LSP (also called LSF) conversion routines
author: Monty <monty@xiph.org>
modifications by: Monty
- last modification date: Aug 03 1999
+ last modification date: Nov 16 1999
The LSP generation code is taken (with minimal modification) from
"On the Computation of the LSP Frequencies" by Joseph Rothweiler
#include <math.h>
#include <string.h>
#include <stdlib.h>
+#include "os.h"
void vorbis_lsp_to_lpc(double *lsp,double *lpc,int m){
int i,j,m2=m/2;
- double O[m2],E[m2];
- double A,Ae[m2+1],Ao[m2+1];
- double B,Be[m2],Bo[m2];
+ double *O=alloca(sizeof(double)*m2);
+ double *E=alloca(sizeof(double)*m2);
+ double A;
+ double *Ae=alloca(sizeof(double)*(m2+1));
+ double *Ao=alloca(sizeof(double)*(m2+1));
+ double B;
+ double *Be=alloca(sizeof(double)*(m2));
+ double *Bo=alloca(sizeof(double)*(m2));
double temp;
/* even/odd roots setup */
}
static void kw(double *r,int n) {
- double s[n/2+1];
- double c[n+1];
+ double *s=alloca(sizeof(double)*(n/2+1));
+ double *c=alloca(sizeof(double)*(n+1));
int i, j, k;
s[0] = 1.0;
/* Convert lpc coefficients to lsp coefficients */
void vorbis_lpc_to_lsp(double *lpc,double *lsp,int m){
int order2=m/2;
- double g1[order2+1], g2[order2+1];
- double g1r[order2+1], g2r[order2+1];
+ double *g1=alloca(sizeof(double)*(order2+1));
+ double *g2=alloca(sizeof(double)*(order2+1));
+ double *g1r=alloca(sizeof(double)*(order2+1));
+ double *g2r=alloca(sizeof(double)*(order2+1));
int i;
/* Compute the lengths of the x polynomials. */
#include <string.h>
#include <math.h>
#include "mdct.h"
+#include "os.h"
/* build lookups for trig functions; also pre-figure scaling and
some window function algebra. */
}
}
-static inline double *_mdct_kernel(double *x, double *w,
- int n, int n2, int n4, int n8,
- mdct_lookup *init){
+static double *_mdct_kernel(double *x, double *w,
+ int n, int n2, int n4, int n8,
+ mdct_lookup *init){
int i;
/* step 2 */
void mdct_forward(mdct_lookup *init, double *in, double *out, double *window){
int n=init->n;
- double x[n/2];
- double w[n/2];
+ double *x=alloca(sizeof(double)*(n/2));
+ double *w=alloca(sizeof(double)*(n/2));
double *xx;
int n2=n>>1;
int n4=n>>2;
void mdct_backward(mdct_lookup *init, double *in, double *out, double *window){
int n=init->n;
- double x[n/2];
- double w[n/2];
+ double *x=alloca(sizeof(double)*(n/2));
+ double *w=alloca(sizeof(double)*(n/2));
double *xx;
int n2=n>>1;
int n4=n>>2;
/* dummy, dummy, dummy, dummy */
0, NULL, 0, NULL,
/* smallblock, largeblock, LPC order (small, large) */
- {512, 4096}, {16,16},
+ {2048, 2048}, {16,16},
/* spectral octaves (small, large), spectral channels */
{5,5}, 2,
/* thresh sample period, preecho clamp trigger threshhold, range, dummy */
--- /dev/null
+/********************************************************************
+ * *
+ * 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: #ifdef jail to whip a few platforms into the UNIX ideal.
+
+ ********************************************************************/
+
+#ifndef _V_IFDEFJAIL_H_
+#define _V_IFDEFJAIL_H_
+
+#ifndef M_PI
+#define M_PI (3.1415926539)
+#endif
+
+#ifndef rint
+/* not strictly correct, but Vorbis doesn't care */
+#define rint(x) (floor((x)+0.5))
+#endif
+
+#ifndef alloca
+#ifdef _WIN32
+#define alloca(x) (_alloca(x))
+#endif
+#endif
+
+#endif
+
+
function: spectrum envelope and residue code/decode
author: Monty <xiphmont@mit.edu>
modifications by: Monty
- last modification date: Oct 17 1999
+ last modification date: Nov 16 1999
********************************************************************/
#include <stdio.h>
#include <math.h>
+#include "os.h"
#include "codec.h"
#include "bitwise.h"
#include "spectrum.h"
/* this code is still seriously abbreviated. I'm filling in pieces as
we go... --Monty 19991004 */
-/* unlike other LPC-based coders, we never apply the filter, only
+/* unlike other LPC-based coders, we never apply the filter but only
inspect the frequency response, thus we don't need to guard against
instability. However, two coefficients quantising to the same
value will cause the response to explode. */
int bits=rint(log(n)/log(2));
int i;
-
+
_oggpack_write(&vb->opb,amp*327680,18);
for(i=0;i<m;i++){
_oggpack_write(&vb->opb,val,bits);
lsp[i]=(last+=val)*M_PI/n;
- /* Underpowered but sufficient */
+ /* Underpowered but sufficient for now. In the real spec (coming
+ soon), a distance of zero can't happen. */
if(lsp[i]<dlast+min)lsp[i]=dlast+min;
dlast=lsp[i];
}
int i;
for(i=0;i<n;i++){
-
- int val=rint(data[i]/curve[i]);
+ int val=0;
+ if(curve[i]!=0.)val=rint(data[i]/curve[i]);
if(val>16)val=16;
if(val<-16)val=-16;
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
+#include "os.h"
#include "codec.h"
#include "vorbisfile.h"
function: window functions
author: Monty <xiphmont@mit.edu>
modifications by: Monty
- last modification date: Jul 27 1999
+ last modification date: Nov 16 1999
********************************************************************/
#include <stdlib.h>
#include <math.h>
+#include "os.h"
/* The 'vorbis window' is sin(sin(x)*sin(x)*2pi) */
return(ret);
}
+