Skip to content

Commit 881848d

Browse files
committed
sampleconv.h: Use 128 as midpoint for unsigned 8-bit.
I've seen both 127 and 128 suggested, but 128 seems to be the more common convention.
1 parent 6b1912d commit 881848d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sampleconv.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#if BIT_PERFECT
3636
/* these clip, but are bit perfect */
37-
#define SAMPLE_TO_U8(x) ((uint8_t) (((x) * 128.0 + 127.0 < 0.0) ? 0 : lrint((x) * 128.0 + 127.0)))
38-
#define U8_TO_SAMPLE(x) (((sample_t) (x) - 127.0) / 128.0)
37+
#define SAMPLE_TO_U8(x) ((uint8_t) (((x) * 128.0 + 128.0 > 255.0) ? 255.0 : lrint((x) * 128.0 + 128.0)))
38+
#define U8_TO_SAMPLE(x) (((sample_t) (x) - 128.0) / 128.0)
3939
#define SAMPLE_TO_S8(x) ((int8_t) (((x) * 128.0 > 127.0) ? 127 : lrint((x) * 128.0)))
4040
#define S8_TO_SAMPLE(x) ((sample_t) (x) / 128.0)
4141
#define SAMPLE_TO_S16(x) ((int16_t) (((x) * 32768.0 > 32767.0) ? 32767 : lrint((x) * 32768.0)))

0 commit comments

Comments
 (0)