write j bits into the bit stream
(final LameInternalFlags gfc, final int val, int j)
| 98 | * write j bits into the bit stream |
| 99 | */ |
| 100 | private void putbits2(final LameInternalFlags gfc, final int val, int j) { |
| 101 | assert (j < MAX_LENGTH - 2); |
| 102 | |
| 103 | while (j > 0) { |
| 104 | int k; |
| 105 | if (bufBitIdx == 0) { |
| 106 | bufBitIdx = 8; |
| 107 | bufByteIdx++; |
| 108 | assert (bufByteIdx < Lame.LAME_MAXMP3BUFFER); |
| 109 | assert (gfc.header[gfc.w_ptr].write_timing >= totbit); |
| 110 | if (gfc.header[gfc.w_ptr].write_timing == totbit) { |
| 111 | putheader_bits(gfc); |
| 112 | } |
| 113 | buf[bufByteIdx] = 0; |
| 114 | } |
| 115 | |
| 116 | k = Math.min(j, bufBitIdx); |
| 117 | j -= k; |
| 118 | |
| 119 | bufBitIdx -= k; |
| 120 | |
| 121 | assert (j < MAX_LENGTH); |
| 122 | /* 32 too large on 32 bit machines */ |
| 123 | assert (bufBitIdx < MAX_LENGTH); |
| 124 | |
| 125 | buf[bufByteIdx] |= ((val >> j) << bufBitIdx); |
| 126 | totbit += k; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * write j bits into the bit stream, ignoring frame headers |
no test coverage detected