# vorbis makefile configured for use with gcc on any platform
-# $Id: Makefile.in,v 1.2 1999/07/13 07:48:11 mwhitson Exp $
+# $Id: Makefile.in,v 1.3 1999/12/30 03:46:16 xiphmont Exp $
###############################################################################
# #
@SET_MAKE@
-SUBDIRS = lib cmdline
+SUBDIRS = lib examples #cmdline
all debug profile selftest target clean:
@for dir in $(SUBDIRS); do (cd $$dir && $(MAKE) $(MFLAGS) $@) || exit 1; done
# glibc 2.0/2.1
case $host in
- i?86-*-linux*)
- DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char"
- OPT="-O20 -ffast-math -D__NO_MATH_INLINES -fsigned-char"
- PROFILE="-pg -g -O20 -D__NO_MATH_INLINES -fsigned-char";;
+ *-*-linux*)
+ DEBUG="-g -Wall -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
+ OPT="-O20 -ffast-math -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
+ PROFILE="-pg -g -O20 -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char";;
sparc-sun-*)
DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char -mv8"
OPT="-O20 -ffast-math -D__NO_MATH_INLINES -fsigned-char -mv8"
ac_given_srcdir=$srcdir
-trap 'rm -fr `echo "Makefile lib/Makefile cmdline/Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+trap 'rm -fr `echo "Makefile lib/Makefile examples/Makefile vq/Makefile cmdline/Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
EOF
cat >> $CONFIG_STATUS <<EOF
cat >> $CONFIG_STATUS <<EOF
-CONFIG_FILES=\${CONFIG_FILES-"Makefile lib/Makefile cmdline/Makefile"}
+CONFIG_FILES=\${CONFIG_FILES-"Makefile lib/Makefile examples/Makefile vq/Makefile cmdline/Makefile"}
EOF
cat >> $CONFIG_STATUS <<\EOF
for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
-# $Id: configure.in,v 1.6 1999/12/17 07:04:11 xiphmont Exp $
+# $Id: configure.in,v 1.7 1999/12/30 03:46:18 xiphmont Exp $
AC_INIT(lib/mdct.c)
#AC_CONFIG_HEADER(config.h)
# glibc 2.0/2.1
case $host in
- i?86-*-linux*)
- DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char"
- OPT="-O20 -ffast-math -D__NO_MATH_INLINES -fsigned-char"
- PROFILE="-pg -g -O20 -D__NO_MATH_INLINES -fsigned-char";;
+ *-*-linux*)
+ DEBUG="-g -Wall -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
+ OPT="-O20 -ffast-math -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"
+ PROFILE="-pg -g -O20 -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char";;
sparc-sun-*)
DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char -mv8"
OPT="-O20 -ffast-math -D__NO_MATH_INLINES -fsigned-char -mv8"
#AC_SUBST(LIBGTKDIR)
AC_SUBST(pthread_lib)
-AC_OUTPUT(Makefile lib/Makefile cmdline/Makefile vq/Makefile)
+AC_OUTPUT(Makefile lib/Makefile examples/Makefile vq/Makefile cmdline/Makefile)
--- /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: illustrate simple use of chained bitstream and vorbisfile.a
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ last modification date: Nov 02 1999
+
+ ********************************************************************/
+
+#include "codec.h"
+#include "vorbisfile.h"
+
+int main(){
+ OggVorbis_File ov;
+ int i;
+
+ /* open the file/pipe on stdin */
+ if(ov_open(stdin,&ov,NULL,-1)==-1){
+ printf("Could not open input as an OggVorbis file.\n\n");
+ exit(1);
+ }
+
+ /* print details about each logical bitstream in the input */
+ if(ov_seekable(&ov)){
+ 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));
+
+ }else{
+ printf("Standard input was not seekable.\n"
+ "First logical bitstream information:\n\n");
+ }
+
+ 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 %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));
+ printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
+ }
+
+ ov_clear(&ov);
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /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: simple example decoder
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ 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. Vorbisfile.a is somewhat more complex than the code below. */
+
+/* Note that this is POSIX, not ANSI code */
+
+#include <stdio.h>
+#include <math.h>
+#include "codec.h"
+
+int16_t convbuffer[4096]; /* take 8k out of the data segment, not the stack */
+int convsize=4096;
+
+int main(){
+ ogg_sync_state oy; /* sync and verify incoming physical bitstream */
+ ogg_stream_state os; /* take physical pages, weld into a logical
+ stream of packets */
+ ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
+ ogg_packet op; /* one raw packet of data for decode */
+
+ vorbis_info vi; /* struct that stores all the static vorbis bitstream
+ settings */
+ vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+ vorbis_block vb; /* local working space for packet->PCM decode */
+
+ char *buffer;
+ int bytes;
+
+ /********** Decode setup ************/
+
+ ogg_sync_init(&oy); /* Now we can read pages */
+
+ while(1){ /* we repeat if the bitstream is chained */
+ int eos=0;
+ int i;
+
+ /* grab some data at the head of the stream. We want the first page
+ (which is guaranteed to be small and only contain the Vorbis
+ stream initial header) We need the first page to get the stream
+ serialno. */
+
+ /* submit a 4k block to libvorbis' Ogg layer */
+ buffer=ogg_sync_buffer(&oy,4096);
+ bytes=fread(buffer,1,4096,stdin);
+ ogg_sync_wrote(&oy,bytes);
+
+ /* Get the first page. */
+ if(ogg_sync_pageout(&oy,&og)!=1){
+ /* have we simply run out of data? If so, we're done. */
+ if(bytes<4096)break;
+
+ /* error case. Must not be Vorbis data */
+ fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
+ exit(1);
+ }
+
+ /* Get the serial number and set up the rest of decode. */
+ /* serialno first; use it to set up a logical stream */
+ ogg_stream_init(&os,ogg_page_serialno(&og));
+
+ /* extract the initial header from the first page and verify that the
+ Ogg bitstream is in fact Vorbis data */
+
+ /* I handle the initial header first instead of just having the code
+ read all three Vorbis headers at once because reading the initial
+ header is an easy way to identify a Vorbis bitstream and it's
+ useful to see that functionality seperated out. */
+
+ vorbis_info_init(&vi);
+ if(ogg_stream_pagein(&os,&og)<0){
+ /* error; stream version mismatch perhaps */
+ fprintf(stderr,"Error reading first page of Ogg bitstream data.\n");
+ exit(1);
+ }
+
+ if(ogg_stream_packetout(&os,&op)!=1){
+ /* no page? must not be vorbis */
+ fprintf(stderr,"Error reading initial header packet.\n");
+ exit(1);
+ }
+
+ if(vorbis_info_headerin(&vi,&op)<0){
+ /* error case; not a vorbis header */
+ fprintf(stderr,"This Ogg bitstream does not contain Vorbis "
+ "audio data.\n");
+ exit(1);
+ }
+
+ /* At this point, we're sure we're Vorbis. We've set up the logical
+ (Ogg) bitstream decoder. Get the comment and codebook headers and
+ set up the Vorbis decoder */
+
+ /* The next two packets in order are the comment and codebook headers.
+ They're likely large and may span multiple pages. Thus we reead
+ and submit data until we get our two pacakets, watching that no
+ pages are missing. If a page is missing, error out; losing a
+ header page is the only place where missing data is fatal. */
+
+ i=0;
+ while(i<2){
+ while(i<2){
+ int result=ogg_sync_pageout(&oy,&og);
+ if(result==0)break; /* Need more data */
+ /* Don't complain about missing or corrupt data yet. We'll
+ catch it at the packet output phase */
+ if(result==1){
+ ogg_stream_pagein(&os,&og); /* we can ignore any errors here
+ as they'll also become apparent
+ at packetout */
+ while(i<2){
+ result=ogg_stream_packetout(&os,&op);
+ if(result==0)break;
+ if(result==-1){
+ /* Uh oh; data at some point was corrupted or missing!
+ We can't tolerate that in a header. Die. */
+ fprintf(stderr,"Corrupt secondary header. Exiting.\n");
+ exit(1);
+ }
+ vorbis_info_headerin(&vi,&op);
+ i++;
+ }
+ }
+ }
+ /* no harm in not checking before adding more */
+ buffer=ogg_sync_buffer(&oy,4096);
+ bytes=fread(buffer,1,4096,stdin);
+ if(bytes==0){
+ fprintf(stderr,"End of file before finding all Vorbis headers!\n");
+ exit(1);
+ }
+ ogg_sync_wrote(&oy,bytes);
+ }
+
+ /* Throw the comments plus a few lines about the bitstream we're
+ decoding */
+ {
+ char **ptr=vi.user_comments;
+ while(*ptr){
+ fprintf(stderr,"%s\n",*ptr);
+ ++ptr;
+ }
+ fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
+ fprintf(stderr,"Encoded by: %s\n\n",vi.vendor);
+ }
+
+ convsize=4096/vi.channels;
+
+ /* OK, got and parsed all three headers. Initialize the Vorbis
+ packet->PCM decoder. */
+ vorbis_synthesis_init(&vd,&vi); /* central decode state */
+ vorbis_block_init(&vd,&vb); /* local state for most of the decode
+ so multiple block decodes can
+ proceed in parallel. We could init
+ multiple vorbis_block structures
+ for vd here */
+
+ /* The rest is just a straight decode loop until end of stream */
+ while(!eos){
+ while(!eos){
+ int result=ogg_sync_pageout(&oy,&og);
+ if(result==0)break; /* need more data */
+ if(result==-1){ /* missing or corrupt data at this page position */
+ fprintf(stderr,"Corrupt or missing data in bitstream; "
+ "continuing...\n");
+ }else{
+ ogg_stream_pagein(&os,&og); /* can safely ignore errors at
+ this point */
+ while(1){
+ result=ogg_stream_packetout(&os,&op);
+ if(result==0)break; /* need more data */
+ if(result==-1){ /* missing or corrupt data at this page position */
+ /* no reason to complain; already complained above */
+ }else{
+ /* we have a packet. Decode it */
+ double **pcm;
+ int samples;
+
+ vorbis_synthesis(&vb,&op);
+ vorbis_synthesis_blockin(&vd,&vb);
+ /*
+
+ **pcm is a multichannel double vector. In stereo, for
+ example, pcm[0] is left, and pcm[1] is right. samples is
+ the size of each channel. Convert the float values
+ (-1.<=range<=1.) to whatever PCM format and write it out */
+
+ while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
+ int j;
+ int clipflag=0;
+ int out=(samples<convsize?samples:convsize);
+
+ /* convert doubles to 16 bit signed ints (host order) and
+ interleave */
+ for(i=0;i<vi.channels;i++){
+ int16_t *ptr=convbuffer+i;
+ double *mono=pcm[i];
+ for(j=0;j<out;j++){
+ int val=mono[j]*32767.;
+ /* might as well guard against clipping */
+ if(val>32767){
+ val=32767;
+ clipflag=1;
+ }
+ if(val<-32768){
+ val=-32768;
+ clipflag=1;
+ }
+ *ptr=val;
+ ptr+=2;
+ }
+ }
+
+ if(clipflag)
+ fprintf(stderr,"Clipping in frame %ld\n",vd.sequence);
+
+
+ fwrite(convbuffer,2*vi.channels,out,stdout);
+
+ vorbis_synthesis_read(&vd,out); /* tell libvorbis how
+ many samples we
+ actually consumed */
+ }
+ }
+ }
+ if(ogg_page_eos(&og))eos=1;
+ }
+ }
+ if(!eos){
+ buffer=ogg_sync_buffer(&oy,4096);
+ bytes=fread(buffer,1,4096,stdin);
+ ogg_sync_wrote(&oy,bytes);
+ if(bytes==0)eos=1;
+ }
+ }
+
+ /* clean up this logical bitstream; before exit we see if we're
+ followed by another [chained] */
+
+ ogg_stream_clear(&os);
+
+ /* ogg_page and ogg_packet structs always point to storage in
+ libvorbis. They're never freed or manipulated directly */
+
+ vorbis_dsp_clear(&vd);
+ vorbis_block_clear(&vb);
+ vorbis_info_clear(&vi); /* must be called last */
+ }
+
+ /* OK, clean up the framer */
+ ogg_sync_clear(&oy);
+
+ fprintf(stderr,"Done.\n");
+ return(0);
+}
+
--- /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: simple example encoder
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ 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 <math.h>
+#include "codec.h"
+
+#define READ 1024
+signed char readbuffer[READ*4+44]; /* out of the data segment, not the stack */
+
+int main(){
+ ogg_stream_state os; /* take physical pages, weld into a logical
+ stream of packets */
+ ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
+ ogg_packet op; /* one raw packet of data for decode */
+
+ vorbis_info vi; /* struct that stores all the static vorbis bitstream
+ settings */
+ vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+ vorbis_block vb; /* local working space for packet->PCM decode */
+
+ int eos=0;
+
+ /* we cheat on the WAV header; we just bypass 44 bytes and never
+ verify that it matches 16bit/stereo/44.1kHz. This is just an
+ example, after all. */
+
+ fread(readbuffer,1,44,stdin);
+
+ /********** Encode setup ************/
+
+ /* choose an encoding mode */
+ /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */
+ vorbis_info_modeset(&vi,0);
+
+ /* add a comment */
+ vorbis_info_addcomment(&vi,"Track encoded by encoder_example.c");
+
+ /* set up the analysis state and auxiliary encoding storage */
+ vorbis_analysis_init(&vd,&vi);
+ vorbis_block_init(&vd,&vb);
+
+ /* set up our packet->stream encoder */
+ /* pick a random serial number; that way we can more likely build
+ chained streams just by concatenation */
+ srandom(time(NULL));
+ ogg_stream_init(&os,random());
+
+ /* Vorbis streams begin with three headers; the initial header (with
+ most of the codec setup parameters) which is mandated by the Ogg
+ bitstream spec. The second header holds any comment fields. The
+ third header holds the bitstream codebook. We merely need to
+ make the headers, then pass them to libvorbis one at a time;
+ libvorbis handles the additional Ogg bitstream constraints */
+
+ {
+ ogg_packet header;
+ ogg_packet header_comm;
+ ogg_packet header_code;
+
+ vorbis_info_headerout(&vi,&header,&header_comm,&header_code);
+ ogg_stream_packetin(&os,&header); /* automatically placed in its own
+ page */
+ ogg_stream_packetin(&os,&header_comm);
+ ogg_stream_packetin(&os,&header_code);
+
+ /* no need to write out here. We'll get to that in the main loop */
+ }
+
+ while(!eos){
+ long i;
+ long bytes=fread(readbuffer,1,READ*4,stdin); /* stereo hardwired here */
+
+ if(bytes==0){
+ /* end of file. this can be done implicitly in the mainline,
+ but it's easier to see here in non-clever fashion.
+ Tell the library we're at end of stream so that it can handle
+ the last frame and mark end of stream in the output properly */
+ vorbis_analysis_wrote(&vd,0);
+
+ }else{
+ /* data to encode */
+
+ /* expose the buffer to submit data */
+ double **buffer=vorbis_analysis_buffer(&vd,READ);
+
+ /* uninterleave samples */
+ for(i=0;i<bytes/4;i++){
+ buffer[0][i]=((readbuffer[i*4+1]<<8)|
+ (0x00ff&(int)readbuffer[i*4]))/32768.;
+ buffer[1][i]=((readbuffer[i*4+3]<<8)|
+ (0x00ff&(int)readbuffer[i*4+2]))/32768.;
+ }
+
+ /* tell the library how much we actually submitted */
+ vorbis_analysis_wrote(&vd,i);
+ }
+
+ /* vorbis does some data preanalysis, then divvies up blocks for
+ more involved (potentially parallel) processing. Get a single
+ block for encoding now */
+ while(vorbis_analysis_blockout(&vd,&vb)==1){
+
+ /* analysis */
+ vorbis_analysis(&vb,&op);
+
+ /* weld the packet into the bitstream */
+ ogg_stream_packetin(&os,&op);
+
+ /* write out pages (if any) */
+ while(!eos){
+ int result=ogg_stream_pageout(&os,&og);
+ if(result==0)break;
+ fwrite(og.header,1,og.header_len,stdout);
+ fwrite(og.body,1,og.body_len,stdout);
+
+ /* this could be set above, but for illustrative purposes, I do
+ it here (to show that vorbis does know where the stream ends) */
+
+ if(ogg_page_eos(&og))eos=1;
+
+ }
+ }
+ }
+
+ /* clean up and exit. vorbis_info_clear() must be called last */
+
+ ogg_stream_clear(&os);
+ vorbis_dsp_clear(&vd);
+ vorbis_block_clear(&vb);
+ vorbis_info_clear(&vi);
+
+ /* ogg_page and ogg_packet structs always point to storage in
+ libvorbis. They're never freed or manipulated directly */
+
+ fprintf(stderr,"Done.\n");
+ return(0);
+}
+
--- /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: codec headers
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ last modification date: Dec 29 1999
+
+ ********************************************************************/
+
+#ifndef _vorbis_codec_h_
+#define _vorbis_codec_h_
+
+#include <sys/types.h> /* get BSD style 16/32/64 bit types */
+
+/* if no BSD width types, get them from the configure script */
+#ifndef int64_t
+# define int64_t size64
+#endif
+#ifndef int32_t
+# define int32_t size32
+#endif
+#ifndef int16_t
+# define int16_t size16
+#endif
+
+/* lookup structures for various simple transforms *****************/
+
+typedef struct {
+ int n;
+ struct vorbis_info *vi;
+
+ double *noisethresh;
+ double *maskthresh;
+
+} psy_lookup;
+
+typedef struct {
+ int n;
+ int log2n;
+
+ double *trig;
+ int *bitrev;
+
+} mdct_lookup;
+
+typedef struct {
+ int n;
+ double *trigcache;
+ int *splitcache;
+} drft_lookup;
+
+typedef struct {
+ int winlen;
+ double *window;
+ mdct_lookup mdct;
+} envelope_lookup;
+
+typedef struct lpclook{
+ /* encode lookups */
+ int *uscale;
+ double *escale;
+ drft_lookup fft;
+
+ /* en/decode lookups */
+ long *dscale;
+ int *iscale;
+ double *ifrac;
+ double *norm;
+ int n;
+ int ln;
+ int m;
+
+} lpc_lookup;
+
+/* structures for various internal data abstractions ********************/
+
+typedef struct {
+ long endbyte;
+ int endbit;
+
+ unsigned char *buffer;
+ unsigned char *ptr;
+ long storage;
+
+} oggpack_buffer;
+
+/* vobis_info contains all the setup information specific to the specific
+ compression/decompression mode in progress (eg, psychoacoustic settings,
+ channel setup, options, codebook etc) *********************************/
+
+#define THRESH_POINTS 20
+
+typedef struct vorbis_info{
+ int channels;
+ long rate;
+ int version;
+
+ /* The below bitrate declarations are *hints*.
+ Combinations of the three values carry the following implications:
+
+ all three set to the same value:
+ implies a fixed rate bitstream
+ only nominal set:
+ implies a VBR stream that averages the nominal bitrate. No hard
+ upper/lower limit
+ upper and or lower set:
+ implies a VBR bitstream that obeys the bitrate limits. nominal
+ may also be set to give a nominal rate.
+ none set:
+ the coder does not care to speculate.
+ */
+
+ long bitrate_upper;
+ long bitrate_nominal;
+ long bitrate_lower;
+
+ char **user_comments;
+ int comments;
+ char *vendor;
+
+ int blocksize[2];
+ int floororder[2];
+ int flooroctaves[2];
+
+ int floorch;
+
+ /* int smallblock;
+ int largeblock;
+ int floororder;
+ int flooroctaves;
+ int floorch;*/
+
+ /* no mapping, coupling, balance yet. */
+
+ /*int balanceorder;
+ int balanceoctaves;
+ this would likely need to be by channel and blocksize anyway*/
+
+ /* Encode-side settings for analysis */
+
+ int envelopesa;
+ double preecho_thresh;
+ double preecho_clamp;
+
+ double *threshhold_points;
+ double noisethresh[THRESH_POINTS];
+ double lnoise;
+ double hnoise;
+ double noisebias;
+ double maskthresh[THRESH_POINTS];
+ double lroll;
+ double hroll;
+ double maskbias;
+
+ /* local storage, only used on the encoding size. This way the
+ application does not need to worry about freeing some packets'
+ memory and not others'. Packet storage is always tracked */
+ char *header;
+ char *header1;
+ char *header2;
+
+} vorbis_info;
+
+/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
+
+typedef struct {
+ unsigned char *header;
+ long header_len;
+ unsigned char *body;
+ long body_len;
+} ogg_page;
+
+/* ogg_stream_state contains the current encode/decode state of a logical
+ Ogg bitstream **********************************************************/
+
+typedef struct {
+ unsigned char *body_data; /* bytes from packet bodies */
+ long body_storage; /* storage elements allocated */
+ long body_fill; /* elements stored; fill mark */
+ long body_returned; /* elements of fill returned */
+
+
+ int *lacing_vals; /* The values that will go to the segment table */
+ int64_t *pcm_vals; /* pcm_pos values for headers. Not compact
+ this way, but it is simple coupled to the
+ lacing fifo */
+ long lacing_storage;
+ long lacing_fill;
+ long lacing_packet;
+ long lacing_returned;
+
+ unsigned char header[282]; /* working space for header encode */
+ int header_fill;
+
+ int e_o_s; /* set when we have buffered the last packet in the
+ logical bitstream */
+ int b_o_s; /* set after we've written the initial page
+ of a logical bitstream */
+ long serialno;
+ long pageno;
+ long packetno; /* sequence number for decode; the framing
+ knows where there's a hole in the data,
+ but we need coupling so that the codec
+ (which is in a seperate abstraction
+ layer) also knows about the gap */
+ int64_t pcmpos;
+
+} ogg_stream_state;
+
+/* ogg_packet is used to encapsulate the data and metadata belonging
+ to a single raw Ogg/Vorbis packet *************************************/
+
+typedef struct {
+ unsigned char *packet;
+ long bytes;
+ long b_o_s;
+ long e_o_s;
+
+ int64_t frameno;
+ long packetno; /* sequence number for decode; the framing
+ knows where there's a hole in the data,
+ but we need coupling so that the codec
+ (which is in a seperate abstraction
+ layer) also knows about the gap */
+
+} ogg_packet;
+
+typedef struct {
+ unsigned char *data;
+ int storage;
+ int fill;
+ int returned;
+
+ int unsynced;
+ int headerbytes;
+ int bodybytes;
+} ogg_sync_state;
+
+/* vorbis_dsp_state buffers the current vorbis audio
+ analysis/synthesis state. The DSP state belongs to a specific
+ logical bitstream ****************************************************/
+
+typedef struct vorbis_dsp_state{
+ int analysisp;
+ vorbis_info *vi;
+
+ double *window[2][2][2]; /* windowsize, leadin, leadout */
+ envelope_lookup ve;
+ mdct_lookup vm[2];
+ lpc_lookup vl[2];
+ lpc_lookup vbal[2];
+ psy_lookup vp[2];
+
+ double **pcm;
+ double **pcmret;
+ int pcm_storage;
+ int pcm_current;
+ int pcm_returned;
+
+ double *multipliers;
+ int envelope_storage;
+ int envelope_current;
+
+ int eofflag;
+
+ long lW;
+ long W;
+ long nW;
+ long centerW;
+
+ long frameno;
+ long sequence;
+
+ int64_t gluebits;
+ int64_t time_envelope_bits;
+ int64_t spectral_envelope_bits;
+ int64_t spectral_residue_bits;
+
+} vorbis_dsp_state;
+
+/* vorbis_block is a single block of data to be processed as part of
+the analysis/synthesis stream; it belongs to a specific logical
+bitstream, but is independant from other vorbis_blocks belonging to
+that logical bitstream. *************************************************/
+
+typedef struct vorbis_block{
+ double **pcm;
+ double **lpc;
+ double **lsp;
+ double *amp;
+ oggpack_buffer opb;
+
+ int pcm_channels; /* allocated, not used */
+ int pcm_storage; /* allocated, not used */
+ int floor_channels;
+ int floor_storage;
+
+ long lW;
+ long W;
+ long nW;
+ int pcmend;
+
+ int eofflag;
+ int frameno;
+ int sequence;
+ vorbis_dsp_state *vd; /* For read-only access of configuration */
+
+ long gluebits;
+ long time_envelope_bits;
+ long spectral_envelope_bits;
+ long spectral_residue_bits;
+
+} vorbis_block;
+
+/* libvorbis encodes in two abstraction layers; first we perform DSP
+ and produce a packet (see docs/analysis.txt). The packet is then
+ coded into a framed OggSquish bitstream by the second layer (see
+ docs/framing.txt). Decode is the reverse process; we sync/frame
+ the bitstream and extract individual packets, then decode the
+ packet back into PCM audio.
+
+ The extra framing/packetizing is used in streaming formats, such as
+ files. Over the net (such as with UDP), the framing and
+ packetization aren't necessary as they're provided by the transport
+ and the streaming layer is not used */
+
+/* OggSquish BITSREAM PRIMITIVES: encoding **************************/
+
+extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
+extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
+
+/* OggSquish BITSREAM PRIMITIVES: decoding **************************/
+
+extern int ogg_sync_init(ogg_sync_state *oy);
+extern int ogg_sync_clear(ogg_sync_state *oy);
+extern int ogg_sync_destroy(ogg_sync_state *oy);
+extern int ogg_sync_reset(ogg_sync_state *oy);
+
+extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
+extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
+extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
+extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
+extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
+extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
+
+/* OggSquish BITSREAM PRIMITIVES: general ***************************/
+
+extern int ogg_stream_init(ogg_stream_state *os,int serialno);
+extern int ogg_stream_clear(ogg_stream_state *os);
+extern int ogg_stream_reset(ogg_stream_state *os,long expected_pageno);
+extern int ogg_stream_destroy(ogg_stream_state *os);
+extern int ogg_stream_eof(ogg_stream_state *os);
+
+extern int ogg_page_version(ogg_page *og);
+extern int ogg_page_continued(ogg_page *og);
+extern int ogg_page_bos(ogg_page *og);
+extern int ogg_page_eos(ogg_page *og);
+extern int64_t ogg_page_frameno(ogg_page *og);
+extern int ogg_page_serialno(ogg_page *og);
+extern int ogg_page_pageno(ogg_page *og);
+
+/* Vorbis PRIMITIVES: general ***************************************/
+
+extern void vorbis_dsp_clear(vorbis_dsp_state *v);
+
+extern void vorbis_info_init(vorbis_info *vi);
+extern void vorbis_info_clear(vorbis_info *vi);
+extern int vorbis_info_modeset(vorbis_info *vi, int mode);
+extern int vorbis_info_addcomment(vorbis_info *vi, char *comment);
+extern int vorbis_info_headerin(vorbis_info *vi,ogg_packet *op);
+extern int vorbis_info_headerout(vorbis_info *vi,
+ ogg_packet *op,
+ ogg_packet *op_comm,
+ ogg_packet *op_code);
+
+extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
+extern int vorbis_block_clear(vorbis_block *vb);
+
+/* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
+extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
+
+extern double **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
+extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
+extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
+extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
+
+/* Vorbis PRIMITIVES: synthesis layer *******************************/
+extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
+
+extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
+extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
+extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
+extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
+
+#define min(x,y) ((x)>(y)?(y):(x))
+#define max(x,y) ((x)<(y)?(y):(x))
+
+ /* 20log10(x) */
+#define todB(x) ((x)==0?-9.e40:log(fabs(x))*8.6858896)
+#define fromdB(x) (exp((x)*.11512925))
+
+#endif
+
--- /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: stdio-based convenience library for opening/seeking/decoding
+ author: Monty <xiphmont@mit.edu>
+ modifications by: Monty
+ last modification date: Nov 04 1999
+
+ ********************************************************************/
+
+#ifndef _OV_FILE_H_
+#define _OV_FILE_H_
+
+#include <stdio.h>
+#include "codec.h"
+
+typedef struct {
+ FILE *f;
+ int seekable;
+ long offset;
+ long end;
+ ogg_sync_state oy;
+
+ /* If the FILE handle isn't seekable (eg, a pipe), only the current
+ stream appears */
+ int links;
+ long *offsets;
+ long *dataoffsets;
+ long *serialnos;
+ int64_t *pcmlengths;
+ vorbis_info *vi;
+
+ /* Decoding working state local storage */
+ int64_t pcm_offset;
+ int decode_ready;
+ long current_serialno;
+ int current_link;
+
+ ogg_stream_state os; /* take physical pages, weld into a logical
+ stream of packets */
+ vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+ vorbis_block vb; /* local working space for packet->PCM decode */
+
+} OggVorbis_File;
+
+extern int ov_clear(OggVorbis_File *vf);
+extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
+
+extern long ov_bitrate(OggVorbis_File *vf,int i);
+extern long ov_streams(OggVorbis_File *vf);
+extern long ov_seekable(OggVorbis_File *vf);
+extern long ov_serialnumber(OggVorbis_File *vf,int i);
+
+extern long ov_raw_total(OggVorbis_File *vf,int i);
+extern int64_t ov_pcm_total(OggVorbis_File *vf,int i);
+extern double ov_time_total(OggVorbis_File *vf,int i);
+
+extern int ov_raw_seek(OggVorbis_File *vf,long pos);
+extern int ov_pcm_seek(OggVorbis_File *vf,int64_t pos);
+extern int ov_time_seek(OggVorbis_File *vf,double pos);
+
+extern long ov_raw_tell(OggVorbis_File *vf);
+extern int64_t ov_pcm_tell(OggVorbis_File *vf);
+extern double ov_time_tell(OggVorbis_File *vf);
+
+extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
+
+extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
+ int bigendianp,int word,int sgned,int *bitstream);
+
+#endif
+
+
+
+
+
+
+
# vorbis makefile configured for use with gcc on any platform
-# $Id: Makefile.in,v 1.15 1999/11/17 03:52:56 xiphmont Exp $
+# $Id: Makefile.in,v 1.16 1999/12/30 03:46:19 xiphmont Exp $
###############################################################################
# #
# (unless, of course, you know what you are doing :) ##########################
@SET_MAKE@
-FLAGS=-I. @TYPESIZES@ @CFLAGS@
+FLAGS=-I. -I../include @TYPESIZES@ @CFLAGS@
OPT=@OPT@ $(FLAGS)
DEBUG=@DEBUG@ $(FLAGS)
PROFILE=@PROFILE@ $(FLAGS)
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 os.h
+HFILES = ../include/codec.h ../include/vorbisfile.h \
+ bitwise.h envelope.h lpc.h lsp.h \
+ psy.h smallft.h window.h xlogmap.h os.h mdct.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
+ spectrum.o vorbisfile.o
all:
$(MAKE) target CFLAGS="$(OPT)"
profile:
$(MAKE) target CFLAGS="$(PROFILE)"
-target: libvorbis.a vorbisfile.a $(BINFILES)
+target: libvorbis.a vorbisfile.a
selftest:
$(MAKE) clean
@./test_framing
@./test_bitwise
-encoder_example: $(EFILES) libvorbis.a
- $(CC) $(CFLAGS) $(LDFLAGS) encoder_example.o libvorbis.a -o \
- encoder_example -lm
-
-decoder_example: $(EFILES) libvorbis.a
- $(CC) $(CFLAGS) $(LDFLAGS) decoder_example.o libvorbis.a -o \
- decoder_example -lm
-
-chaining_example: $(EFILES) libvorbis.a vorbisfile.a
- $(CC) $(CFLAGS) $(LDFLAGS) chaining_example.o \
- vorbisfile.a libvorbis.a -o chaining_example -lm
-
libvorbis.a: $(LFILES)
$(AR) -r libvorbis.a $^
$(RANLIB) libvorbis.a
-vorbisfile.a: $(FFILES)
+vorbisfile.a: $(LFILES)
$(AR) -r vorbisfile.a $^
$(RANLIB) vorbisfile.a
$(LFILES): $(HFILES)
-$(FFILES): $(HFILES) vorbisfile.h
-$(EFILES): $(HFILES) vorbisfile.h
-
-info.o: modes.h
.c.o:
$(CC) $(CFLAGS) -c $<
clean:
- -rm -f *.o *.a test* *~ *.out ogg config.* $(BINFILES) tone
+ -rm -f *.o *.a test* *~ *.out ogg config.* tone
distclean: clean
-rf -f Makefile
+++ /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: illustrate simple use of chained bitstream and vorbisfile.a
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- last modification date: Nov 02 1999
-
- ********************************************************************/
-
-#include "codec.h"
-#include "vorbisfile.h"
-
-int main(){
- OggVorbis_File ov;
- int i;
-
- /* open the file/pipe on stdin */
- if(ov_open(stdin,&ov,NULL,-1)==-1){
- printf("Could not open input as an OggVorbis file.\n\n");
- exit(1);
- }
-
- /* print details about each logical bitstream in the input */
- if(ov_seekable(&ov)){
- 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));
-
- }else{
- printf("Standard input was not seekable.\n"
- "First logical bitstream information:\n\n");
- }
-
- 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 %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));
- printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
- }
-
- ov_clear(&ov);
- return 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
+++ /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: codec headers
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- last modification date: Nov 04 1999
-
- ********************************************************************/
-
-#ifndef _vorbis_codec_h_
-#define _vorbis_codec_h_
-
-#include <sys/types.h> /* get BSD style 16/32/64 bit types */
-
-/* If we have defines from the configure script, use those */
-#ifndef size64
-# define size64 int64_t
-#endif
-#ifndef size32
-# define size32 int32_t
-#endif
-#ifndef size16
-# define size16 int16_t
-#endif
-
-/* lookup structures for various simple transforms *****************/
-
-typedef struct {
- int n;
- struct vorbis_info *vi;
-
- double *noisethresh;
- double *maskthresh;
-
-} psy_lookup;
-
-typedef struct {
- int n;
- int log2n;
-
- double *trig;
- int *bitrev;
-
-} mdct_lookup;
-
-typedef struct {
- int n;
- double *trigcache;
- int *splitcache;
-} drft_lookup;
-
-typedef struct {
- int winlen;
- double *window;
- mdct_lookup mdct;
-} envelope_lookup;
-
-typedef struct lpclook{
- /* encode lookups */
- int *uscale;
- double *escale;
- drft_lookup fft;
-
- /* en/decode lookups */
- long *dscale;
- int *iscale;
- double *ifrac;
- double *norm;
- int n;
- int ln;
- int m;
-
-} lpc_lookup;
-
-/* structures for various internal data abstractions ********************/
-
-typedef struct {
- long endbyte;
- int endbit;
-
- unsigned char *buffer;
- unsigned char *ptr;
- long storage;
-
-} oggpack_buffer;
-
-/* vobis_info contains all the setup information specific to the specific
- compression/decompression mode in progress (eg, psychoacoustic settings,
- channel setup, options, codebook etc) *********************************/
-
-#define THRESH_POINTS 20
-
-typedef struct vorbis_info{
- int channels;
- long rate;
- int version;
-
- /* The below bitrate declarations are *hints*.
- Combinations of the three values carry the following implications:
-
- all three set to the same value:
- implies a fixed rate bitstream
- only nominal set:
- implies a VBR stream that averages the nominal bitrate. No hard
- upper/lower limit
- upper and or lower set:
- implies a VBR bitstream that obeys the bitrate limits. nominal
- may also be set to give a nominal rate.
- none set:
- the coder does not care to speculate.
- */
-
- long bitrate_upper;
- long bitrate_nominal;
- long bitrate_lower;
-
- char **user_comments;
- int comments;
- char *vendor;
-
- int blocksize[2];
- int floororder[2];
- int flooroctaves[2];
-
- int floorch;
-
- /* int smallblock;
- int largeblock;
- int floororder;
- int flooroctaves;
- int floorch;*/
-
- /* no mapping, coupling, balance yet. */
-
- /*int balanceorder;
- int balanceoctaves;
- this would likely need to be by channel and blocksize anyway*/
-
- /* Encode-side settings for analysis */
-
- int envelopesa;
- double preecho_thresh;
- double preecho_clamp;
-
- double *threshhold_points;
- double noisethresh[THRESH_POINTS];
- double lnoise;
- double hnoise;
- double noisebias;
- double maskthresh[THRESH_POINTS];
- double lroll;
- double hroll;
- double maskbias;
-
- /* local storage, only used on the encoding size. This way the
- application does not need to worry about freeing some packets'
- memory and not others'. Packet storage is always tracked */
- char *header;
- char *header1;
- char *header2;
-
-} vorbis_info;
-
-/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
-
-typedef struct {
- unsigned char *header;
- long header_len;
- unsigned char *body;
- long body_len;
-} ogg_page;
-
-/* ogg_stream_state contains the current encode/decode state of a logical
- Ogg bitstream **********************************************************/
-
-typedef struct {
- unsigned char *body_data; /* bytes from packet bodies */
- long body_storage; /* storage elements allocated */
- long body_fill; /* elements stored; fill mark */
- long body_returned; /* elements of fill returned */
-
-
- int *lacing_vals; /* The values that will go to the segment table */
- size64 *pcm_vals; /* pcm_pos values for headers. Not compact
- this way, but it is simple coupled to the
- lacing fifo */
- long lacing_storage;
- long lacing_fill;
- long lacing_packet;
- long lacing_returned;
-
- unsigned char header[282]; /* working space for header encode */
- int header_fill;
-
- int e_o_s; /* set when we have buffered the last packet in the
- logical bitstream */
- int b_o_s; /* set after we've written the initial page
- of a logical bitstream */
- long serialno;
- long pageno;
- long packetno; /* sequence number for decode; the framing
- knows where there's a hole in the data,
- but we need coupling so that the codec
- (which is in a seperate abstraction
- layer) also knows about the gap */
- size64 pcmpos;
-
-} ogg_stream_state;
-
-/* ogg_packet is used to encapsulate the data and metadata belonging
- to a single raw Ogg/Vorbis packet *************************************/
-
-typedef struct {
- unsigned char *packet;
- long bytes;
- long b_o_s;
- long e_o_s;
-
- size64 frameno;
- long packetno; /* sequence number for decode; the framing
- knows where there's a hole in the data,
- but we need coupling so that the codec
- (which is in a seperate abstraction
- layer) also knows about the gap */
-
-} ogg_packet;
-
-typedef struct {
- unsigned char *data;
- int storage;
- int fill;
- int returned;
-
- int unsynced;
- int headerbytes;
- int bodybytes;
-} ogg_sync_state;
-
-/* vorbis_dsp_state buffers the current vorbis audio
- analysis/synthesis state. The DSP state belongs to a specific
- logical bitstream ****************************************************/
-
-typedef struct vorbis_dsp_state{
- int analysisp;
- vorbis_info *vi;
-
- double *window[2][2][2]; /* windowsize, leadin, leadout */
- envelope_lookup ve;
- mdct_lookup vm[2];
- lpc_lookup vl[2];
- lpc_lookup vbal[2];
- psy_lookup vp[2];
-
- double **pcm;
- double **pcmret;
- int pcm_storage;
- int pcm_current;
- int pcm_returned;
-
- double *multipliers;
- int envelope_storage;
- int envelope_current;
-
- int eofflag;
-
- long lW;
- long W;
- long nW;
- long centerW;
-
- long frameno;
- long sequence;
-
- size64 gluebits;
- size64 time_envelope_bits;
- size64 spectral_envelope_bits;
- size64 spectral_residue_bits;
-
-} vorbis_dsp_state;
-
-/* vorbis_block is a single block of data to be processed as part of
-the analysis/synthesis stream; it belongs to a specific logical
-bitstream, but is independant from other vorbis_blocks belonging to
-that logical bitstream. *************************************************/
-
-typedef struct vorbis_block{
- double **pcm;
- double **lpc;
- double **lsp;
- double *amp;
- oggpack_buffer opb;
-
- int pcm_channels; /* allocated, not used */
- int pcm_storage; /* allocated, not used */
- int floor_channels;
- int floor_storage;
-
- long lW;
- long W;
- long nW;
- int pcmend;
-
- int eofflag;
- int frameno;
- int sequence;
- vorbis_dsp_state *vd; /* For read-only access of configuration */
-
- long gluebits;
- long time_envelope_bits;
- long spectral_envelope_bits;
- long spectral_residue_bits;
-
-} vorbis_block;
-
-/* libvorbis encodes in two abstraction layers; first we perform DSP
- and produce a packet (see docs/analysis.txt). The packet is then
- coded into a framed OggSquish bitstream by the second layer (see
- docs/framing.txt). Decode is the reverse process; we sync/frame
- the bitstream and extract individual packets, then decode the
- packet back into PCM audio.
-
- The extra framing/packetizing is used in streaming formats, such as
- files. Over the net (such as with UDP), the framing and
- packetization aren't necessary as they're provided by the transport
- and the streaming layer is not used */
-
-/* OggSquish BITSREAM PRIMITIVES: encoding **************************/
-
-extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
-extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
-
-/* OggSquish BITSREAM PRIMITIVES: decoding **************************/
-
-extern int ogg_sync_init(ogg_sync_state *oy);
-extern int ogg_sync_clear(ogg_sync_state *oy);
-extern int ogg_sync_destroy(ogg_sync_state *oy);
-extern int ogg_sync_reset(ogg_sync_state *oy);
-
-extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
-extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
-extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
-extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
-extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
-extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
-
-/* OggSquish BITSREAM PRIMITIVES: general ***************************/
-
-extern int ogg_stream_init(ogg_stream_state *os,int serialno);
-extern int ogg_stream_clear(ogg_stream_state *os);
-extern int ogg_stream_reset(ogg_stream_state *os,long expected_pageno);
-extern int ogg_stream_destroy(ogg_stream_state *os);
-extern int ogg_stream_eof(ogg_stream_state *os);
-
-extern int ogg_page_version(ogg_page *og);
-extern int ogg_page_continued(ogg_page *og);
-extern int ogg_page_bos(ogg_page *og);
-extern int ogg_page_eos(ogg_page *og);
-extern size64 ogg_page_frameno(ogg_page *og);
-extern int ogg_page_serialno(ogg_page *og);
-extern int ogg_page_pageno(ogg_page *og);
-
-/* Vorbis PRIMITIVES: general ***************************************/
-
-extern void vorbis_dsp_clear(vorbis_dsp_state *v);
-
-extern void vorbis_info_init(vorbis_info *vi);
-extern void vorbis_info_clear(vorbis_info *vi);
-extern int vorbis_info_modeset(vorbis_info *vi, int mode);
-extern int vorbis_info_addcomment(vorbis_info *vi, char *comment);
-extern int vorbis_info_headerin(vorbis_info *vi,ogg_packet *op);
-extern int vorbis_info_headerout(vorbis_info *vi,
- ogg_packet *op,
- ogg_packet *op_comm,
- ogg_packet *op_code);
-
-extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
-extern int vorbis_block_clear(vorbis_block *vb);
-
-/* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
-extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
-
-extern double **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
-extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
-extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
-extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
-
-/* Vorbis PRIMITIVES: synthesis layer *******************************/
-extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
-
-extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
-extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
-extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
-extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
-
-#define min(x,y) ((x)>(y)?(y):(x))
-#define max(x,y) ((x)<(y)?(y):(x))
-
- /* 20log10(x) */
-#define todB(x) ((x)==0?-9.e40:log(fabs(x))*8.6858896)
-#define fromdB(x) (exp((x)*.11512925))
-
-#endif
-
+++ /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: simple example decoder
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- 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. Vorbisfile.a is somewhat more complex than the code below. */
-
-/* Note that this is POSIX, not ANSI code */
-
-#include <stdio.h>
-#include <math.h>
-#include "codec.h"
-
-int16_t convbuffer[4096]; /* take 8k out of the data segment, not the stack */
-int convsize=4096;
-
-int main(){
- ogg_sync_state oy; /* sync and verify incoming physical bitstream */
- ogg_stream_state os; /* take physical pages, weld into a logical
- stream of packets */
- ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
- ogg_packet op; /* one raw packet of data for decode */
-
- vorbis_info vi; /* struct that stores all the static vorbis bitstream
- settings */
- vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
- vorbis_block vb; /* local working space for packet->PCM decode */
-
- char *buffer;
- int bytes;
-
- /********** Decode setup ************/
-
- ogg_sync_init(&oy); /* Now we can read pages */
-
- while(1){ /* we repeat if the bitstream is chained */
- int eos=0;
- int i;
-
- /* grab some data at the head of the stream. We want the first page
- (which is guaranteed to be small and only contain the Vorbis
- stream initial header) We need the first page to get the stream
- serialno. */
-
- /* submit a 4k block to libvorbis' Ogg layer */
- buffer=ogg_sync_buffer(&oy,4096);
- bytes=fread(buffer,1,4096,stdin);
- ogg_sync_wrote(&oy,bytes);
-
- /* Get the first page. */
- if(ogg_sync_pageout(&oy,&og)!=1){
- /* have we simply run out of data? If so, we're done. */
- if(bytes<4096)break;
-
- /* error case. Must not be Vorbis data */
- fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
- exit(1);
- }
-
- /* Get the serial number and set up the rest of decode. */
- /* serialno first; use it to set up a logical stream */
- ogg_stream_init(&os,ogg_page_serialno(&og));
-
- /* extract the initial header from the first page and verify that the
- Ogg bitstream is in fact Vorbis data */
-
- /* I handle the initial header first instead of just having the code
- read all three Vorbis headers at once because reading the initial
- header is an easy way to identify a Vorbis bitstream and it's
- useful to see that functionality seperated out. */
-
- vorbis_info_init(&vi);
- if(ogg_stream_pagein(&os,&og)<0){
- /* error; stream version mismatch perhaps */
- fprintf(stderr,"Error reading first page of Ogg bitstream data.\n");
- exit(1);
- }
-
- if(ogg_stream_packetout(&os,&op)!=1){
- /* no page? must not be vorbis */
- fprintf(stderr,"Error reading initial header packet.\n");
- exit(1);
- }
-
- if(vorbis_info_headerin(&vi,&op)<0){
- /* error case; not a vorbis header */
- fprintf(stderr,"This Ogg bitstream does not contain Vorbis "
- "audio data.\n");
- exit(1);
- }
-
- /* At this point, we're sure we're Vorbis. We've set up the logical
- (Ogg) bitstream decoder. Get the comment and codebook headers and
- set up the Vorbis decoder */
-
- /* The next two packets in order are the comment and codebook headers.
- They're likely large and may span multiple pages. Thus we reead
- and submit data until we get our two pacakets, watching that no
- pages are missing. If a page is missing, error out; losing a
- header page is the only place where missing data is fatal. */
-
- i=0;
- while(i<2){
- while(i<2){
- int result=ogg_sync_pageout(&oy,&og);
- if(result==0)break; /* Need more data */
- /* Don't complain about missing or corrupt data yet. We'll
- catch it at the packet output phase */
- if(result==1){
- ogg_stream_pagein(&os,&og); /* we can ignore any errors here
- as they'll also become apparent
- at packetout */
- while(i<2){
- result=ogg_stream_packetout(&os,&op);
- if(result==0)break;
- if(result==-1){
- /* Uh oh; data at some point was corrupted or missing!
- We can't tolerate that in a header. Die. */
- fprintf(stderr,"Corrupt secondary header. Exiting.\n");
- exit(1);
- }
- vorbis_info_headerin(&vi,&op);
- i++;
- }
- }
- }
- /* no harm in not checking before adding more */
- buffer=ogg_sync_buffer(&oy,4096);
- bytes=fread(buffer,1,4096,stdin);
- if(bytes==0){
- fprintf(stderr,"End of file before finding all Vorbis headers!\n");
- exit(1);
- }
- ogg_sync_wrote(&oy,bytes);
- }
-
- /* Throw the comments plus a few lines about the bitstream we're
- decoding */
- {
- char **ptr=vi.user_comments;
- while(*ptr){
- fprintf(stderr,"%s\n",*ptr);
- ++ptr;
- }
- fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi.channels,vi.rate);
- fprintf(stderr,"Encoded by: %s\n\n",vi.vendor);
- }
-
- convsize=4096/vi.channels;
-
- /* OK, got and parsed all three headers. Initialize the Vorbis
- packet->PCM decoder. */
- vorbis_synthesis_init(&vd,&vi); /* central decode state */
- vorbis_block_init(&vd,&vb); /* local state for most of the decode
- so multiple block decodes can
- proceed in parallel. We could init
- multiple vorbis_block structures
- for vd here */
-
- /* The rest is just a straight decode loop until end of stream */
- while(!eos){
- while(!eos){
- int result=ogg_sync_pageout(&oy,&og);
- if(result==0)break; /* need more data */
- if(result==-1){ /* missing or corrupt data at this page position */
- fprintf(stderr,"Corrupt or missing data in bitstream; "
- "continuing...\n");
- }else{
- ogg_stream_pagein(&os,&og); /* can safely ignore errors at
- this point */
- while(1){
- result=ogg_stream_packetout(&os,&op);
- if(result==0)break; /* need more data */
- if(result==-1){ /* missing or corrupt data at this page position */
- /* no reason to complain; already complained above */
- }else{
- /* we have a packet. Decode it */
- double **pcm;
- int samples;
-
- vorbis_synthesis(&vb,&op);
- vorbis_synthesis_blockin(&vd,&vb);
- /*
-
- **pcm is a multichannel double vector. In stereo, for
- example, pcm[0] is left, and pcm[1] is right. samples is
- the size of each channel. Convert the float values
- (-1.<=range<=1.) to whatever PCM format and write it out */
-
- while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
- int j;
- int clipflag=0;
- int out=(samples<convsize?samples:convsize);
-
- /* convert doubles to 16 bit signed ints (host order) and
- interleave */
- for(i=0;i<vi.channels;i++){
- int16_t *ptr=convbuffer+i;
- double *mono=pcm[i];
- for(j=0;j<out;j++){
- int val=mono[j]*32767.;
- /* might as well guard against clipping */
- if(val>32767){
- val=32767;
- clipflag=1;
- }
- if(val<-32768){
- val=-32768;
- clipflag=1;
- }
- *ptr=val;
- ptr+=2;
- }
- }
-
- if(clipflag)
- fprintf(stderr,"Clipping in frame %ld\n",vd.sequence);
-
-
- fwrite(convbuffer,2*vi.channels,out,stdout);
-
- vorbis_synthesis_read(&vd,out); /* tell libvorbis how
- many samples we
- actually consumed */
- }
- }
- }
- if(ogg_page_eos(&og))eos=1;
- }
- }
- if(!eos){
- buffer=ogg_sync_buffer(&oy,4096);
- bytes=fread(buffer,1,4096,stdin);
- ogg_sync_wrote(&oy,bytes);
- if(bytes==0)eos=1;
- }
- }
-
- /* clean up this logical bitstream; before exit we see if we're
- followed by another [chained] */
-
- ogg_stream_clear(&os);
-
- /* ogg_page and ogg_packet structs always point to storage in
- libvorbis. They're never freed or manipulated directly */
-
- vorbis_dsp_clear(&vd);
- vorbis_block_clear(&vb);
- vorbis_info_clear(&vi); /* must be called last */
- }
-
- /* OK, clean up the framer */
- ogg_sync_clear(&oy);
-
- fprintf(stderr,"Done.\n");
- return(0);
-}
-
+++ /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: simple example encoder
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- 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 <math.h>
-#include "codec.h"
-
-#define READ 1024
-signed char readbuffer[READ*4+44]; /* out of the data segment, not the stack */
-
-int main(){
- ogg_stream_state os; /* take physical pages, weld into a logical
- stream of packets */
- ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
- ogg_packet op; /* one raw packet of data for decode */
-
- vorbis_info vi; /* struct that stores all the static vorbis bitstream
- settings */
- vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
- vorbis_block vb; /* local working space for packet->PCM decode */
-
- int eos=0;
-
- /* we cheat on the WAV header; we just bypass 44 bytes and never
- verify that it matches 16bit/stereo/44.1kHz. This is just an
- example, after all. */
-
- fread(readbuffer,1,44,stdin);
-
- /********** Encode setup ************/
-
- /* choose an encoding mode */
- /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */
- vorbis_info_modeset(&vi,0);
-
- /* add a comment */
- vorbis_info_addcomment(&vi,"Track encoded by encoder_example.c");
-
- /* set up the analysis state and auxiliary encoding storage */
- vorbis_analysis_init(&vd,&vi);
- vorbis_block_init(&vd,&vb);
-
- /* set up our packet->stream encoder */
- /* pick a random serial number; that way we can more likely build
- chained streams just by concatenation */
- srandom(time(NULL));
- ogg_stream_init(&os,random());
-
- /* Vorbis streams begin with three headers; the initial header (with
- most of the codec setup parameters) which is mandated by the Ogg
- bitstream spec. The second header holds any comment fields. The
- third header holds the bitstream codebook. We merely need to
- make the headers, then pass them to libvorbis one at a time;
- libvorbis handles the additional Ogg bitstream constraints */
-
- {
- ogg_packet header;
- ogg_packet header_comm;
- ogg_packet header_code;
-
- vorbis_info_headerout(&vi,&header,&header_comm,&header_code);
- ogg_stream_packetin(&os,&header); /* automatically placed in its own
- page */
- ogg_stream_packetin(&os,&header_comm);
- ogg_stream_packetin(&os,&header_code);
-
- /* no need to write out here. We'll get to that in the main loop */
- }
-
- while(!eos){
- long i;
- long bytes=fread(readbuffer,1,READ*4,stdin); /* stereo hardwired here */
-
- if(bytes==0){
- /* end of file. this can be done implicitly in the mainline,
- but it's easier to see here in non-clever fashion.
- Tell the library we're at end of stream so that it can handle
- the last frame and mark end of stream in the output properly */
- vorbis_analysis_wrote(&vd,0);
-
- }else{
- /* data to encode */
-
- /* expose the buffer to submit data */
- double **buffer=vorbis_analysis_buffer(&vd,READ);
-
- /* uninterleave samples */
- for(i=0;i<bytes/4;i++){
- buffer[0][i]=((readbuffer[i*4+1]<<8)|
- (0x00ff&(int)readbuffer[i*4]))/32768.;
- buffer[1][i]=((readbuffer[i*4+3]<<8)|
- (0x00ff&(int)readbuffer[i*4+2]))/32768.;
- }
-
- /* tell the library how much we actually submitted */
- vorbis_analysis_wrote(&vd,i);
- }
-
- /* vorbis does some data preanalysis, then divvies up blocks for
- more involved (potentially parallel) processing. Get a single
- block for encoding now */
- while(vorbis_analysis_blockout(&vd,&vb)==1){
-
- /* analysis */
- vorbis_analysis(&vb,&op);
-
- /* weld the packet into the bitstream */
- ogg_stream_packetin(&os,&op);
-
- /* write out pages (if any) */
- while(!eos){
- int result=ogg_stream_pageout(&os,&og);
- if(result==0)break;
- fwrite(og.header,1,og.header_len,stdout);
- fwrite(og.body,1,og.body_len,stdout);
-
- /* this could be set above, but for illustrative purposes, I do
- it here (to show that vorbis does know where the stream ends) */
-
- if(ogg_page_eos(&og))eos=1;
-
- }
- }
- }
-
- /* clean up and exit. vorbis_info_clear() must be called last */
-
- ogg_stream_clear(&os);
- vorbis_dsp_clear(&vd);
- vorbis_block_clear(&vb);
- vorbis_info_clear(&vi);
-
- /* ogg_page and ogg_packet structs always point to storage in
- libvorbis. They're never freed or manipulated directly */
-
- fprintf(stderr,"Done.\n");
- return(0);
-}
-
return((int)(og->header[5]&0x04));
}
-size64 ogg_page_frameno(ogg_page *og){
+int64_t ogg_page_frameno(ogg_page *og){
unsigned char *page=og->header;
- size64 pcmpos=page[13]&(0xff);
+ int64_t pcmpos=page[13]&(0xff);
pcmpos= (pcmpos<<8)|(page[12]&0xff);
pcmpos= (pcmpos<<8)|(page[11]&0xff);
pcmpos= (pcmpos<<8)|(page[10]&0xff);
/* helper to initialize lookup for direct-table CRC */
-static unsigned size32 crc_lookup[256];
+static unsigned int32_t crc_lookup[256];
static int crc_ready=0;
-static unsigned size32 _ogg_crc_entry(unsigned long index){
+static unsigned int32_t _ogg_crc_entry(unsigned long index){
int i;
unsigned long r;
os->lacing_storage=1024;
os->lacing_vals=malloc(os->lacing_storage*sizeof(int));
- os->pcm_vals=malloc(os->lacing_storage*sizeof(size64));
+ os->pcm_vals=malloc(os->lacing_storage*sizeof(int64_t));
/* initialize the crc_lookup table if not done */
_ogg_crc_init();
if(os->lacing_storage<=os->lacing_fill+needed){
os->lacing_storage+=(needed+32);
os->lacing_vals=realloc(os->lacing_vals,os->lacing_storage*sizeof(int));
- os->pcm_vals=realloc(os->pcm_vals,os->lacing_storage*sizeof(size64));
+ os->pcm_vals=realloc(os->pcm_vals,os->lacing_storage*sizeof(int64_t));
}
}
perform the checksum silmultaneously with other copies */
static void _os_checksum(ogg_page *og){
- unsigned size32 crc_reg=0;
+ unsigned int32_t crc_reg=0;
int i;
for(i=0;i<og->header_len;i++)
int vals=0,bytes=0;
int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
long acc=0;
- size64 pcm_pos=os->pcm_vals[0];
+ int64_t pcm_pos=os->pcm_vals[0];
/* construct a page */
/* decide how many segments to include */
os->lacing_fill-=vals;
memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(int));
- memmove(os->pcm_vals,os->pcm_vals+vals,os->lacing_fill*sizeof(size64));
+ memmove(os->pcm_vals,os->pcm_vals+vals,os->lacing_fill*sizeof(int64_t));
os->body_returned=bytes;
/* set pointers in the ogg_page struct */
int continued=ogg_page_continued(og);
int bos=ogg_page_bos(og);
int eos=ogg_page_eos(og);
- size64 pcmpos=ogg_page_frameno(og);
+ int64_t pcmpos=ogg_page_frameno(og);
int serialno=ogg_page_serialno(og);
int pageno=ogg_page_pageno(og);
int segments=header[26];
memmove(os->lacing_vals,os->lacing_vals+lr,
(os->lacing_fill-lr)*sizeof(int));
memmove(os->pcm_vals,os->pcm_vals+lr,
- (os->lacing_fill-lr)*sizeof(size64));
+ (os->lacing_fill-lr)*sizeof(int64_t));
}
os->lacing_fill-=lr;
os->lacing_packet-=lr;
+++ /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: predefined encoding modes
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- last modification date: Oct 22 1999
-
- ********************************************************************/
-
-#ifndef _V_MODES_H_
-#define _V_MODES_H_
-
-#include <stdio.h>
-#include "codec.h"
-
-double threshhold_points[THRESH_POINTS]=
-/* 0Hz 24kHz
- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 */
-{0.,.01,.02,.03,.04,.06,.08,.1,.15,.2,.25,.3,.34,.4,.45,.5,.6,.7,.8,1.};
-
-vorbis_info predef_modes[]={
- /* CD quality stereo, no channel coupling */
-
- /* channels, sample rate, upperkbps, nominalkbps, lowerkbps */
- { 2, 44100, 0,0,0,
- /* dummy, dummy, dummy, dummy */
- 0, NULL, 0, NULL,
- /* smallblock, largeblock, LPC order (small, large) */
- {256, 2048}, {16,16},
- /* spectral octaves (small, large), spectral channels */
- {5,5}, 2,
- /* thresh sample period, preecho clamp trigger threshhold, range, dummy */
- 64, 4, 2, NULL,
- /* noise masking curve dB attenuation levels [20] */
- {-12,-12,-18,-18,-18,-18,-18,-18,-18,-12,
- -8,-4,0,0,1,2,3,3,4,5},
- /*{-100,-100,-100,-100,-100,-100,-100,-24,-24,-24,
- -24,-24,-24,-24,-24,-24,-24,-24,-24,-24}*/
- /* noise masking scale biases */
- .95,1.01,.01,
- /* tone masking curve dB attenuation levels [20] */
- {-20,-20,-20,-20,-20,-20,-20,-20,-20,-20,
- -20,-20,-20,-20,-20,-20,-20,-20,-20,-20},
- /* tone masking rolloff settings (dB per octave), octave bias */
- 90,60,.001,
- NULL,NULL,NULL},
-
-};
-
-#define predef_mode_max 0
-
-#endif
int bits=rint(log(n)/log(2));
int i;
+
+#if 0
+ if(amp>0){
+ {
+ FILE *out=fopen("lspdiff.vqd","a");
+ for(i=0;i<m;i++)
+ fprintf(out,"%lf ",lsp[i]);
+ fprintf(out,"\n");
+ fclose(out);
+ }
+ }
+#endif
_oggpack_write(&vb->opb,amp*327680,18);
vf->vi=calloc(vf->links,sizeof(vorbis_info));
vf->dataoffsets=malloc(vf->links*sizeof(long));
- vf->pcmlengths=malloc(vf->links*sizeof(size64));
+ vf->pcmlengths=malloc(vf->links*sizeof(int64_t));
vf->serialnos=malloc(vf->links*sizeof(long));
for(i=0;i<vf->links;i++){
if(vf->decode_ready){
ogg_packet op;
int result=ogg_stream_packetout(&vf->os,&op);
- size64 frameno;
+ int64_t frameno;
if(result==-1)return(-1); /* hole in the data. alert the toplevel */
if(result>0){
if(i>=vf->links)return(-1);
if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
if(i<0){
- size64 bits;
+ int64_t bits;
int i;
for(i=0;i<vf->links;i++)
bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
PCM length (samples) of that logical bitstream for i==0 to n
-1 if the stream is not seekable (we can't know the length)
*/
-size64 ov_pcm_total(OggVorbis_File *vf,int i){
+int64_t ov_pcm_total(OggVorbis_File *vf,int i){
if(!vf->seekable || i>=vf->links)return(-1);
if(i<0){
- size64 acc=0;
+ int64_t acc=0;
int i;
for(i=0;i<vf->links;i++)
acc+=ov_pcm_total(vf,i);
returns zero on success, nonzero on failure */
-int ov_pcm_seek(OggVorbis_File *vf,size64 pos){
+int ov_pcm_seek(OggVorbis_File *vf,int64_t pos){
int link=-1;
- size64 total=ov_pcm_total(vf,-1);
+ int64_t total=ov_pcm_total(vf,-1);
if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
if(pos<0 || pos>total)goto seek_error;
bitstream could make our task impossible. Account for that (it
would be an error condition) */
{
- size64 target=pos-total;
+ int64_t target=pos-total;
long end=vf->offsets[link+1];
long begin=vf->offsets[link];
long best=begin;
if(ret==-1){
end=bisect;
}else{
- size64 frameno=ogg_page_frameno(&og);
+ int64_t frameno=ogg_page_frameno(&og);
if(frameno<target){
best=ret; /* raw offset of packet with frameno */
begin=vf->offset; /* raw offset of next packet */
/* translate time to PCM position and call ov_pcm_seek */
int link=-1;
- size64 pcm_total=ov_pcm_total(vf,-1);
+ int64_t pcm_total=ov_pcm_total(vf,-1);
double time_total=ov_time_total(vf,-1);
if(!vf->seekable)return(-1); /* don't dump machine if we can't seek */
/* enough information to convert time offset to pcm offset */
{
- size64 target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
+ int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
return(ov_pcm_seek(vf,target));
}
}
/* return PCM offset (sample) of next PCM sample to be read */
-size64 ov_pcm_tell(OggVorbis_File *vf){
+int64_t ov_pcm_tell(OggVorbis_File *vf){
return(vf->pcm_offset);
}
/* translate time to PCM position and call ov_pcm_seek */
int link=-1;
- size64 pcm_total=0;
+ int64_t pcm_total=0;
double time_total=0.;
if(vf->seekable){
+++ /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: stdio-based convenience library for opening/seeking/decoding
- author: Monty <xiphmont@mit.edu>
- modifications by: Monty
- last modification date: Nov 04 1999
-
- ********************************************************************/
-
-#ifndef _OV_FILE_H_
-#define _OV_FILE_H_
-
-#include <stdio.h>
-#include "codec.h"
-
-typedef struct {
- FILE *f;
- int seekable;
- long offset;
- long end;
- ogg_sync_state oy;
-
- /* If the FILE handle isn't seekable (eg, a pipe), only the current
- stream appears */
- int links;
- long *offsets;
- long *dataoffsets;
- long *serialnos;
- size64 *pcmlengths;
- vorbis_info *vi;
-
- /* Decoding working state local storage */
- size64 pcm_offset;
- int decode_ready;
- long current_serialno;
- int current_link;
-
- ogg_stream_state os; /* take physical pages, weld into a logical
- stream of packets */
- vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
- vorbis_block vb; /* local working space for packet->PCM decode */
-
-} OggVorbis_File;
-
-extern int ov_clear(OggVorbis_File *vf);
-extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
-
-extern long ov_bitrate(OggVorbis_File *vf,int i);
-extern long ov_streams(OggVorbis_File *vf);
-extern long ov_seekable(OggVorbis_File *vf);
-extern long ov_serialnumber(OggVorbis_File *vf,int i);
-
-extern long ov_raw_total(OggVorbis_File *vf,int i);
-extern size64 ov_pcm_total(OggVorbis_File *vf,int i);
-extern double ov_time_total(OggVorbis_File *vf,int i);
-
-extern int ov_raw_seek(OggVorbis_File *vf,long pos);
-extern int ov_pcm_seek(OggVorbis_File *vf,size64 pos);
-extern int ov_time_seek(OggVorbis_File *vf,double pos);
-
-extern long ov_raw_tell(OggVorbis_File *vf);
-extern size64 ov_pcm_tell(OggVorbis_File *vf);
-extern double ov_time_tell(OggVorbis_File *vf);
-
-extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
-
-extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
- int bigendianp,int word,int sgned,int *bitstream);
-
-#endif
-
-
-
-
-
-
-