Example #1
0
static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  int i;
  int vendorlen=oggpack_read1(opb,32);
    
  //int vendorlen=oggpack_read(opb,32);

  if(vendorlen<0)goto err_out;
  vc->vendor=(char *)calloc(vendorlen+1,1);
  _v_readstring(opb,vc->vendor,vendorlen);
  vc->comments=oggpack_read1(opb,32);    
  //vc->comments=oggpack_read(opb,32);

  if(vc->comments<0)goto err_out;
  vc->user_comments=(char **)calloc(vc->comments+1,sizeof(*vc->user_comments));
  vc->comment_lengths=(int *)calloc(vc->comments+1, sizeof(*vc->comment_lengths));
	    
  for(i=0;i<vc->comments;i++){
    int len=oggpack_read1(opb,32);         
     //int len=oggpack_read(opb,32);

    if(len<0)goto err_out;
	vc->comment_lengths[i]=len;
    vc->user_comments[i]=(char *)calloc(len+1,1);
    _v_readstring(opb,vc->user_comments[i],len);
  }	  
  if(oggpack_read1(opb,1)!=1)goto err_out; /* EOP check */
  //if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */

  return(0);
 err_out:
  vorbis_comment_clear(vc);
  return(OV_EBADHEADER);
}
Example #2
0
static int BURGERCALL _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
	codec_setup_info     *ci=static_cast<codec_setup_info *>(vi->codec_setup);
	if(!ci)return(OV_EFAULT);

	vi->version=oggpack_read(opb,32);
	if(vi->version!=0)return(OV_EVERSION);

	vi->channels=oggpack_read(opb,8);
	vi->rate=oggpack_read(opb,32);

	vi->bitrate_upper=oggpack_read(opb,32);
	vi->bitrate_nominal=oggpack_read(opb,32);
	vi->bitrate_lower=oggpack_read(opb,32);

	ci->blocksizes[0]=1<<oggpack_read(opb,4);
	ci->blocksizes[1]=1<<oggpack_read(opb,4);

	if(vi->rate<1)goto err_out;
	if(vi->channels<1)goto err_out;
	if(ci->blocksizes[0]<8)goto err_out; 
	if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;

	if(oggpack_read1(opb)!=1)goto err_out; /* EOP check */

	return(0);
err_out:
	vorbis_info_clear(vi);
	return(OV_EBADHEADER);
}
Example #3
0
static int BURGERCALL _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
	int i;
	int vendorlen=oggpack_read(opb,32);
	if(vendorlen>=0) {
		vc->vendor=static_cast<char *>(AllocAPointerClear(vendorlen+1));
		_v_readstring(opb,vc->vendor,vendorlen);
		vc->comments=oggpack_read(opb,32);
		if(vc->comments>=0) {
			vc->user_comments=static_cast<char **>(AllocAPointerClear((vc->comments+1)*sizeof(*vc->user_comments)));
			vc->comment_lengths=static_cast<int *>(AllocAPointerClear((vc->comments+1)*sizeof(*vc->comment_lengths)));

			for(i=0;i<vc->comments;i++){
				int len=oggpack_read(opb,32);
				if(len<0)goto err_out;
				vc->comment_lengths[i]=len;
				vc->user_comments[i]=static_cast<char *>(AllocAPointerClear(len+1));
				_v_readstring(opb,vc->user_comments[i],len);
			}	  
			if (oggpack_read1(opb)==1) {/* EOP check */
				return(0);
			}
		}
	}
