Module Name:    src
Committed By:   martin
Date:           Sun Nov 23 13:07:05 UTC 2014

Modified Files:
        src/sys/arch/arm/allwinner [netbsd-7]: awin_hdmiaudio.c files.awin
        src/sys/conf [netbsd-7]: files
        src/sys/dev [netbsd-7]: audio.c audio_if.h
        src/sys/dev/pad [netbsd-7]: files.pad pad.c padvar.h
        src/sys/modules/pad [netbsd-7]: Makefile
Added Files:
        src/sys/dev [netbsd-7]: auvolconv.c auvolconv.h
Removed Files:
        src/sys/dev/pad [netbsd-7]: padvol.c padvol.h

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #249):
        sys/modules/pad/Makefile: revision 1.2
        sys/arch/arm/allwinner/awin_hdmiaudio.c: revision 1.5
        sys/dev/pad/pad.c: revision 1.22
        sys/dev/pad/padvol.c: file removal
        sys/dev/pad/files.pad: revision 1.5
        sys/dev/auvolconv.c: revision 1.1
        sys/dev/pad/padvol.h: file removal
        sys/dev/audio.c: revision 1.266
        sys/dev/files.audio: revision 1.3 (via patch: sys/conf/files)
        sys/dev/auvolconv.h: revision 1.1
        sys/dev/pad/padvar.h: revision 1.5
        sys/dev/audio_if.h: revision 1.70
        sys/arch/arm/allwinner/files.awin: revision 1.26
Add common audio converters for software volume control. Only supports
slinear16_le and slinear16_be for now.
Convert pad(4) and awin_hdmiaudio to use the new converters.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.3 -r1.3.2.4 src/sys/arch/arm/allwinner/awin_hdmiaudio.c
cvs rdiff -u -r1.8.10.3 -r1.8.10.4 src/sys/arch/arm/allwinner/files.awin
cvs rdiff -u -r1.1096.2.3 -r1.1096.2.4 src/sys/conf/files
cvs rdiff -u -r1.263 -r1.263.2.1 src/sys/dev/audio.c
cvs rdiff -u -r1.67 -r1.67.24.1 src/sys/dev/audio_if.h
cvs rdiff -u -r0 -r1.2.2.2 src/sys/dev/auvolconv.c
cvs rdiff -u -r0 -r1.1.2.2 src/sys/dev/auvolconv.h
cvs rdiff -u -r1.4 -r1.4.38.1 src/sys/dev/pad/files.pad
cvs rdiff -u -r1.21 -r1.21.2.1 src/sys/dev/pad/pad.c
cvs rdiff -u -r1.4 -r1.4.24.1 src/sys/dev/pad/padvar.h
cvs rdiff -u -r1.6 -r0 src/sys/dev/pad/padvol.c
cvs rdiff -u -r1.3 -r0 src/sys/dev/pad/padvol.h
cvs rdiff -u -r1.1 -r1.1.40.1 src/sys/modules/pad/Makefile

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

Modified files:

