|
30 | 30 | * this is true for all supported formats.
|
31 | 31 | */
|
32 | 32 |
|
33 |
| -#define S24_SIGN_EXTEND(x) ((x & 0x800000) ? x | ~0x7fffff : x) |
| 33 | +#define S24_SIGN_EXTEND(x) (((x) & 0x800000) ? (x) | ~0x7fffff : (x)) |
34 | 34 |
|
35 | 35 | #if BIT_PERFECT
|
36 | 36 | /* these clip, but are bit perfect */
|
37 |
| - #define SAMPLE_TO_U8(x) ((uint8_t) ((x * 128.0 + 127.0 <= -0.5) ? 0 : lround(x * 128.0 + 127.0))) |
38 |
| - #define U8_TO_SAMPLE(x) (((sample_t) x - 127.0) / 128.0) |
39 |
| - #define SAMPLE_TO_S8(x) ((int8_t) ((x * 128.0 >= 127.5) ? 127 : lround(x * 128.0))) |
40 |
| - #define S8_TO_SAMPLE(x) ((sample_t) x / 128.0) |
41 |
| - #define SAMPLE_TO_S16(x) ((int16_t) ((x * 32768.0 >= 32767.5) ? 32767 : lround(x * 32768.0))) |
42 |
| - #define S16_TO_SAMPLE(x) ((sample_t) x / 32768.0) |
43 |
| - #define SAMPLE_TO_S24(x) ((int32_t) ((x * 8388608.0 >= 8388607.5) ? 8388607 : lround(x * 8388608.0))) |
| 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) |
| 39 | + #define SAMPLE_TO_S8(x) ((int8_t) (((x) * 128.0 > 127.0) ? 127 : lrint((x) * 128.0))) |
| 40 | + #define S8_TO_SAMPLE(x) ((sample_t) (x) / 128.0) |
| 41 | + #define SAMPLE_TO_S16(x) ((int16_t) (((x) * 32768.0 > 32767.0) ? 32767 : lrint((x) * 32768.0))) |
| 42 | + #define S16_TO_SAMPLE(x) ((sample_t) (x) / 32768.0) |
| 43 | + #define SAMPLE_TO_S24(x) ((int32_t) (((x) * 8388608.0 > 8388607.0) ? 8388607 : lrint((x) * 8388608.0))) |
44 | 44 | #define S24_TO_SAMPLE(x) ((sample_t) S24_SIGN_EXTEND(x) / 8388608.0)
|
45 |
| - #define SAMPLE_TO_S32(x) ((int32_t) ((x * 2147483648.0 >= 2147483647.5) ? 2147483647 : lround(x * 2147483648.0))) |
46 |
| - #define S32_TO_SAMPLE(x) ((sample_t) x / 2147483648.0) |
| 45 | + #define SAMPLE_TO_S32(x) ((int32_t) (((x) * 2147483648.0 > 2147483647.0) ? 2147483647 : lrint((x) * 2147483648.0))) |
| 46 | + #define S32_TO_SAMPLE(x) ((sample_t) (x) / 2147483648.0) |
47 | 47 | #else
|
48 | 48 | /* these do not clip, but are also not bit perfect */
|
49 |
| - #define SAMPLE_TO_U8(x) ((uint8_t) lround(x * 127.0 + 127.0)) |
50 |
| - #define U8_TO_SAMPLE(x) (((sample_t) x - 127.0) / 128.0) |
51 |
| - #define SAMPLE_TO_S8(x) ((int8_t) lround(x * 127.0)) |
52 |
| - #define S8_TO_SAMPLE(x) ((sample_t) x / 128.0) |
53 |
| - #define SAMPLE_TO_S16(x) ((int16_t) lround(x * 32767.0)) |
54 |
| - #define S16_TO_SAMPLE(x) ((sample_t) x / 32768.0) |
55 |
| - #define SAMPLE_TO_S24(x) ((int32_t) lround(x * 8388607.0)) |
| 49 | + #define SAMPLE_TO_U8(x) ((uint8_t) lrint((x) * 127.0 + 127.0)) |
| 50 | + #define U8_TO_SAMPLE(x) (((sample_t) (x) - 127.0) / 128.0) |
| 51 | + #define SAMPLE_TO_S8(x) ((int8_t) lrint((x) * 127.0)) |
| 52 | + #define S8_TO_SAMPLE(x) ((sample_t) (x) / 128.0) |
| 53 | + #define SAMPLE_TO_S16(x) ((int16_t) lrint((x) * 32767.0)) |
| 54 | + #define S16_TO_SAMPLE(x) ((sample_t) (x) / 32768.0) |
| 55 | + #define SAMPLE_TO_S24(x) ((int32_t) lrint((x) * 8388607.0)) |
56 | 56 | #define S24_TO_SAMPLE(x) ((sample_t) S24_SIGN_EXTEND(x) / 8388608.0)
|
57 |
| - #define SAMPLE_TO_S32(x) ((int32_t) lround(x * 2147483647.0)) |
58 |
| - #define S32_TO_SAMPLE(x) ((sample_t) x / 2147483648.0) |
| 57 | + #define SAMPLE_TO_S32(x) ((int32_t) lrint((x) * 2147483647.0)) |
| 58 | + #define S32_TO_SAMPLE(x) ((sample_t) (x) / 2147483648.0) |
59 | 59 | #endif
|
60 | 60 |
|
61 |
| -#define SAMPLE_TO_FLOAT(x) ((float) x) |
62 |
| -#define FLOAT_TO_SAMPLE(x) ((sample_t) x) |
63 |
| -#define SAMPLE_TO_DOUBLE(x) ((double) x) |
64 |
| -#define DOUBLE_TO_SAMPLE(x) ((sample_t) x) |
| 61 | +#define SAMPLE_TO_FLOAT(x) ((float) (x)) |
| 62 | +#define FLOAT_TO_SAMPLE(x) ((sample_t) (x)) |
| 63 | +#define SAMPLE_TO_DOUBLE(x) ((double) (x)) |
| 64 | +#define DOUBLE_TO_SAMPLE(x) ((sample_t) (x)) |
65 | 65 |
|
66 | 66 | void write_buf_u8(sample_t *, void *, ssize_t);
|
67 | 67 | void read_buf_u8(void *, sample_t *, ssize_t);
|
|
0 commit comments