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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*================================================================
* seq.c
* sequencer control routine for awe sound driver
*
* Copyright (C) 1996-1999 Takashi Iwai
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*================================================================*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <math.h>
#include <fcntl.h>
#ifdef __FreeBSD__
# include <machine/soundcard.h>
#elif defined(linux)
# include <linux/soundcard.h>
#endif
#include <awe_voice.h>
#include <util.h>
#include "seq.h"
SEQ_DEFINEBUF(128);
int seqfd;
void seqbuf_dump()
{
if (_seqbufptr)
if (write(seqfd, _seqbuf, _seqbufptr) == -1) {
perror("write device");
exit(-1);
}
_seqbufptr = 0;
}
#define MAX_CARDS 16
int awe_dev;
/*int max_synth_voices;*/
static void seq_init_priv(char *devname, int devidx);
void seq_init(char *devname, int devidx)
{
if (devname == NULL)
seq_init_priv(OSS_SEQUENCER_DEV, devidx);
else
seq_init_priv(devname, devidx);
}
static void seq_init_priv(char *devname, int devidx)
{
int i;
int nrsynths;
struct synth_info card_info;
if ((seqfd = open(devname, O_WRONLY, 0)) < 0) {
perror(devname);
exit(1);
}
if (ioctl(seqfd, SNDCTL_SEQ_NRSYNTHS, &nrsynths) == -1) {
fprintf(stderr, "there is no soundcard\n");
exit(1);
}
if (devidx >= 0) {
card_info.device = devidx;
if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &card_info) < 0 ||
card_info.synth_type != SYNTH_TYPE_SAMPLE ||
card_info.synth_subtype != SAMPLE_TYPE_AWE32) {
fprintf(stderr, "invalid soundcard (device = %s, index = %d)\n", devname, devidx);
exit(1);
}
awe_dev = devidx;
} else {
/* auto probe */
awe_dev = -1;
for (i = 0; i < nrsynths; i++) {
card_info.device = i;
if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &card_info) == -1) {
fprintf(stderr, "cannot get info on soundcard\n");
perror(devname);
exit(1);
}
if (card_info.synth_type == SYNTH_TYPE_SAMPLE
&& card_info.synth_subtype == SAMPLE_TYPE_AWE32) {
awe_dev = i;
/*max_synth_voices = card_info.nr_voices;*/
break;
}
}
if (awe_dev < 0) {
fprintf(stderr, "No AWE synth device is found\n");
exit(1);
}
}
}
int seq_reset_samples(void)
{
if (ioctl(seqfd, SNDCTL_SEQ_RESETSAMPLES, &awe_dev) == -1) {
perror("Sample reset");
exit(1);
}
return 0;
}
void seq_end(void)
{
SEQ_DUMPBUF();
/*ioctl(seqfd, SNDCTL_SEQ_SYNC);*/
close(seqfd);
}
int seq_remove_samples(void)
{
AWE_REMOVE_LAST_SAMPLES(seqfd, awe_dev);
return 0;
}
void seq_default_atten(int val)
{
AWE_MISC_MODE(awe_dev, AWE_MD_ZERO_ATTEN, val);
SEQ_DUMPBUF();
}
void seq_set_gus_bank(int bank)
{
AWE_SET_GUS_BANK(awe_dev, bank);
SEQ_DUMPBUF();
}
int seq_load_rawpatch(void *patch, int len)
{
return write(seqfd, patch, len);
}
int seq_load_patch(void *patch, int len)
{
awe_patch_info *p;
SEQ_DUMPBUF();
p = (awe_patch_info*)patch;
p->key = AWE_PATCH;
p->device_no = awe_dev;
p->sf_id = 0;
return write(seqfd, patch, len);
}
int seq_mem_avail(void)
{
int mem_avail = awe_dev;
ioctl(seqfd, SNDCTL_SYNTH_MEMAVL, &mem_avail);
return mem_avail;
}
int seq_zero_atten(int atten)
{
/* set zero attenuation level; this doesn't use seqbuf */
/* flag 0x40 is the ossseq global flag */
_AWE_CMD_NOW(seqfd, awe_dev, 0, _AWE_MISC_MODE|0x40,
AWE_MD_ZERO_ATTEN, atten);
return 0;
}
|