Move bitreader_dump and bitwriter_dump functions to test_libFLAC

This commit is contained in:
Martijn van Beurden 2022-11-16 20:42:17 +01:00
parent 5663f11795
commit 1cb59f0b0f
6 changed files with 56 additions and 56 deletions

View File

@ -346,36 +346,6 @@ FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *
}
}
void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
{
uint32_t i, j;
if(br == 0) {
fprintf(out, "bitreader is NULL\n");
}
else {
fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits);
for(i = 0; i < br->words; i++) {
fprintf(out, "%08X: ", i);
for(j = 0; j < FLAC__BITS_PER_WORD; j++)
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(br->bytes > 0) {
fprintf(out, "%08X: ", i);
for(j = 0; j < br->bytes*8; j++)
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
}
void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
{
FLAC__ASSERT(0 != br);

View File

@ -198,30 +198,6 @@ void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
bw->words = bw->bits = 0;
}
void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
{
uint32_t i, j;
if(bw == 0) {
fprintf(out, "bitwriter is NULL\n");
}
else {
fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
for(i = 0; i < bw->words; i++) {
fprintf(out, "%08X: ", i);
for(j = 0; j < FLAC__BITS_PER_WORD; j++)
fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(bw->bits > 0) {
fprintf(out, "%08X: ", i);
for(j = 0; j < bw->bits; j++)
fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
}
FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
{
const FLAC__byte *buffer;

View File

@ -55,7 +55,6 @@ void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
void FLAC__bitreader_set_framesync_location(FLAC__BitReader *br);
FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *br);
void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
/*
* CRC functions

View File

@ -50,7 +50,6 @@ void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
/*
* CRC functions

View File

@ -59,12 +59,45 @@ struct FLAC__BitReader {
uint32_t read_crc16; /* the running frame CRC */
uint32_t crc16_offset; /* the number of words in the current buffer that should not be CRC'd */
uint32_t crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
FLAC__bool read_limit_set; /* whether reads are limited */
uint32_t read_limit; /* the remaining size of what can be read */
uint32_t last_seen_framesync; /* the location of the last seen framesync, if it is in the buffer, in bits from front of buffer */
FLAC__BitReaderReadCallback read_callback;
void *client_data;
};
static FLAC__bool read_callback(FLAC__byte buffer[], size_t *bytes, void *data);
static void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
{
uint32_t i, j;
if(br == 0) {
fprintf(out, "bitreader is NULL\n");
}
else {
fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits);
for(i = 0; i < br->words; i++) {
fprintf(out, "%08X: ", i);
for(j = 0; j < FLAC__BITS_PER_WORD; j++)
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(br->bytes > 0) {
fprintf(out, "%08X: ", i);
for(j = 0; j < br->bytes*8; j++)
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
}
FLAC__bool test_bitreader(void)
{
FLAC__BitReader *br;

View File

@ -60,6 +60,29 @@ struct FLAC__BitWriter {
#define WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
#define TOTAL_BITS(bw) (WORDS_TO_BITS((bw)->words) + (bw)->bits)
static void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
{
uint32_t i, j;
if(bw == 0) {
fprintf(out, "bitwriter is NULL\n");
}
else {
fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, TOTAL_BITS(bw));
for(i = 0; i < bw->words; i++) {
fprintf(out, "%08X: ", i);
for(j = 0; j < FLAC__BITS_PER_WORD; j++)
fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(bw->bits > 0) {
fprintf(out, "%08X: ", i);
for(j = 0; j < bw->bits; j++)
fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
}
FLAC__bool test_bitwriter(void)
{