Home | History | Annotate | Line # | Download | only in dev
midisyn.c revision 1.17.2.10
      1  1.17.2.10      chap /*	$NetBSD: midisyn.c,v 1.17.2.10 2006/05/20 04:31:59 chap Exp $	*/
      2        1.1  augustss 
      3        1.1  augustss /*
      4        1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5        1.1  augustss  * All rights reserved.
      6        1.1  augustss  *
      7        1.5  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8       1.13    keihan  * by Lennart Augustsson (augustss (at) NetBSD.org).
      9        1.1  augustss  *
     10        1.1  augustss  * Redistribution and use in source and binary forms, with or without
     11        1.1  augustss  * modification, are permitted provided that the following conditions
     12        1.1  augustss  * are met:
     13        1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     14        1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     15        1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  augustss  *    documentation and/or other materials provided with the distribution.
     18        1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     19        1.1  augustss  *    must display the following acknowledgement:
     20        1.1  augustss  *        This product includes software developed by the NetBSD
     21        1.1  augustss  *        Foundation, Inc. and its contributors.
     22        1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1  augustss  *    contributors may be used to endorse or promote products derived
     24        1.1  augustss  *    from this software without specific prior written permission.
     25        1.1  augustss  *
     26        1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     37        1.1  augustss  */
     38        1.9     lukem 
     39        1.9     lukem #include <sys/cdefs.h>
     40  1.17.2.10      chap __KERNEL_RCSID(0, "$NetBSD: midisyn.c,v 1.17.2.10 2006/05/20 04:31:59 chap Exp $");
     41        1.1  augustss 
     42        1.1  augustss #include <sys/param.h>
     43        1.1  augustss #include <sys/ioctl.h>
     44        1.1  augustss #include <sys/fcntl.h>
     45        1.1  augustss #include <sys/vnode.h>
     46        1.1  augustss #include <sys/select.h>
     47        1.1  augustss #include <sys/proc.h>
     48        1.1  augustss #include <sys/malloc.h>
     49        1.1  augustss #include <sys/systm.h>
     50        1.1  augustss #include <sys/syslog.h>
     51        1.1  augustss #include <sys/kernel.h>
     52        1.1  augustss #include <sys/audioio.h>
     53        1.1  augustss #include <sys/midiio.h>
     54        1.1  augustss #include <sys/device.h>
     55        1.1  augustss 
     56        1.1  augustss #include <dev/audio_if.h>
     57        1.3  augustss #include <dev/midi_if.h>
     58        1.1  augustss #include <dev/midivar.h>
     59        1.1  augustss #include <dev/midisynvar.h>
     60        1.1  augustss 
     61        1.1  augustss #ifdef AUDIO_DEBUG
     62        1.1  augustss #define DPRINTF(x)	if (midisyndebug) printf x
     63        1.1  augustss #define DPRINTFN(n,x)	if (midisyndebug >= (n)) printf x
     64        1.1  augustss int	midisyndebug = 0;
     65        1.1  augustss #else
     66        1.1  augustss #define DPRINTF(x)
     67        1.1  augustss #define DPRINTFN(n,x)
     68        1.1  augustss #endif
     69        1.1  augustss 
     70        1.8  augustss int	midisyn_findvoice(midisyn *, int, int);
     71        1.8  augustss void	midisyn_freevoice(midisyn *, int);
     72        1.8  augustss int	midisyn_allocvoice(midisyn *, u_int32_t, u_int32_t);
     73        1.8  augustss u_int32_t midisyn_note_to_freq(int);
     74        1.8  augustss u_int32_t midisyn_finetune(u_int32_t, int, int, int);
     75        1.8  augustss 
     76  1.17.2.10      chap int	midisyn_open(void *, int,
     77        1.8  augustss 		     void (*iintr)(void *, int),
     78        1.8  augustss 		     void (*ointr)(void *), void *arg);
     79        1.8  augustss void	midisyn_close(void *);
     80   1.17.2.2      chap int	midisyn_sysrt(void *, int);
     81        1.8  augustss void	midisyn_getinfo(void *, struct midi_info *);
     82  1.17.2.10      chap int	midisyn_ioctl(void *, u_long, caddr_t, int, struct lwp *);
     83        1.1  augustss 
     84  1.17.2.10      chap const struct midi_hw_if midisyn_hw_if = {
     85        1.1  augustss 	midisyn_open,
     86        1.1  augustss 	midisyn_close,
     87   1.17.2.2      chap 	midisyn_sysrt,
     88        1.1  augustss 	midisyn_getinfo,
     89        1.1  augustss 	midisyn_ioctl,
     90        1.1  augustss };
     91        1.1  augustss 
     92   1.17.2.2      chap int	midisyn_channelmsg(void *, int, int, u_char *, int);
     93   1.17.2.2      chap int	midisyn_commonmsg(void *, int, u_char *, int);
     94   1.17.2.2      chap int	midisyn_sysex(void *, u_char *, int);
     95   1.17.2.2      chap 
     96   1.17.2.2      chap struct midi_hw_if_ext midisyn_hw_if_ext = {
     97   1.17.2.2      chap 	.channel = midisyn_channelmsg,
     98   1.17.2.2      chap 	.common  = midisyn_commonmsg,
     99   1.17.2.2      chap 	.sysex   = midisyn_sysex,
    100   1.17.2.2      chap };
    101        1.1  augustss 
    102        1.1  augustss int
    103        1.8  augustss midisyn_open(void *addr, int flags, void (*iintr)(void *, int),
    104        1.8  augustss 	     void (*ointr)(void *), void *arg)
    105        1.1  augustss {
    106        1.1  augustss 	midisyn *ms = addr;
    107        1.1  augustss 
    108        1.1  augustss 	DPRINTF(("midisyn_open: ms=%p ms->mets=%p\n", ms, ms->mets));
    109        1.1  augustss 	if (ms->mets->open)
    110        1.1  augustss 		return (ms->mets->open(ms, flags));
    111        1.1  augustss 	else
    112        1.1  augustss 		return (0);
    113        1.1  augustss }
    114        1.1  augustss 
    115        1.1  augustss void
    116        1.8  augustss midisyn_close(void *addr)
    117        1.1  augustss {
    118        1.1  augustss 	midisyn *ms = addr;
    119        1.4   mycroft 	struct midisyn_methods *fs;
    120        1.4   mycroft 	int v;
    121        1.1  augustss 
    122        1.1  augustss 	DPRINTF(("midisyn_close: ms=%p ms->mets=%p\n", ms, ms->mets));
    123        1.4   mycroft 	fs = ms->mets;
    124        1.4   mycroft 	for (v = 0; v < ms->nvoice; v++)
    125        1.4   mycroft 		if (ms->voices[v].inuse) {
    126        1.4   mycroft 			fs->noteoff(ms, v, 0, 0);
    127        1.4   mycroft 			midisyn_freevoice(ms, v);
    128        1.4   mycroft 		}
    129        1.4   mycroft 	if (fs->close)
    130        1.4   mycroft 		fs->close(ms);
    131        1.1  augustss }
    132        1.1  augustss 
    133        1.1  augustss void
    134        1.8  augustss midisyn_getinfo(void *addr, struct midi_info *mi)
    135        1.1  augustss {
    136        1.1  augustss 	midisyn *ms = addr;
    137        1.1  augustss 
    138        1.1  augustss 	mi->name = ms->name;
    139        1.1  augustss 	mi->props = 0;
    140   1.17.2.2      chap 
    141   1.17.2.2      chap 	midi_register_hw_if_ext(&midisyn_hw_if_ext);
    142        1.1  augustss }
    143        1.1  augustss 
    144        1.1  augustss int
    145  1.17.2.10      chap midisyn_ioctl(void *maddr, u_long cmd, caddr_t addr, int flag, struct lwp *l)
    146        1.1  augustss {
    147        1.1  augustss 	midisyn *ms = maddr;
    148        1.1  augustss 
    149        1.1  augustss 	if (ms->mets->ioctl)
    150  1.17.2.10      chap 		return (ms->mets->ioctl(ms, cmd, addr, flag, l));
    151        1.1  augustss 	else
    152        1.1  augustss 		return (EINVAL);
    153        1.1  augustss }
    154        1.1  augustss 
    155        1.1  augustss int
    156        1.8  augustss midisyn_findvoice(midisyn *ms, int chan, int note)
    157        1.1  augustss {
    158        1.1  augustss 	u_int cn;
    159        1.1  augustss 	int v;
    160        1.1  augustss 
    161        1.1  augustss 	if (!(ms->flags & MS_DOALLOC))
    162        1.1  augustss 		return (chan);
    163        1.3  augustss 	cn = MS_CHANNOTE(chan, note);
    164        1.1  augustss 	for (v = 0; v < ms->nvoice; v++)
    165        1.3  augustss 		if (ms->voices[v].chan_note == cn && ms->voices[v].inuse)
    166        1.1  augustss 			return (v);
    167        1.1  augustss 	return (-1);
    168        1.1  augustss }
    169        1.1  augustss 
    170        1.1  augustss void
    171        1.8  augustss midisyn_attach(struct midi_softc *sc, midisyn *ms)
    172        1.1  augustss {
    173        1.1  augustss 	if (ms->flags & MS_DOALLOC) {
    174  1.17.2.10      chap 		ms->voices = malloc(ms->nvoice * sizeof (struct voice),
    175       1.10   tsutsui 				    M_DEVBUF, M_WAITOK|M_ZERO);
    176        1.1  augustss 		ms->seqno = 1;
    177        1.1  augustss 		if (ms->mets->allocv == 0)
    178        1.1  augustss 			ms->mets->allocv = &midisyn_allocvoice;
    179        1.1  augustss 	}
    180        1.1  augustss 	sc->hw_if = &midisyn_hw_if;
    181        1.1  augustss 	sc->hw_hdl = ms;
    182        1.1  augustss 	DPRINTF(("midisyn_attach: ms=%p\n", sc->hw_hdl));
    183        1.1  augustss }
    184        1.1  augustss 
    185        1.1  augustss void
    186        1.8  augustss midisyn_freevoice(midisyn *ms, int voice)
    187        1.1  augustss {
    188        1.1  augustss 	if (!(ms->flags & MS_DOALLOC))
    189        1.1  augustss 		return;
    190        1.3  augustss 	ms->voices[voice].inuse = 0;
    191        1.1  augustss }
    192        1.1  augustss 
    193        1.1  augustss int
    194        1.8  augustss midisyn_allocvoice(midisyn *ms, u_int32_t chan, u_int32_t note)
    195        1.1  augustss {
    196        1.1  augustss 	int bestv, v;
    197        1.1  augustss 	u_int bestseq, s;
    198        1.1  augustss 
    199        1.1  augustss 	if (!(ms->flags & MS_DOALLOC))
    200        1.1  augustss 		return (chan);
    201        1.1  augustss 	/* Find a free voice, or if no free voice is found the oldest. */
    202        1.1  augustss 	bestv = 0;
    203        1.3  augustss 	bestseq = ms->voices[0].seqno + (ms->voices[0].inuse ? 0x40000000 : 0);
    204        1.1  augustss 	for (v = 1; v < ms->nvoice; v++) {
    205        1.1  augustss 		s = ms->voices[v].seqno;
    206        1.3  augustss 		if (ms->voices[v].inuse)
    207        1.3  augustss 			s += 0x40000000;
    208        1.1  augustss 		if (s < bestseq) {
    209        1.1  augustss 			bestseq = s;
    210        1.1  augustss 			bestv = v;
    211        1.1  augustss 		}
    212        1.1  augustss 	}
    213        1.3  augustss 	DPRINTFN(10,("midisyn_allocvoice: v=%d seq=%d cn=%x inuse=%d\n",
    214  1.17.2.10      chap 		     bestv, ms->voices[bestv].seqno,
    215        1.3  augustss 		     ms->voices[bestv].chan_note,
    216        1.3  augustss 		     ms->voices[bestv].inuse));
    217        1.3  augustss #ifdef AUDIO_DEBUG
    218        1.3  augustss 	if (ms->voices[bestv].inuse)
    219  1.17.2.10      chap 		DPRINTFN(1,("midisyn_allocvoice: steal %x\n",
    220        1.3  augustss 			    ms->voices[bestv].chan_note));
    221        1.3  augustss #endif
    222        1.3  augustss 	ms->voices[bestv].chan_note = MS_CHANNOTE(chan, note);
    223        1.1  augustss 	ms->voices[bestv].seqno = ms->seqno++;
    224        1.3  augustss 	ms->voices[bestv].inuse = 1;
    225        1.1  augustss 	return (bestv);
    226        1.1  augustss }
    227        1.1  augustss 
    228        1.1  augustss int
    229   1.17.2.2      chap midisyn_sysrt(void *addr, int b)
    230   1.17.2.2      chap {
    231   1.17.2.2      chap 	return 0;
    232   1.17.2.2      chap }
    233   1.17.2.2      chap 
    234   1.17.2.2      chap int midisyn_channelmsg(void *addr, int status, int chan, u_char *buf, int len)
    235        1.1  augustss {
    236        1.1  augustss 	midisyn *ms = addr;
    237        1.1  augustss 	int voice = 0;		/* initialize to keep gcc quiet */
    238        1.1  augustss 	struct midisyn_methods *fs;
    239        1.1  augustss 	u_int32_t note, vel;
    240        1.1  augustss 
    241   1.17.2.2      chap 	DPRINTF(("midisyn_channelmsg: ms=%p status=%#02x chan=%d\n",
    242   1.17.2.2      chap 	       ms, status, chan));
    243        1.1  augustss 	fs = ms->mets;
    244   1.17.2.2      chap 	note = buf[1];
    245        1.1  augustss 	if (ms->flags & MS_FREQXLATE)
    246        1.1  augustss 		note = midisyn_note_to_freq(note);
    247   1.17.2.2      chap 	vel = buf[2];
    248   1.17.2.2      chap 
    249   1.17.2.2      chap 	switch (status) {
    250        1.1  augustss 	case MIDI_NOTEOFF:
    251   1.17.2.2      chap 		voice = midisyn_findvoice(ms, chan, buf[1]);
    252        1.1  augustss 		if (voice >= 0) {
    253        1.1  augustss 			fs->noteoff(ms, voice, note, vel);
    254        1.1  augustss 			midisyn_freevoice(ms, voice);
    255        1.1  augustss 		}
    256        1.1  augustss 		break;
    257        1.1  augustss 	case MIDI_NOTEON:
    258   1.17.2.2      chap 		voice = fs->allocv(ms, chan, buf[1]);
    259        1.1  augustss 		fs->noteon(ms, voice, note, vel);
    260        1.1  augustss 		break;
    261        1.1  augustss 	case MIDI_KEY_PRESSURE:
    262        1.1  augustss 		if (fs->keypres) {
    263   1.17.2.2      chap 			voice = midisyn_findvoice(ms, voice, buf[1]);
    264        1.1  augustss 			if (voice >= 0)
    265        1.1  augustss 				fs->keypres(ms, voice, note, vel);
    266        1.1  augustss 		}
    267        1.1  augustss 		break;
    268        1.1  augustss 	case MIDI_CTL_CHANGE:
    269        1.1  augustss 		if (fs->ctlchg)
    270   1.17.2.2      chap 			fs->ctlchg(ms, chan, buf[1], vel);
    271        1.1  augustss 		break;
    272        1.1  augustss 	case MIDI_PGM_CHANGE:
    273        1.1  augustss 		if (fs->pgmchg)
    274   1.17.2.2      chap 			fs->pgmchg(ms, chan, buf[1]);
    275        1.1  augustss 		break;
    276        1.1  augustss 	case MIDI_CHN_PRESSURE:
    277        1.1  augustss 		if (fs->chnpres) {
    278   1.17.2.2      chap 			voice = midisyn_findvoice(ms, chan, buf[1]);
    279   1.17.2.2      chap 			if (voice >= 0) /* XXX should do all voices on chan */
    280        1.1  augustss 				fs->chnpres(ms, voice, note);
    281        1.1  augustss 		}
    282        1.1  augustss 		break;
    283        1.1  augustss 	case MIDI_PITCH_BEND:
    284        1.1  augustss 		if (fs->pitchb) {
    285   1.17.2.2      chap 			voice = midisyn_findvoice(ms, chan, buf[1]);
    286   1.17.2.2      chap 			if (voice >= 0) /* XXX buf1-2 are a 14-bit bend value */
    287        1.1  augustss 				fs->pitchb(ms, chan, note, vel);
    288        1.1  augustss 		}
    289        1.1  augustss 		break;
    290        1.1  augustss 	}
    291   1.17.2.2      chap 	return 0;
    292   1.17.2.2      chap }
    293   1.17.2.2      chap 
    294   1.17.2.2      chap int midisyn_commonmsg(void *addr, int status, u_char *buf, int len)
    295   1.17.2.2      chap {
    296   1.17.2.2      chap 	return 0;
    297   1.17.2.2      chap }
    298   1.17.2.2      chap 
    299   1.17.2.2      chap int midisyn_sysex(void *addr, u_char *buf, int len)
    300   1.17.2.2      chap {
    301   1.17.2.2      chap 	midisyn *ms = addr;
    302   1.17.2.2      chap 	if (ms->mets->sysex) {
    303   1.17.2.2      chap 		while ( len --> 0 )
    304   1.17.2.2      chap 			ms->mets->sysex(ms, *buf++);
    305   1.17.2.2      chap 	}
    306   1.17.2.2      chap 	return 0;
    307        1.1  augustss }
    308        1.1  augustss 
    309        1.1  augustss /*
    310        1.1  augustss  * Convert a MIDI note to the corresponding frequency.
    311        1.1  augustss  * The frequency is scaled by 2^16.
    312        1.1  augustss  */
    313        1.1  augustss u_int32_t
    314        1.8  augustss midisyn_note_to_freq(int note)
    315        1.1  augustss {
    316        1.1  augustss 	int o, n, f;
    317        1.1  augustss #define BASE_OCTAVE 5
    318        1.7  jdolecek 	static const u_int32_t notes[] = {
    319        1.1  augustss 		17145893, 18165441, 19245614, 20390018, 21602472, 22887021,
    320        1.1  augustss 		24247954, 25689813, 27217409, 28835840, 30550508, 32367136
    321        1.1  augustss 	};
    322        1.1  augustss 
    323        1.1  augustss 
    324        1.1  augustss 	o = note / 12;
    325        1.1  augustss 	n = note % 12;
    326        1.1  augustss 
    327        1.1  augustss 	f = notes[n];
    328        1.1  augustss 
    329        1.1  augustss 	if (o < BASE_OCTAVE)
    330        1.1  augustss 		f >>= (BASE_OCTAVE - o);
    331        1.1  augustss 	else if (o > BASE_OCTAVE)
    332        1.1  augustss 		f <<= (o - BASE_OCTAVE);
    333        1.1  augustss 	return (f);
    334        1.3  augustss }
    335        1.3  augustss 
    336        1.3  augustss u_int32_t
    337        1.8  augustss midisyn_finetune(u_int32_t base_freq, int bend, int range, int vibrato_cents)
    338        1.3  augustss {
    339  1.17.2.10      chap 	static const u_int16_t semitone_tuning[24] =
    340        1.3  augustss 	{
    341  1.17.2.10      chap /*   0 */ 10000, 10595, 11225, 11892, 12599, 13348, 14142, 14983,
    342  1.17.2.10      chap /*   8 */ 15874, 16818, 17818, 18877, 20000, 21189, 22449, 23784,
    343        1.3  augustss /*  16 */ 25198, 26697, 28284, 29966, 31748, 33636, 35636, 37755
    344        1.3  augustss 	};
    345        1.7  jdolecek 	static const u_int16_t cent_tuning[100] =
    346        1.3  augustss 	{
    347  1.17.2.10      chap /*   0 */ 10000, 10006, 10012, 10017, 10023, 10029, 10035, 10041,
    348  1.17.2.10      chap /*   8 */ 10046, 10052, 10058, 10064, 10070, 10075, 10081, 10087,
    349  1.17.2.10      chap /*  16 */ 10093, 10099, 10105, 10110, 10116, 10122, 10128, 10134,
    350  1.17.2.10      chap /*  24 */ 10140, 10145, 10151, 10157, 10163, 10169, 10175, 10181,
    351  1.17.2.10      chap /*  32 */ 10187, 10192, 10198, 10204, 10210, 10216, 10222, 10228,
    352  1.17.2.10      chap /*  40 */ 10234, 10240, 10246, 10251, 10257, 10263, 10269, 10275,
    353  1.17.2.10      chap /*  48 */ 10281, 10287, 10293, 10299, 10305, 10311, 10317, 10323,
    354  1.17.2.10      chap /*  56 */ 10329, 10335, 10341, 10347, 10353, 10359, 10365, 10371,
    355  1.17.2.10      chap /*  64 */ 10377, 10383, 10389, 10395, 10401, 10407, 10413, 10419,
    356  1.17.2.10      chap /*  72 */ 10425, 10431, 10437, 10443, 10449, 10455, 10461, 10467,
    357  1.17.2.10      chap /*  80 */ 10473, 10479, 10485, 10491, 10497, 10503, 10509, 10515,
    358  1.17.2.10      chap /*  88 */ 10521, 10528, 10534, 10540, 10546, 10552, 10558, 10564,
    359        1.3  augustss /*  96 */ 10570, 10576, 10582, 10589
    360        1.3  augustss 	};
    361        1.3  augustss 	u_int32_t amount;
    362        1.3  augustss 	int negative, semitones, cents, multiplier;
    363        1.3  augustss 
    364        1.3  augustss 	if (range == 0)
    365        1.3  augustss 		return base_freq;
    366        1.3  augustss 
    367        1.3  augustss 	if (base_freq == 0)
    368        1.3  augustss 		return base_freq;
    369        1.3  augustss 
    370        1.3  augustss 	if (range >= 8192)
    371        1.3  augustss 		range = 8192;
    372        1.3  augustss 
    373        1.3  augustss 	bend = bend * range / 8192;
    374        1.3  augustss 	bend += vibrato_cents;
    375        1.3  augustss 
    376        1.3  augustss 	if (bend == 0)
    377        1.3  augustss 		return base_freq;
    378        1.3  augustss 
    379        1.3  augustss 	if (bend < 0) {
    380        1.3  augustss 		bend = -bend;
    381        1.3  augustss 		negative = 1;
    382  1.17.2.10      chap 	} else
    383        1.3  augustss 		negative = 0;
    384        1.3  augustss 
    385        1.3  augustss 	if (bend > range)
    386        1.3  augustss 		bend = range;
    387        1.3  augustss 
    388        1.3  augustss 	multiplier = 1;
    389        1.3  augustss 	while (bend > 2399) {
    390        1.3  augustss 		multiplier *= 4;
    391        1.3  augustss 		bend -= 2400;
    392        1.3  augustss 	}
    393        1.3  augustss 
    394        1.3  augustss 	semitones = bend / 100;
    395        1.3  augustss 	cents = bend % 100;
    396        1.3  augustss 
    397        1.3  augustss 	amount = semitone_tuning[semitones] * multiplier * cent_tuning[cents]
    398        1.3  augustss 		/ 10000;
    399        1.3  augustss 
    400        1.3  augustss 	if (negative)
    401        1.3  augustss 		return (base_freq * 10000 / amount);	/* Bend down */
    402        1.3  augustss 	else
    403        1.3  augustss 		return (base_freq * amount / 10000);	/* Bend up */
    404        1.1  augustss }
    405        1.1  augustss 
    406