err_out:
	vorbis_comment_clear(vc);
	return(OV_EBADHEADER);
}
Example #4
0
static int _vorbis_skip_comment(oggpack_buffer *opb)
{
 int i,vendorlen,comments;

 vendorlen=oggpack_read32(opb,32);
 if(vendorlen<0)
  goto err_out;
 oggpack_adv(opb,vendorlen*8);
 comments=oggpack_read32(opb,32);
 if(comments<0)
  goto err_out;

 for(i=0;i<comments;i++){
  int len=oggpack_read32(opb,32);
  if(len<0)
   goto err_out;
  oggpack_adv(opb,len*8);
 }
 if(oggpack_read1(opb)!=1)
  goto err_out; /* EOP check */
 oggpack_adv(opb,7); // byte alignment

 return(0);
err_out:
 return(OV_EBADHEADER);
}
Example #5
0
static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  while(bytes--){
    *buf++=(char)oggpack_read1(o,8);         
   //  *buf++=(char)oggpack_read(o,8);

  }
}
Example #6
0
static PyObject * py_ogg_oggpack_read1(PyObject *self, PyObject *args) {
  int size;
  long c_out;
  oggpack_buffer * b;
  PyArg_ParseTuple(args, "s#", &b, &size);
  c_out = oggpack_read1(b);
  return Py_BuildValue("l", c_out);
};
Example #7
0
int vorbis_synthesis(vorbis_block *vb,ogg_packet *op)
{
 vorbis_dsp_state     *vd=vb->vd;
 backend_lookup_state *b=vd->backend_state;
 vorbis_info          *vi=vd->vi;
 codec_setup_info     *ci=vi->codec_setup;
 oggpack_buffer       *opb=&vb->opb;
 int                   type,mode;

 oggpack_readinit(opb,op->packet,op->bytes);

 if(oggpack_read1(opb)!=0)
  return(OV_ENOTAUDIO);

 mode=oggpack_read32(opb,b->modebits);
 if((mode==-1) || (mode>=ci->modes))
  return(OV_EBADPACKET);

 vb->mode=mode;
 vb->W=ci->mode_param[mode]->blockflag;
 if(vb->W){
  vb->lW=oggpack_read1(opb);
  vb->nW=oggpack_read1(opb);
  if(vb->nW==-1)
   return(OV_EBADPACKET);
 }else{
  vb->lW=0;
  vb->nW=0;
 }

 vb->granulepos=op->granulepos;
 vb->sequence=op->packetno-3;
 vb->eofflag=op->e_o_s;

 vb->pcmend=ci->blocksizes[vb->W];

 type=ci->map_type[ci->mode_param[mode]->mapping];

 return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->mapping]));
}
/*
 * Class:     org_tritonus_lowlevel_ogg_Buffer
 * Method:    read1
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_org_tritonus_lowlevel_ogg_Buffer_read1
(JNIEnv* env, jobject obj)
{
	oggpack_buffer*	handle;
	int		nReturn;

	if (debug_flag) { fprintf(debug_file, "Java_org_tritonus_lowlevel_ogg_Buffer_read1(): begin\n"); }
	handle = getHandle(env, obj);
	nReturn = oggpack_read1(handle);
	if (debug_flag) { fprintf(debug_file, "Java_org_tritonus_lowlevel_ogg_Buffer_read1(): end\n"); }
	return nReturn;
}
Example #9
0
vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
  int j,tmp;

  vorbis_info_floor0 *info=(vorbis_info_floor0 *)malloc(sizeof(*info));
 /* info->order=oggpack_read(opb,8);
  info->rate=oggpack_read(opb,16);
  info->barkmap=oggpack_read(opb,16);
  info->ampbits=oggpack_read(opb,6);
  info->ampdB=oggpack_read(opb,8);
  info->numbooks=oggpack_read(opb,4)+1;
  */

  tmp = oggpack_read1(opb,24);
  info->order=tmp & 0xff;
  info->rate=(tmp & 0xffff00)>>8;
  tmp = oggpack_read1(opb,22);
  info->barkmap=tmp & 0xffff;
  info->ampbits=(tmp&0x3f0000)>>16;
  tmp = oggpack_read1(opb,12);
  info->ampdB=tmp & 0xff;
  info->numbooks=((tmp&0xf00)>>8) + 1;

  if(info->order<1)goto err_out;
  if(info->rate<1)goto err_out;
  if(info->barkmap<1)goto err_out;
  if(info->numbooks<1)goto err_out;
    
  for(j=0;j<info->numbooks;j++){
    info->books[j]=oggpack_read1(opb,8);
    // info->books[j]=oggpack_read(opb,8);
    if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  }
  return(info);

 err_out:
  floor0_free_info(info);
  return(0);
}
Example #10
0
vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  int i,tmp,rtmp;
  vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)calloc(1,sizeof(*info));
  codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
  memset(info,0,sizeof(*info));
  if(oggpack_read1(opb,1))
    info->submaps=oggpack_read1(opb,4)+1;

  //if(oggpack_read(opb,1))
   // info->submaps=oggpack_read(opb,4)+1;
  else
    info->submaps=1;
  if(oggpack_read1(opb,1)){

  //if(oggpack_read(opb,1)){
    info->coupling_steps=oggpack_read1(opb,8)+1;
    //info->coupling_steps=oggpack_read(opb,8)+1;
    //modify by archin
    tmp = ilog(vi->channels)<<1;
    
    for(i=0;i<info->coupling_steps;i++){
      //int testM = info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels));
      //int testA = info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels));       

      int testM;//=info->coupling_mag[i]=Ogg_Bit_Read(opb,ilog(vi->channels));
      int testA;//=info->coupling_ang[i]=Ogg_Bit_Read(opb,ilog(vi->channels));       
      rtmp = oggpack_read1(opb,tmp);
      testM= info->coupling_mag[i] = (rtmp & ((1<<(tmp>>1)) - 1));
      testA = info->coupling_ang[i]= ((rtmp & ((1<<tmp) - 1))>>(tmp>>1));
      if(testM<0 || 
	      testA<0 || 
	      testM==testA || 
	      testM>=vi->channels ||
	      testA>=vi->channels) goto err_out;
    }

  }
