Page MenuHomeFreeBSD

D48421.diff
No OneTemporary

D48421.diff

diff --git a/sys/dev/sound/pcm/feeder_mixer.c b/sys/dev/sound/pcm/feeder_mixer.c
--- a/sys/dev/sound/pcm/feeder_mixer.c
+++ b/sys/dev/sound/pcm/feeder_mixer.c
@@ -64,7 +64,7 @@
y = pcm_sample_read_calc(dst, \
AFMT_##SIGN##BIT##_##ENDIAN); \
z = INTPCM##BIT##_T(x) + y; \
- x = PCM_CLAMP_##SIGN##BIT(z); \
+ x = pcm_clamp(z, AFMT_##SIGN##BIT##_##ENDIAN); \
pcm_sample_write(dst, x, \
AFMT_##SIGN##BIT##_##ENDIAN); \
} while (count != 0); \
diff --git a/sys/dev/sound/pcm/feeder_volume.c b/sys/dev/sound/pcm/feeder_volume.c
--- a/sys/dev/sound/pcm/feeder_volume.c
+++ b/sys/dev/sound/pcm/feeder_volume.c
@@ -66,7 +66,7 @@
x = pcm_sample_read_calc(dst, \
AFMT_##SIGN##BIT##_##ENDIAN); \
v = FEEDVOLUME_CALC##BIT(x, vol[matrix[i]]); \
- x = PCM_CLAMP_##SIGN##BIT(v); \
+ x = pcm_clamp(v, AFMT_##SIGN##BIT##_##ENDIAN); \
pcm_sample_write(dst, x, \
AFMT_##SIGN##BIT##_##ENDIAN); \
} while (i != 0); \
diff --git a/sys/dev/sound/pcm/pcm.h b/sys/dev/sound/pcm/pcm.h
--- a/sys/dev/sound/pcm/pcm.h
+++ b/sys/dev/sound/pcm/pcm.h
@@ -103,32 +103,6 @@
#define INTPCM24_T(v) ((intpcm24_t)(v))
#define INTPCM32_T(v) ((intpcm32_t)(v))
-#define PCM_CLAMP_S8(val) \
- (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \
- (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val)))
-#define PCM_CLAMP_S16(val) \
- (((val) > PCM_S16_MAX) ? PCM_S16_MAX : \
- (((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val)))
-#define PCM_CLAMP_S24(val) \
- (((val) > PCM_S24_MAX) ? PCM_S24_MAX : \
- (((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val)))
-
-#ifdef SND_PCM_64
-#define PCM_CLAMP_S32(val) \
- (((val) > PCM_S32_MAX) ? PCM_S32_MAX : \
- (((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val)))
-#else /* !SND_PCM_64 */
-#define PCM_CLAMP_S32(val) \
- (((val) > PCM_S24_MAX) ? PCM_S32_MAX : \
- (((val) < PCM_S24_MIN) ? PCM_S32_MIN : \
- ((val) << PCM_FXSHIFT)))
-#endif /* SND_PCM_64 */
-
-#define PCM_CLAMP_U8(val) PCM_CLAMP_S8(val)
-#define PCM_CLAMP_U16(val) PCM_CLAMP_S16(val)
-#define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val)
-#define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val)
-
static const struct {
const uint8_t ulaw_to_u8[G711_TABLE_SIZE];
const uint8_t alaw_to_u8[G711_TABLE_SIZE];
@@ -370,4 +344,28 @@
pcm_sample_write(dst, v, fmt);
}
+static __always_inline __unused intpcm_t
+pcm_clamp(intpcm32_t sample, uint32_t fmt)
+{
+ fmt = AFMT_ENCODING(fmt);
+
+ switch (AFMT_BIT(fmt)) {
+ case 8:
+ return ((sample > PCM_S8_MAX) ? PCM_S8_MAX :
+ ((sample < PCM_S8_MIN) ? PCM_S8_MIN : sample));
+ case 16:
+ return ((sample > PCM_S16_MAX) ? PCM_S16_MAX :
+ ((sample < PCM_S16_MIN) ? PCM_S16_MIN : sample));
+ case 24:
+ return ((sample > PCM_S24_MAX) ? PCM_S24_MAX :
+ ((sample < PCM_S24_MIN) ? PCM_S24_MIN : sample));
+ case 32:
+ return ((sample > PCM_S32_MAX) ? PCM_S32_MAX :
+ ((sample < PCM_S32_MIN) ? PCM_S32_MIN : sample));
+ default:
+ printf("%s(): unknown format: 0x%08x\n", __func__, fmt);
+ __assert_unreachable();
+ }
+}
+
#endif /* !_SND_PCM_H_ */

File Metadata

Mime Type
text/plain
Expires
Sat, Feb 1, 2:34 AM (20 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16374112
Default Alt Text
D48421.diff (3 KB)

Event Timeline