diff --git a/sys/dev/sound/pcm/feeder.h b/sys/dev/sound/pcm/feeder.h --- a/sys/dev/sound/pcm/feeder.h +++ b/sys/dev/sound/pcm/feeder.h @@ -167,9 +167,6 @@ typedef intpcm_t intpcm_read_t(uint8_t *); typedef void intpcm_write_t(uint8_t *, intpcm_t); -intpcm_read_t *feeder_format_read_op(uint32_t); -intpcm_write_t *feeder_format_write_op(uint32_t); - /* 4Front OSS stuffs */ int feeder_matrix_oss_get_channel_order(struct pcmchan_matrix *, unsigned long long *); 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 @@ -153,9 +153,11 @@ dst += j * PCM_##BIT##_BPS; \ do { \ dst -= PCM_##BIT##_BPS; \ - v = _PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \ + v = pcm_sample_read(dst, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ v = ((intpcm64_t)pmul * v) >> pshift; \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v); \ + pcm_sample_write(dst, v, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ } while (--j != 0); \ \ return; \ @@ -168,8 +170,8 @@ i = 0; \ j = info->channels; \ do { \ - v = _PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \ - v <<= 32 - BIT; \ + v = pcm_sample_read(dst, AFMT_##SIGN##BIT##_##ENDIAN, \ + true); \ v = ((intpcm64_t)pmul * v) >> pshift; \ \ w = (intpcm64_t)v * treble->b0; \ @@ -198,8 +200,8 @@ v = FEEDEQ_CLAMP(w); \ info->bass.o1[i] = v; \ \ - v >>= 32 - BIT; \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v); \ + pcm_sample_write(dst, v, AFMT_##SIGN##BIT##_##ENDIAN, \ + true); \ dst += PCM_##BIT##_BPS; \ i++; \ } while (--j != 0); \ diff --git a/sys/dev/sound/pcm/feeder_format.c b/sys/dev/sound/pcm/feeder_format.c --- a/sys/dev/sound/pcm/feeder_format.c +++ b/sys/dev/sound/pcm/feeder_format.c @@ -43,76 +43,10 @@ struct feed_format_info { uint32_t ibps, obps; uint32_t ialign, oalign, channels; - intpcm_read_t *read; - intpcm_write_t *write; + uint32_t rdfmt, wrfmt; uint8_t reservoir[FEEDFORMAT_RESERVOIR]; }; -#define INTPCM_DECLARE_OP_WRITE(SIGN, BIT, ENDIAN, SHIFT) \ -static __inline void \ -intpcm_write_##SIGN##BIT##ENDIAN(uint8_t *dst, intpcm_t v) \ -{ \ - \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v >> SHIFT); \ -} - -#define INTPCM_DECLARE_OP_8(SIGN, ENDIAN) \ -static __inline intpcm_t \ -intpcm_read_##SIGN##8##ENDIAN(uint8_t *src) \ -{ \ - \ - return (_PCM_READ_##SIGN##8##_##ENDIAN(src) << 24); \ -} \ -INTPCM_DECLARE_OP_WRITE(SIGN, 8, ENDIAN, 24) - -#define INTPCM_DECLARE_OP_16(SIGN, ENDIAN) \ -static __inline intpcm_t \ -intpcm_read_##SIGN##16##ENDIAN(uint8_t *src) \ -{ \ - \ - return (_PCM_READ_##SIGN##16##_##ENDIAN(src) << 16); \ -} \ -INTPCM_DECLARE_OP_WRITE(SIGN, 16, ENDIAN, 16) - -#define INTPCM_DECLARE_OP_24(SIGN, ENDIAN) \ -static __inline intpcm_t \ -intpcm_read_##SIGN##24##ENDIAN(uint8_t *src) \ -{ \ - \ - return (_PCM_READ_##SIGN##24##_##ENDIAN(src) << 8); \ -} \ -INTPCM_DECLARE_OP_WRITE(SIGN, 24, ENDIAN, 8) - -#define INTPCM_DECLARE_OP_32(SIGN, ENDIAN) \ -static __inline intpcm_t \ -intpcm_read_##SIGN##32##ENDIAN(uint8_t *src) \ -{ \ - \ - return (_PCM_READ_##SIGN##32##_##ENDIAN(src)); \ -} \ - \ -static __inline void \ -intpcm_write_##SIGN##32##ENDIAN(uint8_t *dst, intpcm_t v) \ -{ \ - \ - _PCM_WRITE_##SIGN##32##_##ENDIAN(dst, v); \ -} - -INTPCM_DECLARE_OP_8(S, NE) -INTPCM_DECLARE_OP_16(S, LE) -INTPCM_DECLARE_OP_16(S, BE) -INTPCM_DECLARE_OP_24(S, LE) -INTPCM_DECLARE_OP_24(S, BE) -INTPCM_DECLARE_OP_32(S, LE) -INTPCM_DECLARE_OP_32(S, BE) -INTPCM_DECLARE_OP_8(U, NE) -INTPCM_DECLARE_OP_16(U, LE) -INTPCM_DECLARE_OP_16(U, BE) -INTPCM_DECLARE_OP_24(U, LE) -INTPCM_DECLARE_OP_24(U, BE) -INTPCM_DECLARE_OP_32(U, LE) -INTPCM_DECLARE_OP_32(U, BE) - static const struct { const uint8_t ulaw_to_u8[G711_TABLE_SIZE]; const uint8_t alaw_to_u8[G711_TABLE_SIZE]; @@ -125,120 +59,340 @@ U8_TO_ALAW }; -static __inline intpcm_t -intpcm_read_ulaw(uint8_t *src) +/* Format conversions */ +__always_inline intpcm_t +pcm_sample_read(uint8_t *src, uint32_t fmt, bool shift) { - return (_G711_TO_INTPCM(xlaw_conv_tables.ulaw_to_u8, *src) << 24); -} + intpcm_t v; -static __inline intpcm_t -intpcm_read_alaw(uint8_t *src) -{ - return (_G711_TO_INTPCM(xlaw_conv_tables.alaw_to_u8, *src) << 24); -} + fmt = AFMT_ENCODING(fmt); + switch (fmt) { + case AFMT_AC3: + v = 0; + break; + case AFMT_MU_LAW: + v = _G711_TO_INTPCM(xlaw_conv_tables.ulaw_to_u8, *src); + break; + case AFMT_A_LAW: + v = _G711_TO_INTPCM(xlaw_conv_tables.alaw_to_u8, *src); + break; + case AFMT_S8: + v = INTPCM_T(*(int8_t *)src); + break; + case AFMT_U8: + v = INTPCM_T(*(int8_t *)src ^ 0x80); + break; + case AFMT_S16_LE: + v = INTPCM_T(src[0] | (int8_t)src[1] << 8); + break; + case AFMT_S16_BE: + v = INTPCM_T(src[1] | (int8_t)src[0] << 8); + break; + case AFMT_U16_LE: + v = INTPCM_T(src[0] | ((int8_t)src[1] ^ 0x80) << 8); + break; + case AFMT_U16_BE: + v = INTPCM_T(src[1] | ((int8_t)src[0] ^ 0x80) << 8); + break; + case AFMT_S24_LE: + v = INTPCM_T(src[0] | src[1] << 8 | (int8_t)src[2] << 16); + break; + case AFMT_S24_BE: + v = INTPCM_T(src[2] | src[1] << 8 | (int8_t)src[0] << 16); + break; + case AFMT_U24_LE: + v = INTPCM_T(src[0] | src[1] << 8 | + ((int8_t)src[2] ^ 0x80) << 16); + break; + case AFMT_U24_BE: + v = INTPCM_T(src[2] | src[1] << 8 | + ((int8_t)src[0] ^ 0x80) << 16); + break; + case AFMT_S32_LE: + v = INTPCM_T(src[0] | src[1] << 8 | src[2] << 16 | + (int8_t)src[3] << 24); + break; + case AFMT_S32_BE: + v = INTPCM_T(src[3] | src[2] << 8 | src[1] << 16 | + (int8_t)src[0] << 24); + break; + case AFMT_U32_LE: + v = INTPCM_T(src[0] | src[1] << 8 | src[2] << 16 | + ((int8_t)src[3] ^ 0x80) << 24); + break; + case AFMT_U32_BE: + v = INTPCM_T(src[3] | src[2] << 8 | src[1] << 16 | + ((int8_t)src[0] ^ 0x80) << 24); + break; + default: + printf("%s(): unknown format: 0x%08x\n", __func__, fmt); + v = 0; + break; + } -static __inline void -intpcm_write_ulaw(uint8_t *dst, intpcm_t v) -{ - *dst = _INTPCM_TO_G711(xlaw_conv_tables.u8_to_ulaw, v >> 24); -} +#ifndef SND_PCM_64 + if (fmt & AFMT_32BIT) + v >>= PCM_FXSHIFT; +#endif -static __inline void -intpcm_write_alaw(uint8_t *dst, intpcm_t v) -{ - *dst = _INTPCM_TO_G711(xlaw_conv_tables.u8_to_alaw, v >> 24); + if (shift) + v <<= 32 - AFMT_BIT(fmt); + + return (v); } -/* - * dummy ac3/dts passthrough, etc. - * XXX assume as s16le. - */ -static __inline intpcm_t -intpcm_read_null(uint8_t *src __unused) +__always_inline void +pcm_sample_write(uint8_t *dst, intpcm_t v, uint32_t fmt, bool shift) { + fmt = AFMT_ENCODING(fmt); - return (0); + if (shift) + v >>= 32 - AFMT_BIT(fmt); + +#ifndef SND_PCM_64 + if (fmt & AFMT_32BIT) + v <<= PCM_FXSHIFT; +#endif + + switch (fmt) { + case AFMT_AC3: + *(int16_t *)dst = 0; + break; + case AFMT_MU_LAW: + *dst = _INTPCM_TO_G711(xlaw_conv_tables.u8_to_ulaw, v); + break; + case AFMT_A_LAW: + *dst = _INTPCM_TO_G711(xlaw_conv_tables.u8_to_alaw, v); + break; + case AFMT_S8: + *(int8_t *)dst = v; + break; + case AFMT_U8: + *(int8_t *)dst = v ^ 0x80; + break; + case AFMT_S16_LE: + dst[0] = v; + dst[1] = v >> 8; + break; + case AFMT_S16_BE: + dst[1] = v; + dst[0] = v >> 8; + break; + case AFMT_U16_LE: + dst[0] = v; + dst[1] = (v >> 8) ^ 0x80; + break; + case AFMT_U16_BE: + dst[1] = v; + dst[0] = (v >> 8) ^ 0x80; + break; + case AFMT_S24_LE: + dst[0] = v; + dst[1] = v >> 8; + dst[2] = v >> 16; + break; + case AFMT_S24_BE: + dst[2] = v; + dst[1] = v >> 8; + dst[0] = v >> 16; + break; + case AFMT_U24_LE: + dst[0] = v; + dst[1] = v >> 8; + dst[2] = (v >> 16) ^ 0x80; + break; + case AFMT_U24_BE: + dst[2] = v; + dst[1] = v >> 8; + dst[0] = (v >> 16) ^ 0x80; + break; + case AFMT_S32_LE: + dst[0] = v; + dst[1] = v >> 8; + dst[2] = v >> 16; + dst[3] = v >> 24; + break; + case AFMT_S32_BE: + dst[3] = v; + dst[2] = v >> 8; + dst[1] = v >> 16; + dst[0] = v >> 24; + break; + case AFMT_U32_LE: + dst[0] = v; + dst[1] = v >> 8; + dst[2] = v >> 16; + dst[3] = (v >> 24) ^ 0x80; + break; + case AFMT_U32_BE: + dst[3] = v; + dst[2] = v >> 8; + dst[1] = v >> 16; + dst[0] = (v >> 24) ^ 0x80; + break; + default: + printf("%s(): unknown format: 0x%08x\n", __func__, fmt); + break; + } } -static __inline void -intpcm_write_null(uint8_t *dst, intpcm_t v __unused) +static void +feed_format_conv_test(uint32_t fmt) { + const char *str; + intpcm_t in, out; + int i, mask = 0, flip = 0, shift; + enum { + RD_NORM = 0, + RD_SHIFT, + WR_NORM, + WR_SHIFT, + LAST + }; + + shift = 32 - AFMT_BIT(fmt); + for (i = 0; i < LAST; i++) { + /* + * Choose hardcoded inputs with a predictable pattern so that + * it's easy to examine the output of these tests. Also use the + * same bit-depth for both the input and output, to avoid + * complicating the code below. + */ + if (fmt & AFMT_8BIT) { + in = 0x00000011; + mask = 0x000000ff; + } else if (fmt & AFMT_16BIT) { + in = 0x00002211; + mask = 0x0000ffff; + } else if (fmt & AFMT_24BIT) { + in = 0x00332211; + mask = 0x00ffffff; + } else if (fmt & AFMT_32BIT) { + in = 0x44332211; + mask = 0xffffffff; + } - _PCM_WRITE_S16_LE(dst, 0); -} + /* Unsigned non-native endian conversions flip the LSB. */ + if ((fmt & (AFMT_SIGNED | AFMT_NE)) == 0 && + (i == WR_NORM || i == WR_SHIFT)) + flip = 0x80; + else + flip = 1 << (AFMT_BIT(fmt) - 1); -#define FEEDFORMAT_ENTRY(SIGN, BIT, ENDIAN) \ - { \ - AFMT_##SIGN##BIT##_##ENDIAN, \ - intpcm_read_##SIGN##BIT##ENDIAN, \ - intpcm_write_##SIGN##BIT##ENDIAN \ - } -static const struct { - uint32_t format; - intpcm_read_t *read; - intpcm_write_t *write; -} feed_format_ops[] = { - FEEDFORMAT_ENTRY(S, 8, NE), - FEEDFORMAT_ENTRY(S, 16, LE), - FEEDFORMAT_ENTRY(S, 24, LE), - FEEDFORMAT_ENTRY(S, 32, LE), - FEEDFORMAT_ENTRY(S, 16, BE), - FEEDFORMAT_ENTRY(S, 24, BE), - FEEDFORMAT_ENTRY(S, 32, BE), - FEEDFORMAT_ENTRY(U, 8, NE), - FEEDFORMAT_ENTRY(U, 16, LE), - FEEDFORMAT_ENTRY(U, 24, LE), - FEEDFORMAT_ENTRY(U, 32, LE), - FEEDFORMAT_ENTRY(U, 16, BE), - FEEDFORMAT_ENTRY(U, 24, BE), - FEEDFORMAT_ENTRY(U, 32, BE), - { - AFMT_MU_LAW, - intpcm_read_ulaw, intpcm_write_ulaw - }, - { - AFMT_A_LAW, - intpcm_read_alaw, intpcm_write_alaw - }, - { - AFMT_AC3, - intpcm_read_null, intpcm_write_null + switch (i) { + case RD_NORM: + out = pcm_sample_read((uint8_t *)&in, fmt, false); + str = "read_norm"; + break; + case RD_SHIFT: + out = pcm_sample_read((uint8_t *)&in, fmt, true); + str = "read_shift"; + break; + case WR_NORM: + pcm_sample_write((uint8_t *)&out, in, fmt, false); + str = "write_norm"; + break; + case WR_SHIFT: + /* + * Normally the sample we'd write would be already + * shifted by pcm_sample_read(), so do it here manually + * to emulate this behavior. + */ + in <<= shift; + pcm_sample_write((uint8_t *)&out, in, fmt, true); + str = "write_shift"; + break; + default: + return; + } + + /* If we shifted, the output is 32-bit long. */ + if (i == RD_NORM || i == WR_NORM) + out &= mask; + + printf("%s(0x%08x): in=0x%08x, out=0x%08x\n", str, fmt, in, out); + + /* + * Do the reverse operations to bring the sample back to the + * original input, so that we can verify that the conversion + * was correct. + */ + if (i == RD_SHIFT) { + out >>= shift; + out &= mask; + } +#ifndef SND_PCM_64 + if (fmt & AFMT_32BIT && (i == RD_NORM || i == RD_SHIFT)) + out <<= PCM_FXSHIFT; +#endif + if ((fmt & AFMT_SIGNED) == 0) + out ^= flip; + if ((fmt & AFMT_NE) == 0) { + if (fmt & AFMT_16BIT) + out = __bswap16(out); + else if (fmt & AFMT_24BIT) + out = __bswap32(out) >> 8; + else if (fmt & AFMT_32BIT) + out = __bswap32(out); + } +#ifndef SND_PCM_64 + if (fmt & AFMT_32BIT && (i == WR_NORM || i == WR_SHIFT)) + out >>= PCM_FXSHIFT; +#endif + if (i == WR_SHIFT) + out <<= shift; + + if (in != out) { + printf("%s(0x%08x): error: expected=0x%08x, " + "got=0x%08x\n", str, fmt, in, out); + } } -}; +} + +static int +sysctl_hw_snd_feeder_format_conv_test(SYSCTL_HANDLER_ARGS) +{ + int err, val; + + val = 0; + err = sysctl_handle_int(oidp, &val, 0, req); + if (err != 0 || req->newptr == NULL || val == 0) + return (err); + + /*feed_format_conv_test(AFMT_AC3);*/ + /*feed_format_conv_test(AFMT_MU_LAW);*/ + /*feed_format_conv_test(AFMT_A_LAW);*/ + feed_format_conv_test(AFMT_S8); + feed_format_conv_test(AFMT_U8); + feed_format_conv_test(AFMT_S16_NE); + feed_format_conv_test(AFMT_S16_OE); + feed_format_conv_test(AFMT_U16_NE); + feed_format_conv_test(AFMT_U16_OE); + feed_format_conv_test(AFMT_S24_NE); + feed_format_conv_test(AFMT_S24_OE); + feed_format_conv_test(AFMT_U24_NE); + feed_format_conv_test(AFMT_U24_OE); + feed_format_conv_test(AFMT_S32_NE); + feed_format_conv_test(AFMT_S32_OE); + feed_format_conv_test(AFMT_U32_NE); + feed_format_conv_test(AFMT_U32_OE); + + return (0); +} +SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_format_conv_test, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0, + sysctl_hw_snd_feeder_format_conv_test, "I", "unit test format conversions"); static int feed_format_init(struct pcm_feeder *f) { struct feed_format_info *info; - intpcm_read_t *rd_op; - intpcm_write_t *wr_op; - size_t i; if (f->desc->in == f->desc->out || AFMT_CHANNEL(f->desc->in) != AFMT_CHANNEL(f->desc->out)) return (EINVAL); - rd_op = NULL; - wr_op = NULL; - - for (i = 0; i < nitems(feed_format_ops) && - (rd_op == NULL || wr_op == NULL); i++) { - if (rd_op == NULL && - AFMT_ENCODING(f->desc->in) == feed_format_ops[i].format) - rd_op = feed_format_ops[i].read; - if (wr_op == NULL && - AFMT_ENCODING(f->desc->out) == feed_format_ops[i].format) - wr_op = feed_format_ops[i].write; - } - - if (rd_op == NULL || wr_op == NULL) { - printf("%s(): failed to initialize io ops " - "in=0x%08x out=0x%08x\n", - __func__, f->desc->in, f->desc->out); - return (EINVAL); - } - info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT | M_ZERO); if (info == NULL) return (ENOMEM); @@ -247,11 +401,11 @@ info->ibps = AFMT_BPS(f->desc->in); info->ialign = info->ibps * info->channels; - info->read = rd_op; + info->rdfmt = AFMT_ENCODING(f->desc->in); info->obps = AFMT_BPS(f->desc->out); info->oalign = info->obps * info->channels; - info->write = wr_op; + info->wrfmt = AFMT_ENCODING(f->desc->out); f->data = info; @@ -335,8 +489,8 @@ count -= j * info->obps; do { - v = info->read(src); - info->write(dst, v); + v = pcm_sample_read(src, info->rdfmt, true); + pcm_sample_write(dst, v, info->wrfmt, true); dst += info->obps; src += info->ibps; } while (--j != 0); @@ -360,29 +514,3 @@ }; FEEDER_DECLARE(feeder_format, NULL); - -intpcm_read_t * -feeder_format_read_op(uint32_t format) -{ - size_t i; - - for (i = 0; i < nitems(feed_format_ops); i++) { - if (AFMT_ENCODING(format) == feed_format_ops[i].format) - return (feed_format_ops[i].read); - } - - return (NULL); -} - -intpcm_write_t * -feeder_format_write_op(uint32_t format) -{ - size_t i; - - for (i = 0; i < nitems(feed_format_ops); i++) { - if (AFMT_ENCODING(format) == feed_format_ops[i].format) - return (feed_format_ops[i].write); - } - - return (NULL); -} diff --git a/sys/dev/sound/pcm/feeder_matrix.c b/sys/dev/sound/pcm/feeder_matrix.c --- a/sys/dev/sound/pcm/feeder_matrix.c +++ b/sys/dev/sound/pcm/feeder_matrix.c @@ -65,10 +65,6 @@ uint32_t ialign, oalign; uint32_t in, out; feed_matrix_t apply; -#ifdef FEEDMATRIX_GENERIC - intpcm_read_t *rd; - intpcm_write_t *wr; -#endif struct { int chn[SND_CHN_T_MAX + 1]; int mul, shift; @@ -127,16 +123,17 @@ for (i = 0; info->matrix[i].chn[0] != SND_CHN_T_EOF; \ i++) { \ if (info->matrix[i].chn[0] == SND_CHN_T_NULL) { \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, \ - 0); \ + pcm_sample_write(dst, 0, \ + AFMT_##SIGN##BIT##_##ENDIAN, false);\ dst += PCM_##BIT##_BPS; \ continue; \ } else if (info->matrix[i].chn[1] == \ SND_CHN_T_EOF) { \ - v = _PCM_READ_##SIGN##BIT##_##ENDIAN( \ - src + info->matrix[i].chn[0]); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, \ - v); \ + v = pcm_sample_read( \ + src + info->matrix[i].chn[0], \ + AFMT_##SIGN##BIT##_##ENDIAN, false);\ + pcm_sample_write(dst, v, \ + AFMT_##SIGN##BIT##_##ENDIAN, false);\ dst += PCM_##BIT##_BPS; \ continue; \ } \ @@ -145,8 +142,9 @@ for (j = 0; \ info->matrix[i].chn[j] != SND_CHN_T_EOF; \ j++) { \ - v = _PCM_READ_##SIGN##BIT##_##ENDIAN( \ - src + info->matrix[i].chn[j]); \ + v = pcm_sample_read( \ + src + info->matrix[i].chn[j], \ + AFMT_##SIGN##BIT##_##ENDIAN, false);\ accum += v; \ } \ \ @@ -160,7 +158,8 @@ ((accum < PCM_S##BIT##_MIN) ? \ PCM_S##BIT##_MIN : \ accum); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v); \ + pcm_sample_write(dst, v, \ + AFMT_##SIGN##BIT##_##ENDIAN, false); \ dst += PCM_##BIT##_BPS; \ } \ src += info->ialign; \ @@ -249,13 +248,14 @@ for (i = 0; info->matrix[i].chn[0] != SND_CHN_T_EOF; i++) { if (info->matrix[i].chn[0] == SND_CHN_T_NULL) { - info->wr(dst, 0); + pcm_sample_write(dst, 0, info->out, true); dst += info->bps; continue; } else if (info->matrix[i].chn[1] == SND_CHN_T_EOF) { - v = info->rd(src + info->matrix[i].chn[0]); - info->wr(dst, v); + v = pcm_sample_read(src + + info->matrix[i].chn[0], info->in, true) + pcm_sample_write(dst, v, info->out, true); dst += info->bps; continue; } @@ -264,7 +264,8 @@ for (j = 0; info->matrix[i].chn[j] != SND_CHN_T_EOF; j++) { - v = info->rd(src + info->matrix[i].chn[j]); + v = pcm_sample_read(src + + info->matrix[i].chn[j], info->in, true); accum += v; } @@ -275,7 +276,7 @@ v = (accum > PCM_S32_MAX) ? PCM_S32_MAX : ((accum < PCM_S32_MIN) ? PCM_S32_MIN : accum); - info->wr(dst, v); + pcm_sample_write(dst, v, info->out, true); dst += info->bps; } src += info->ialign; @@ -416,12 +417,6 @@ if (info->apply == NULL) { #ifdef FEEDMATRIX_GENERIC - info->rd = feeder_format_read_op(info->in); - info->wr = feeder_format_write_op(info->out); - if (info->rd == NULL || info->wr == NULL) { - free(info, M_DEVBUF); - return (EINVAL); - } info->apply = feed_matrix_apply_generic; #else free(info, M_DEVBUF); 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 @@ -53,11 +53,14 @@ src -= PCM_##BIT##_BPS; \ dst -= PCM_##BIT##_BPS; \ count -= PCM_##BIT##_BPS; \ - x = PCM_READ_##SIGN##BIT##_##ENDIAN(src); \ - y = PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \ + x = pcm_sample_read(src, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ + y = pcm_sample_read(dst, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ z = INTPCM##BIT##_T(x) + y; \ x = PCM_CLAMP_##SIGN##BIT(z); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, x); \ + pcm_sample_write(dst, x, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ } 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 @@ -466,10 +466,10 @@ ch = info->channels; \ \ do { \ - x = _PCM_READ_##SIGN##BIT##_##ENDIAN(sx); \ - y = _PCM_READ_##SIGN##BIT##_##ENDIAN(sy); \ + x = pcm_sample_read(sx, AFMT_##SIGN##BIT##_##ENDIAN, false); \ + y = pcm_sample_read(sy, AFMT_##SIGN##BIT##_##ENDIAN, false); \ x = Z_LINEAR_INTERPOLATE_##BIT(z, x, y); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, x); \ + pcm_sample_write(dst, x, AFMT_##SIGN##BIT##_##ENDIAN, false); \ sx += PCM_##BIT##_BPS; \ sy += PCM_##BIT##_BPS; \ dst += PCM_##BIT##_BPS; \ @@ -511,7 +511,7 @@ c += z >> Z_SHIFT; \ z &= Z_MASK; \ coeff = Z_COEFF_INTERPOLATE(z, z_coeff[c], z_dcoeff[c]); \ - x = _PCM_READ_##SIGN##BIT##_##ENDIAN(p); \ + x = pcm_sample_read(p, AFMT_##SIGN##BIT##_##ENDIAN, false); \ v += Z_NORM_##BIT((intpcm64_t)x * coeff); \ z += info->z_dy; \ p adv##= info->channels * PCM_##BIT##_BPS @@ -569,7 +569,8 @@ else \ v >>= Z_COEFF_SHIFT - Z_GUARD_BIT_##BIT; \ Z_CLIP_CHECK(v, BIT); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, Z_CLAMP(v, BIT)); \ + pcm_sample_write(dst, Z_CLAMP(v, BIT), \ + AFMT_##SIGN##BIT##_##ENDIAN, false); \ } while (ch != 0); \ } @@ -594,11 +595,13 @@ z_pcoeff = info->z_pcoeff + \ ((info->z_alpha * info->z_size) << 1); \ for (i = info->z_size; i != 0; i--) { \ - x = _PCM_READ_##SIGN##BIT##_##ENDIAN(p); \ + x = pcm_sample_read(p, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ v += Z_NORM_##BIT((intpcm64_t)x * *z_pcoeff); \ z_pcoeff++; \ p += info->channels * PCM_##BIT##_BPS; \ - x = _PCM_READ_##SIGN##BIT##_##ENDIAN(p); \ + x = pcm_sample_read(p, AFMT_##SIGN##BIT##_##ENDIAN, \ + false); \ v += Z_NORM_##BIT((intpcm64_t)x * *z_pcoeff); \ z_pcoeff++; \ p += info->channels * PCM_##BIT##_BPS; \ @@ -608,7 +611,8 @@ else \ v >>= Z_COEFF_SHIFT - Z_GUARD_BIT_##BIT; \ Z_CLIP_CHECK(v, BIT); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, Z_CLAMP(v, BIT)); \ + pcm_sample_write(dst, Z_CLAMP(v, BIT), \ + AFMT_##SIGN##BIT##_##ENDIAN, false); \ } 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 @@ -58,10 +58,12 @@ do { \ dst -= PCM_##BIT##_BPS; \ i--; \ - x = PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \ + x = pcm_sample_read(dst, \ + AFMT_##SIGN##BIT##_##ENDIAN, false); \ v = FEEDVOLUME_CALC##BIT(x, vol[matrix[i]]); \ x = PCM_CLAMP_##SIGN##BIT(v); \ - _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, x); \ + pcm_sample_write(dst, x, \ + AFMT_##SIGN##BIT##_##ENDIAN, false); \ } while (i != 0); \ } while (--count != 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 @@ -29,15 +29,6 @@ #ifndef _SND_PCM_H_ #define _SND_PCM_H_ -/* - * Macros for reading/writing PCM sample / int values from bytes array. - * Since every process is done using signed integer (and to make our life - * less miserable), unsigned sample will be converted to its signed - * counterpart and restored during writing back. To avoid overflow, - * we truncate 32bit (and only 32bit) samples down to 24bit (see below - * for the reason), unless SND_PCM_64 is defined. - */ - /* * Automatically turn on 64bit arithmetic on suitable archs * (amd64 64bit, etc..) for wider 32bit samples / integer processing. @@ -104,309 +95,6 @@ #define INTPCM24_T(v) ((intpcm24_t)(v)) #define INTPCM32_T(v) ((intpcm32_t)(v)) -#if BYTE_ORDER == LITTLE_ENDIAN -#define _PCM_READ_S16_LE(b8) INTPCM_T(*((int16_t *)(b8))) -#define _PCM_READ_S32_LE(b8) INTPCM_T(*((int32_t *)(b8))) -#define _PCM_READ_S16_BE(b8) \ - INTPCM_T((b8)[1] | (((int8_t)((b8)[0])) << 8)) -#define _PCM_READ_S32_BE(b8) \ - INTPCM_T((b8)[3] | ((b8)[2] << 8) | ((b8)[1] << 16) | \ - (((int8_t)((b8)[0])) << 24)) - -#define _PCM_WRITE_S16_LE(b8, val) do { \ - *((int16_t *)(b8)) = (val); \ -} while (0) -#define _PCM_WRITE_S32_LE(b8, val) do { \ - *((int32_t *)(b8)) = (val); \ -} while (0) -#define _PCM_WRITE_S16_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[1] = val; \ - b8[0] = val >> 8; \ -} while (0) -#define _PCM_WRITE_S32_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[3] = val; \ - b8[2] = val >> 8; \ - b8[1] = val >> 16; \ - b8[0] = val >> 24; \ -} while (0) - -#define _PCM_READ_U16_LE(b8) \ - INTPCM_T((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) -#define _PCM_READ_U32_LE(b8) \ - INTPCM_T((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) -#define _PCM_READ_U16_BE(b8) \ - INTPCM_T((b8)[1] | (((int8_t)((b8)[0] ^ 0x80)) << 8)) -#define _PCM_READ_U32_BE(b8) \ - INTPCM_T((b8)[3] | ((b8)[2] << 8) | ((b8)[1] << 16) | \ - (((int8_t)((b8)[0] ^ 0x80)) << 24)) - -#define _PCM_WRITE_U16_LE(b8, val) do { \ - *((uint16_t *)(b8)) = (val) ^ 0x8000; \ -} while (0) -#define _PCM_WRITE_U32_LE(b8, val) do { \ - *((uint32_t *)(b8)) = (val) ^ 0x80000000; \ -} while (0) -#define _PCM_WRITE_U16_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[1] = val; \ - b8[0] = (val >> 8) ^ 0x80; \ -} while (0) -#define _PCM_WRITE_U32_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[3] = val; \ - b8[2] = val >> 8; \ - b8[1] = val >> 16; \ - b8[0] = (val >> 24) ^ 0x80; \ -} while (0) - -#define _PCM_READ_S16_NE(b8) _PCM_READ_S16_LE(b8) -#define _PCM_READ_U16_NE(b8) _PCM_READ_U16_LE(b8) -#define _PCM_READ_S32_NE(b8) _PCM_READ_S32_LE(b8) -#define _PCM_READ_U32_NE(b8) _PCM_READ_U32_LE(b8) -#define _PCM_WRITE_S16_NE(b6) _PCM_WRITE_S16_LE(b8) -#define _PCM_WRITE_U16_NE(b6) _PCM_WRITE_U16_LE(b8) -#define _PCM_WRITE_S32_NE(b6) _PCM_WRITE_S32_LE(b8) -#define _PCM_WRITE_U32_NE(b6) _PCM_WRITE_U32_LE(b8) -#else /* !LITTLE_ENDIAN */ -#define _PCM_READ_S16_LE(b8) \ - INTPCM_T((b8)[0] | (((int8_t)((b8)[1])) << 8)) -#define _PCM_READ_S32_LE(b8) \ - INTPCM_T((b8)[0] | ((b8)[1] << 8) | ((b8)[2] << 16) | \ - (((int8_t)((b8)[3])) << 24)) -#define _PCM_READ_S16_BE(b8) INTPCM_T(*((int16_t *)(b8))) -#define _PCM_READ_S32_BE(b8) INTPCM_T(*((int32_t *)(b8))) - -#define _PCM_WRITE_S16_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = val >> 8; \ -} while (0) -#define _PCM_WRITE_S32_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = val >> 8; \ - b8[2] = val >> 16; \ - b8[3] = val >> 24; \ -} while (0) -#define _PCM_WRITE_S16_BE(b8, val) do { \ - *((int16_t *)(b8)) = (val); \ -} while (0) -#define _PCM_WRITE_S32_BE(b8, val) do { \ - *((int32_t *)(b8)) = (val); \ -} while (0) - -#define _PCM_READ_U16_LE(b8) \ - INTPCM_T((b8)[0] | (((int8_t)((b8)[1] ^ 0x80)) << 8)) -#define _PCM_READ_U32_LE(b8) \ - INTPCM_T((b8)[0] | ((b8)[1] << 8) | ((b8)[2] << 16) | \ - (((int8_t)((b8)[3] ^ 0x80)) << 24)) -#define _PCM_READ_U16_BE(b8) \ - INTPCM_T((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) -#define _PCM_READ_U32_BE(b8) \ - INTPCM_T((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) - -#define _PCM_WRITE_U16_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = (val >> 8) ^ 0x80; \ -} while (0) -#define _PCM_WRITE_U32_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = val >> 8; \ - b8[2] = val >> 16; \ - b8[3] = (val >> 24) ^ 0x80; \ -} while (0) -#define _PCM_WRITE_U16_BE(b8, val) do { \ - *((uint16_t *)(b8)) = (val) ^ 0x8000; \ -} while (0) -#define _PCM_WRITE_U32_BE(b8, val) do { \ - *((uint32_t *)(b8)) = (val) ^ 0x80000000; \ -} while (0) - -#define _PCM_READ_S16_NE(b8) _PCM_READ_S16_BE(b8) -#define _PCM_READ_U16_NE(b8) _PCM_READ_U16_BE(b8) -#define _PCM_READ_S32_NE(b8) _PCM_READ_S32_BE(b8) -#define _PCM_READ_U32_NE(b8) _PCM_READ_U32_BE(b8) -#define _PCM_WRITE_S16_NE(b6) _PCM_WRITE_S16_BE(b8) -#define _PCM_WRITE_U16_NE(b6) _PCM_WRITE_U16_BE(b8) -#define _PCM_WRITE_S32_NE(b6) _PCM_WRITE_S32_BE(b8) -#define _PCM_WRITE_U32_NE(b6) _PCM_WRITE_U32_BE(b8) -#endif /* LITTLE_ENDIAN */ - -#define _PCM_READ_S24_LE(b8) \ - INTPCM_T((b8)[0] | ((b8)[1] << 8) | (((int8_t)((b8)[2])) << 16)) -#define _PCM_READ_S24_BE(b8) \ - INTPCM_T((b8)[2] | ((b8)[1] << 8) | (((int8_t)((b8)[0])) << 16)) - -#define _PCM_WRITE_S24_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = val >> 8; \ - b8[2] = val >> 16; \ -} while (0) -#define _PCM_WRITE_S24_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[2] = val; \ - b8[1] = val >> 8; \ - b8[0] = val >> 16; \ -} while (0) - -#define _PCM_READ_U24_LE(b8) \ - INTPCM_T((b8)[0] | ((b8)[1] << 8) | \ - (((int8_t)((b8)[2] ^ 0x80)) << 16)) -#define _PCM_READ_U24_BE(b8) \ - INTPCM_T((b8)[2] | ((b8)[1] << 8) | \ - (((int8_t)((b8)[0] ^ 0x80)) << 16)) - -#define _PCM_WRITE_U24_LE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[0] = val; \ - b8[1] = val >> 8; \ - b8[2] = (val >> 16) ^ 0x80; \ -} while (0) -#define _PCM_WRITE_U24_BE(bb8, vval) do { \ - intpcm_t val = (vval); \ - uint8_t *b8 = (bb8); \ - b8[2] = val; \ - b8[1] = val >> 8; \ - b8[0] = (val >> 16) ^ 0x80; \ -} while (0) - -#if BYTE_ORDER == LITTLE_ENDIAN -#define _PCM_READ_S24_NE(b8) _PCM_READ_S24_LE(b8) -#define _PCM_READ_U24_NE(b8) _PCM_READ_U24_LE(b8) -#define _PCM_WRITE_S24_NE(b6) _PCM_WRITE_S24_LE(b8) -#define _PCM_WRITE_U24_NE(b6) _PCM_WRITE_U24_LE(b8) -#else /* !LITTLE_ENDIAN */ -#define _PCM_READ_S24_NE(b8) _PCM_READ_S24_BE(b8) -#define _PCM_READ_U24_NE(b8) _PCM_READ_U24_BE(b8) -#define _PCM_WRITE_S24_NE(b6) _PCM_WRITE_S24_BE(b8) -#define _PCM_WRITE_U24_NE(b6) _PCM_WRITE_U24_BE(b8) -#endif /* LITTLE_ENDIAN */ -/* - * 8bit sample is pretty much useless since it doesn't provide - * sufficient dynamic range throughout our filtering process. - * For the sake of completeness, declare it anyway. - */ -#define _PCM_READ_S8_NE(b8) INTPCM_T(*((int8_t *)(b8))) -#define _PCM_READ_U8_NE(b8) \ - INTPCM_T((int8_t)(*((uint8_t *)(b8)) ^ 0x80)) - -#define _PCM_WRITE_S8_NE(b8, val) do { \ - *((int8_t *)(b8)) = (val); \ -} while (0) -#define _PCM_WRITE_U8_NE(b8, val) do { \ - *((uint8_t *)(b8)) = (val) ^ 0x80; \ -} while (0) - -/* - * Common macross. Use this instead of "_", unless we want - * the real sample value. - */ - -/* 8bit */ -#define PCM_READ_S8_NE(b8) _PCM_READ_S8_NE(b8) -#define PCM_READ_U8_NE(b8) _PCM_READ_U8_NE(b8) -#define PCM_WRITE_S8_NE(b8, val) _PCM_WRITE_S8_NE(b8, val) -#define PCM_WRITE_U8_NE(b8, val) _PCM_WRITE_U8_NE(b8, val) - -/* 16bit */ -#define PCM_READ_S16_LE(b8) _PCM_READ_S16_LE(b8) -#define PCM_READ_S16_BE(b8) _PCM_READ_S16_BE(b8) -#define PCM_READ_U16_LE(b8) _PCM_READ_U16_LE(b8) -#define PCM_READ_U16_BE(b8) _PCM_READ_U16_BE(b8) - -#define PCM_WRITE_S16_LE(b8, val) _PCM_WRITE_S16_LE(b8, val) -#define PCM_WRITE_S16_BE(b8, val) _PCM_WRITE_S16_BE(b8, val) -#define PCM_WRITE_U16_LE(b8, val) _PCM_WRITE_U16_LE(b8, val) -#define PCM_WRITE_U16_BE(b8, val) _PCM_WRITE_U16_BE(b8, val) - -#define PCM_READ_S16_NE(b8) _PCM_READ_S16_NE(b8) -#define PCM_READ_U16_NE(b8) _PCM_READ_U16_NE(b8) -#define PCM_WRITE_S16_NE(b8) _PCM_WRITE_S16_NE(b8) -#define PCM_WRITE_U16_NE(b8) _PCM_WRITE_U16_NE(b8) - -/* 24bit */ -#define PCM_READ_S24_LE(b8) _PCM_READ_S24_LE(b8) -#define PCM_READ_S24_BE(b8) _PCM_READ_S24_BE(b8) -#define PCM_READ_U24_LE(b8) _PCM_READ_U24_LE(b8) -#define PCM_READ_U24_BE(b8) _PCM_READ_U24_BE(b8) - -#define PCM_WRITE_S24_LE(b8, val) _PCM_WRITE_S24_LE(b8, val) -#define PCM_WRITE_S24_BE(b8, val) _PCM_WRITE_S24_BE(b8, val) -#define PCM_WRITE_U24_LE(b8, val) _PCM_WRITE_U24_LE(b8, val) -#define PCM_WRITE_U24_BE(b8, val) _PCM_WRITE_U24_BE(b8, val) - -#define PCM_READ_S24_NE(b8) _PCM_READ_S24_NE(b8) -#define PCM_READ_U24_NE(b8) _PCM_READ_U24_NE(b8) -#define PCM_WRITE_S24_NE(b8) _PCM_WRITE_S24_NE(b8) -#define PCM_WRITE_U24_NE(b8) _PCM_WRITE_U24_NE(b8) - -/* 32bit */ -#ifdef SND_PCM_64 -#define PCM_READ_S32_LE(b8) _PCM_READ_S32_LE(b8) -#define PCM_READ_S32_BE(b8) _PCM_READ_S32_BE(b8) -#define PCM_READ_U32_LE(b8) _PCM_READ_U32_LE(b8) -#define PCM_READ_U32_BE(b8) _PCM_READ_U32_BE(b8) - -#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, val) -#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, val) -#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, val) -#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, val) - -#define PCM_READ_S32_NE(b8) _PCM_READ_S32_NE(b8) -#define PCM_READ_U32_NE(b8) _PCM_READ_U32_NE(b8) -#define PCM_WRITE_S32_NE(b8) _PCM_WRITE_S32_NE(b8) -#define PCM_WRITE_U32_NE(b8) _PCM_WRITE_U32_NE(b8) -#else /* !SND_PCM_64 */ -/* - * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight: - * Dynamic range for: - * 1) Human =~ 140db - * 2) 16bit = 96db (close enough) - * 3) 24bit = 144db (perfect) - * 4) 32bit = 196db (way too much) - * 5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db - * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit - * is pretty much sufficient for our signed integer processing. - */ -#define PCM_READ_S32_LE(b8) (_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT) -#define PCM_READ_S32_BE(b8) (_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT) -#define PCM_READ_U32_LE(b8) (_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT) -#define PCM_READ_U32_BE(b8) (_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT) - -#define PCM_READ_S32_NE(b8) (_PCM_READ_S32_NE(b8) >> PCM_FXSHIFT) -#define PCM_READ_U32_NE(b8) (_PCM_READ_U32_NE(b8) >> PCM_FXSHIFT) - -#define PCM_WRITE_S32_LE(b8, val) \ - _PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT) -#define PCM_WRITE_S32_BE(b8, val) \ - _PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT) -#define PCM_WRITE_U32_LE(b8, val) \ - _PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT) -#define PCM_WRITE_U32_BE(b8, val) \ - _PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT) - -#define PCM_WRITE_S32_NE(b8, val) \ - _PCM_WRITE_S32_NE(b8, (val) << PCM_FXSHIFT) -#define PCM_WRITE_U32_NE(b8, val) \ - _PCM_WRITE_U32_NE(b8, (val) << PCM_FXSHIFT) -#endif /* SND_PCM_64 */ - #define PCM_CLAMP_S8(val) \ (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \ (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val))) @@ -433,4 +121,7 @@ #define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val) #define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val) +extern __always_inline intpcm_t pcm_sample_read(uint8_t *, uint32_t, bool); +extern __always_inline void pcm_sample_write(uint8_t *, intpcm_t, uint32_t, bool); + #endif /* !_SND_PCM_H_ */