Example #11
0
static vorbis_info_residue0 *_012_unpack(vorbis_info *vi,oggpack_buffer *opb)
{
 int j,acc=0;
 vorbis_info_residue0 *info=_ogg_calloc(1,sizeof(*info));
 codec_setup_info     *ci=vi->codec_setup;

 info->begin=oggpack_read24(opb,24);
 info->len=oggpack_read24(opb,24)-info->begin;
 info->samples_per_partition=oggpack_read24(opb,24)+1;
 info->partitions=oggpack_read24(opb,6)+1;
 info->groupbook=oggpack_read24(opb,8);

 if(info->groupbook>=ci->books)
  goto errout;

 for(j=0;j<info->partitions;j++){
  int cascade=oggpack_read24(opb,3);
  if(oggpack_read1(opb))
   cascade|=(oggpack_read24(opb,5)<<3);
  info->secondstages[j]=cascade;

  acc+=icount(cascade);
 }

 for(j=0;j<acc;j++){
  int list=oggpack_read24(opb,8);
  if(list>=ci->books)
   goto errout;
  info->booklist[j]=list;
 }

 return(info);

errout:
 res012_free_info(info);
 return(NULL);
}
Example #12
0
static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb)
{
 codec_setup_info     *ci=vi->codec_setup;
 if(!ci)
  return(OV_EFAULT);

 if(oggpack_read32(opb,32)!=0) // version
  return(OV_EVERSION);

 vi->channels=vi->outchannels=oggpack_read24(opb,8);
 vi->rate    =oggpack_read32(opb,32);

 oggpack_adv(opb,32);  // bitrate_upper
 vi->bitrate_nominal=oggpack_read32(opb,32);
 oggpack_adv(opb,32);  // bitrate_lower

 ci->blocksizes[0]=1<<oggpack_read24(opb,4);
 ci->blocksizes[1]=1<<oggpack_read24(opb,4);

 if(vi->rate<1)
  goto err_out;
 if(vi->channels<1)
  goto err_out;
 if(ci->blocksizes[0]<8)
  goto err_out;
 if(ci->blocksizes[1]<ci->blocksizes[0])
  goto err_out;

 if(oggpack_read1(opb)!=1)
  goto err_out; /* EOP check */
 oggpack_adv(opb,7); // byte alignment

 return(0);
err_out:
 vorbis_info_clear(vi);
 return(OV_EBADHEADER);
}
Example #13
0
/* all of the real encoding details are here.  The modes, books,
   everything */
