Ignore:
Timestamp:
09/29/06 16:55:39 (18 years ago)
Author:
r2d
Message:
  • added libmpcenc and a common directory
  • can compile libmpcenc and libmpcpsy don't know about linking
Location:
mppenc/branches/r2d/libmpcenc
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • mppenc/branches/r2d/libmpcenc/bitstream.c

    r60 r64  
    1818 */
    1919
    20 #include "mppenc.h"
    21 
    22 
    23 Uint32_t      Buffer [BUFFER_FULL];    // Buffer for bitstream-file
    24 Uint32_t      dword         =  0;      // 32-bit-Word for Bitstream-I/O
    25 int           filled        = 32;      // Position in the the 32-bit-word that's currently about to be filled
    26 unsigned int  Zaehler       =  0;      // Position pointer for the processed bitstream-word (32 bit)
    27 UintMax_t     BufferedBits  =  0;      // Counter for the number of written bits in the bitstream
     20#include "libmpcenc.h"
     21#include "stdio.h"
    2822
    2923
     
    3933
    4034static void
    41 Change_Endian32 ( unsigned int* dst, size_t words32bit )
     35Change_Endian32 ( unsigned int* dst, mpc_size_t words32bit )
    4236{
    4337    for ( ; words32bit--; dst++ ) {
     
    6458
    6559void
    66 FlushBitstream ( FILE* fp, const Uint32_t* buffer, size_t words32bit )
     60FlushBitstream ( FILE* fp, const mpc_uint32_t* buffer, mpc_size_t words32bit )
    6761{
    68     size_t           WrittenDwords = 0;
    69     const Uint32_t*  p             = buffer;
    70     size_t           CC            = words32bit;
     62    mpc_size_t           WrittenDwords = 0;
     63    const mpc_uint32_t*  p             = buffer;
     64    mpc_size_t           CC            = words32bit;
    7165
    7266#if ENDIAN == HAVE_BIG_ENDIAN
    73     Change_Endian32 ( (Uint32_t*)buffer, CC );
     67    Change_Endian32 ( (mpc_uint32_t*)buffer, CC );
    7468#endif
    7569
    76     // Write Buffer
     70    // Write e->Buffer
    7771    do {
    7872        WrittenDwords = fwrite ( p, sizeof(*buffer), words32bit, fp );
     
    8882
    8983#if ENDIAN == HAVE_BIG_ENDIAN
    90     Change_Endian32 ( (Uint32_t*)buffer, CC );
     84    Change_Endian32 ( (mpc_uint32_t*)buffer, CC );
    9185#endif
    9286}
     
    9488
    9589void
    96 UpdateHeader ( FILE* fp, Uint32_t Frames, Uint ValidSamples )
     90UpdateHeader ( FILE* fp, mpc_uint32_t Frames, mpc_uint_t ValidSamples )
    9791{
    98     Uint8_t  buff [4];
     92    mpc_uint8_t  buff [4];
    9993
    10094    // Write framecount to header
     
    10296        return;
    10397
    104     buff [0] = (Uint8_t)(Frames >>  0);
    105     buff [1] = (Uint8_t)(Frames >>  8);
    106     buff [2] = (Uint8_t)(Frames >> 16);
    107     buff [3] = (Uint8_t)(Frames >> 24);
     98    buff [0] = (mpc_uint8_t)(Frames >>  0);
     99    buff [1] = (mpc_uint8_t)(Frames >>  8);
     100    buff [2] = (mpc_uint8_t)(Frames >> 16);
     101    buff [3] = (mpc_uint8_t)(Frames >> 24);
    108102
    109103    fwrite ( buff, 1, 4, fp );
     
    119113
    120114    ValidSamples <<= 4;
    121     ValidSamples  |= 0x800F & (((Uint) buff[1] << 8) | buff[0]);
    122     buff [0] = (Uint8_t)(ValidSamples >>  0);
    123     buff [1] = (Uint8_t)(ValidSamples >>  8);
     115    ValidSamples  |= 0x800F & (((mpc_uint_t) buff[1] << 8) | buff[0]);
     116    buff [0] = (mpc_uint8_t)(ValidSamples >>  0);
     117    buff [1] = (mpc_uint8_t)(ValidSamples >>  8);
    124118
    125119    fwrite ( buff, 1, 2, fp );
     
    131125
    132126
    133 void
    134 WriteBits ( const Uint32_t input, const unsigned int bits )
     127void WriteBits (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits )
    135128{
    136     BufferedBits += bits;
    137     filled       -= bits;
     129    e->BufferedBits += bits;
     130    e->filled       -= bits;
    138131
    139     if      ( filled > 0 ) {
    140         dword  |= input << filled;
     132    if      ( e->filled > 0 ) {
     133        e->dword  |= input << e->filled;
    141134    }
    142     else if ( filled < 0 ) {
    143         Buffer [Zaehler++] = dword | ( input >> -filled );
    144         filled += 32;
    145         dword   = input << filled;
     135    else if ( e->filled < 0 ) {
     136        e->Buffer [e->Zaehler++] = e->dword | ( input >> -e->filled );
     137        e->filled += 32;
     138        e->dword   = input << e->filled;
    146139    }
    147140    else {
    148         Buffer [Zaehler++] = dword | input;
    149         filled  = 32;
    150         dword   =  0;
     141        e->Buffer [e->Zaehler++] = e->dword | input;
     142        e->filled  = 32;
     143        e->dword   =  0;
    151144    }
    152145}
     
    154147// Bits in the original stream have to be 0, maximum X bits allowed to be set in input
    155148// Actual bitstream must have already written ptr[0] and ptr[1]
    156 void
    157 WriteBitsAt ( const Uint32_t input, const unsigned int bits, BitstreamPos const pos )
     149void WriteBitsAt (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits, BitstreamPos const pos )
    158150{
    159     Uint32_t*     ptr    = pos.ptr;
     151    mpc_uint32_t*     ptr    = pos.ptr;
    160152    int           filled = pos.bit - bits;
    161153
    162154//    fprintf ( stderr, "%5u %2u %08lX %2u\n", input, bits, pos.ptr, pos.bit );
    163155
    164     Buffer [Zaehler] = dword;
     156    e->Buffer [e->Zaehler] = e->dword;
    165157
    166158    if      ( filled > 0 ) {
     
    175167    }
    176168
    177     dword = Buffer [Zaehler];
     169    e->dword = e->Buffer [e->Zaehler];
    178170}
    179171
    180172
    181 void
    182 GetBitstreamPos ( BitstreamPos* const pos )
     173void GetBitstreamPos (mpc_encoder * e, BitstreamPos* const pos )
    183174{
    184     pos -> ptr = Buffer + Zaehler;
    185     pos -> bit = filled;
     175    pos -> ptr = e->Buffer + e->Zaehler;
     176    pos -> bit = e->filled;
    186177}
    187178
Note: See TracChangeset for help on using the changeset viewer.