1 /***************************************************************************
2 * S3m/Mod player by Daniel Marks (dmarks@ais.net)
3 * GUS support by David Jeske (jeske@uiuc.edu)
4 *
5 * (C) 1994,1995 By Daniel Marks and David Jeske
6 *
7 * While we retain the copyright to this code, this source code is FREE.
8 * You may use it in any way you wish, in any product you wish. You may
9 * NOT steal the copyright for this code from us.
10 *
11 * We respectfully ask that you email one of us, if possible, if you
12 * produce something significant with this code, or if you have any bug
13 * fixes to contribute. We also request that you give credit where
14 * credit is due if you include part of this code in a program of your own.
15 *
16 * Email: s3mod@uiuc.edu
17 * jeske@uiuc.edu
18 *
19 * See the associated README file for Thanks
20 ***************************************************************************
21 *
22 * linux_dsp.c - Support for the Linux DSP driver from the Voxware(C) Drivers.
23 */
24
25 #ifdef LINUX
26 #include "config.h"
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <fcntl.h>
30 #include <sys/types.h>
31 #include <linux/soundcard.h>
32 #include <bytesex.h>
33 #include "main.h"
34 #include "dsp.h"
35
36 static int audio;
37
get_dsp_device(void)38 int get_dsp_device(void)
39 {
40 uint32 j;
41
42 audio=open("/dev/dsp",O_WRONLY,0);
43 if (audio < 1)
44 {
45 printf("Could not open audio device!\n");
46 exit(1);
47 }
48 if (stereo)
49 {
50 if (ioctl(audio,SNDCTL_DSP_STEREO,&stereo) == -1)
51 stereo = 0;
52 }
53 if (bit16)
54 {
55 j = 16;
56 if (ioctl(audio,SNDCTL_DSP_SAMPLESIZE,&j) == -1) bit16 = 0;
57 if (j != 16) bit16 = 0;
58 }
59 j = mixspeed;
60 if (ioctl(audio,SNDCTL_DSP_SPEED,&j) == -1)
61 {
62 printf("Error setting sample speed\n");
63 exit(1);
64 }
65 mixspeed = j;
66 if (ioctl(audio,SNDCTL_DSP_GETBLKSIZE, &audio_buffer_size) == -1)
67 {
68 printf("Unable to get audio blocksize\n");
69 exit(1);
70 }
71 if ((audio_buffer_size < 4096) || (audio_buffer_size > 131072))
72 {
73 printf("Invalid audio buffer size: %d\n",audio_buffer_size);
74 exit(1);
75 }
76 if (!(audio_start_buffer = (uint8 *) malloc(audio_buffer_size)))
77 {
78 printf("Could not get audio buffer memory!\n");
79 exit(1);
80 }
81 audio_end_buffer = &audio_start_buffer[audio_buffer_size];
82 audio_curptr = audio_start_buffer;
83 return;
84 }
85
write_dsp_device(void * buf,int size)86 void write_dsp_device(void *buf, int size) {
87 write(audio,audio_start_buffer,audio_buffer_size);
88 return;
89 }
90
close_dsp_device()91 void close_dsp_device() {
92 close(audio);
93 return;
94 }
95
96 #endif /* ?LINUX */
97
98