static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp) { uint32_t cw; uint16_t offset = 0; uint8_t extra_bits; cw = faad_showbits(ld, hcbN[cb]); offset = hcb_table[cb][cw].offset; extra_bits = hcb_table[cb][cw].extra_bits; if (extra_bits) { /* we know for sure it's more than hcbN[cb] bits long */ faad_flushbits(ld, hcbN[cb]); offset += (uint16_t)faad_showbits(ld, extra_bits); faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]); } else { faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits); } if (offset > hcb_2_pair_table_size[cb]) { /* printf("ERROR: offset into hcb_2_pair_table = %d >%d!\n", offset, hcb_2_pair_table_size[cb]); */ return 10; } sp[0] = hcb_2_pair_table[cb][offset].x; sp[1] = hcb_2_pair_table[cb][offset].y; return 0; }
/* * adts_header */ int get_adts_header(faacDecHandle hDecoder) { int sync = 0; ADTS_Header *p = &hDecoder->adts_header; faad_byte_align(&hDecoder->ld); sync = faad_showbits(&hDecoder->ld, 12); while (sync != 4096 - 1) { faad_flushbits(&hDecoder->ld, 8); if (faad_bits_done(&hDecoder->ld) != 0) { return -1; } sync = faad_showbits(&hDecoder->ld, 12); } faad_flushbits(&hDecoder->ld, 12); if (hDecoder->frameNum) { faad_getbits(&hDecoder->ld, 16); #if 0 if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ faad_getbits(&hDecoder->ld, 2); #endif } else { /* Syncword found, proceed to read in the fixed ADTS header */ p->fixed.ID = faad_get1bit(&hDecoder->ld); /* 0 -> MPEG4, 1 -> MPEG2 */ hDecoder->isMpeg4 = !p->fixed.ID; p->fixed.layer = faad_getbits(&hDecoder->ld, 2); p->fixed.protection_absent = faad_get1bit(&hDecoder->ld); hDecoder->mc_info.object_type = p->fixed.object_type = faad_getbits(&hDecoder->ld, 2); hDecoder->mc_info.sampling_rate_idx = p->fixed.sampling_rate_idx = faad_getbits(&hDecoder->ld, 4); p->fixed.private_bit = faad_get1bit(&hDecoder->ld); p->fixed.channel_configuration = faad_getbits(&hDecoder->ld, 3); p->fixed.original_copy = faad_get1bit(&hDecoder->ld); p->fixed.home = faad_get1bit(&hDecoder->ld); #if 0 if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ p->fixed.emphasis = faad_getbits(&hDecoder->ld, 2); #endif } /* ...and the variable ADTS header */ p->variable.copy_id_bit = faad_get1bit(&hDecoder->ld); p->variable.copy_id_start = faad_get1bit(&hDecoder->ld); p->variable.frame_length = faad_getbits(&hDecoder->ld, 13); p->variable.buffer_fullness = faad_getbits(&hDecoder->ld, 11); p->variable.raw_blocks = faad_getbits(&hDecoder->ld, 2); /* ADTS error check (ignored) */ if(!p->fixed.protection_absent) faad_getbits(&hDecoder->ld, 16); return 0; }
/* return next n bits (right adjusted) */ uint32_t faad_getbits(bitfile *ld, int n) { long l; l = faad_showbits(ld, n); faad_flushbits(ld, n); return l; }
uint32_t faad_byte_align(bitfile *ld) { int i; if (ld->bitcnt == 0) return 0; i = 8 - ld->bitcnt; faad_flushbits(ld, i); return i; }
uint8_t faad_byte_align(bitfile *ld) { int remainder = (32 - ld->bits_left) & 0x7; if (remainder) { faad_flushbits(ld, 8 - remainder); return (uint8_t)(8 - remainder); } return 0; }