Changeset 81 for libmpcdec/branches/zorg/src/mpc_reader.c
- Timestamp:
- 10/31/06 11:47:09 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpcdec/branches/zorg/src/mpc_reader.c
r70 r81 88 88 89 89 mpc_status 90 mpc_reader_init_stdio(mpc_reader *p_reader, c har *filename)90 mpc_reader_init_stdio(mpc_reader *p_reader, const char *filename) 91 91 { 92 92 mpc_reader tmp_reader; mpc_reader_stdio *p_stdio; int err; … … 149 149 ret = p_reader->seek(p_reader, 0); 150 150 if(!ret) return 0; 151 151 152 152 p_reader->read(p_reader, tmp, sizeof tmp); 153 153 … … 178 178 return ret; 179 179 } 180 181 mpc_status mpc_get_block(mpc_reader * p_reader, mpc_block_t * p_block) 182 { 183 unsigned char tmp; 184 unsigned int size = 2; 185 186 p_block->size = 0; 187 p_reader->read(p_reader, p_block->key, 2); 188 do { 189 p_reader->read(p_reader, &tmp, 1); 190 p_block->size = (p_block->size << 7) | (tmp & 0x7F); 191 size++; 192 } while((tmp & 0x80)); 193 194 if (size > p_block->size) 195 return MPC_STATUS_FILE; 196 197 p_block->size -= size; 198 199 return MPC_STATUS_OK; 200 } 201 202 mpc_status mpc_find_block(mpc_reader * p_reader, mpc_block_t * p_block, 203 char * find_key, char * stop_key) 204 { 205 while (1) { 206 mpc_get_block(p_reader, p_block); 207 if (memcmp(p_block->key, find_key, 2) != 0 && 208 memcmp(p_block->key, stop_key, 2) != 0) 209 p_reader->seek(p_reader, p_block->size); 210 else 211 break; 212 } 213 214 if (memcmp(p_block->key, find_key, 2) != 0) 215 return MPC_STATUS_FILE; 216 217 return MPC_STATUS_OK; 218 } 219 220 mpc_uint32_t mpc_read_bits(mpc_reader * p_reader, mpc_bits_reader * p_bits, 221 int nb_bits) 222 { 223 mpc_uint32_t ret = p_bits->buff; 224 unsigned char tmp = 0; 225 226 while(nb_bits > p_bits->bitsCount){ 227 p_reader->read(p_reader, &tmp, 1); 228 ret = (ret << 8) | tmp; 229 p_bits->bitsCount += 8; 230 } 231 232 p_bits->buff = (unsigned int) ret; 233 p_bits->bitsCount -= nb_bits; 234 ret >>= p_bits->bitsCount; 235 236 if (nb_bits == 32) 237 return ret; 238 else 239 return ret & ((1 << nb_bits) - 1); 240 } 241
Note: See TracChangeset
for help on using the changeset viewer.