9 - 16 bit 2 bytes
17 - 32 bit 4 bytes (also for 24bit if AEC_DATA_3BYTE is not set)
-If you use less bits than the storage size provides, then you have to
-make sure that unused bits are not set. Libaec does not check this for
-performance reasons and will produce undefined output if unused bits
-are set.
+If a sample requires less bits than the storage size provides, then
+you have to make sure that unused bits are not set. Libaec does not
+check this for performance reasons and will produce undefined output
+if unused bits are set. All input data must be a multiple of the
+storage size in bytes. Remaining bytes which do not form a complete
+sample will be ignored.
Libaec accesses next_in and next_out buffers only bytewise. There are
no alignment requirements for these buffers.
struct internal_state *state = strm->state;
do {
- if (strm->avail_in > 0) {
+ if (strm->avail_in >= state->bytes_per_sample) {
state->data_raw[state->i] = state->get_sample(strm);
} else {
if (state->flush == AEC_FLUSH) {
if (strm->bits_per_sample <= 24
&& strm->flags & AEC_DATA_3BYTE) {
- state->rsi_len = 3;
+ state->bytes_per_sample = 3;
if (strm->flags & AEC_DATA_MSB) {
state->get_sample = aec_get_msb_24;
state->get_rsi = aec_get_rsi_msb_24;
state->get_rsi = aec_get_rsi_lsb_24;
}
} else {
- state->rsi_len = 4;
+ state->bytes_per_sample = 4;
if (strm->flags & AEC_DATA_MSB) {
state->get_sample = aec_get_msb_32;
state->get_rsi = aec_get_rsi_msb_32;
else if (strm->bits_per_sample > 8) {
/* 16 bit settings */
state->id_len = 4;
- state->rsi_len = 2;
+ state->bytes_per_sample = 2;
if (strm->flags & AEC_DATA_MSB) {
state->get_sample = aec_get_msb_16;
} else {
/* 8 bit settings */
state->id_len = 3;
- state->rsi_len = 1;
+ state->bytes_per_sample = 1;
state->get_sample = aec_get_8;
state->get_rsi = aec_get_rsi_8;
}
- state->rsi_len *= strm->rsi * strm->block_size;
+ state->rsi_len = strm->rsi * strm->block_size * state->bytes_per_sample;
if (strm->flags & AEC_DATA_SIGNED) {
state->xmin = -(1ULL << (strm->bits_per_sample - 1));
* not */
int zero_ref; /* current zero block has a reference sample */
uint32_t zero_ref_sample;/* reference sample of zero block */
+ int bytes_per_sample; /* storage size of samples in bytes */
int zero_blocks; /* number of contiguous zero blocks */
int block_nonzero; /* 1 if this is the first non-zero block
* after one or more zero blocks */