Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Add common audio converters for software volume cont...
details: https://anonhg.NetBSD.org/src/rev/c6921d33be23
branches: trunk
changeset: 333829:c6921d33be23
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Tue Nov 18 01:53:17 2014 +0000
description:
Add common audio converters for software volume control. Only supports
slinear16_le and slinear16_be for now.
Convert pad(4) to use the new converters.
diffstat:
sys/dev/auvolconv.c | 94 +++++++++++++++++++++++++++++++++++++
sys/dev/auvolconv.h | 42 ++++++++++++++++
sys/dev/files.audio | 4 +-
sys/dev/pad/files.pad | 5 +-
sys/dev/pad/pad.c | 59 +++++++++++++++++++++--
sys/dev/pad/padvar.h | 4 +-
sys/dev/pad/padvol.c | 125 --------------------------------------------------
sys/dev/pad/padvol.h | 53 ---------------------
8 files changed, 197 insertions(+), 189 deletions(-)
diffs (truncated from 490 to 300 lines):
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/auvolconv.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/auvolconv.c Tue Nov 18 01:53:17 2014 +0000
@@ -0,0 +1,94 @@
+/* $NetBSD: auvolconv.c,v 1.1 2014/11/18 01:53:17 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: auvolconv.c,v 1.1 2014/11/18 01:53:17 jmcneill Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/select.h>
+#include <sys/condvar.h>
+#include <sys/kmem.h>
+#include <sys/device.h>
+#include <sys/endian.h>
+
+#include <dev/audiovar.h>
+#include <dev/auconv.h>
+#include <dev/auvolconv.h>
+
+int
+auvolconv_slinear16_le_fetch_to(struct audio_softc *asc,
+ stream_fetcher_t *self, audio_stream_t *dst, int max_used)
+{
+ auvolconv_filter_t *pf;
+ stream_filter_t *this;
+ int16_t j, *wp;
+ int m, err;
+
+ pf = (auvolconv_filter_t *)self;
+ this = &pf->base;
+ max_used = (max_used + 1) & ~1;
+
+ if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used)))
+ return err;
+ m = (dst->end - dst->start) & ~1;
+ m = min(m, max_used);
+ FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
+ j = le16dec(s);
+ wp = (int16_t *)d;
+ le16enc(wp, (j * *pf->vol) / 255);
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+
+ return 0;
+}
+
+int
+auvolconv_slinear16_be_fetch_to(struct audio_softc *asc,
+ stream_fetcher_t *self, audio_stream_t *dst, int max_used)
+{
+ auvolconv_filter_t *pf;
+ stream_filter_t *this;
+ int16_t j, *wp;
+ int m, err;
+
+ pf = (auvolconv_filter_t *)self;
+ this = &pf->base;
+ max_used = (max_used + 1) & ~1;
+
+ if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used)))
+ return err;
+ m = (dst->end - dst->start) & ~1;
+ m = min(m, max_used);
+ FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
+ j = be16dec(s);
+ wp = (int16_t *)d;
+ be16enc(wp, (j * *pf->vol) / 255);
+ } FILTER_LOOP_EPILOGUE(this->src, dst);
+
+ return 0;
+}
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/auvolconv.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/auvolconv.h Tue Nov 18 01:53:17 2014 +0000
@@ -0,0 +1,42 @@
+/* $NetBSD: auvolconv.h,v 1.1 2014/11/18 01:53:17 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_DEV_AUVOLCONV_H
+#define _SYS_DEV_AUVOLCONV_H
+
+int auvolconv_slinear16_le_fetch_to(struct audio_softc *,
+ stream_fetcher_t *, audio_stream_t *, int);
+int auvolconv_slinear16_be_fetch_to(struct audio_softc *,
+ stream_fetcher_t *, audio_stream_t *, int);
+
+typedef struct auvolconv_filter {
+ stream_filter_t base;
+ uint8_t *vol;
+} auvolconv_filter_t;
+
+#endif /* !_SYS_DEV_AUVOLCONV_H */
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/files.audio
--- a/sys/dev/files.audio Tue Nov 18 01:50:12 2014 +0000
+++ b/sys/dev/files.audio Tue Nov 18 01:53:17 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.audio,v 1.2 2014/10/10 17:21:20 uebayasi Exp $
+# $NetBSD: files.audio,v 1.3 2014/11/18 01:53:17 jmcneill Exp $
define audiobus { }
define midibus { }
@@ -9,6 +9,7 @@
define mulaw: auconv
define auconv
define aurateconv
+define auvolconv
# audio and midi devices, attaches to audio hardware driver
#
@@ -25,6 +26,7 @@
file dev/audio.c audio needs-flag
file dev/audiobell.c audiobell
file dev/aurateconv.c aurateconv needs-flag
+file dev/auvolconv.c auvolconv
file dev/midi.c midi needs-flag
file dev/midictl.c midisyn
file dev/midisyn.c midisyn
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/pad/files.pad
--- a/sys/dev/pad/files.pad Tue Nov 18 01:50:12 2014 +0000
+++ b/sys/dev/pad/files.pad Tue Nov 18 01:53:17 2014 +0000
@@ -1,5 +1,4 @@
-# $NetBSD: files.pad,v 1.4 2009/09/08 09:47:42 jmcneill Exp $
+# $NetBSD: files.pad,v 1.5 2014/11/18 01:53:17 jmcneill Exp $
-defpseudodev pad: audiobus, auconv, aurateconv, mulaw
+defpseudodev pad: audiobus, auconv, aurateconv, auvolconv, mulaw
file dev/pad/pad.c pad
-file dev/pad/padvol.c pad
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/pad/pad.c
--- a/sys/dev/pad/pad.c Tue Nov 18 01:50:12 2014 +0000
+++ b/sys/dev/pad/pad.c Tue Nov 18 01:53:17 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.21 2014/07/25 08:10:38 dholland Exp $ */
+/* $NetBSD: pad.c,v 1.22 2014/11/18 01:53:17 jmcneill Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.21 2014/07/25 08:10:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.22 2014/11/18 01:53:17 jmcneill Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -47,9 +47,9 @@
#include <dev/audio_if.h>
#include <dev/audiovar.h>
#include <dev/auconv.h>
+#include <dev/auvolconv.h>
#include <dev/pad/padvar.h>
-#include <dev/pad/padvol.h>
#define PADUNIT(x) minor(x)
@@ -91,6 +91,12 @@
static int pad_round_blocksize(void *, int, int, const audio_params_t *);
static void pad_get_locks(void *, kmutex_t **, kmutex_t **);
+static stream_filter_t *pad_swvol_filter_le(struct audio_softc *,
+ const audio_params_t *, const audio_params_t *);
+static stream_filter_t *pad_swvol_filter_be(struct audio_softc *,
+ const audio_params_t *, const audio_params_t *);
+static void pad_swvol_dtor(stream_filter_t *);
+
static const struct audio_hw_if pad_hw_if = {
.query_encoding = pad_query_encoding,
.set_params = pad_set_params,
@@ -420,11 +426,11 @@
switch (play->encoding) {
case AUDIO_ENCODING_SLINEAR_LE:
if (play->precision == 16 && play->validbits == 16)
- pfil->prepend(pfil, pad_vol_slinear16_le, play);
+ pfil->prepend(pfil, pad_swvol_filter_le, play);
break;
case AUDIO_ENCODING_SLINEAR_BE:
if (play->precision == 16 && play->validbits == 16)
- pfil->prepend(pfil, pad_vol_slinear16_be, play);
+ pfil->prepend(pfil, pad_swvol_filter_be, play);
break;
default:
break;
@@ -623,6 +629,49 @@
*thread = &sc->sc_lock;
}
+static stream_filter_t *
+pad_swvol_filter_le(struct audio_softc *asc,
+ const audio_params_t *from, const audio_params_t *to)
+{
+ auvolconv_filter_t *this;
+ device_t dev = audio_get_device(asc);
+ struct pad_softc *sc = device_private(dev);
+
+ this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP);
+ this->base.base.fetch_to = auvolconv_slinear16_le_fetch_to;
+ this->base.dtor = pad_swvol_dtor;
+ this->base.set_fetcher = stream_filter_set_fetcher;
+ this->base.set_inputbuffer = stream_filter_set_inputbuffer;
+ this->vol = &sc->sc_swvol;
+
+ return (stream_filter_t *)this;
+}
+
+static stream_filter_t *
+pad_swvol_filter_be(struct audio_softc *asc,
+ const audio_params_t *from, const audio_params_t *to)
+{
+ auvolconv_filter_t *this;
+ device_t dev = audio_get_device(asc);
+ struct pad_softc *sc = device_private(dev);
+
+ this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP);
+ this->base.base.fetch_to = auvolconv_slinear16_be_fetch_to;
+ this->base.dtor = pad_swvol_dtor;
+ this->base.set_fetcher = stream_filter_set_fetcher;
+ this->base.set_inputbuffer = stream_filter_set_inputbuffer;
+ this->vol = &sc->sc_swvol;
+
+ return (stream_filter_t *)this;
+}
+
+static void
+pad_swvol_dtor(stream_filter_t *this)
+{
+ if (this)
+ kmem_free(this, sizeof(auvolconv_filter_t));
+}
+
#ifdef _MODULE
MODULE(MODULE_CLASS_DRIVER, pad, NULL);
diff -r cb4c9d33bb23 -r c6921d33be23 sys/dev/pad/padvar.h
--- a/sys/dev/pad/padvar.h Tue Nov 18 01:50:12 2014 +0000
+++ b/sys/dev/pad/padvar.h Tue Nov 18 01:53:17 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: padvar.h,v 1.4 2011/11/23 23:07:33 jmcneill Exp $ */
+/* $NetBSD: padvar.h,v 1.5 2014/11/18 01:53:17 jmcneill Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -50,7 +50,7 @@
uint32_t sc_buflen;
uint32_t sc_rpos, sc_wpos;
- u_int sc_swvol;
Home |
Main Index |
Thread Index |
Old Index