********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.26 2000/02/23 09:24:23 xiphmont Exp $
+ last mod: $Id: block.c,v 1.27 2000/02/23 11:22:43 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
if(v){
vorbis_info *vi=v->vi;
- for(i=0;i<VI_WINDOWB;i++){
- if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
- for(j=0;j<2;j++)
- for(k=0;k<2;k++)
- if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
- }
+ if(v->window[0][0][0])
+ for(i=0;i<VI_WINDOWB;i++){
+ if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
+ for(j=0;j<2;j++)
+ for(k=0;k<2;k++)
+ if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
+ }
+
if(v->pcm){
for(i=0;i<vi->channels;i++)
if(v->pcm[i])free(v->pcm[i]);
if(v->multipliers)free(v->multipliers);
_ve_envelope_clear(&v->ve);
- mdct_clear(v->transform[0][0]);
- mdct_clear(v->transform[1][0]);
- free(v->transform[0][0]);
- free(v->transform[1][0]);
-
- free(v->transform[0]);
- free(v->transform[1]);
+ if(v->transform[0]){
+ mdct_clear(v->transform[0][0]);
+ free(v->transform[0][0]);
+ free(v->transform[0]);
+ }
+ if(v->transform[1]){
+ mdct_clear(v->transform[1][0]);
+ free(v->transform[1][0]);
+ free(v->transform[1]);
+ }
/* free mode lookups; these are actually vorbis_look_mapping structs */
- for(i=0;i<vi->modes;i++){
- int mapnum=vi->mode_param[i]->mapping;
- int maptype=vi->map_type[mapnum];
- _mapping_P[maptype]->free_look(v->mode[i]);
+ if(vi){
+ for(i=0;i<vi->modes;i++){
+ int mapnum=vi->mode_param[i]->mapping;
+ int maptype=vi->map_type[mapnum];
+ _mapping_P[maptype]->free_look(v->mode[i]);
+ }
+ /* free codebooks */
+ for(i=0;i<vi->books;i++)
+ vorbis_book_clear(v->fullbooks+i);
}
- if(v->mode)free(v->mode);
-
- /* free codebooks */
- for(i=0;i<vi->books;i++)
- vorbis_book_clear(v->fullbooks+i);
+
+ if(v->mode)free(v->mode);
if(v->fullbooks)free(v->fullbooks);
/* free header, header1, header2 */
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.10 2000/02/23 09:24:27 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.11 2000/02/23 11:22:44 xiphmont Exp $
********************************************************************/
/* take the coefficients back to a spectral envelope curve */
vorbis_lsp_to_lpc(out,out,look->m);
vorbis_lpc_to_curve(out,out,amp,&look->lpclook);
- fprintf(stderr,"Encoded %d LSP coefficients in %d bits\n",look->m,bits);
+ fprintf(stderr,"Encoded %ld LSP coefficients in %ld bits\n",look->m,bits);
return(1);
}
- fprintf(stderr,"Encoded %d LSP coefficients in %d bits\n",look->m,bits);
+ fprintf(stderr,"Encoded %ld LSP coefficients in %ld bits\n",look->m,bits);
memset(out,0,sizeof(double)*look->n);
return(0);
********************************************************************
function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.20 2000/02/06 13:39:41 xiphmont Exp $
+ last mod: $Id: info.c,v 1.21 2000/02/23 11:22:45 xiphmont Exp $
********************************************************************/
/* Also verify header-ness, vorbis */
{
char buffer[6];
+ int packtype=_oggpack_read(&opb,8);
memset(buffer,0,6);
_v_readstring(&opb,buffer,6);
if(memcmp(buffer,"vorbis",6)){
/* not a vorbis header */
return(-1);
}
- switch(_oggpack_read(&opb,8)){
- case 0x80:
+ switch(packtype){
+ case 0x01: /* least significant *bit* is read first */
if(!op->b_o_s){
/* Not the initial packet */
return(-1);
return(_vorbis_unpack_info(vi,&opb));
- case 0x81:
+ case 0x03: /* least significant *bit* is read first */
if(vi->rate==0){
/* um... we didn't get the initial header */
return(-1);
return(_vorbis_unpack_comment(vc,&opb));
- case 0x82:
+ case 0x05: /* least significant *bit* is read first */
if(vi->rate==0 || vc->vendor==NULL){
/* um... we didn;t get the initial header or comments yet */
return(-1);
static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
/* preamble */
+ _oggpack_write(opb,0x01,8);
_v_writestring(opb,"vorbis");
- _oggpack_write(opb,0x80,8);
/* basic information about the stream */
_oggpack_write(opb,0x00,32);
char temp[]="Xiphophorus libVorbis I 20000121";
/* preamble */
+ _oggpack_write(opb,0x03,8);
_v_writestring(opb,"vorbis");
- _oggpack_write(opb,0x81,8);
/* vendor */
_oggpack_write(opb,strlen(temp),32);
static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
int i;
+ _oggpack_write(opb,0x05,8);
_v_writestring(opb,"vorbis");
- _oggpack_write(opb,0x82,8);
/* books */
_oggpack_write(opb,vi->books-1,8);
********************************************************************
function: residue backend 0 implementation
- last mod: $Id: res0.c,v 1.7 2000/02/23 09:24:31 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.8 2000/02/23 11:22:46 xiphmont Exp $
********************************************************************/
}
}
-/* not yet */
void pack(vorbis_info_residue *vr,oggpack_buffer *opb){
vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
int j,acc=0;
}
for(i=0;i<possible_partitions;i++)resbitsT+=resbits[i];
- fprintf(stderr,"Encoded %ld res vectors in %d phrasing and %d res bits\n\t",
+ fprintf(stderr,"Encoded %ld res vectors in %ld phrasing and %ld res bits\n\t",
ch*(info->end-info->begin),phrasebits,resbitsT);
for(i=0;i<possible_partitions;i++)
fprintf(stderr,"%ld(%ld):%ld ",i,resvals[i],resbits[i]);
partword[j]=look->decodemap[vorbis_book_decode(look->phrasebook,
&vb->opb)];
- /* now we encode interleaved residual values for the partitions */
+ /* 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];
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
- last mod: $Id: vorbisfile.c,v 1.14 2000/01/28 09:05:18 xiphmont Exp $
+ last mod: $Id: vorbisfile.c,v 1.15 2000/02/23 11:22:47 xiphmont Exp $
********************************************************************/
int i,ret;
vf->vi=calloc(vf->links,sizeof(vorbis_info));
+ vf->vc=calloc(vf->links,sizeof(vorbis_info));
vf->dataoffsets=malloc(vf->links*sizeof(long));
vf->pcmlengths=malloc(vf->links*sizeof(int64_t));
vf->serialnos=malloc(vf->links*sizeof(long));