ref: d8942ea8e649e57d0c66a55636611bf1fd4640ad
parent: f0ecfdab409648d3b834c84412d89c2d0f899be6
author: robs <robs>
date: Sat Dec 2 06:49:18 EST 2006
Use st_sample_t conversion macros where appropriate.
--- a/src/g711.h
+++ b/src/g711.h
@@ -12,10 +12,10 @@
extern uint8_t _st_13linear2alaw[0x2000];
extern int16_t _st_alaw2linear16[256];
-#define st_13linear2alaw(sw) (_st_13linear2alaw[(sw + 0x1000)])
+#define st_13linear2alaw(sw) (_st_13linear2alaw[((sw) + 0x1000)])
#define st_alaw2linear16(uc) (_st_alaw2linear16[uc])
extern uint8_t _st_14linear2ulaw[0x4000];
extern int16_t _st_ulaw2linear16[256];
-#define st_14linear2ulaw(sw) (_st_14linear2ulaw[(sw + 0x2000)])
+#define st_14linear2ulaw(sw) (_st_14linear2ulaw[((sw) + 0x2000)])
#define st_ulaw2linear16(uc) (_st_ulaw2linear16[uc])
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -190,7 +190,7 @@
return (0);
}
p->sample = sample_rate;
- *buf++ = (p->sample - 128) * 0x1000000L;
+ *buf++ = ST_UNSIGNED_BYTE_TO_SAMPLE(p->sample);
p->huffcount--;
p->nrbits = 0;
done++;
@@ -227,9 +227,9 @@
p->sample = (p->sample + datum) & 0xff;
p->huffcount--;
if (p->sample == 0)
- *buf++ = -127 * 0x1000000L;
+ *buf++ = ST_UNSIGNED_BYTE_TO_SAMPLE(1);
else
- *buf++ = (p->sample - 128) * 0x1000000L;
+ *buf++ = ST_UNSIGNED_BYTE_TO_SAMPLE(p->sample);
p->dictentry = 0;
done++;
len--;
@@ -326,9 +326,7 @@
while (len-- > 0) {
datum = *buf++;
- datum >>= 24;
- datum ^= 128;
- p->data[p->pos++] = datum;
+ p->data[p->pos++] = ST_SAMPLE_TO_UNSIGNED_BYTE(datum);
}
return (save_len - len);
--- a/src/raw.c
+++ b/src/raw.c
@@ -54,20 +54,20 @@
0x3F, 0xBF, 0x7F, 0xFF
};
-#define ST_ULAW_BYTE_TO_SAMPLE(d) ((st_sample_t)(st_ulaw2linear16(d)) << 16)
-#define ST_ALAW_BYTE_TO_SAMPLE(d) ((st_sample_t)(st_alaw2linear16(d)) << 16)
-#define ST_SAMPLE_TO_ULAW_BYTE(d) (st_14linear2ulaw((int16_t)((d) >> 18)))
-#define ST_SAMPLE_TO_ALAW_BYTE(d) (st_13linear2alaw((int16_t)((d) >> 19)))
+#define ST_ULAW_BYTE_TO_SAMPLE(d) ST_SIGNED_WORD_TO_SAMPLE(st_ulaw2linear16(d))
+#define ST_ALAW_BYTE_TO_SAMPLE(d) ST_SIGNED_WORD_TO_SAMPLE(st_alaw2linear16(d))
+#define ST_SAMPLE_TO_ULAW_BYTE(d) st_14linear2ulaw(ST_SAMPLE_TO_SIGNED_WORD(d) >> 2)
+#define ST_SAMPLE_TO_ALAW_BYTE(d) st_13linear2alaw(ST_SAMPLE_TO_SIGNED_WORD(d) >> 3)
/* Some hardware sends MSB last. These account for that */
#define ST_INVERT_ULAW_BYTE_TO_SAMPLE(d) \
- ((st_sample_t)(st_ulaw2linear16(cswap[d])) << 16)
+ ST_SIGNED_WORD_TO_SAMPLE(st_ulaw2linear16(cswap[d]))
#define ST_INVERT_ALAW_BYTE_TO_SAMPLE(d) \
- ((st_sample_t)(st_alaw2linear16(cswap[d])) << 16)
+ ST_SIGNED_WORD_TO_SAMPLE(st_alaw2linear16(cswap[d]))
#define ST_SAMPLE_TO_INVERT_ULAW_BYTE(d) \
- (cswap[st_14linear2ulaw((int16_t)((d) >> 18))])
+ cswap[st_14linear2ulaw(ST_SAMPLE_TO_SIGNED_WORD(d) >> 2)]
#define ST_SAMPLE_TO_INVERT_ALAW_BYTE(d) \
- (cswap[st_13linear2alaw((int16_t)((d) >> 19))])
+ cswap[st_13linear2alaw(ST_SAMPLE_TO_SIGNED_WORD(d) >> 3)]
static void rawdefaults(ft_t ft);