Index: src/sys/arch/arm/allwinner/awin_hdmiaudio.c
diff -u src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.3.2.3 src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.3.2.4
--- src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.3.2.3	Tue Nov 18 18:19:09 2014
+++ src/sys/arch/arm/allwinner/awin_hdmiaudio.c	Sun Nov 23 13:07:04 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_hdmiaudio.c,v 1.3.2.3 2014/11/18 18:19:09 snj Exp $ */
+/* $NetBSD: awin_hdmiaudio.c,v 1.3.2.4 2014/11/23 13:07:04 martin Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_hdmiaudio.c,v 1.3.2.3 2014/11/18 18:19:09 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_hdmiaudio.c,v 1.3.2.4 2014/11/23 13:07:04 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: awin_hdmiaud
 #include <sys/audioio.h>
 #include <dev/audio_if.h>
 #include <dev/auconv.h>
+#include <dev/auvolconv.h>
 
 #include <arm/allwinner/awin_reg.h>
 #include <arm/allwinner/awin_var.h>
@@ -73,7 +74,6 @@ struct awin_hdmiaudio_softc {
 	struct audio_format	sc_format;
 	struct audio_encoding_set *sc_encodings;
 
-	audio_params_t		sc_pparam;
 	struct awin_dma_channel *sc_pdma;
 	void			(*sc_pint)(void *);
 	void			*sc_pintarg;
@@ -81,6 +81,8 @@ struct awin_hdmiaudio_softc {
 	bus_addr_t		sc_pend;
 	bus_addr_t		sc_pcur;
 	int			sc_pblksize;
+
+	uint8_t			sc_swvol;
 };
 
 static int	awin_hdmiaudio_match(device_t, cfdata_t, void *);
@@ -129,6 +131,10 @@ static int	awin_hdmiaudio_trigger_input(
 					     const audio_params_t *);
 static void	awin_hdmiaudio_get_locks(void *, kmutex_t **, kmutex_t **);
 
+static stream_filter_t *awin_hdmiaudio_swvol_filter(struct audio_softc *,
+    const audio_params_t *, const audio_params_t *);
+static void	awin_hdmiaudio_swvol_dtor(stream_filter_t *);
+
 static const struct audio_hw_if awin_hdmiaudio_hw_if = {
 	.open = awin_hdmiaudio_open,
 	.close = awin_hdmiaudio_close,
@@ -235,6 +241,8 @@ awin_hdmiaudio_attach(device_t parent, d
 		return;
 	}
 
+	sc->sc_swvol = 255;
+
 	awin_hdmiaudio_rescan(self, NULL, NULL);
 }
 
@@ -385,9 +393,9 @@ awin_hdmiaudio_set_params(void *priv, in
 		    AUMODE_PLAY, play, true, pfil);
 		if (index < 0)
 			return EINVAL;
-		sc->sc_pparam = pfil->req_size > 0 ?
-		    pfil->filters[0].param :
-		    *play;
+		if (pfil->req_size > 0)
+			play = &pfil->filters[0].param;
+		pfil->prepend(pfil, awin_hdmiaudio_swvol_filter, play);
 	}
 
 	return 0;
@@ -415,9 +423,12 @@ awin_hdmiaudio_halt_input(void *priv)
 static int
 awin_hdmiaudio_set_port(void *priv, mixer_ctrl_t *mc)
 {
+	struct awin_hdmiaudio_softc *sc = priv;
+
 	switch (mc->dev) {
 	case HDMIAUDIO_OUTPUT_MASTER_VOLUME:
 	case HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME:
+		sc->sc_swvol = mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
 		return 0;
 	}
 
@@ -427,11 +438,14 @@ awin_hdmiaudio_set_port(void *priv, mixe
 static int
 awin_hdmiaudio_get_port(void *priv, mixer_ctrl_t *mc)
 {
+	struct awin_hdmiaudio_softc *sc = priv;
+	uint8_t vol = sc->sc_swvol;
+
 	switch (mc->dev) {
 	case HDMIAUDIO_OUTPUT_MASTER_VOLUME:
 	case HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME:
-		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 255;
-		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 255;
+		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = vol;
+		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = vol;
 		return 0;
 	}
 
@@ -679,3 +693,28 @@ awin_hdmiaudio_get_locks(void *priv, kmu
 	*intr = &sc->sc_intr_lock;
 	*thread = &sc->sc_lock;
 }
+
+static stream_filter_t *
+awin_hdmiaudio_swvol_filter(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 awin_hdmiaudio_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 = awin_hdmiaudio_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
+awin_hdmiaudio_swvol_dtor(stream_filter_t *this)
+{
+	if (this)
+		kmem_free(this, sizeof(auvolconv_filter_t));
+}

Index: src/sys/arch/arm/allwinner/files.awin
diff -u src/sys/arch/arm/allwinner/files.awin:1.8.10.3 src/sys/arch/arm/allwinner/files.awin:1.8.10.4
--- src/sys/arch/arm/allwinner/files.awin:1.8.10.3	Fri Nov 14 13:37:39 2014
+++ src/sys/arch/arm/allwinner/files.awin	Sun Nov 23 13:07:04 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.awin,v 1.8.10.3 2014/11/14 13:37:39 martin Exp $
+#	$NetBSD: files.awin,v 1.8.10.4 2014/11/23 13:07:04 martin Exp $
 #
 # Configuration info for Allwinner ARM Peripherals
 #
@@ -144,7 +144,7 @@ attach	awinhdmi at awinio with awin_hdmi
 file	arch/arm/allwinner/awin_hdmi.c		awin_hdmi
 
 # A20/A31 HDMI audio (HDMIAUDIO)
-device	awinhdmiaudio: audiobus, auconv, mulaw, aurateconv
+device	awinhdmiaudio: audiobus, auconv, mulaw, aurateconv, auvolconv
 attach	awinhdmiaudio at awinio with awin_hdmiaudio
 file	arch/arm/allwinner/awin_hdmiaudio.c	awin_hdmiaudio
 

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1096.2.3 src/sys/conf/files:1.1096.2.4
--- src/sys/conf/files:1.1096.2.3	Wed Nov 12 19:54:46 2014
+++ src/sys/conf/files	Sun Nov 23 13:07:05 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1096.2.3 2014/11/12 19:54:46 martin Exp $
+#	$NetBSD: files,v 1.1096.2.4 2014/11/23 13:07:05 martin Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20100430
@@ -317,6 +317,7 @@ define	firmload
 define	mulaw
 define	auconv
 define	aurateconv
+define	auvolconv
 
 # audio and midi devices, attaches to audio hardware driver
 #
@@ -1491,6 +1492,7 @@ file	dev/auconv.c			auconv | mulaw
 file	dev/audio.c			audio | midi | midibus	needs-flag
 file	dev/audiobell.c			audiobell
 file	dev/aurateconv.c		aurateconv		needs-flag
+file	dev/auvolconv.c			auvolconv
 file	dev/bio.c			bio			needs-flag
 file	dev/ccd.c			ccd
 file	dev/cgd.c			cgd

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.263 src/sys/dev/audio.c:1.263.2.1
--- src/sys/dev/audio.c:1.263	Fri Jul 25 08:10:35 2014
+++ src/sys/dev/audio.c	Sun Nov 23 13:07:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.263 2014/07/25 08:10:35 dholland Exp $	*/
+/*	$NetBSD: audio.c,v 1.263.2.1 2014/11/23 13:07:05 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -155,7 +155,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.263 2014/07/25 08:10:35 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.263.2.1 2014/11/23 13:07:05 martin Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -4246,6 +4246,14 @@ audioprint(void *aux, const char *pnp)
 #endif /* NAUDIO > 0 || (NMIDI > 0 || NMIDIBUS > 0) */
 
 #if NAUDIO > 0
