********************************************************************
function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.8 2000/06/14 10:13:35 xiphmont Exp $
+ last mod: $Id: decoder_example.c,v 1.9 2000/06/15 09:18:34 xiphmont Exp $
********************************************************************/
double **pcm;
int samples;
- vorbis_synthesis(&vb,&op);
- vorbis_synthesis_blockin(&vd,&vb);
+ if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
+ vorbis_synthesis_blockin(&vd,&vb);
/*
**pcm is a multichannel double vector. In stereo, for
********************************************************************
function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.7 2000/05/12 08:38:20 msmith Exp $
+ last mod: $Id: encoder_example.c,v 1.8 2000/06/15 09:18:34 xiphmont Exp $
********************************************************************/
/* analysis */
vorbis_analysis(&vb,&op);
-
+
/* weld the packet into the bitstream */
ogg_stream_packetin(&os,&op);
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.15 2000/06/14 01:38:31 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.16 2000/06/15 09:18:34 xiphmont Exp $
********************************************************************/
int j,k;
int ampraw=_oggpack_read(&vb->opb,info->ampbits);
- if(ampraw>0){
+ if(ampraw>0){ /* also handles the -1 out of data case */
long maxval=(1<<info->ampbits)-1;
double amp=(float)ampraw/maxval*info->ampdB;
int booknum=_oggpack_read(&vb->opb,_ilog(info->numbooks));
- codebook *b=vb->vd->fullbooks+info->books[booknum];
- double last=0.;
- memset(out,0,sizeof(double)*look->m);
-
- for(j=0;j<look->m;j+=b->dim)
- vorbis_book_decodevs(b,out+j,&vb->opb,1,-1);
- for(j=0;j<look->m;){
- for(k=0;k<b->dim;k++,j++)out[j]+=last;
- last=out[j-1];
+ if(booknum!=-1){
+ codebook *b=vb->vd->fullbooks+info->books[booknum];
+ double last=0.;
+
+ memset(out,0,sizeof(double)*look->m);
+
+ for(j=0;j<look->m;j+=b->dim)
+ if(vorbis_book_decodevs(b,out+j,&vb->opb,1,-1)==-1)goto eop;
+ for(j=0;j<look->m;){
+ for(k=0;k<b->dim;k++,j++)out[j]+=last;
+ last=out[j-1];
+ }
+
+ /* take the coefficients back to a spectral envelope curve */
+ vorbis_lsp_to_lpc(out,out,look->m);
+ _lpc_to_curve(out,out,amp,look,"",0);
+
+ for(j=0;j<look->n;j++)out[j]= fromdB(out[j]-info->ampdB);
+ return(1);
}
+ }
- /* take the coefficients back to a spectral envelope curve */
- vorbis_lsp_to_lpc(out,out,look->m);
- _lpc_to_curve(out,out,amp,look,"",0);
-
- for(j=0;j<look->n;j++)out[j]= fromdB(out[j]-info->ampdB);
- return(1);
- }else
- memset(out,0,sizeof(double)*look->n);
-
+ eop:
+ memset(out,0,sizeof(double)*look->n);
return(0);
}
********************************************************************
function: residue backend 0 implementation
- last mod: $Id: res0.c,v 1.14 2000/06/14 08:19:22 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.15 2000/06/15 09:18:34 xiphmont Exp $
********************************************************************/
int dim=books[j]->dim;
int step=n/dim;
for(i=0;i<step;i++)
- vorbis_book_decodevs(books[j],work+i,opb,step,0);
+ if(vorbis_book_decodevs(books[j],work+i,opb,step,0)==-1)
+ return(-1);
}
for(i=0;i<n;i++)
return(0);
}
+/* a truncated packet here just means 'stop working'; it's not an error */
int inverse(vorbis_block *vb,vorbis_look_residue *vl,double **in,int ch){
- long i,j,k,l;
+ long i,j,k,l,transend=vb->pcmend/2;
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
vorbis_info_residue0 *info=look->info;
double *work=alloca(sizeof(double)*samples_per_partition);
partvals=partwords*partitions_per_word;
+ /* make sure we're zeroed up to the start */
+ for(j=0;j<ch;j++)
+ memset(in[j],0,sizeof(double)*info->begin);
+
for(i=info->begin,l=0;i<info->end;){
/* fetch the partition word for each channel */
for(j=0;j<ch;j++){
int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
+ if(temp==-1)goto eopbreak;
partword[j]=look->decodemap[temp];
- if(partword[j]==NULL)exit(1);
+ if(partword[j]==NULL)goto errout;
}
/* now we decode interleaved residual values for the partitions */
for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)
for(j=0;j<ch;j++){
int part=partword[j][k];
- _decodepart(&vb->opb,work,in[j]+i,samples_per_partition,
+ if(_decodepart(&vb->opb,work,in[j]+i,samples_per_partition,
info->secondstages[part],
- look->partbooks[part]);
+ look->partbooks[part])==-1)goto eopbreak;
}
}
+ eopbreak:
+ if(i<transend){
+ for(j=0;j<ch;j++)
+ memset(in[j]+i,0,sizeof(double)*(transend-i));
+ }
+
+ return(0);
+
+ errout:
+ for(j=0;j<ch;j++)
+ memset(in[j],0,sizeof(double)*transend);
return(0);
}
********************************************************************
function: single-block PCM synthesis
- last mod: $Id: synthesis.c,v 1.15 2000/02/12 08:33:10 xiphmont Exp $
+ last mod: $Id: synthesis.c,v 1.16 2000/06/15 09:18:34 xiphmont Exp $
********************************************************************/
vorbis_info *vi=vd->vi;
oggpack_buffer *opb=&vb->opb;
int type,mode,i;
-
+
/* first things first. Make sure decode is ready */
_vorbis_block_ripcord(vb);
_oggpack_readinit(opb,op->packet,op->bytes);
/* read our mode and pre/post windowsize */
mode=_oggpack_read(opb,vd->modebits);
+ if(mode==-1)return(-1);
+
vb->mode=mode;
vb->W=vi->mode_param[mode]->blockflag;
if(vb->W){
vb->lW=_oggpack_read(opb,1);
vb->nW=_oggpack_read(opb,1);
+ if(vb->nW==-1) return(-1);
}else{
vb->lW=0;
vb->nW=0;
libvorbis:
-libvorbis isn't doing the 'how much data in the last frame' trick from
-the PCM counter/last page flag.
-
Implement correct truncated packet handling; this is mostly a case of
'intiialize vectors and check return values' in res0.c:inverse (but
not entirely)
Option for brute-forcing vq search on maptype 2 (helps on undertrained
sets).
+vorbisfile instantaneous bitrate info
+
+encoder switch interface for binary compat through changes; ioctl()-like?
+
API changes:
break up some of the more monolithic calls (eg, allow access
to MDCT domain data, additional low level framing capability)
other:
command line suite
+'crashme'
\ No newline at end of file