5c4f14268e
(approved by recht and jschauma)
157 lines
4.1 KiB
Text
157 lines
4.1 KiB
Text
$NetBSD: patch-au,v 1.1 2005/03/28 19:52:21 schwarz Exp $
|
|
|
|
--- audio_sgi.c.orig 2005-03-07 13:54:23.000000000 +0100
|
|
+++ audio_sgi.c 2005-03-07 13:54:27.000000000 +0100
|
|
@@ -6,20 +6,48 @@
|
|
|
|
#include "mpg123.h"
|
|
|
|
+#ifdef AL_RESOURCE /* as a test whether we use the "new" IRIX
|
|
+ audio libraries */
|
|
+#define NEW_IRIX_AUDIO
|
|
+#define HAVE_ALGETERRORSTRING
|
|
+#else
|
|
+#define alClosePort(x) ALcloseport(x)
|
|
+#define alFreeConfig(x) ALfreeconfig(x)
|
|
+#define alGetFilled(x) ALgetfilled(x)
|
|
+#define alSetChannels(x,y) ALsetchannels(x,y)
|
|
+#define alSetQueueSize(x,y) ALsetqueuesize(x,y)
|
|
+#define alSetSampFmt(x,y) ALsetsampfmt(x,y)
|
|
+#define alSetWidth(x,y) ALsetwidth(x,y)
|
|
+#define alNewConfig() ALnewconfig()
|
|
+#define alOpenPort(x,y,z) ALopenport(x,y,z)
|
|
+#endif
|
|
|
|
/* Analog output constant */
|
|
static const char analog_output_res_name[] = ".AnalogOut";
|
|
|
|
+/* Routine to print a message to stderr; uses alGetErrorString(oserror)
|
|
+ if available */
|
|
+
|
|
+void errormessage(const char *message)
|
|
+{
|
|
+#ifdef HAVE_ALGETERRORSTRING
|
|
+ fprintf(stderr,"%s : %s\n",message,alGetErrorString(oserror()));
|
|
+#else
|
|
+ fprintf(stderr,"%s error\n",message);
|
|
+#endif
|
|
+}
|
|
|
|
int audio_open(struct audio_info_struct *ai)
|
|
{
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
int dev = AL_DEFAULT_OUTPUT;
|
|
+#endif
|
|
|
|
ai->config = alNewConfig();
|
|
|
|
/* Test for correct completion */
|
|
if (ai->config == 0) {
|
|
- fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_open");
|
|
exit(-1);
|
|
}
|
|
|
|
@@ -33,6 +61,8 @@
|
|
alSetSampFmt(ai->config,AL_SAMPFMT_TWOSCOMP);
|
|
alSetQueueSize(ai->config, 131069);
|
|
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
+
|
|
/* Setup output device to specified module. If there is no module
|
|
specified in ai structure, use the default four output */
|
|
if ((ai->device) != NULL) {
|
|
@@ -61,15 +91,16 @@
|
|
/* Set the device */
|
|
if (alSetDevice(ai->config,dev) < 0)
|
|
{
|
|
- fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_open");
|
|
exit(-1);
|
|
}
|
|
|
|
+#endif /* NEW_IRIX_AUDIO */
|
|
+
|
|
/* Open the audio port */
|
|
ai->port = alOpenPort("mpg123-VSC", "w", ai->config);
|
|
if(ai->port == NULL) {
|
|
- fprintf(stderr, "Unable to open audio channel: %s\n",
|
|
- alGetErrorString(oserror()));
|
|
+ errormessage("Unable to open audio channel");
|
|
exit(-1);
|
|
}
|
|
|
|
@@ -99,22 +130,30 @@
|
|
|
|
int audio_set_rate(struct audio_info_struct *ai)
|
|
{
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
int dev = alGetDevice(ai->config);
|
|
ALpv params[1];
|
|
+#else
|
|
+ int dev;
|
|
+ long params[2] = {AL_OUTPUT_RATE, AL_RATE_44100};
|
|
+ params[1] = ai->rate;
|
|
+ dev=ALsetparams(AL_DEFAULT_DEVICE, params, 2);
|
|
+#endif
|
|
|
|
/* Make sure the device is OK */
|
|
if (dev < 0)
|
|
{
|
|
- fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_set_rate");
|
|
return 1;
|
|
}
|
|
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
params[0].param = AL_OUTPUT_RATE;
|
|
params[0].value.ll = alDoubleToFixed(ai->rate);
|
|
|
|
if (alSetParams(dev, params,1) < 0)
|
|
- fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror()));
|
|
-
|
|
+ errormessage("audio_set_rate");
|
|
+#endif
|
|
return 0;
|
|
}
|
|
|
|
@@ -128,7 +167,7 @@
|
|
ret = alSetChannels(ai->config, AL_MONO);
|
|
|
|
if (ret < 0)
|
|
- fprintf(stderr,"audio_set_channels : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_set_channels");
|
|
|
|
return 0;
|
|
}
|
|
@@ -136,10 +175,10 @@
|
|
int audio_set_format(struct audio_info_struct *ai)
|
|
{
|
|
if (alSetSampFmt(ai->config,AL_SAMPFMT_TWOSCOMP) < 0)
|
|
- fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_set_format");
|
|
|
|
if (alSetWidth(ai->config,AL_SAMPLE_16) < 0)
|
|
- fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
|
|
+ errormessage("audio_set_format");
|
|
|
|
return 0;
|
|
}
|
|
@@ -153,9 +192,17 @@
|
|
int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
|
|
{
|
|
if(ai->format == AUDIO_FORMAT_SIGNED_8)
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
alWriteFrames(ai->port, buf, len>>1);
|
|
+#else
|
|
+ ALwritesamps(ai->port, buf, len);
|
|
+#endif
|
|
else
|
|
+#ifdef NEW_IRIX_AUDIO
|
|
alWriteFrames(ai->port, buf, len>>2);
|
|
+#else
|
|
+ ALwritesamps(ai->port, buf, len>>1);
|
|
+#endif
|
|
|
|
return len;
|
|
}
|