+device_t
+audio_get_device(struct audio_softc *sc)
+{
+	return sc->sc_dev;
+}
+#endif
+
+#if NAUDIO > 0
 static void
 audio_mixer_capture(struct audio_softc *sc)
 {

Index: src/sys/dev/audio_if.h
diff -u src/sys/dev/audio_if.h:1.67 src/sys/dev/audio_if.h:1.67.24.1
--- src/sys/dev/audio_if.h:1.67	Wed Nov 23 23:07:31 2011
+++ src/sys/dev/audio_if.h	Sun Nov 23 13:07:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio_if.h,v 1.67 2011/11/23 23:07:31 jmcneill Exp $	*/
+/*	$NetBSD: audio_if.h,v 1.67.24.1 2014/11/23 13:07:05 martin Exp $	*/
 
 /*
  * Copyright (c) 1994 Havard Eidnes.
@@ -258,6 +258,9 @@ struct audio_attach_args {
 device_t audio_attach_mi(const struct audio_hw_if *, void *, device_t);
 int	audioprint(void *, const char *);
 
+/* Get the hw device from an audio softc */
+device_t audio_get_device(struct audio_softc *);
+
 /* Device identity flags */
 #define SOUND_DEVICE		0
 #define AUDIO_DEVICE		0x80

Index: src/sys/dev/pad/files.pad
diff -u src/sys/dev/pad/files.pad:1.4 src/sys/dev/pad/files.pad:1.4.38.1
--- src/sys/dev/pad/files.pad:1.4	Tue Sep  8 09:47:42 2009
+++ src/sys/dev/pad/files.pad	Sun Nov 23 13:07:05 2014
@@ -1,5 +1,4 @@
-# $NetBSD: files.pad,v 1.4 2009/09/08 09:47:42 jmcneill Exp $
+# $NetBSD: files.pad,v 1.4.38.1 2014/11/23 13:07:05 martin 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/pad.c
diff -u src/sys/dev/pad/pad.c:1.21 src/sys/dev/pad/pad.c:1.21.2.1
--- src/sys/dev/pad/pad.c:1.21	Fri Jul 25 08:10:38 2014
+++ src/sys/dev/pad/pad.c	Sun Nov 23 13:07:04 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.21 2014/07/25 08:10:38 dholland Exp $ */
+/* $NetBSD: pad.c,v 1.21.2.1 2014/11/23 13:07:04 martin 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.21.2.1 2014/11/23 13:07:04 martin 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);

Index: src/sys/dev/pad/padvar.h
diff -u src/sys/dev/pad/padvar.h:1.4 src/sys/dev/pad/padvar.h:1.4.24.1
--- src/sys/dev/pad/padvar.h:1.4	Wed Nov 23 23:07:33 2011
+++ src/sys/dev/pad/padvar.h	Sun Nov 23 13:07:05 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: padvar.h,v 1.4 2011/11/23 23:07:33 jmcneill Exp $ */
+/* $NetBSD: padvar.h,v 1.4.24.1 2014/11/23 13:07:05 martin 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/modules/pad/Makefile
diff -u src/sys/modules/pad/Makefile:1.1 src/sys/modules/pad/Makefile:1.1.40.1
--- src/sys/modules/pad/Makefile:1.1	Fri Apr  9 13:41:45 2010
+++ src/sys/modules/pad/Makefile	Sun Nov 23 13:07:04 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2010/04/09 13:41:45 ahoka Exp $
+# $NetBSD: Makefile,v 1.1.40.1 2014/11/23 13:07:04 martin Exp $
 
 .include "../Makefile.inc"
 
@@ -7,6 +7,5 @@
 KMOD=   pad
 
 SRCS=	pad.c
-SRCS+=	padvol.c
 
 .include <bsd.kmodule.mk>

Added files:

Index: src/sys/dev/auvolconv.c
diff -u /dev/null src/sys/dev/auvolconv.c:1.2.2.2
--- /dev/null	Sun Nov 23 13:07:05 2014
+++ src/sys/dev/auvolconv.c	Sun Nov 23 13:07:05 2014
@@ -0,0 +1,94 @@
+/* $NetBSD: auvolconv.c,v 1.2.2.2 2014/11/23 13:07:05 martin 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.2.2.2 2014/11/23 13:07:05 martin 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.2.2
--- /dev/null	Sun Nov 23 13:07:05 2014
+++ src/sys/dev/auvolconv.h	Sun Nov 23 13:07:05 2014
@@ -0,0 +1,42 @@
+/* $NetBSD: auvolconv.h,v 1.1.2.2 2014/11/23 13:07:05 martin 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