1 /* MikMod sound library
2 (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 /*==============================================================================
25 Driver for output on SGI audio system (needs libaudio from the dmedia
28 ==============================================================================*/
32 Written by Stephan Kanthak <kanthak@i6.informatik.rwth-aachen.de>
34 Fragment configuration:
35 =======================
37 You can use the driver options fragsize and bufsize to override the
38 default size of the audio buffer. If you experience crackles & pops,
39 try experimenting with these values.
41 Please read the SGI section of libmikmod's README file first before
42 contacting the author because there are some things to know about the
43 specials of the SGI audio driver.
51 #include "mikmod_internals.h"
60 #include <dmedia/audio.h>
62 #define DEFAULT_SGI_BUFSIZE 40000
63 #define DEFAULT_SGI_FRAGSIZE (DEFAULT_SGI_BUFSIZE / 2)
65 static ALconfig sgi_config;
66 static ALport sgi_port;
67 static int sample_factor;
68 static int sgi_fragsize=DEFAULT_SGI_FRAGSIZE;
69 static int sgi_bufsize=DEFAULT_SGI_BUFSIZE;
70 static SBYTE *audiobuffer=NULL;
72 static void SGI_CommandLine(const CHAR *cmdline)
76 if ((ptr=MD_GetAtom("fragsize",cmdline,0)) != NULL) {
77 sgi_fragsize=atol(ptr);
79 } else sgi_fragsize=DEFAULT_SGI_FRAGSIZE;
81 if ((ptr=MD_GetAtom("bufsize",cmdline,0)) != NULL) {
82 sgi_bufsize=atol(ptr);
84 } else sgi_bufsize=DEFAULT_SGI_BUFSIZE;
87 static BOOL SGI_IsThere(void)
90 return(ALqueryparams(AL_DEFAULT_DEVICE,0,0))?1:0;
93 static int SGI_Init(void)
95 long chpars[] = { AL_OUTPUT_RATE, AL_RATE_22050 };
99 chpars[1] = AL_RATE_8000;
102 chpars[1] = AL_RATE_11025;
105 chpars[1] = AL_RATE_16000;
108 chpars[1] = AL_RATE_22050;
111 chpars[1] = AL_RATE_32000;
114 chpars[1] = AL_RATE_44100;
117 chpars[1] = AL_RATE_48000;
120 _mm_errno=MMERR_SGI_SPEED;
123 ALseterrorhandler(0);
124 ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
126 if (!(sgi_config=ALnewconfig())) {
127 _mm_errno=MMERR_OPENING_AUDIO;
131 if (md_mode&DMODE_16BITS) {
132 if (ALsetwidth(sgi_config,AL_SAMPLE_16)<0) {
133 _mm_errno=MMERR_SGI_16BIT;
138 if (ALsetwidth(sgi_config,AL_SAMPLE_8)<0) {
139 _mm_errno=MMERR_SGI_8BIT;
145 if (md_mode&DMODE_STEREO) {
146 if (ALsetchannels(sgi_config,AL_STEREO)<0) {
147 _mm_errno=MMERR_SGI_STEREO;
151 if (ALsetchannels(sgi_config,AL_MONO)<0) {
152 _mm_errno=MMERR_SGI_MONO;
157 if ((getenv("MM_SGI_FRAGSIZE"))&&(sgi_fragsize!=DEFAULT_SGI_FRAGSIZE))
158 sgi_fragsize=atol(getenv("MM_SGI_FRAGSIZE"));
159 if (!sgi_fragsize) sgi_fragsize=DEFAULT_SGI_FRAGSIZE;
160 if ((getenv("MM_SGI_BUFSIZE"))&&(sgi_bufsize!=DEFAULT_SGI_BUFSIZE))
161 sgi_bufsize=atol(getenv("MM_SGI_BUFSIZE"));
162 if (!sgi_bufsize) sgi_fragsize=DEFAULT_SGI_BUFSIZE;
164 ALsetqueuesize(sgi_config, sgi_bufsize);
165 if (!(sgi_port=ALopenport("libmikmod","w",sgi_config))) {
166 _mm_errno=MMERR_OPENING_AUDIO;
170 if(!(audiobuffer=(SBYTE*)MikMod_malloc(sgi_fragsize))) return 1;
175 static void SGI_Exit(void)
178 MikMod_free(audiobuffer);
182 static void SGI_Update(void)
184 ALwritesamps(sgi_port,audiobuffer,
185 VC_WriteBytes(audiobuffer,sgi_fragsize)>>sample_factor);
188 MIKMODAPI MDRIVER drv_sgi={
191 "SGI Audio System driver v0.5",
194 "fragsize:r:0,99999,20000:Sound buffer fragment size\n"
195 "bufsize:r:0,199999,40000:Sound buffer total size\n",
212 VC_VoiceSetFrequency,
213 VC_VoiceGetFrequency,