Skip to content

Commit

Permalink
audio format: use bswap*()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Denis-Courmont committed Aug 17, 2011
1 parent 9ff7bdc commit 0a2f90d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions modules/audio_filter/converter/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,42 +481,38 @@ static void S24toFl32(block_t *bdst, const block_t *bsrc)
}

/* */
#define XCHG(type, a, b) \
do { type _tmp = a; a = b; b = _tmp; } while(0)
static void Swap64(block_t *b)
{
uint8_t *data = (uint8_t *)b->p_buffer;
uint64_t *data = (uint64_t *)b->p_buffer;
for (size_t i = 0; i < b->i_buffer / 8; i++) {
XCHG(uint8_t, data[0], data[7]);
XCHG(uint8_t, data[1], data[6]);
XCHG(uint8_t, data[2], data[5]);
XCHG(uint8_t, data[3], data[4]);
data += 8;
*data = bswap64 (*data);
data++;
}
}
static void Swap32(block_t *b)
{
uint8_t *data = (uint8_t *)b->p_buffer;
uint32_t *data = (uint32_t *)b->p_buffer;
for (size_t i = 0; i < b->i_buffer / 4; i++) {
XCHG(uint8_t, data[0], data[3]);
XCHG(uint8_t, data[1], data[2]);
data += 4;
*data = bswap32 (*data);
data++;
}
}
static void Swap24(block_t *b)
{
uint8_t *data = (uint8_t *)b->p_buffer;
for (size_t i = 0; i < b->i_buffer / 3; i++) {
XCHG(uint8_t, data[0], data[2]);
uint8_t buf = data[0];
data[0] = data[2];
data[2] = buf;
data += 3;
}
}
static void Swap16(block_t *b)
{
uint8_t *data = (uint8_t *)b->p_buffer;
uint16_t *data = (uint16_t *)b->p_buffer;
for (size_t i = 0; i < b->i_buffer / 2; i++) {
XCHG(uint8_t, data[0], data[1]);
data += 2;
*data = bswap16 (*data);
data++;
}
}

Expand Down

0 comments on commit 0a2f90d

Please sign in to comment.