Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pad / padvol.c
blob7407012fbb57fc6e9610f1eba66c558378fbe15a
1 /* $NetBSD: padvol.c,v 1.3 2008/06/06 20:51:51 mlelstv Exp $ */
3 /*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: padvol.c,v 1.3 2008/06/06 20:51:51 mlelstv Exp $");
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/select.h>
35 #include <sys/condvar.h>
36 #include <sys/kmem.h>
37 #include <sys/device.h>
39 #include <dev/audiovar.h>
40 #include <dev/auconv.h>
42 #include <dev/pad/padvar.h>
43 #include <dev/pad/padvol.h>
45 typedef struct pad_filter {
46 stream_filter_t base;
47 struct audio_softc *audiosc;
48 } pad_filter_t;
50 static void
51 pad_filter_dtor(stream_filter_t *this)
53 if (this)
54 kmem_free(this, sizeof(pad_filter_t));
57 static stream_filter_t *
58 pad_filter_factory(struct audio_softc *sc,
59 int (*fetch_to)(stream_fetcher_t *, audio_stream_t *, int))
61 pad_filter_t *this;
63 this = kmem_alloc(sizeof(pad_filter_t), KM_SLEEP);
64 this->base.base.fetch_to = fetch_to;
65 this->base.dtor = pad_filter_dtor;
66 this->base.set_fetcher = stream_filter_set_fetcher;
67 this->base.set_inputbuffer = stream_filter_set_inputbuffer;
68 this->audiosc = sc;
70 return (stream_filter_t *)this;
73 PAD_DEFINE_FILTER(pad_vol_slinear16_le)
75 pad_filter_t *pf;
76 pad_softc_t *sc;
77 stream_filter_t *this;
78 int16_t j, *wp;
79 int m, err;
81 pf = (pad_filter_t *)self;
82 sc = device_private(pf->audiosc->sc_dev);
83 this = &pf->base;
84 max_used = (max_used + 1) & ~1;
86 if ((err = this->prev->fetch_to(this->prev, this->src, max_used)))
87 return err;
88 m = (dst->end - dst->start) & ~1;
89 m = min(m, max_used);
90 FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
91 j = (s[1] << 8 | s[0]);
92 wp = (int16_t *)d;
93 *wp = ((j * sc->sc_swvol) / 255);
94 } FILTER_LOOP_EPILOGUE(this->src, dst);
96 return 0;
99 PAD_DEFINE_FILTER(pad_vol_slinear16_be)
101 pad_filter_t *pf;
102 pad_softc_t *sc;
103 stream_filter_t *this;
104 int16_t j, *wp;
105 int m, err;
107 pf = (pad_filter_t *)self;
108 sc = device_private(pf->audiosc->sc_dev);
109 this = &pf->base;
110 max_used = (max_used + 1) & ~1;
112 if ((err = this->prev->fetch_to(this->prev, this->src, max_used)))
113 return err;
114 m = (dst->end - dst->start) & ~1;
115 m = min(m, max_used);
116 FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
117 j = (s[0] << 8 | s[1]);
118 wp = (int16_t *)d;
119 *wp = ((j * sc->sc_swvol) / 255);
120 } FILTER_LOOP_EPILOGUE(this->src, dst);
122 return 0;