Commit 2ff10a2c authored by Monty's avatar Monty
Browse files

Minor changes to compile cleanly with MSVC++

added os.h
use alloca instead of non-constants in automatic declarations

Monty

svn path=/trunk/vorbis/; revision=172
parent d4b19020
# 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 $
###############################################################################
# #
......@@ -16,7 +16,7 @@
# (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)
......@@ -28,15 +28,13 @@ RANLIB=@RANLIB@
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)"
......@@ -50,8 +48,7 @@ analysis:
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
......@@ -93,4 +90,8 @@ info.o: modes.h
$(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
......@@ -14,16 +14,17 @@
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"
......@@ -81,8 +82,8 @@ int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
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];
......
......@@ -460,7 +460,7 @@ int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
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);
......
......@@ -33,7 +33,7 @@ int main(){
/* 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));
......@@ -46,7 +46,7 @@ int main(){
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));
......
......@@ -73,6 +73,7 @@ typedef struct lpclook{
drft_lookup fft;
/* en/decode lookups */
long *dscale;
int *iscale;
double *ifrac;
double *norm;
......
......@@ -14,14 +14,15 @@
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>
......@@ -158,7 +159,7 @@ int main(){
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);
}
......@@ -214,7 +215,7 @@ int main(){
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;
......
......@@ -14,13 +14,15 @@
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>
......
......@@ -25,6 +25,7 @@
#include <stdio.h>
#include <math.h>
#include "os.h"
#include "codec.h"
#include "mdct.h"
#include "envelope.h"
......@@ -55,11 +56,11 @@ void _ve_envelope_clear(envelope_lookup *e){
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]);
......@@ -70,7 +71,7 @@ static void _ve_deltas(double *deltas,double *pcm,int n,double *window,
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;
......
......@@ -408,7 +408,7 @@ char *ogg_sync_buffer(ogg_sync_state *oy, long size){
}
/* 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){
......
......@@ -14,7 +14,7 @@
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
********************************************************************/
......@@ -50,6 +50,7 @@ Carsten Bormann
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "os.h"
#include "smallft.h"
#include "lpc.h"
#include "xlogmap.h"
......@@ -63,7 +64,8 @@ Carsten Bormann
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 */
......@@ -119,7 +121,7 @@ double vorbis_lpc_from_data(double *data,double *lpc,int n,int m){
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;
......@@ -254,7 +256,7 @@ double vorbis_curve_to_lpc(double *curve,double *lpc,lpc_lookup *l){
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
......@@ -295,11 +297,9 @@ double vorbis_curve_to_lpc(double *curve,double *lpc,lpc_lookup *l){
/* 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 */
......@@ -333,7 +333,7 @@ void _vlpc_de_helper(double *curve,double *lpc,double amp,
/* 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);
......@@ -364,7 +364,7 @@ void vorbis_lpc_to_curve(double *curve,double *lpc,double amp,lpc_lookup *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){
......@@ -383,7 +383,7 @@ void vorbis_lpc_apply(double *residue,double *lpc,double amp,lpc_lookup *l){
}
}
/* 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){
......@@ -394,7 +394,8 @@ void vorbis_lpc_residue(double *coeff,double *prime,int m,
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++)
......@@ -424,7 +425,7 @@ void vorbis_lpc_predict(double *coeff,double *prime,int m,
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++)
......
......@@ -14,7 +14,7 @@
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
......@@ -27,12 +27,18 @@
#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 */
......@@ -72,8 +78,8 @@ void vorbis_lsp_to_lpc(double *lsp,double *lpc,int m){
}
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;
......@@ -132,8 +138,10 @@ static void cacm283(double *a,int ord,double *r){
/* 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. */
......
......@@ -41,6 +41,7 @@
#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. */
......@@ -97,9 +98,9 @@ void mdct_clear(mdct_lookup *l){
}
}
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 */
......@@ -200,8 +201,8 @@ static inline double *_mdct_kernel(double *x, double *w,
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;
......@@ -269,8 +270,8 @@ void mdct_forward(mdct_lookup *init, double *in, double *out, double *window){
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;
......
......@@ -37,7 +37,7 @@ vorbis_info predef_modes[]={
/* 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 */
......
......@@ -11,55 +11,28 @@
* *
********************************************************************
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
function: #ifdef jail to whip a few platforms into the UNIX ideal.
********************************************************************/
#include <stdlib.h>
#ifndef _V_IFDEFJAIL_H_
#define _V_IFDEFJAIL_H_
#include "codec.h"
#ifndef M_PI
#define M_PI (3.1415926539)
#endif
/* 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
*/
#ifndef rint
/* not strictly correct, but Vorbis doesn't care */
#define rint(x) (floor((x)+0.5))
#endif
typedef struct vorbis_codebook{
#ifndef alloca
#ifdef _WIN32
#define alloca(x) (_alloca(x))
#endif
#endif
int entries;
/*** codebook side ****************************************************/
#endif
/* 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;
......@@ -14,12 +14,13 @@
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"
......@@ -27,7 +28,7 @@
/* 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. */
......@@ -45,7 +46,7 @@ int _vs_spectrum_encode(vorbis_block *vb,double amp,double *lsp){
int bits=rint(log(n)/log(2));
int i;
_oggpack_write(&vb->opb,amp*327680,18);
for(i=0;i<m;i++){
......@@ -53,7 +54,8 @@ int _vs_spectrum_encode(vorbis_block *vb,double amp,double *lsp){
_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];
}
......@@ -91,8 +93,8 @@ void _vs_residue_quantize(double *data,double *curve,
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;
......
......@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "os.h"
#include "codec.h"
#include "vorbisfile.h"
......
......@@ -14,12 +14,13 @@
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) */
......@@ -52,3 +53,4 @@ double *_vorbis_window(int window,int left,int right){
return(ret);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment