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
|
#ifndef AMIGA
#include "config.h"
#endif
#ifdef VOXWARE
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include "pokeysnd.h"
static char *rcsid = "$Id: sound.c,v 1.5 1998/02/21 15:20:42 david Exp $";
/* 0002 = 2 Fragments */
/* 0007 = means each fragment is 2^2 or 128 bytes */
/* See voxware docs in /usr/src/linux/drivers/sound for more info */
#define FRAG_SPEC 0x0002000a
#define FALSE 0
#define TRUE 1
static char dsp_buffer[44100];
static int sndbufsize;
static int gain = 8;
static sound_enabled = TRUE;
static int dsp_fd;
static int dsp_sample_rate;
static int dsp_sample_rate_divisor = 35;
static int AUDCTL = 0x00;
static int AUDF[4] =
{0, 0, 0, 0};
static int AUDC[4] =
{0, 0, 0, 0};
void Voxware_Initialise(int *argc, char *argv[])
{
int i, j;
for (i = j = 1; i < *argc; i++) {
if (strcmp(argv[i], "-sound") == 0)
sound_enabled = TRUE;
else if (strcmp(argv[i], "-nosound") == 0)
sound_enabled = FALSE;
else if (strcmp(argv[i], "-dsp_divisor") == 0)
sscanf(argv[++i], "%d", &dsp_sample_rate_divisor);
else
argv[j++] = argv[i];
}
*argc = j;
if (sound_enabled) {
int channel;
int dspbits;
unsigned int formats;
int tmp;
dsp_fd = open("/dev/dsp", O_WRONLY, 0777);
if (dsp_fd == -1) {
perror("/dev/dsp");
exit(1);
}
/*
* Get sound formats
*/
ioctl(dsp_fd, SNDCTL_DSP_GETFMTS, &formats);
/*
* Set sound of sound fragment to special?
*/
tmp = FRAG_SPEC;
ioctl(dsp_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
/*
* Get preferred buffer size
*/
ioctl(dsp_fd, SNDCTL_DSP_GETBLKSIZE, &sndbufsize);
/*
* Set to 8bit sound
*/
dspbits = 8;
ioctl(dsp_fd, SNDCTL_DSP_SAMPLESIZE, &dspbits);
ioctl(dsp_fd, SOUND_PCM_READ_BITS, &dspbits);
/*
* Set sample rate
*/
ioctl(dsp_fd, SNDCTL_DSP_SPEED, &dsp_sample_rate);
ioctl(dsp_fd, SOUND_PCM_READ_RATE, &dsp_sample_rate);
Pokey_sound_init(FREQ_17_EXACT, dsp_sample_rate, 1);
}
}
void Voxware_Exit(void)
{
if (sound_enabled)
close(dsp_fd);
}
void Voxware_UpdateSound(void)
{
if (sound_enabled) {
sndbufsize = dsp_sample_rate / dsp_sample_rate_divisor;
Pokey_process(dsp_buffer, sndbufsize);
/*
* Send sound buffer to DSP device
*/
write(dsp_fd, dsp_buffer, sndbufsize);
}
}
void Atari_AUDC(int channel, int byte)
{
channel--;
Update_pokey_sound(/* 0xd201 */ 1 + channel + channel, byte, 0, gain);
}
void Atari_AUDF(int channel, int byte)
{
channel--;
Update_pokey_sound(/* 0xd200 */ 0 + channel + channel, byte, 0, gain);
}
void Atari_AUDCTL(int byte)
{
Update_pokey_sound(/* 0xd208 */ 8, byte, 0, gain);
}
#else
void Atari_AUDC(int channel, int byte)
{
}
void Atari_AUDF(int channel, int byte)
{
}
void Atari_AUDCTL(int byte)
{
}
#endif
|