Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev mulaw/alaw_to_linearN macros replaced with individua...
details: https://anonhg.NetBSD.org/src/rev/7a98fe5031b5
branches: trunk
changeset: 358385:7a98fe5031b5
user: nat <nat%NetBSD.org@localhost>
date: Wed Dec 27 00:12:06 2017 +0000
description:
mulaw/alaw_to_linearN macros replaced with individual faster filters.
NFC.
diffstat:
sys/dev/mulaw.c | 589 ++++++++++++++++++++++++++++++++++---------------------
sys/dev/mulaw.h | 29 +-
2 files changed, 378 insertions(+), 240 deletions(-)
diffs (truncated from 694 to 300 lines):
diff -r 65824b9aa13b -r 7a98fe5031b5 sys/dev/mulaw.c
--- a/sys/dev/mulaw.c Tue Dec 26 20:04:03 2017 +0000
+++ b/sys/dev/mulaw.c Wed Dec 27 00:12:06 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mulaw.c,v 1.32 2017/06/26 12:17:09 nat Exp $ */
+/* $NetBSD: mulaw.c,v 1.33 2017/12/27 00:12:06 nat Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.32 2017/06/26 12:17:09 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.33 2017/12/27 00:12:06 nat Exp $");
#include <sys/types.h>
#include <sys/systm.h>
@@ -295,119 +295,198 @@
return 0;
}
-#define MULAWTOLINEARN(n_prec) \
-DEFINE_FILTER(mulaw_to_linear##n_prec) \
-{ \
- stream_filter_t *this; \
- int hw, j, m, err; \
- \
- hw = n_prec / NBBY; \
- this = (stream_filter_t *)self; \
- max_used = (max_used + 1) & ~1; /* round up to even */ \
- if ((err = this->prev->fetch_to(sc, this->prev, \
- this->src, max_used / hw))) \
- return err; \
- m = (dst->end - dst->start) & ~1; \
- m = min(m, max_used); \
- switch (dst->param.encoding) { \
- case AUDIO_ENCODING_ULINEAR_LE: \
- FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) { \
- j = hw - 2; \
- d[hw - 2] = mulawtolin16[s[0]][1]; \
- d[hw - 1] = mulawtolin16[s[0]][0]; \
- while (j > 0) \
- d[--j] = 0; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_ULINEAR_BE: \
- FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) { \
- j = 2; \
- d[0] = mulawtolin16[s[0]][0]; \
- d[1] = mulawtolin16[s[0]][1]; \
- while (j < hw) \
- d[j++] = 0; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_SLINEAR_LE: \
- FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) { \
- j = hw - 2; \
- d[hw - 2] = mulawtolin16[s[0]][1]; \
- d[hw - 1] = mulawtolin16[s[0]][0] ^ 0x80; \
- while (j > 0) \
- d[--j] = 0; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_SLINEAR_BE: \
- FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) { \
- j = 2; \
- d[0] = mulawtolin16[s[0]][0] ^ 0x80; \
- d[1] = mulawtolin16[s[0]][1]; \
- while (j < hw) \
- d[j++] = 0; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- default: \
- aprint_error( \
- "%s: encoding must be [s/u]linear_[le/be]\n", \
- __func__); \
- break; \
- } \
- return 0; \
+DEFINE_FILTER(mulaw_to_linear16)
+{
+ stream_filter_t *this;
+ int m, err;
+
+ this = (stream_filter_t *)self;
+ max_used = (max_used + 1) & ~1;
+ if ((err = this->prev->fetch_to(sc, this->prev,
+ this->src, max_used / 2)))
+ return err;
+ m = (dst->end - dst->start) & ~1;
+ m = min(m, max_used);
+ switch (dst->param.encoding) {
+ case AUDIO_ENCODING_ULINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+ d[1] = mulawtolin16[s[0]][0];
+ d[0] = mulawtolin16[s[0]][1];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_ULINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+ d[0] = mulawtolin16[s[0]][0];
+ d[1] = mulawtolin16[s[0]][1];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+ d[1] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[0] = mulawtolin16[s[0]][1];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+ d[0] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[1] = mulawtolin16[s[0]][1];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ default:
+ aprint_error(
+ "%s: encoding must be [s/u]linear_[le/be]\n",
+ __func__);
+ break;
+ }
+ return 0;
+}
+
+DEFINE_FILTER(mulaw_to_linear24)
+{
+ stream_filter_t *this;
+ int m, err;
+
+ this = (stream_filter_t *)self;
+ max_used = (max_used + 1) & ~1;
+ if ((err = this->prev->fetch_to(sc, this->prev,
+ this->src, max_used / 3)))
+ return err;
+ m = (dst->end - dst->start) & ~1;
+ m = min(m, max_used);
+ switch (dst->param.encoding) {
+ case AUDIO_ENCODING_ULINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 3, m) {
+ d[2] = mulawtolin16[s[0]][0];
+ d[1] = mulawtolin16[s[0]][1];
+ d[0] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_ULINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 3, m) {
+ d[0] = mulawtolin16[s[0]][0];
+ d[1] = mulawtolin16[s[0]][1];
+ d[2] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 3, m) {
+ d[2] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[1] = mulawtolin16[s[0]][1];
+ d[0] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 3, m) {
+ d[0] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[1] = mulawtolin16[s[0]][1];
+ d[2] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ default:
+ aprint_error(
+ "%s: encoding must be [s/u]linear_[le/be]\n",
+ __func__);
+ break;
+ }
+ return 0;
}
-MULAWTOLINEARN(32)
-MULAWTOLINEARN(24)
-MULAWTOLINEARN(16)
+DEFINE_FILTER(mulaw_to_linear32)
+{
+ stream_filter_t *this;
+ int m, err;
-#define LINEARNTOMULAW(n_prec, n_valid) \
-DEFINE_FILTER(linear##n_prec##_##n_valid##_to_mulaw) \
-{ \
- stream_filter_t *this; \
- int hw, m, err; \
- \
- hw = n_prec / NBBY; \
- this = (stream_filter_t *)self; \
- if ((err = this->prev->fetch_to(sc, this->prev, this->src, \
- max_used * hw))) \
- return err; \
- m = dst->end - dst->start; \
- m = min(m, max_used); \
- switch (this->src->param.encoding) { \
- case AUDIO_ENCODING_SLINEAR_LE: \
- FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) { \
- d[0] = lintomulaw[s[hw - 1] ^ 0x80]; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_SLINEAR_BE: \
- FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) { \
- d[0] = lintomulaw[s[0] ^ 0x80]; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_ULINEAR_LE: \
- FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) { \
- d[0] = lintomulaw[s[hw - 1]]; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- case AUDIO_ENCODING_ULINEAR_BE: \
- FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) { \
- d[0] = lintomulaw[s[0]]; \
- } FILTER_LOOP_EPILOGUE(this->src, dst); \
- break; \
- default: \
- aprint_error( \
- "%s: encoding must be [s/u]linear_[le/be]\n", \
- __func__); \
- break; \
- } \
- return 0; \
+ this = (stream_filter_t *)self;
+ max_used = (max_used + 1) & ~1;
+ if ((err = this->prev->fetch_to(sc, this->prev,
+ this->src, max_used / 4)))
+ return err;
+ m = (dst->end - dst->start) & ~1;
+ m = min(m, max_used);
+ switch (dst->param.encoding) {
+ case AUDIO_ENCODING_ULINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 4, m) {
+ d[3] = mulawtolin16[s[0]][0];
+ d[2] = mulawtolin16[s[0]][1];
+ d[1] = 0;
+ d[0] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_ULINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 4, m) {
+ d[0] = mulawtolin16[s[0]][0];
+ d[1] = mulawtolin16[s[0]][1];
+ d[2] = 0;
+ d[3] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 4, m) {
+ d[3] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[2] = mulawtolin16[s[0]][1];
+ d[1] = 0;
+ d[0] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, 1, dst, 4, m) {
+ d[0] = mulawtolin16[s[0]][0] ^ 0x80;
+ d[1] = mulawtolin16[s[0]][1];
+ d[2] = 0;
+ d[3] = 0;
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ default:
+ aprint_error(
+ "%s: encoding must be [s/u]linear_[le/be]\n",
+ __func__);
+ break;
+ }
+ return 0;
+}
+
+DEFINE_FILTER(linearN_to_mulaw)
+{
+ stream_filter_t *this;
+ int hw, m, err;
+
+ this = (stream_filter_t *)self;
+ hw = this->src->param.precision / NBBY;
+ if ((err = this->prev->fetch_to(sc, this->prev, this->src,
+ max_used * hw)))
+ return err;
+ m = dst->end - dst->start;
+ m = min(m, max_used);
+ switch (this->src->param.encoding) {
+ case AUDIO_ENCODING_SLINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) {
+ d[0] = lintomulaw[s[hw - 1] ^ 0x80];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_SLINEAR_BE:
+ FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) {
+ d[0] = lintomulaw[s[0] ^ 0x80];
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+ break;
+ case AUDIO_ENCODING_ULINEAR_LE:
+ FILTER_LOOP_PROLOGUE(this->src, hw, dst, 1, m) {
+ d[0] = lintomulaw[s[hw - 1]];
Home |
Main Index |
Thread Index |
Old Index