static int BURGERCALL _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  codec_setup_info     *ci=static_cast<codec_setup_info *>(vi->codec_setup);
  int i;
  if(!ci)return(OV_EFAULT);

  /* codebooks */
  ci->books=oggpack_read(opb,8)+1;
  /*ci->book_param=AllocAPointerClear(ci->books*sizeof(*ci->book_param));*/
  for(i=0;i<ci->books;i++){
    ci->book_param[i]=static_cast<static_codebook *>(AllocAPointerClear(sizeof(*ci->book_param[i])));
    if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  }

  /* time backend settings */
  ci->times=oggpack_read(opb,6)+1;
  /*ci->time_type=AllocAPointer(ci->times*sizeof(*ci->time_type));*/
  /*ci->time_param=AllocAPointerClear(ci->times*sizeof(void *));*/
  for(i=0;i<ci->times;i++){
    ci->time_type[i]=oggpack_read(opb,16);
    if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out;
    ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb);
    if(!ci->time_param[i])goto err_out;
  }

  /* floor backend settings */
  ci->floors=oggpack_read(opb,6)+1;
  /*ci->floor_type=AllocAPointer(ci->floors*sizeof(*ci->floor_type));*/
  /*ci->floor_param=AllocAPointerClear(ci->floors*sizeof(void *));*/
  for(i=0;i<ci->floors;i++){
    ci->floor_type[i]=oggpack_read(opb,16);
    if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
    ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
    if(!ci->floor_param[i])goto err_out;
  }

  /* residue backend settings */
  ci->residues=oggpack_read(opb,6)+1;
  /*ci->residue_type=AllocAPointer(ci->residues*sizeof(*ci->residue_type));*/
  /*ci->residue_param=AllocAPointerClear(ci->residues*sizeof(void *));*/
  for(i=0;i<ci->residues;i++){
    ci->residue_type[i]=oggpack_read(opb,16);
    if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
    ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
    if(!ci->residue_param[i])goto err_out;
  }

  /* map backend settings */
  ci->maps=oggpack_read(opb,6)+1;
  /*ci->map_type=AllocAPointer(ci->maps*sizeof(*ci->map_type));*/
  /*ci->map_param=AllocAPointerClear(ci->maps*sizeof(void *));*/
  for(i=0;i<ci->maps;i++){
    ci->map_type[i]=oggpack_read(opb,16);
    if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
    ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
    if(!ci->map_param[i])goto err_out;
  }
  
  /* mode settings */
  ci->modes=oggpack_read(opb,6)+1;
  /*vi->mode_param=AllocAPointerClear(vi->modes*sizeof(void *));*/
  for(i=0;i<ci->modes;i++){
    ci->mode_param[i]=static_cast<vorbis_info_mode *>(AllocAPointerClear(sizeof(*ci->mode_param[i])));
    ci->mode_param[i]->blockflag=oggpack_read1(opb);
    ci->mode_param[i]->windowtype=oggpack_read(opb,16);
    ci->mode_param[i]->transformtype=oggpack_read(opb,16);
    ci->mode_param[i]->mapping=oggpack_read(opb,8);

    if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
    if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
    if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  }
  
  if(oggpack_read1(opb)!=1)goto err_out; /* top level EOP check */

  return(0);
 err_out:
  vorbis_info_clear(vi);
  return(OV_EBADHEADER);
}
Example #14
0
static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
{
 int i;
 vorbis_info_mapping0 *info=_ogg_calloc(1,sizeof(*info));
 codec_setup_info     *ci=vi->codec_setup;

 if(!info)
  goto err_out;

 _ogg_memset(info,0,sizeof(*info));

 if(oggpack_read1(opb))
  info->submaps=oggpack_read24(opb,4)+1;
 else
  info->submaps=1;

 if(oggpack_read1(opb)){
  info->coupling_steps=oggpack_read24(opb,8)+1;

  info->coupling_mag=_ogg_malloc(sizeof(*info->coupling_mag)*info->coupling_steps);
  info->coupling_ang=_ogg_malloc(sizeof(*info->coupling_ang)*info->coupling_steps);
  if(!info->coupling_mag || !info->coupling_ang)
   goto err_out;

  for(i=0;i<info->coupling_steps;i++){
   int testM=info->coupling_mag[i]=oggpack_read24(opb,ilog(vi->channels));
   int testA=info->coupling_ang[i]=oggpack_read24(opb,ilog(vi->channels));

   if(testM<0 || testA<0 || testM==testA || testM>=vi->channels || testA>=vi->channels)
    goto err_out;
  }
 }

 if(oggpack_read24(opb,2)!=0)
  goto err_out;

 info->chmuxlist=_ogg_calloc(vi->channels,sizeof(*info->chmuxlist));
 if(!info->chmuxlist)
  goto err_out;

 if(info->submaps>1){
  for(i=0;i<vi->channels;i++){
   info->chmuxlist[i]=oggpack_read24(opb,4);
   if(info->chmuxlist[i]>=info->submaps)
    goto err_out;
  }
 }

 info->floorsubmap=_ogg_malloc(sizeof(*info->floorsubmap)*info->submaps);
 info->residuesubmap=_ogg_malloc(sizeof(*info->residuesubmap)*info->submaps);
 if(!info->floorsubmap || !info->residuesubmap)
  goto err_out;

 for(i=0;i<info->submaps;i++){
  oggpack_adv(opb,8);
  info->floorsubmap[i]=oggpack_read24(opb,8);
  if(info->floorsubmap[i]>=ci->floors)
   goto err_out;
  info->residuesubmap[i]=oggpack_read24(opb,8);
  if(info->residuesubmap[i]>=ci->residues)
   goto err_out;
 }

 info->pcmbundle =_ogg_malloc(sizeof(*info->pcmbundle)*vi->channels);
 info->nonzero   =_ogg_malloc(sizeof(*info->nonzero)*vi->channels);
 info->floormemo =_ogg_malloc(sizeof(*info->floormemo)*vi->channels);
 if(!info->pcmbundle || !info->nonzero || !info->floormemo)
  goto err_out;

 return info;

err_out:
 mapping0_free_info(info);
 return(NULL);
}
Example #15
0
vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
  int j,k,count=0,maxclass=-1,rangebits;

  vorbis_info_floor1 *info=(vorbis_info_floor1 *)calloc(1,sizeof(*info));
  /* read partitions */
  info->partitions=oggpack_read1(opb,5); /* only 0 to 31 legal */
   // info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */

  for(j=0;j<info->partitions;j++){
    info->partitionclass[j]=oggpack_read1(opb,4); /* only 0 to 15 legal */
     //info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
    if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  }

  /* read partition classes */
  for(j=0;j<maxclass+1;j++){
    info->class_dim[j]=oggpack_read1(opb,3)+1; /* 1 to 8 */
    info->class_subs[j]=oggpack_read1(opb,2); /* 0,1,2,3 bits */
         
   // info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
   // info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */

    if(info->class_subs[j]<0)
      goto err_out;
    if(info->class_subs[j])info->class_book[j]=oggpack_read1(opb,8);
        
   // if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);

    if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
      goto err_out;
    for(k=0;k<(1<<info->class_subs[j]);k++){
      info->class_subbook[j][k]=oggpack_read1(opb,8)-1;             
     //  info->class_subbook[j][k]=oggpack_read(opb,8)-1;

      if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
	goto err_out;
    }
  }

  /* read the post list */
  info->mult=oggpack_read1(opb,2)+1;     /* only 1,2,3,4 legal now */ 
  rangebits=oggpack_read1(opb,4);
  //info->mult=oggpack_read(opb,2)+1;     /* only 1,2,3,4 legal now */ 
  //rangebits=oggpack_read(opb,4);

  for(j=0,k=0;j<info->partitions;j++){
    count+=info->class_dim[info->partitionclass[j]]; 
    for(;k<count;k++){
      int t=info->postlist[k+2]=oggpack_read1(opb,rangebits);             
    //   int t=info->postlist[k+2]=oggpack_read(opb,rangebits);

      if(t<0 || t>=(1<<rangebits))
	goto err_out;
    }
  }
  info->postlist[0]=0;
  info->postlist[1]=1<<rangebits;

  return(info);
  
 err_out:
  floor1_free_info(info);
  return(0);
}
Example #16
0
int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  int i,j,tmp;
  memset(s,0,sizeof(*s));

  /* make sure alignment is correct */
  if(oggpack_read1(opb,24)!=0x564342)goto _eofout;
  // if(oggpack_read(opb,24)!=0x564342)goto _eofout;

  /* first the basic parameters */
  s->dim=oggpack_read1(opb,16);
   //s->dim=oggpack_read(opb,16);

  s->entries=oggpack_read1(opb,24);
    //s->entries=oggpack_read(opb,24);

  if(s->entries==-1)goto _eofout;

  /* codeword ordering.... length ordered or unordered? */
  switch((int)oggpack_read1(opb,1)){
    //switch((int)oggpack_read(opb,1)){

  case 0:
    /* unordered */
    s->lengthlist=(int *)malloc(sizeof(*s->lengthlist)*s->entries);

    /* allocated but unused entries? */
    if(oggpack_read1(opb,1)){
    //if(oggpack_read(opb,1)){
      /* yes, unused entries */

      for(i=0;i<s->entries;i++){
	if(oggpack_read1(opb,1)){
   //if(oggpack_read(opb,1)){
	  long num=oggpack_read1(opb,5);
      //long num=oggpack_read(opb,5);
	  if(num==-1)goto _eofout;
	  s->lengthlist[i]=num+1;
	}else
	  s->lengthlist[i]=0;
      }
    }else{
      /* all entries used; no tagging */
      for(i=0;i<s->entries;i++){
	long num=oggpack_read1(opb,5);
   //  long num=oggpack_read(opb,5);
	if(num==-1)goto _eofout;
	s->lengthlist[i]=num+1;
      }
    }
    
    break;
  case 1:
    /* ordered */
    {
      long length=oggpack_read1(opb,5)+1;
       //long length=oggpack_read(opb,5)+1;
      s->lengthlist=(int *)malloc(sizeof(*s->lengthlist)*s->entries);

      for(i=0;i<s->entries;){
	long num=oggpack_read1(opb,vorbisilog(s->entries-i));
     //long num=oggpack_read(opb,vorbisilog(s->entries-i));
	if(num==-1)goto _eofout;
	for(j=0;j<num && i<s->entries;j++,i++)
	  s->lengthlist[i]=length;
	length++;
      }
    }
    break;
  default:
    /* EOF */
    return(-1);
  }
  
  /* Do we have a mapping to unpack? */
  switch((s->maptype=oggpack_read1(opb,4))){
    //switch((s->maptype=oggpack_read(opb,4))){
  case 0:
    /* no mapping */
    break;
  case 1: case 2:
    /* implicitly populated value mapping */
    /* explicitly populated value mapping */

    s->q_min=oggpack_read1(opb,32);
    s->q_delta=oggpack_read1(opb,32);
    tmp = oggpack_read1(opb,5);
    s->q_quant = (tmp & 0xf) + 1;
    s->q_sequencep = ((tmp & 0x10)>>4);
    //s->q_quant=oggpack_read(opb,4)+1;
    //s->q_sequencep=oggpack_read(opb,1);
   
    {
      int quantvals=0;
      switch(s->maptype){
      case 1:
	quantvals=_book_maptype1_quantvals(s);
	break;
      case 2:
	quantvals=s->entries*s->dim;
	break;
      }
      
      /* quantized values */
      s->quantlist=(long *)malloc(sizeof(*s->quantlist)*quantvals);
      for(i=0;i<quantvals;i++)
	s->quantlist[i]=oggpack_read1(opb,s->q_quant);
   //   s->quantlist[i]=oggpack_read(opb,s->q_quant);
      if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
    }
    break;
  default:
    goto _errout;
  }

  /* all set */
  return(0);
  
 _errout:
 _eofout:
  vorbis_staticbook_clear(s);
  return(-1); 
}
JNIEXPORT jlong JNICALL Java_org_echocat_jogg_OggPackBufferJNI_read1
    (JNIEnv *env, jclass thisClass, jlong handle) {

    return (jlong) oggpack_read1((oggpack_buffer*) handle);
}
Example #18
0
static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb)
{
 codec_setup_info     *ci=vi->codec_setup;
 int i;

 if(!ci)
  return(OV_EFAULT);

 ci->books=oggpack_read24(opb,8)+1;
 for(i=0;i<ci->books;i++){
  ci->book_param[i]=_ogg_calloc(1,sizeof(*ci->book_param[i]));
  if(vorbis_staticbook_unpack(opb,ci->book_param[i]))
   goto err_out;
 }

 {
  int times=oggpack_read24(opb,6)+1;
  for(i=0;i<times;i++){
   int test=oggpack_read24(opb,16);
   if(test<0 || test>=VI_TIMEB)
    goto err_out;
  }
 }

 ci->floors=oggpack_read24(opb,6)+1;
 for(i=0;i<ci->floors;i++){
  ci->floor_type[i]=oggpack_read24(opb,16);
  if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)
   goto err_out;
  ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  if(!ci->floor_param[i])
   goto err_out;
 }

 ci->residues=oggpack_read24(opb,6)+1;
 for(i=0;i<ci->residues;i++){
  ci->residue_type[i]=oggpack_read24(opb,16);
  if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)
   goto err_out;
  ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  if(!ci->residue_param[i])
   goto err_out;
 }

 ci->maps=oggpack_read24(opb,6)+1;
 for(i=0;i<ci->maps;i++){
  ci->map_type[i]=oggpack_read24(opb,16);
  if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)
   goto err_out;
  ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  if(!ci->map_param[i])
   goto err_out;
 }

 ci->modes=oggpack_read24(opb,6)+1;
 for(i=0;i<ci->modes;i++){
  ci->mode_param[i]=_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  ci->mode_param[i]->blockflag=oggpack_read1(opb);
  ci->mode_param[i]->windowtype=oggpack_read24(opb,16);
  ci->mode_param[i]->transformtype=oggpack_read24(opb,16);
  ci->mode_param[i]->mapping=oggpack_read24(opb,8);

  if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
 }

 if(oggpack_read1(opb)!=1)
  goto err_out; /* top level EOP check */
 oggpack_adv(opb,7); // byte alignment

 return(0);
err_out:
 vorbis_info_clear(vi);
 return(OV_EBADHEADER);
}