summaryrefslogtreecommitdiff
path: root/audio/mpg123/patches/patch-au
blob: e09d2aa28a84222775894514b935074532d55cec (plain)
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
$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;
 }