1 /* $NetBSD: padvol.c,v 1.3 2008/06/06 20:51:51 mlelstv Exp $ */
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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>
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
{
47 struct audio_softc
*audiosc
;
51 pad_filter_dtor(stream_filter_t
*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))
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
;
70 return (stream_filter_t
*)this;
73 PAD_DEFINE_FILTER(pad_vol_slinear16_le
)
77 stream_filter_t
*this;
81 pf
= (pad_filter_t
*)self
;
82 sc
= device_private(pf
->audiosc
->sc_dev
);
84 max_used
= (max_used
+ 1) & ~1;
86 if ((err
= this->prev
->fetch_to(this->prev
, this->src
, max_used
)))
88 m
= (dst
->end
- dst
->start
) & ~1;
90 FILTER_LOOP_PROLOGUE(this->src
, 2, dst
, 2, m
) {
91 j
= (s
[1] << 8 | s
[0]);
93 *wp
= ((j
* sc
->sc_swvol
) / 255);
94 } FILTER_LOOP_EPILOGUE(this->src
, dst
);
99 PAD_DEFINE_FILTER(pad_vol_slinear16_be
)
103 stream_filter_t
*this;
107 pf
= (pad_filter_t
*)self
;
108 sc
= device_private(pf
->audiosc
->sc_dev
);
110 max_used
= (max_used
+ 1) & ~1;
112 if ((err
= this->prev
->fetch_to(this->prev
, this->src
, max_used
)))
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]);
119 *wp
= ((j
* sc
->sc_swvol
) / 255);
120 } FILTER_LOOP_EPILOGUE(this->src
, dst
);