Module Name:    src
Committed By:   jmcneill
Date:           Tue Nov 18 01:53:17 UTC 2014

Modified Files:
        src/sys/dev: files.audio
        src/sys/dev/pad: files.pad pad.c padvar.h
Added Files:
        src/sys/dev: auvolconv.c auvolconv.h
Removed Files:
        src/sys/dev/pad: padvol.c padvol.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/auvolconv.c src/sys/dev/auvolconv.h
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/files.audio
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/pad/files.pad src/sys/dev/pad/padvar.h
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/pad/pad.c
cvs rdiff -u -r1.6 -r0 src/sys/dev/pad/padvol.c
cvs rdiff -u -r1.3 -r0 src/sys/dev/pad/padvol.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/files.audio
diff -u src/sys/dev/files.audio:1.2 src/sys/dev/files.audio:1.3
--- src/sys/dev/files.audio:1.2	Fri Oct 10 17:21:20 2014
+++ src/sys/dev/files.audio	Tue Nov 18 01:53:17 2014
@@ -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	midisyn
 define	mulaw: auconv
 define	auconv
 define	aurateconv
+define	auvolconv
 
 # audio and midi devices, attaches to audio hardware driver
 #
@@ -25,6 +26,7 @@ file	dev/auconv.c			auconv
 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

Index: src/sys/dev/pad/files.pad
diff -u src/sys/dev/pad/files.pad:1.4 src/sys/dev/pad/files.pad:1.5
--- src/sys/dev/pad/files.pad:1.4	Tue Sep  8 09:47:42 2009
+++ src/sys/dev/pad/files.pad	Tue Nov 18 01:53:17 2014
@@ -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
Index: src/sys/dev/pad/padvar.h
diff -u src/sys/dev/pad/padvar.h:1.4 src/sys/dev/pad/padvar.h:1.5
--- src/sys/dev/pad/padvar.h:1.4	Wed Nov 23 23:07:33 2011
+++ src/sys/dev/pad/padvar.h	Tue Nov 18 01:53:17 2014
@@ -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 <jmcne...@invisible.ca>
@@ -50,7 +50,7 @@ typedef struct pad_softc {
 	uint32_t	sc_buflen;
 	uint32_t	sc_rpos, sc_wpos;
 
-	u_int		sc_swvol;
+	uint8_t		sc_swvol;
 } pad_softc_t;
 
 #endif /* !_SYS_DEV_PAD_PADVAR_H */

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.21 src/sys/dev/pad/pad.c:1.22
--- src/sys/dev/pad/pad.c:1.21	Fri Jul 25 08:10:38 2014
+++ src/sys/dev/pad/pad.c	Tue Nov 18 01:53:17 2014
@@ -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 <jmcne...@invisible.ca>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.21
 #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_get_props(void *);
 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 @@ pad_set_params(void *opaque, int setmode
 	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 @@ pad_get_locks(void *opaque, kmutex_t **i
 	*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);

Added files:

Index: src/sys/dev/auvolconv.c
diff -u /dev/null src/sys/dev/auvolconv.c:1.1
--- /dev/null	Tue Nov 18 01:53:17 2014
+++ src/sys/dev/auvolconv.c	Tue Nov 18 01:53:17 2014
@@ -0,0 +1,94 @@
+/* $NetBSD: auvolconv.c,v 1.1 2014/11/18 01:53:17 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
+ * 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;
+}
Index: src/sys/dev/auvolconv.h
diff -u /dev/null src/sys/dev/auvolconv.h:1.1
--- /dev/null	Tue Nov 18 01:53:17 2014
+++ src/sys/dev/auvolconv.h	Tue Nov 18 01:53:17 2014
@@ -0,0 +1,42 @@
+/* $NetBSD: auvolconv.h,v 1.1 2014/11/18 01:53:17 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
+ * 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 */

Reply via email to