Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144964992
D48421.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D48421.diff
View Options
diff --git a/sys/dev/sound/pcm/feeder_eq.c b/sys/dev/sound/pcm/feeder_eq.c
--- a/sys/dev/sound/pcm/feeder_eq.c
+++ b/sys/dev/sound/pcm/feeder_eq.c
@@ -135,10 +135,6 @@
#define FEEDEQ_ERR_CLIP_CHECK(...)
#endif
-#define FEEDEQ_CLAMP(v) (((v) > PCM_S32_MAX) ? PCM_S32_MAX : \
- (((v) < PCM_S32_MIN) ? PCM_S32_MIN : \
- (v)))
-
#define FEEDEQ_DECLARE(SIGN, BIT, ENDIAN) \
static void \
feed_eq_biquad_##SIGN##BIT##ENDIAN(struct feed_eq_info *info, \
@@ -187,7 +183,7 @@
info->treble.o2[i] = info->treble.o1[i]; \
w >>= FEEDEQ_COEFF_SHIFT; \
FEEDEQ_ERR_CLIP_CHECK(treble, w); \
- v = FEEDEQ_CLAMP(w); \
+ v = pcm_clamp(w, AFMT_S32_NE); \
info->treble.o1[i] = v; \
\
w = (intpcm64_t)v * bass->b0; \
@@ -200,7 +196,7 @@
info->bass.o2[i] = info->bass.o1[i]; \
w >>= FEEDEQ_COEFF_SHIFT; \
FEEDEQ_ERR_CLIP_CHECK(bass, w); \
- v = FEEDEQ_CLAMP(w); \
+ v = pcm_clamp(w, AFMT_S32_NE); \
info->bass.o1[i] = v; \
\
pcm_sample_write_norm(dst, v, \
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_calc(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_rate.c b/sys/dev/sound/pcm/feeder_rate.c
--- a/sys/dev/sound/pcm/feeder_rate.c
+++ b/sys/dev/sound/pcm/feeder_rate.c
@@ -502,10 +502,6 @@
#define Z_CLIP_CHECK(...)
#endif
-#define Z_CLAMP(v, BIT) \
- (((v) > PCM_S##BIT##_MAX) ? PCM_S##BIT##_MAX : \
- (((v) < PCM_S##BIT##_MIN) ? PCM_S##BIT##_MIN : (v)))
-
/*
* Sine Cardinal (SINC) Interpolation. Scaling is done in 64 bit, so
* there's no point to hold the plate any longer. All samples will be
@@ -574,7 +570,7 @@
else \
v >>= Z_COEFF_SHIFT - Z_GUARD_BIT_##BIT; \
Z_CLIP_CHECK(v, BIT); \
- pcm_sample_write(dst, Z_CLAMP(v, BIT), \
+ pcm_sample_write(dst, pcm_clamp(v, AFMT_##SIGN##BIT##_##ENDIAN),\
AFMT_##SIGN##BIT##_##ENDIAN); \
} while (ch != 0); \
}
@@ -614,7 +610,7 @@
else \
v >>= Z_COEFF_SHIFT - Z_GUARD_BIT_##BIT; \
Z_CLIP_CHECK(v, BIT); \
- pcm_sample_write(dst, Z_CLAMP(v, BIT), \
+ pcm_sample_write(dst, pcm_clamp(v, AFMT_##SIGN##BIT##_##ENDIAN),\
AFMT_##SIGN##BIT##_##ENDIAN); \
} while (ch != 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,8 @@
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_calc(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,42 @@
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();
+ }
+}
+
+static __always_inline __unused intpcm_t
+pcm_clamp_calc(intpcm32_t sample, uint32_t fmt)
+{
+#ifndef SND_PCM_64
+ if (fmt & AFMT_32BIT) {
+ return ((sample > PCM_S24_MAX) ? PCM_S32_MAX :
+ ((sample < PCM_S24_MIN) ? PCM_S32_MIN :
+ sample << PCM_FXSHIFT));
+ }
+#endif
+
+ return (pcm_clamp(sample, fmt));
+}
+
#endif /* !_SND_PCM_H_ */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 15, 1:44 PM (8 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28743487
Default Alt Text
D48421.diff (5 KB)
Attached To
Mode
D48421: sound: Turn clamp macros into a function
Attached
Detach File
Event Timeline
Log In to Comment