Changeset 64 for mppenc/branches/r2d/libmpcenc/bitstream.c
- Timestamp:
- 09/29/06 16:55:39 (18 years ago)
- Location:
- mppenc/branches/r2d/libmpcenc
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcenc/bitstream.c
r60 r64 18 18 */ 19 19 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" 28 22 29 23 … … 39 33 40 34 static void 41 Change_Endian32 ( unsigned int* dst, size_t words32bit )35 Change_Endian32 ( unsigned int* dst, mpc_size_t words32bit ) 42 36 { 43 37 for ( ; words32bit--; dst++ ) { … … 64 58 65 59 void 66 FlushBitstream ( FILE* fp, const Uint32_t* buffer,size_t words32bit )60 FlushBitstream ( FILE* fp, const mpc_uint32_t* buffer, mpc_size_t words32bit ) 67 61 { 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; 71 65 72 66 #if ENDIAN == HAVE_BIG_ENDIAN 73 Change_Endian32 ( ( Uint32_t*)buffer, CC );67 Change_Endian32 ( (mpc_uint32_t*)buffer, CC ); 74 68 #endif 75 69 76 // Write Buffer70 // Write e->Buffer 77 71 do { 78 72 WrittenDwords = fwrite ( p, sizeof(*buffer), words32bit, fp ); … … 88 82 89 83 #if ENDIAN == HAVE_BIG_ENDIAN 90 Change_Endian32 ( ( Uint32_t*)buffer, CC );84 Change_Endian32 ( (mpc_uint32_t*)buffer, CC ); 91 85 #endif 92 86 } … … 94 88 95 89 void 96 UpdateHeader ( FILE* fp, Uint32_t Frames, Uint ValidSamples )90 UpdateHeader ( FILE* fp, mpc_uint32_t Frames, mpc_uint_t ValidSamples ) 97 91 { 98 Uint8_t buff [4];92 mpc_uint8_t buff [4]; 99 93 100 94 // Write framecount to header … … 102 96 return; 103 97 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); 108 102 109 103 fwrite ( buff, 1, 4, fp ); … … 119 113 120 114 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); 124 118 125 119 fwrite ( buff, 1, 2, fp ); … … 131 125 132 126 133 void 134 WriteBits ( const Uint32_t input, const unsigned int bits ) 127 void WriteBits (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits ) 135 128 { 136 BufferedBits += bits;137 filled -= bits;129 e->BufferedBits += bits; 130 e->filled -= bits; 138 131 139 if ( filled > 0 ) {140 dword |= input <<filled;132 if ( e->filled > 0 ) { 133 e->dword |= input << e->filled; 141 134 } 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; 146 139 } 147 140 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; 151 144 } 152 145 } … … 154 147 // Bits in the original stream have to be 0, maximum X bits allowed to be set in input 155 148 // 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 ) 149 void WriteBitsAt (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits, BitstreamPos const pos ) 158 150 { 159 Uint32_t* ptr = pos.ptr;151 mpc_uint32_t* ptr = pos.ptr; 160 152 int filled = pos.bit - bits; 161 153 162 154 // fprintf ( stderr, "%5u %2u %08lX %2u\n", input, bits, pos.ptr, pos.bit ); 163 155 164 Buffer [Zaehler] =dword;156 e->Buffer [e->Zaehler] = e->dword; 165 157 166 158 if ( filled > 0 ) { … … 175 167 } 176 168 177 dword = Buffer [Zaehler];169 e->dword = e->Buffer [e->Zaehler]; 178 170 } 179 171 180 172 181 void 182 GetBitstreamPos ( BitstreamPos* const pos ) 173 void GetBitstreamPos (mpc_encoder * e, BitstreamPos* const pos ) 183 174 { 184 pos -> ptr = Buffer +Zaehler;185 pos -> bit = filled;175 pos -> ptr = e->Buffer + e->Zaehler; 176 pos -> bit = e->filled; 186 177 } 187 178
Note: See TracChangeset
for help on using the changeset viewer.