midi_pcppi.c revision 1.2 1 /* $NetBSD: midi_pcppi.c,v 1.2 1998/08/12 21:36:21 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Author: Lennart Augustsson
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/errno.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44 #include <sys/proc.h>
45 #include <sys/conf.h>
46 #include <sys/select.h>
47 #include <sys/audioio.h>
48 #include <sys/midiio.h>
49
50 #include <dev/isa/pcppivar.h>
51
52 #include <dev/audio_if.h>
53 #include <dev/midivar.h>
54 #include <dev/midisynvar.h>
55
56 #define MAX_DURATION 30 /* turn off sound automagically after 30 s */
57
58 struct midi_pcppi_softc {
59 struct midi_softc sc_mididev;
60 midisyn sc_midisyn;
61 };
62
63 int midi_pcppi_match __P((struct device *, struct cfdata *, void *));
64 void midi_pcppi_attach __P((struct device *, struct device *, void *));
65
66 void midi_pcppi_on __P((midisyn *, u_int32_t, u_int32_t, u_int32_t));
67 void midi_pcppi_off __P((midisyn *, u_int32_t, u_int32_t, u_int32_t));
68 void midi_pcppi_close __P((midisyn *));
69
70 struct cfattach midi_pcppi_ca = {
71 sizeof(struct midi_pcppi_softc), midi_pcppi_match, midi_pcppi_attach
72 };
73
74 struct midisyn_methods midi_pcppi_hw = {
75 0, /* open */
76 midi_pcppi_close,
77 0, /* ioctl */
78 0, /* allocv */
79 midi_pcppi_on,
80 midi_pcppi_off,
81 0,
82 0,
83 0,
84 0,
85 0,
86 0,
87 };
88
89 int midi_pcppi_attached = 0; /* Not very nice */
90
91 int
92 midi_pcppi_match(parent, match, aux)
93 struct device *parent;
94 struct cfdata *match;
95 void *aux;
96 {
97 return (!midi_pcppi_attached);
98 }
99
100 void
101 midi_pcppi_attach(parent, self, aux)
102 struct device *parent;
103 struct device *self;
104 void *aux;
105 {
106 struct midi_pcppi_softc *sc = (struct midi_pcppi_softc *)self;
107 struct pcppi_attach_args *pa = (struct pcppi_attach_args *)aux;
108 midisyn *ms;
109
110 ms = &sc->sc_midisyn;
111 ms->mets = &midi_pcppi_hw;
112 strcpy(ms->name, "PC speaker");
113 ms->nvoice = 1;
114 ms->flags = MS_DOALLOC | MS_FREQXLATE;
115 ms->data = pa->pa_cookie;
116
117 midi_pcppi_attached++;
118
119 midisyn_attach(&sc->sc_mididev, ms, parent);
120 }
121
122 void
123 midi_pcppi_on(ms, chan, note, vel)
124 midisyn *ms;
125 u_int32_t chan, note, vel;
126 {
127 pcppi_tag_t t = ms->data;
128
129 /*printf("ON %p %d\n", t, note >> 16);*/
130 pcppi_bell(t, MIDISYN_FREQ_TO_HZ(note), MAX_DURATION * hz, 0);
131 }
132
133 void
134 midi_pcppi_off(ms, chan, note, vel)
135 midisyn *ms;
136 u_int32_t chan, note, vel;
137 {
138 pcppi_tag_t t = ms->data;
139
140 /*printf("OFF %p %d\n", t, note >> 16);*/
141 pcppi_bell(t, 0, 0, 0);
142 }
143
144 void
145 midi_pcppi_close(ms)
146 midisyn *ms;
147 {
148 pcppi_tag_t t = ms->data;
149
150 /* Make sure we are quiet. */
151 pcppi_bell(t, 0, 0, 0);
152 }
153