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