1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
TiMidity++ -- MIDI to WAVE converter and player
Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
bsd20_a.c
Written by Yamate Keiichiro <keiich-y@is.aist-nara.ac.jp>
*/
/*
* BSD/OS 2.0 audio
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <i386/isa/sblast.h>
#include "timidity.h"
#include "output.h"
#include "controls.h"
#include "timer.h"
#include "instrum.h"
#include "playmidi.h"
#include "miditrace.h"
static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
static void close_output(void);
static int output_data(char *buf, int32 nbytes);
static int acntl(int request, void *arg);
/* export the playback mode */
#define dpm bsdi_play_mode
PlayMode dpm = {
DEFAULT_RATE, PE_SIGNED|PE_MONO, PF_PCM_STREAM|PF_CAN_TRACE,
-1,
{0}, /* default: get all the buffer fragments you can */
"BSD/OS sblast dsp", 'd',
"/dev/sb_dsp",
open_output,
close_output,
output_data,
acntl
};
static int open_output(void)
{
int fd, tmp, warnings=0;
if ((fd=open(dpm.name, O_RDWR | O_NDELAY, 0)) < 0)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
dpm.name, strerror(errno));
return -1;
}
/* They can't mean these */
dpm.encoding &= ~(PE_ULAW|PE_ALAW|PE_BYTESWAP);
/* Set sample width to whichever the user wants. If it fails, try
the other one. */
if (dpm.encoding & PE_16BIT)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: sblast only 8bit",
dpm.name);
close(fd);
return -1;
}
tmp = ((~dpm.encoding) & PE_16BIT) ? PCM_8 : 0;
ioctl(fd, DSP_IOCTL_COMPRESS, &tmp);
dpm.encoding &= ~PE_SIGNED;
/* Try stereo or mono, whichever the user wants. If it fails, try
the other. */
tmp=(dpm.encoding & PE_MONO) ? 0 : 1;
ioctl(fd, DSP_IOCTL_STEREO, &tmp);
/* Set the sample rate */
tmp=dpm.rate * ((dpm.encoding & PE_MONO) ? 1 : 2);
ioctl(fd, DSP_IOCTL_SPEED, &tmp);
if (tmp != dpm.rate)
{
dpm.rate=tmp / ((dpm.encoding & PE_MONO) ? 1 : 2);;
ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
"Output rate adjusted to %d Hz", dpm.rate);
warnings=1;
}
/* Older VoxWare drivers don't have buffer fragment capabilities */
if (dpm.extra_param[0])
{
ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
"%s doesn't support buffer fragments", dpm.name);
warnings=1;
}
tmp = 16384;
ioctl(fd, DSP_IOCTL_BUFSIZE, &tmp);
dpm.fd = fd;
return warnings;
}
static int output_data(char *buf, int32 nbytes)
{
while ((-1==write(dpm.fd, buf, nbytes)) && errno==EINTR)
;
}
static void close_output(void)
{
if(dpm.fd != -1)
{
close(dpm.fd);
dpm.fd = -1;
}
}
static int acntl(int request, void *arg)
{
switch(request)
{
case PM_REQ_DISCARD:
return ioctl(dpm.fd, DSP_IOCTL_RESET);
}
return -1;
}
|