2005-02-17 09:08:18 +00:00
|
|
|
/********************************************************************
|
|
|
|
* *
|
|
|
|
* THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
|
|
|
|
* *
|
|
|
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
|
|
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
|
|
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
|
|
|
* *
|
|
|
|
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
|
|
|
|
* BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
|
|
|
|
* *
|
|
|
|
********************************************************************
|
|
|
|
|
|
|
|
function: basic codebook pack/unpack/code/decode operations
|
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
|
2005-02-28 20:55:31 +00:00
|
|
|
#include "config-tremor.h"
|
2005-02-17 09:08:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "ogg.h"
|
|
|
|
#include "ivorbiscodec.h"
|
|
|
|
#include "codebook.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
/* unpacks a codebook from the packet buffer into the codebook struct,
|
|
|
|
readies the codebook auxiliary structures for decode *************/
|
2010-12-08 16:07:46 +00:00
|
|
|
static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
|
2005-02-17 09:08:18 +00:00
|
|
|
long i,j;
|
2010-12-08 16:07:46 +00:00
|
|
|
static_codebook *s=_ogg_calloc(1,sizeof(*s));
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* make sure alignment is correct */
|
|
|
|
if(oggpack_read(opb,24)!=0x564342)goto _eofout;
|
|
|
|
|
|
|
|
/* first the basic parameters */
|
|
|
|
s->dim=oggpack_read(opb,16);
|
|
|
|
s->entries=oggpack_read(opb,24);
|
|
|
|
if(s->entries==-1)goto _eofout;
|
2010-12-06 16:40:05 +00:00
|
|
|
|
|
|
|
if(_ilog(s->dim)+_ilog(s->entries)>24)goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* codeword ordering.... length ordered or unordered? */
|
|
|
|
switch((int)oggpack_read(opb,1)){
|
2010-12-08 16:48:17 +00:00
|
|
|
case 0:{
|
|
|
|
long unused;
|
|
|
|
/* allocated but unused entries? */
|
|
|
|
unused=oggpack_read(opb,1);
|
|
|
|
if((s->entries*(unused?1:5)+7)>>3>opb->storage-oggpack_bytes(opb))
|
|
|
|
goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
/* unordered */
|
|
|
|
s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
|
|
|
|
|
|
|
|
/* allocated but unused entries? */
|
2010-12-08 16:48:17 +00:00
|
|
|
if(unused){
|
2005-02-17 09:08:18 +00:00
|
|
|
/* yes, unused entries */
|
|
|
|
|
|
|
|
for(i=0;i<s->entries;i++){
|
2010-03-05 09:48:07 +00:00
|
|
|
if(oggpack_read(opb,1)){
|
|
|
|
long num=oggpack_read(opb,5);
|
|
|
|
if(num==-1)goto _eofout;
|
|
|
|
s->lengthlist[i]=num+1;
|
|
|
|
}else
|
|
|
|
s->lengthlist[i]=0;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
/* all entries used; no tagging */
|
|
|
|
for(i=0;i<s->entries;i++){
|
2010-03-05 09:48:07 +00:00
|
|
|
long num=oggpack_read(opb,5);
|
|
|
|
if(num==-1)goto _eofout;
|
|
|
|
s->lengthlist[i]=num+1;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2010-12-08 16:48:17 +00:00
|
|
|
}
|
2005-02-17 09:08:18 +00:00
|
|
|
case 1:
|
|
|
|
/* ordered */
|
|
|
|
{
|
|
|
|
long length=oggpack_read(opb,5)+1;
|
2010-12-08 16:48:17 +00:00
|
|
|
if(length==0)goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
|
|
|
|
|
|
|
|
for(i=0;i<s->entries;){
|
2010-12-12 17:59:05 +00:00
|
|
|
long num=oggpack_read(opb,_ilog(s->entries-i));
|
|
|
|
if(num==-1)goto _eofout;
|
|
|
|
if(length>32 || num>s->entries-i ||
|
|
|
|
(num>0 && (num-1)>>(length>>1)>>((length+1)>>1))>0){
|
|
|
|
goto _errout;
|
|
|
|
}
|
|
|
|
for(j=0;j<num;j++,i++)
|
|
|
|
s->lengthlist[i]=length;
|
|
|
|
length++;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* EOF */
|
2010-12-08 16:07:46 +00:00
|
|
|
goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do we have a mapping to unpack? */
|
|
|
|
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_read(opb,32);
|
|
|
|
s->q_delta=oggpack_read(opb,32);
|
|
|
|
s->q_quant=oggpack_read(opb,4)+1;
|
|
|
|
s->q_sequencep=oggpack_read(opb,1);
|
2010-12-07 16:55:36 +00:00
|
|
|
if(s->q_sequencep==-1)goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
int quantvals=0;
|
|
|
|
switch(s->maptype){
|
|
|
|
case 1:
|
2010-12-06 16:44:40 +00:00
|
|
|
quantvals=(s->dim==0?0:_book_maptype1_quantvals(s));
|
2010-03-05 09:48:07 +00:00
|
|
|
break;
|
2005-02-17 09:08:18 +00:00
|
|
|
case 2:
|
2010-03-05 09:48:07 +00:00
|
|
|
quantvals=s->entries*s->dim;
|
|
|
|
break;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* quantized values */
|
2010-12-08 16:48:17 +00:00
|
|
|
if((quantvals*s->q_quant+7)>>3>opb->storage-oggpack_bytes(opb))
|
|
|
|
goto _eofout;
|
2005-02-17 09:08:18 +00:00
|
|
|
s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
|
|
|
|
for(i=0;i<quantvals;i++)
|
2010-03-05 09:48:07 +00:00
|
|
|
s->quantlist[i]=oggpack_read(opb,s->q_quant);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto _errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all set */
|
2010-12-08 16:07:46 +00:00
|
|
|
return(s);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
_errout:
|
|
|
|
_eofout:
|
2010-12-08 16:07:46 +00:00
|
|
|
vorbis_staticbook_destroy(s);
|
|
|
|
return(NULL);
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the 'eliminate the decode tree' optimization actually requires the
|
|
|
|
codewords to be MSb first, not LSb. This is an annoying inelegancy
|
|
|
|
(and one of the first places where carefully thought out design
|
|
|
|
turned out to be wrong; Vorbis II and future Ogg codecs should go
|
|
|
|
to an MSb bitpacker), but not actually the huge hit it appears to
|
|
|
|
be. The first-stage decode table catches most words so that
|
|
|
|
bitreverse is not in the main execution path. */
|
|
|
|
|
2009-12-23 18:05:11 +00:00
|
|
|
static inline ogg_uint32_t bitreverse(register ogg_uint32_t x)
|
|
|
|
{
|
2009-12-23 23:44:56 +00:00
|
|
|
unsigned tmp, ret;
|
2010-03-16 04:47:24 +00:00
|
|
|
#ifdef _ARM_ASSEM_
|
2009-12-23 23:44:56 +00:00
|
|
|
#if ARM_ARCH >= 6
|
|
|
|
unsigned mask = 0x0f0f0f0f;
|
2009-12-23 18:05:11 +00:00
|
|
|
#else
|
2009-12-23 23:44:56 +00:00
|
|
|
unsigned mask = 0x00ff00ff;
|
2009-12-23 18:05:11 +00:00
|
|
|
#endif
|
2009-12-23 23:44:56 +00:00
|
|
|
asm (
|
|
|
|
#if ARM_ARCH >= 6
|
|
|
|
"rev %[r], %[x] \n" /* swap halfwords and bytes */
|
|
|
|
"and %[t], %[m], %[r] \n" /* Sequence is one instruction */
|
|
|
|
"eor %[r], %[t], %[r] \n" /* longer than on <= ARMv5, but */
|
|
|
|
"mov %[t], %[t], lsl #4 \n" /* interlock free */
|
|
|
|
"orr %[r], %[t], %[r], lsr #4\n" /* nibbles swapped */
|
|
|
|
"eor %[m], %[m], %[m], lsl #2\n" /* mask = 0x33333333 */
|
|
|
|
"and %[t], %[m], %[r] \n"
|
|
|
|
"eor %[r], %[t], %[r] \n"
|
|
|
|
"mov %[t], %[t], lsl #2 \n"
|
|
|
|
"orr %[r], %[t], %[r], lsr #2\n" /* dibits swapped */
|
|
|
|
"eor %[m], %[m], %[m], lsl #1\n" /* mask = 0x55555555 */
|
|
|
|
"and %[t], %[m], %[r] \n"
|
|
|
|
"eor %[r], %[t], %[r] \n"
|
|
|
|
"mov %[t], %[t], lsl #1 \n"
|
|
|
|
"orr %[r], %[t], %[r], lsr #1\n" /* bits swapped */
|
|
|
|
#else /* ARM_ARCH <= 5 */
|
|
|
|
"mov %[r], %[x], ror #16 \n" /* swap halfwords */
|
|
|
|
"and %[t], %[m], %[r], lsr #8\n"
|
|
|
|
"eor %[r], %[r], %[t], lsl #8\n"
|
|
|
|
"orr %[r], %[t], %[r], lsl #8\n" /* bytes swapped */
|
|
|
|
"eor %[m], %[m], %[m], lsl #4\n" /* mask = 0x0f0f0f0f */
|
|
|
|
"and %[t], %[m], %[r], lsr #4\n"
|
|
|
|
"eor %[r], %[r], %[t], lsl #4\n"
|
|
|
|
"orr %[r], %[t], %[r], lsl #4\n" /* nibbles swapped */
|
|
|
|
"eor %[m], %[m], %[m], lsl #2\n" /* mask = 0x33333333 */
|
|
|
|
"and %[t], %[m], %[r], lsr #2\n"
|
|
|
|
"eor %[r], %[r], %[t], lsl #2\n"
|
|
|
|
"orr %[r], %[t], %[r], lsl #2\n" /* dibits swapped */
|
|
|
|
"eor %[m], %[m], %[m], lsl #1\n" /* mask = 0x55555555 */
|
|
|
|
"and %[t], %[m], %[r], lsr #1\n"
|
|
|
|
"eor %[r], %[r], %[t], lsl #1\n"
|
|
|
|
"orr %[r], %[t], %[r], lsl #1\n" /* bits swapped */
|
|
|
|
#endif /* ARM_ARCH */
|
|
|
|
: /* outputs */
|
|
|
|
[m]"+r"(mask),
|
|
|
|
[r]"=r"(ret),
|
|
|
|
[t]"=r"(tmp)
|
|
|
|
: /* inputs */
|
|
|
|
[x]"r"(x)
|
|
|
|
);
|
2010-03-16 04:47:24 +00:00
|
|
|
#else /* !_ARM_ASSEM_ */
|
2009-12-23 23:44:56 +00:00
|
|
|
|
|
|
|
#ifdef CPU_COLDFIRE
|
|
|
|
ret = x;
|
2010-11-15 16:02:17 +00:00
|
|
|
asm ("swap %[r]" : [r] "+d" (ret)); /* swap halfwords */
|
2009-12-23 23:44:56 +00:00
|
|
|
#else
|
|
|
|
ret = (x>>16) | (x<<16);
|
2009-12-23 18:05:11 +00:00
|
|
|
#endif
|
2009-12-23 23:44:56 +00:00
|
|
|
tmp = ret & 0x00ff00ff;
|
|
|
|
ret ^= tmp;
|
|
|
|
ret = (ret >> 8) | (tmp << 8); /* bytes swapped */
|
|
|
|
tmp = ret & 0x0f0f0f0f;
|
|
|
|
ret ^= tmp;
|
|
|
|
ret = (ret >> 4) | (tmp << 4); /* 4-bit units swapped */
|
|
|
|
tmp = ret & 0x33333333;
|
|
|
|
ret ^= tmp;
|
|
|
|
ret = (ret >> 2) | (tmp << 2); /* 2-bit units swapped */
|
|
|
|
tmp = ret & 0x55555555;
|
|
|
|
ret ^= tmp;
|
|
|
|
ret = (ret >> 1) | (tmp << 1); /* done */
|
2010-03-16 04:47:24 +00:00
|
|
|
#endif /* !_ARM_ASSEM_ */
|
2009-12-23 23:44:56 +00:00
|
|
|
return ret;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:31:07 +00:00
|
|
|
static inline long bisect_codelist(long lo, long hi, ogg_uint32_t cache,
|
|
|
|
const ogg_uint32_t *codelist)
|
|
|
|
{
|
|
|
|
ogg_uint32_t testword=bitreverse(cache);
|
|
|
|
long p;
|
|
|
|
while(LIKELY(p = (hi-lo) >> 1) > 0){
|
|
|
|
if(codelist[lo+p] > testword)
|
|
|
|
hi -= p;
|
|
|
|
else
|
|
|
|
lo += p;
|
|
|
|
}
|
|
|
|
return lo;
|
|
|
|
}
|
|
|
|
|
2007-07-01 17:58:49 +00:00
|
|
|
STIN long decode_packed_entry_number(codebook *book,
|
2010-03-05 09:48:07 +00:00
|
|
|
oggpack_buffer *b){
|
2005-02-17 09:08:18 +00:00
|
|
|
int read=book->dec_maxlength;
|
|
|
|
long lo,hi;
|
|
|
|
long lok = oggpack_look(b,book->dec_firsttablen);
|
|
|
|
|
2008-11-22 16:56:20 +00:00
|
|
|
if (LIKELY(lok >= 0)) {
|
2010-07-01 20:31:07 +00:00
|
|
|
ogg_int32_t entry = book->dec_firsttable[lok];
|
|
|
|
if(UNLIKELY(entry < 0)){
|
2005-02-17 09:08:18 +00:00
|
|
|
lo=(entry>>15)&0x7fff;
|
|
|
|
hi=book->used_entries-(entry&0x7fff);
|
|
|
|
}else{
|
|
|
|
oggpack_adv(b, book->dec_codelengths[entry-1]);
|
|
|
|
return(entry-1);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
lo=0;
|
|
|
|
hi=book->used_entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
lok = oggpack_look(b, read);
|
|
|
|
|
|
|
|
while(lok<0 && read>1)
|
|
|
|
lok = oggpack_look(b, --read);
|
2007-07-01 17:58:49 +00:00
|
|
|
|
|
|
|
if(lok<0){
|
|
|
|
oggpack_adv(b,1); /* force eop */
|
|
|
|
return -1;
|
|
|
|
}
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* bisect search for the codeword in the ordered list */
|
|
|
|
{
|
2010-07-01 20:31:07 +00:00
|
|
|
lo = bisect_codelist(lo, hi, lok, book->codelist);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
if(book->dec_codelengths[lo]<=read){
|
|
|
|
oggpack_adv(b, book->dec_codelengths[lo]);
|
|
|
|
return(lo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-01 17:58:49 +00:00
|
|
|
oggpack_adv(b, read+1);
|
2005-02-17 09:08:18 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2007-09-27 21:58:51 +00:00
|
|
|
static long decode_packed_block(codebook *book, oggpack_buffer *b,
|
2007-03-24 14:06:56 +00:00
|
|
|
long *buf, int n){
|
|
|
|
long *bufptr = buf;
|
|
|
|
long *bufend = buf + n;
|
|
|
|
|
|
|
|
while (bufptr<bufend) {
|
2010-12-06 14:36:52 +00:00
|
|
|
if(b->endbyte < b->storage - 8) {
|
2007-03-24 14:06:56 +00:00
|
|
|
ogg_uint32_t *ptr;
|
|
|
|
unsigned long bit, bitend;
|
|
|
|
unsigned long adr;
|
|
|
|
ogg_uint32_t cache = 0;
|
|
|
|
int cachesize = 0;
|
2010-10-31 14:48:40 +00:00
|
|
|
const unsigned int cachemask = (1<<book->dec_firsttablen)-1;
|
|
|
|
const int book_dec_maxlength = book->dec_maxlength;
|
|
|
|
const ogg_uint32_t *book_dec_firsttable = book->dec_firsttable;
|
|
|
|
const long book_used_entries = book->used_entries;
|
|
|
|
const ogg_uint32_t *book_codelist = book->codelist;
|
|
|
|
const char *book_dec_codelengths = book->dec_codelengths;
|
2007-03-24 14:06:56 +00:00
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
adr = (unsigned long)b->ptr;
|
|
|
|
bit = (adr&3)*8+b->endbit;
|
2010-10-31 14:48:40 +00:00
|
|
|
ptr = (ogg_uint32_t*)(adr&~3);
|
2010-12-06 14:36:52 +00:00
|
|
|
bitend = ((adr&3)+(b->storage-b->endbyte))*8;
|
2007-03-24 14:06:56 +00:00
|
|
|
while (bufptr<bufend){
|
2010-10-31 14:48:40 +00:00
|
|
|
if (UNLIKELY(cachesize<book_dec_maxlength)) {
|
2010-03-05 09:48:07 +00:00
|
|
|
if (bit-cachesize+32>=bitend)
|
|
|
|
break;
|
|
|
|
bit-=cachesize;
|
2010-10-31 14:48:40 +00:00
|
|
|
cache = letoh32(ptr[bit>>5]);
|
|
|
|
if (bit&31) {
|
|
|
|
cache >>= (bit&31);
|
|
|
|
cache |= letoh32(ptr[(bit>>5)+1]) << (32-(bit&31));
|
|
|
|
}
|
2010-03-05 09:48:07 +00:00
|
|
|
cachesize=32;
|
|
|
|
bit+=32;
|
|
|
|
}
|
2010-02-22 19:44:05 +00:00
|
|
|
|
2010-10-31 14:48:40 +00:00
|
|
|
ogg_int32_t entry = book_dec_firsttable[cache&cachemask];
|
2010-07-01 20:31:07 +00:00
|
|
|
if(UNLIKELY(entry < 0)){
|
2010-10-31 14:48:40 +00:00
|
|
|
const long lo = (entry>>15)&0x7fff, hi = book_used_entries-(entry&0x7fff);
|
|
|
|
entry = bisect_codelist(lo, hi, cache, book_codelist);
|
2010-03-05 09:48:07 +00:00
|
|
|
}else
|
|
|
|
entry--;
|
|
|
|
|
2010-10-31 14:48:40 +00:00
|
|
|
*bufptr++ = entry;
|
|
|
|
int l = book_dec_codelengths[entry];
|
|
|
|
cachesize -= l;
|
|
|
|
cache >>= l;
|
2007-03-24 14:06:56 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
adr=(unsigned long)b->ptr;
|
2007-03-24 14:06:56 +00:00
|
|
|
bit-=(adr&3)*8+cachesize;
|
2010-12-06 14:36:52 +00:00
|
|
|
b->endbyte+=bit/8;
|
|
|
|
b->ptr+=bit/8;
|
|
|
|
b->endbit=bit&7;
|
2007-03-24 14:06:56 +00:00
|
|
|
} else {
|
|
|
|
long r = decode_packed_entry_number(book, b);
|
|
|
|
if (r == -1) return bufptr-buf;
|
|
|
|
*bufptr++ = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
/* Decode side is specced and easier, because we don't need to find
|
|
|
|
matches using different criteria; we simply read and map. There are
|
|
|
|
two things we need to do 'depending':
|
|
|
|
|
|
|
|
We may need to support interleave. We don't really, but it's
|
|
|
|
convenient to do it here rather than rebuild the vector later.
|
|
|
|
|
|
|
|
Cascades may be additive or multiplicitive; this is not inherent in
|
|
|
|
the codebook, but set in the code using the codebook. Like
|
|
|
|
interleaving, it's easiest to do it here.
|
|
|
|
addmul==0 -> declarative (set the value)
|
|
|
|
addmul==1 -> additive
|
|
|
|
addmul==2 -> multiplicitive */
|
|
|
|
|
|
|
|
/* returns the [original, not compacted] entry number or -1 on eof *********/
|
|
|
|
long vorbis_book_decode(codebook *book, oggpack_buffer *b){
|
2007-07-01 17:58:49 +00:00
|
|
|
if(book->used_entries>0){
|
|
|
|
long packed_entry=decode_packed_entry_number(book,b);
|
|
|
|
if(packed_entry>=0)
|
|
|
|
return(book->dec_index[packed_entry]);
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
/* if there's no dec_index, the codebook unpacking isn't collapsed */
|
2007-07-01 17:58:49 +00:00
|
|
|
return(-1);
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns 0 on OK or -1 on eof *************************************/
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
/* decode vector / dim granularity gaurding is done in the upper layer */
|
2005-02-17 09:08:18 +00:00
|
|
|
long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
|
2010-03-05 09:48:07 +00:00
|
|
|
oggpack_buffer *b,int n,int point){
|
2007-07-01 17:58:49 +00:00
|
|
|
if(book->used_entries>0){
|
|
|
|
int step=n/book->dim;
|
|
|
|
long *entry = (long *)alloca(sizeof(*entry)*step);
|
|
|
|
ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step);
|
|
|
|
int i,j,o;
|
|
|
|
int shift=point-book->binarypoint;
|
|
|
|
|
|
|
|
if(shift>=0){
|
|
|
|
for (i = 0; i < step; i++) {
|
2010-03-05 09:48:07 +00:00
|
|
|
entry[i]=decode_packed_entry_number(book,b);
|
|
|
|
if(entry[i]==-1)return(-1);
|
|
|
|
t[i] = book->valuelist+entry[i]*book->dim;
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
for(i=0,o=0;i<book->dim;i++,o+=step)
|
2010-03-05 09:48:07 +00:00
|
|
|
for (j=0;j<step;j++)
|
|
|
|
a[o+j]+=t[j][i]>>shift;
|
2007-07-01 17:58:49 +00:00
|
|
|
}else{
|
|
|
|
for (i = 0; i < step; i++) {
|
2010-03-05 09:48:07 +00:00
|
|
|
entry[i]=decode_packed_entry_number(book,b);
|
|
|
|
if(entry[i]==-1)return(-1);
|
|
|
|
t[i] = book->valuelist+entry[i]*book->dim;
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
for(i=0,o=0;i<book->dim;i++,o+=step)
|
2010-03-05 09:48:07 +00:00
|
|
|
for (j=0;j<step;j++)
|
|
|
|
a[o+j]+=t[j][i]<<-shift;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
/* decode vector / dim granularity gaurding is done in the upper layer */
|
2005-02-17 09:08:18 +00:00
|
|
|
long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
|
2010-03-05 09:48:07 +00:00
|
|
|
oggpack_buffer *b,int n,int point){
|
2007-07-01 17:58:49 +00:00
|
|
|
if(book->used_entries>0){
|
|
|
|
int i,j,entry;
|
|
|
|
ogg_int32_t *t;
|
|
|
|
int shift=point-book->binarypoint;
|
|
|
|
|
|
|
|
if(shift>=0){
|
|
|
|
for(i=0;i<n;){
|
2010-03-05 09:48:07 +00:00
|
|
|
entry = decode_packed_entry_number(book,b);
|
|
|
|
if(entry==-1)return(-1);
|
|
|
|
t = book->valuelist+entry*book->dim;
|
|
|
|
for (j=0;j<book->dim;)
|
|
|
|
a[i++]+=t[j++]>>shift;
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
shift = -shift;
|
|
|
|
for(i=0;i<n;){
|
2010-03-05 09:48:07 +00:00
|
|
|
entry = decode_packed_entry_number(book,b);
|
|
|
|
if(entry==-1)return(-1);
|
|
|
|
t = book->valuelist+entry*book->dim;
|
|
|
|
for (j=0;j<book->dim;)
|
|
|
|
a[i++]+=t[j++]<<shift;
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
/* unlike the others, we guard against n not being an integer number
|
|
|
|
of <dim> internally rather than in the upper layer (called only by
|
|
|
|
floor0) */
|
2005-02-17 09:08:18 +00:00
|
|
|
long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
|
2010-03-05 09:48:07 +00:00
|
|
|
oggpack_buffer *b,int n,int point){
|
2007-07-01 17:58:49 +00:00
|
|
|
if(book->used_entries>0){
|
|
|
|
int i,j,entry;
|
|
|
|
ogg_int32_t *t;
|
|
|
|
int shift=point-book->binarypoint;
|
|
|
|
|
|
|
|
if(shift>=0){
|
|
|
|
|
|
|
|
for(i=0;i<n;){
|
2010-03-05 09:48:07 +00:00
|
|
|
entry = decode_packed_entry_number(book,b);
|
|
|
|
if(entry==-1)return(-1);
|
|
|
|
t = book->valuelist+entry*book->dim;
|
2010-12-12 17:59:05 +00:00
|
|
|
for (j=0;i<n && j<book->dim;){
|
2010-03-05 09:48:07 +00:00
|
|
|
a[i++]=t[j++]>>shift;
|
|
|
|
}
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
shift = -shift;
|
|
|
|
for(i=0;i<n;){
|
2010-03-05 09:48:07 +00:00
|
|
|
entry = decode_packed_entry_number(book,b);
|
|
|
|
if(entry==-1)return(-1);
|
|
|
|
t = book->valuelist+entry*book->dim;
|
2010-12-12 17:59:05 +00:00
|
|
|
for (j=0;i<n && j<book->dim;){
|
2010-03-05 09:48:07 +00:00
|
|
|
a[i++]=t[j++]<<shift;
|
|
|
|
}
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
2007-07-01 17:58:49 +00:00
|
|
|
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
int i;
|
2005-02-17 09:08:18 +00:00
|
|
|
for(i=0;i<n;){
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
a[i++]=0;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
libtremor: merge upstream revisions 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17555, 17572, bringing in various fixes and finally bringing our libtremor up to date, for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28773 a1c6a512-1295-4272-9138-f99709370657
2010-12-08 17:28:17 +00:00
|
|
|
/* decode vector / dim granularity gaurding is done in the upper layer */
|
2007-09-27 21:58:51 +00:00
|
|
|
static long vorbis_book_decodevv_add_2ch_even(codebook *book,ogg_int32_t **a,
|
|
|
|
long offset,oggpack_buffer *b,
|
2010-05-12 22:41:17 +00:00
|
|
|
unsigned int n,int point){
|
|
|
|
long k,chunk,read;
|
2007-09-27 21:58:51 +00:00
|
|
|
int shift=point-book->binarypoint;
|
|
|
|
long entries[32];
|
|
|
|
ogg_int32_t *p0 = &(a[0][offset]);
|
|
|
|
ogg_int32_t *p1 = &(a[1][offset]);
|
2010-05-12 22:41:17 +00:00
|
|
|
const unsigned long dim = book->dim;
|
|
|
|
const ogg_int32_t * const vlist = book->valuelist;
|
2007-09-27 21:58:51 +00:00
|
|
|
|
|
|
|
if(shift>=0){
|
2010-05-12 22:41:17 +00:00
|
|
|
while(n>0){
|
2007-09-27 21:58:51 +00:00
|
|
|
chunk=32;
|
2010-05-12 22:41:17 +00:00
|
|
|
if (16*dim>n)
|
|
|
|
chunk=(n*2-1)/dim + 1;
|
2007-09-27 21:58:51 +00:00
|
|
|
read = decode_packed_block(book,b,entries,chunk);
|
|
|
|
for(k=0;k<read;k++){
|
2010-05-12 22:41:17 +00:00
|
|
|
const ogg_int32_t *t = vlist+entries[k]*dim;
|
|
|
|
const ogg_int32_t *u = t+dim;
|
2007-09-27 21:58:51 +00:00
|
|
|
do{
|
|
|
|
*p0++ += *t++>>shift;
|
|
|
|
*p1++ += *t++>>shift;
|
|
|
|
}while(t<u);
|
|
|
|
}
|
|
|
|
if (read<chunk)return-1;
|
2010-05-12 22:41:17 +00:00
|
|
|
n -= read*dim/2;
|
2007-09-27 21:58:51 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
shift = -shift;
|
2010-05-12 22:41:17 +00:00
|
|
|
while(n>0){
|
2007-09-27 21:58:51 +00:00
|
|
|
chunk=32;
|
2010-05-12 22:41:17 +00:00
|
|
|
if (16*dim>n)
|
|
|
|
chunk=(n*2-1)/dim + 1;
|
2007-09-27 21:58:51 +00:00
|
|
|
read = decode_packed_block(book,b,entries,chunk);
|
|
|
|
for(k=0;k<read;k++){
|
2010-05-12 22:41:17 +00:00
|
|
|
const ogg_int32_t *t = vlist+entries[k]*dim;
|
|
|
|
const ogg_int32_t *u = t+dim;
|
2007-09-27 21:58:51 +00:00
|
|
|
do{
|
|
|
|
*p0++ += *t++<<shift;
|
|
|
|
*p1++ += *t++<<shift;
|
|
|
|
}while(t<u);
|
|
|
|
}
|
|
|
|
if (read<chunk)return-1;
|
2010-05-12 22:41:17 +00:00
|
|
|
n -= read*dim/2;
|
2007-09-27 21:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-05-27 09:14:00 +00:00
|
|
|
long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
|
2010-03-05 09:48:07 +00:00
|
|
|
long offset,int ch,
|
|
|
|
oggpack_buffer *b,int n,int point){
|
2009-02-17 17:01:09 +00:00
|
|
|
if(LIKELY(book->used_entries>0)){
|
2007-07-01 17:58:49 +00:00
|
|
|
long i,j,k,chunk,read;
|
|
|
|
int chptr=0;
|
|
|
|
int shift=point-book->binarypoint;
|
|
|
|
long entries[32];
|
2007-03-24 14:06:56 +00:00
|
|
|
|
2007-09-27 21:58:51 +00:00
|
|
|
if (!(book->dim&1) && ch==2)
|
|
|
|
return vorbis_book_decodevv_add_2ch_even(book,a,offset,b,n,point);
|
|
|
|
|
2007-07-01 17:58:49 +00:00
|
|
|
if(shift>=0){
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2007-07-01 17:58:49 +00:00
|
|
|
for(i=offset;i<offset+n;){
|
|
|
|
chunk=32;
|
|
|
|
if (chunk*book->dim>(offset+n-i)*ch)
|
|
|
|
chunk=((offset+n-i)*ch+book->dim-1)/book->dim;
|
|
|
|
read = decode_packed_block(book,b,entries,chunk);
|
|
|
|
for(k=0;k<read;k++){
|
2010-03-05 09:48:07 +00:00
|
|
|
const ogg_int32_t *t = book->valuelist+entries[k]*book->dim;
|
|
|
|
for (j=0;j<book->dim;j++){
|
|
|
|
a[chptr++][i]+=t[j]>>shift;
|
|
|
|
if(chptr==ch){
|
|
|
|
chptr=0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
if (read<chunk)return-1;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
2007-07-01 17:58:49 +00:00
|
|
|
}else{
|
|
|
|
shift = -shift;
|
|
|
|
for(i=offset;i<offset+n;){
|
|
|
|
chunk=32;
|
|
|
|
if (chunk*book->dim>(offset+n-i)*ch)
|
|
|
|
chunk=((offset+n-i)*ch+book->dim-1)/book->dim;
|
|
|
|
read = decode_packed_block(book,b,entries,chunk);
|
|
|
|
for(k=0;k<read;k++){
|
2010-03-05 09:48:07 +00:00
|
|
|
const ogg_int32_t *t = book->valuelist+entries[k]*book->dim;
|
|
|
|
for (j=0;j<book->dim;j++){
|
|
|
|
a[chptr++][i]+=t[j]<<shift;
|
|
|
|
if(chptr==ch){
|
|
|
|
chptr=0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2007-07-01 17:58:49 +00:00
|
|
|
}
|
|
|
|
if (read<chunk)return-1;
|
2005-02-17 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
2010-12-06 14:36:52 +00:00
|
|
|
|