internal int unpack(csBuffer opb)
{
int i;
//memset(s,0,sizeof(static_codebook));
// make sure alignment is correct
if(opb.read(24)!=0x564342)
{
// goto _eofout;
clear();
return(-1);
}
// first the basic parameters
dim=opb.read(16);
entries=opb.read(24);
if(entries==-1)
{
// goto _eofout;
clear();
return(-1);
}
// codeword ordering.... length ordered or unordered?
switch(opb.read(1))
{
case 0:
// unordered
lengthlist=new int[entries];
// allocated but unused entries?
if(opb.read(1)!=0)
{
// yes, unused entries
for(i=0;i<entries;i++)
{
if(opb.read(1)!=0)
{
int num=opb.read(5);
if(num==-1)
{
// goto _eofout;
clear();
return(-1);
}
lengthlist[i]=num+1;
}
else
{
lengthlist[i]=0;
}
}
}
else
{
// all entries used; no tagging
for(i=0;i<entries;i++)
{
int num=opb.read(5);
if(num==-1)
{
// goto _eofout;
clear();
return(-1);
}
lengthlist[i]=num+1;
}
}
break;
case 1:
// ordered
{
int length=opb.read(5)+1;
lengthlist=new int[entries];
for(i=0;i<entries;)
{
int num=opb.read(ilog(entries-i));
if(num==-1)
{
// goto _eofout;
clear();
return(-1);
}
for(int j=0;j<num;j++,i++)
{
lengthlist[i]=length;
}
length++;
}
}
break;
default:
// EOF
return(-1);
}
// Do we have a mapping to unpack?
switch((maptype=opb.read(4)))
{
case 0:
// no mapping
break;
case 1:
case 2:
// implicitly populated value mapping
// explicitly populated value mapping
q_min=opb.read(32);
q_delta=opb.read(32);
q_quant=opb.read(4)+1;
q_sequencep=opb.read(1);
{
int quantvals=0;
switch(maptype)
{
case 1:
quantvals=maptype1_quantvals();
break;
case 2:
quantvals=entries*dim;
break;
}
// quantized values
quantlist=new int[quantvals];
for(i=0;i<quantvals;i++)
{
quantlist[i]=opb.read(q_quant);
}
if(quantlist[quantvals-1]==-1)
{
// goto _eofout;
clear();
return(-1);
}
}
break;
default:
// goto _eofout;
clear();
return(-1);
}
// all set
return(0);
// _errout:
// _eofout:
// vorbis_staticbook_clear(s);
// return(-1);
}