Commit 92bd99e7 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

converted some macros which can't fail and therefore don't need to be macros

parent 214be50c
...@@ -337,7 +337,7 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -337,7 +337,7 @@ int ae_decode(ae_streamp strm, int flush)
switch(state->mode) switch(state->mode)
{ {
case M_ID: case M_ID:
if (strm->pp if (strm->pp
&& (strm->total_out / strm->block_size) % strm->segment_size == 0) && (strm->total_out / strm->block_size) % strm->segment_size == 0)
state->ref = 1; state->ref = 1;
else else
......
...@@ -105,40 +105,33 @@ int ae_encode_init(ae_streamp strm) ...@@ -105,40 +105,33 @@ int ae_encode_init(ae_streamp strm)
return AE_OK; return AE_OK;
} }
#define EMIT(d, n) \ static inline void emit(encode_state *state, uint32_t data, int bits)
do \ {
{ \ while(bits)
int bits = (n); \ {
uint32_t data = (d); \ data &= ((1UL << bits) - 1);
while(bits) \ if (bits <= state->bitp)
{ \ {
data &= ((1UL << bits) - 1); \ data <<= state->bitp - bits;
if (bits <= state->bitp) \ *state->bp_out += data;
{ \ state->bitp -= bits;
data <<= state->bitp - bits; \ bits = 0;
*state->bp_out += data; \ }
state->bitp -= bits; \ else
bits = 0; \ {
} \ *state->bp_out += data >> (bits - state->bitp);
else \ bits -= state->bitp;
{ \ *++state->bp_out = 0;
*state->bp_out += data >> (bits - state->bitp); \ state->bitp = 8;
bits -= state->bitp; \ }
*++state->bp_out = 0; \ }
state->bitp = 8; \ }
} \
} \ static inline void emitfs(encode_state *state, uint32_t fs)
} \ {
while (0) emit(state, 0, fs);
emit(state, 1, 1);
}
#define EMITFS(d) \
do \
{ \
EMIT(0, d); \
EMIT(1, 1); \
} \
while (0)
int ae_encode(ae_streamp strm, int flush) int ae_encode(ae_streamp strm, int flush)
{ {
...@@ -200,7 +193,7 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -200,7 +193,7 @@ int ae_encode(ae_streamp strm, int flush)
if user wants to flush, i.e. we got if user wants to flush, i.e. we got
all input there is. all input there is.
*/ */
EMIT(0xff, state->bitp); emit(state, 0xff, state->bitp);
*state->next_out++ = *state->bp_out; *state->next_out++ = *state->bp_out;
strm->avail_out--; strm->avail_out--;
strm->total_out++; strm->total_out++;
...@@ -351,15 +344,15 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -351,15 +344,15 @@ int ae_encode(ae_streamp strm, int flush)
} }
case M_ENCODE_SPLIT: case M_ENCODE_SPLIT:
EMIT(k + 1, state->id_len); emit(state, k + 1, state->id_len);
if (state->ref) if (state->ref)
EMIT(state->block_in[0], strm->bit_per_sample); emit(state, state->block_in[0], strm->bit_per_sample);
for (i = state->ref; i < strm->block_size; i++) for (i = state->ref; i < strm->block_size; i++)
EMITFS(state->block_in[i] >> k); emitfs(state, state->block_in[i] >> k);
for (i = state->ref; i < strm->block_size; i++) for (i = state->ref; i < strm->block_size; i++)
EMIT(state->block_in[i], k); emit(state, state->block_in[i], k);
state->mode = M_FLUSH_BLOCK; state->mode = M_FLUSH_BLOCK;
...@@ -367,7 +360,7 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -367,7 +360,7 @@ int ae_encode(ae_streamp strm, int flush)
if (strm->avail_in == 0 && flush == AE_FLUSH) if (strm->avail_in == 0 && flush == AE_FLUSH)
{ {
/* pad last byte with 1 bits */ /* pad last byte with 1 bits */
EMIT(0xff, state->bitp); emit(state, 0xff, state->bitp);
} }
state->i = 0; state->i = 0;
state->mode = M_FLUSH_BLOCK_LOOP; state->mode = M_FLUSH_BLOCK_LOOP;
...@@ -387,34 +380,34 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -387,34 +380,34 @@ int ae_encode(ae_streamp strm, int flush)
break; break;
case M_ENCODE_UNCOMP: case M_ENCODE_UNCOMP:
EMIT(0x1f, state->id_len); emit(state, 0x1f, state->id_len);
for (i = 0; i < strm->block_size; i++) for (i = 0; i < strm->block_size; i++)
EMIT(state->block_in[i], strm->bit_per_sample); emit(state, state->block_in[i], strm->bit_per_sample);
state->mode = M_FLUSH_BLOCK; state->mode = M_FLUSH_BLOCK;
break; break;
case M_ENCODE_SE: case M_ENCODE_SE:
EMIT(1, state->id_len + 1); emit(state, 1, state->id_len + 1);
if (state->ref) if (state->ref)
EMIT(state->block_in[0], strm->bit_per_sample); emit(state, state->block_in[0], strm->bit_per_sample);
for (i = 0; i < strm->block_size; i+= 2) for (i = 0; i < strm->block_size; i+= 2)
{ {
d = state->block_in[i] + state->block_in[i + 1]; d = state->block_in[i] + state->block_in[i + 1];
EMITFS(d * (d + 1) / 2 + state->block_in[i + 1]); emitfs(state, d * (d + 1) / 2 + state->block_in[i + 1]);
} }
state->mode = M_FLUSH_BLOCK; state->mode = M_FLUSH_BLOCK;
break; break;
case M_ENCODE_ZERO: case M_ENCODE_ZERO:
EMIT(0, state->id_len + 1); emit(state, 0, state->id_len + 1);
if (state->zero_ref) if (state->zero_ref)
{ {
EMIT(state->zero_ref_sample, strm->bit_per_sample); emit(state, state->zero_ref_sample, strm->bit_per_sample);
} }
EMITFS(state->zero_blocks - 1); emitfs(state, state->zero_blocks - 1);
state->zero_blocks = 0; state->zero_blocks = 0;
state->mode = M_FLUSH_BLOCK; state->mode = M_FLUSH_BLOCK;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment