1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/* MPEG Sound library
(C) 1997 by Jung woo-jae */
// Bitwindow.cc
// It's bit reservior for MPEG layer 3
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "mpegsound.h"
#ifndef WORDS_BIGENDIAN
#define _KEY 0
#else
#define _KEY 3
#endif
int Mpegbitwindow::getbits(int bits)
{
union
{
char store[4];
int current;
}u;
int bi;
if(!bits)return 0;
u.current=0;
bi=(bitindex&7);
// u.store[_KEY]=buffer[(bitindex>>3)&(WINDOWSIZE-1)]<<bi;
u.store[_KEY]=buffer[bitindex>>3]<<bi;
bi=8-bi;
bitindex+=bi;
while(bits)
{
if(!bi)
{
// u.store[_KEY]=buffer[(bitindex>>3)&(WINDOWSIZE-1)];
u.store[_KEY]=buffer[bitindex>>3];
bitindex+=8;
bi=8;
}
if(bits>=bi)
{
u.current<<=bi;
bits-=bi;
bi=0;
}
else
{
u.current<<=bits;
bi-=bits;
bits=0;
}
}
bitindex-=bi;
return (u.current>>8);
}
|