midi_pcppi.c revision 1.1 1 /* $NetBSD: midi_pcppi.c,v 1.1 1998/08/12 18:16:36 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
69 struct cfattach midi_pcppi_ca = {
70 sizeof(struct midi_pcppi_softc), midi_pcppi_match, midi_pcppi_attach
71 };
72
73 struct midisyn_methods midi_pcppi_hw = {
74 0, /* open */
75 0, /* close */
76 0, /* ioctl */
77 0, /* allocv */
78 midi_pcppi_on,
79 midi_pcppi_off,
80 0,
81 0,
82 0,
83 0,
84 0,
85 0,
86 };
87
88 int midi_pcppi_attached = 0; /* Not very nice */
89
90 int
91 midi_pcppi_match(parent, match, aux)
92 struct device *parent;
93 struct cfdata *match;
94 void *aux;
95 {
96 return (!midi_pcppi_attached);
97 }
98
99 void
100 midi_pcppi_attach(parent, self, aux)
101 struct device *parent;
102 struct device *self;
103 void *aux;
104 {
105 struct midi_pcppi_softc *sc = (struct midi_pcppi_softc *)self;
106 struct pcppi_attach_args *pa = (struct pcppi_attach_args *)aux;
107 midisyn *ms;
108
109 ms = &sc->sc_midisyn;
110 ms->mets = &midi_pcppi_hw;
111 strcpy(ms->name, "PC speaker");
112 ms->nvoice = 1;
113 ms->flags = MS_DOALLOC | MS_FREQXLATE;
114 ms->data = pa->pa_cookie;
115
116 midi_pcppi_attached++;
117
118 midisyn_attach(&sc->sc_mididev, ms, parent);
119 }
120
121 void
122 midi_pcppi_on(ms, chan, note, vel)
123 midisyn *ms;
124 u_int32_t chan, note, vel;
125 {
126 pcppi_tag_t t = ms->data;
127
128 /*printf("ON %p %d\n", t, note >> 16);*/
129 pcppi_bell(t, MIDISYN_FREQ_TO_HZ(note), MAX_DURATION * hz, 0);
130 }
131
132 void
133 midi_pcppi_off(ms, chan, note, vel)
134 midisyn *ms;
135 u_int32_t chan, note, vel;
136 {
137 pcppi_tag_t t = ms->data;
138
139 /*printf("OFF %p %d\n", t, note >> 16);*/
140 pcppi_bell(t, 0, 0, 0);
141 }
142