zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
openal-info.c
Go to the documentation of this file.
1 /*
2  * OpenAL Info Utility
3  *
4  * Copyright (c) 2010 by Chris Robinson <chris.kcat@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include "AL/alc.h"
29 #include "AL/al.h"
30 #include "AL/alext.h"
31 
32 #ifndef ALC_ENUMERATE_ALL_EXT
33 #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
34 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
35 #endif
36 
37 #ifndef ALC_EXT_EFX
38 #define ALC_EFX_MAJOR_VERSION 0x20001
39 #define ALC_EFX_MINOR_VERSION 0x20002
40 #define ALC_MAX_AUXILIARY_SENDS 0x20003
41 #endif
42 
43 
44 #define MAX_WIDTH 80
45 
46 static void printList(const char *list, char separator)
47 {
48  size_t col = MAX_WIDTH, len;
49  const char *indent = " ";
50  const char *next;
51 
52  if(!list || *list == '\0')
53  {
54  fprintf(stdout, "\n%s!!! none !!!\n", indent);
55  return;
56  }
57 
58  do {
59  next = strchr(list, separator);
60  if(next)
61  {
62  len = next-list;
63  do {
64  next++;
65  } while(*next == separator);
66  }
67  else
68  len = strlen(list);
69 
70  if(len + col + 2 >= MAX_WIDTH)
71  {
72  fprintf(stdout, "\n%s", indent);
73  col = strlen(indent);
74  }
75  else
76  {
77  fputc(' ', stdout);
78  col++;
79  }
80 
81  len = fwrite(list, 1, len, stdout);
82  col += len;
83 
84  if(!next || *next == '\0')
85  break;
86  fputc(',', stdout);
87  col++;
88 
89  list = next;
90  } while(1);
91  fputc('\n', stdout);
92 }
93 
94 static void printDeviceList(const char *list)
95 {
96  if(!list || *list == '\0')
97  printf(" !!! none !!!\n");
98  else do {
99  printf(" %s\n", list);
100  list += strlen(list) + 1;
101  } while(*list != '\0');
102 }
103 
104 
105 static ALenum checkALErrors(int linenum)
106 {
107  ALenum err = alGetError();
108  if(err != AL_NO_ERROR)
109  printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum);
110  return err;
111 }
112 #define checkALErrors() checkALErrors(__LINE__)
113 
114 static ALCenum checkALCErrors(ALCdevice *device, int linenum)
115 {
116  ALCenum err = alcGetError(device);
117  if(err != ALC_NO_ERROR)
118  printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
119  return err;
120 }
121 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
122 
123 
124 static void printALCInfo(ALCdevice *device)
125 {
126  ALCint major, minor;
127 
128  if(device)
129  {
130  const ALCchar *devname = NULL;
131  printf("\n");
132  if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
133  devname = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
134  if(checkALCErrors(device) != ALC_NO_ERROR || !devname)
135  devname = alcGetString(device, ALC_DEVICE_SPECIFIER);
136  printf("** Info for device \"%s\" **\n", devname);
137  }
138  alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
139  alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
140  if(checkALCErrors(device) == ALC_NO_ERROR)
141  printf("ALC version: %d.%d\n", major, minor);
142  if(device)
143  {
144  printf("ALC extensions:");
145  printList(alcGetString(device, ALC_EXTENSIONS), ' ');
146  checkALCErrors(device);
147  }
148 }
149 
150 static void printALInfo(void)
151 {
152  printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
153  printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
154  printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
155  printf("OpenAL extensions:");
157  checkALErrors();
158 }
159 
160 static void printEFXInfo(ALCdevice *device)
161 {
162  ALCint major, minor, sends;
163  static const ALchar filters[][32] = {
164  "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
165  };
166  char filterNames[] = "Low-pass,High-pass,Band-pass,";
167  static const ALchar effects[][32] = {
168  "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
169  "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
170  "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
171  "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
172  "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
173  };
174  static const ALchar dedeffects[][64] = {
175  "AL_EFFECT_DEDICATED_DIALOGUE",
176  "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
177  };
178  char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
179  "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
180  "Ring Modulator,Autowah,Compressor,Equalizer,"
181  "Dedicated Dialog,Dedicated LFE,";
182  char *current;
183  int i;
184 
185  if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
186  {
187  printf("EFX not available\n");
188  return;
189  }
190 
191  alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
192  alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
193  if(checkALCErrors(device) == ALC_NO_ERROR)
194  printf("EFX version: %d.%d\n", major, minor);
195  alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
196  if(checkALCErrors(device) == ALC_NO_ERROR)
197  printf("Max auxiliary sends: %d\n", sends);
198 
199  current = filterNames;
200  for(i = 0;filters[i][0];i++)
201  {
202  char *next = strchr(current, ',');
203  ALenum val;
204 
205  val = alGetEnumValue(filters[i]);
206  if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
207  memmove(current, next+1, strlen(next));
208  else
209  current = next+1;
210  }
211  printf("Supported filters:");
212  printList(filterNames, ',');
213 
214  current = effectNames;
215  for(i = 0;effects[i][0];i++)
216  {
217  char *next = strchr(current, ',');
218  ALenum val;
219 
220  val = alGetEnumValue(effects[i]);
221  if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
222  memmove(current, next+1, strlen(next));
223  else
224  current = next+1;
225  }
226  if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
227  {
228  for(i = 0;dedeffects[i][0];i++)
229  {
230  char *next = strchr(current, ',');
231  ALenum val;
232 
233  val = alGetEnumValue(dedeffects[i]);
234  if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
235  memmove(current, next+1, strlen(next));
236  else
237  current = next+1;
238  }
239  }
240  else
241  {
242  for(i = 0;dedeffects[i][0];i++)
243  {
244  char *next = strchr(current, ',');
245  memmove(current, next+1, strlen(next));
246  }
247  }
248  printf("Supported effects:");
249  printList(effectNames, ',');
250 }
251 
252 int main(int argc, char *argv[])
253 {
254  ALCdevice *device;
256 
257  if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
258  strcmp(argv[1], "-h") == 0))
259  {
260  printf("Usage: %s [playback device]\n", argv[0]);
261  return 0;
262  }
263 
264  printf("Available playback devices:\n");
265  if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
267  else
269  printf("Available capture devices:\n");
271 
272  if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
273  printf("Default playback device: %s\n",
275  else
276  printf("Default playback device: %s\n",
278  printf("Default capture device: %s\n",
280 
282 
283  device = alcOpenDevice((argc>1) ? argv[1] : NULL);
284  if(!device)
285  {
286  printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
287  return 1;
288  }
289  printALCInfo(device);
290 
291  context = alcCreateContext(device, NULL);
292  if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
293  {
294  if(context)
295  alcDestroyContext(context);
296  alcCloseDevice(device);
297  printf("\n!!! Failed to set a context !!!\n\n");
298  return 1;
299  }
300 
301  printALInfo();
302  printEFXInfo(device);
303 
304  alcMakeContextCurrent(NULL);
305  alcDestroyContext(context);
306  alcCloseDevice(device);
307 
308  return 0;
309 }
#define ALC_CAPTURE_DEVICE_SPECIFIER
Definition: alc.h:149
#define AL_VERSION
Definition: al.h:385
#define ALC_MINOR_VERSION
Definition: alc.h:122
GLuint const GLfloat * val
Definition: glew.h:2715
ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALsizei size, ALCint *data)
Definition: ALc.c:2188
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
char ALchar
Definition: al.h:41
#define NULL
Definition: ftobjs.h:61
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
Definition: ALc.c:2590
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *Device)
Definition: ALc.c:2884
ALC_API const ALCchar *ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum param)
Definition: ALc.c:2066
AL_API ALenum AL_APIENTRY alGetError(void)
Definition: alError.c:46
#define memmove
Definition: SDL_qsort.c:81
#define ALC_EFX_MINOR_VERSION
Definition: openal-info.c:39
ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
Definition: ALc.c:2539
#define AL_FALSE
Definition: al.h:83
GLenum GLsizei len
Definition: glew.h:7035
static void printALInfo(void)
Definition: openal-info.c:150
char ALCchar
Definition: alc.h:42
AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *ename)
Definition: alExtension.c:95
static void printList(const char *list, char separator)
Definition: openal-info.c:46
#define ALC_DEFAULT_DEVICE_SPECIFIER
Definition: alc.h:129
static void printDeviceList(const char *list)
Definition: openal-info.c:94
#define ALC_FALSE
Definition: alc.h:81
static void printEFXInfo(ALCdevice *device)
Definition: openal-info.c:160
#define AL_EXTENSIONS
Definition: al.h:389
static void printALCInfo(ALCdevice *device)
Definition: openal-info.c:124
#define ALC_MAJOR_VERSION
Definition: alc.h:121
int ALenum
Definition: al.h:65
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
Definition: ALc.c:2027
#define ALC_DEVICE_SPECIFIER
Definition: alc.h:136
ALC_API ALCcontext *ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
Definition: ALc.c:2463
#define checkALErrors()
Definition: openal-info.c:112
#define ALC_NO_ERROR
Definition: alc.h:102
#define ALC_EXTENSIONS
Definition: alc.h:138
#define ALC_EFX_MAJOR_VERSION
Definition: openal-info.c:38
AL_API const ALchar *AL_APIENTRY alGetString(ALenum param)
Definition: alState.c:437
#define checkALCErrors(x)
Definition: openal-info.c:121
int ALCint
Definition: alc.h:57
#define ALC_MAX_AUXILIARY_SENDS
Definition: openal-info.c:40
TParseContext * context
int i
Definition: pngrutil.c:1377
#define ALC_ALL_DEVICES_SPECIFIER
Definition: openal-info.c:34
int ALCenum
Definition: alc.h:66
#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
Definition: alc.h:151
#define AL_VENDOR
Definition: al.h:383
ALC_API ALCdevice *ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
Definition: ALc.c:2658
#define AL_NO_ERROR
Definition: al.h:364
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
Definition: ALc.c:2373
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER
Definition: openal-info.c:33
#define AL_RENDERER
Definition: al.h:387
#define MAX_WIDTH
Definition: openal-info.c:44