| 152 | }; |
| 153 | |
| 154 | class BitUnpacker { |
| 155 | public: |
| 156 | // Constructor |
| 157 | BitUnpacker(int bits, std::ifstream& fo) |
| 158 | : bits(bits), fo(fo), mask((1 << bits) - 1), current_value(0), current_bits(0) {} |
| 159 | |
| 160 | // Member function to pull a single value from the stream |
| 161 | int pull() { |
| 162 | while (current_bits < bits) { |
| 163 | char buf; |
| 164 | if (!fo.read(&buf, 1)) { |
| 165 | return {}; // returns empty optional indicating end of stream |
| 166 | } |
| 167 | uint8_t character = static_cast<uint8_t>(buf); |
| 168 | current_value += character << current_bits; |
| 169 | current_bits += 8; |
| 170 | } |
| 171 | |
| 172 | int out = current_value & mask; |
| 173 | current_value >>= bits; |
| 174 | current_bits -= bits; |
| 175 | return out; // returns the extracted value |
| 176 | } |
| 177 | |
| 178 | private: |
| 179 | int bits; |
| 180 | std::ifstream& fo; |
| 181 | int mask; |
| 182 | int current_value; |
| 183 | int current_bits; |
| 184 | }; |
| 185 | |
| 186 | void write_encodec_header(std::ofstream & fo, uint32_t audio_length) { |
| 187 | json metadata = { |
nothing calls this directly
no outgoing calls
no test coverage detected