Add a WAVEFORM_FRACONE macro and minor cleanups for the ring modulator
[openal-soft/android.git] / utils / openal-info.c
blobeab068aca09ef45711998ce6957aeff8e6e58afe
1 /*
2 * OpenAL Info Utility
4 * Copyright (c) 2010 by Chris Robinson <chris.kcat@gmail.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
25 #include <stdio.h>
26 #include <string.h>
28 #include "AL/alc.h"
29 #include "AL/al.h"
30 #include "AL/alext.h"
32 #ifndef ALC_ENUMERATE_ALL_EXT
33 #define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
34 #define ALC_ALL_DEVICES_SPECIFIER 0x1013
35 #endif
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
44 #define MAX_WIDTH 80
46 static void printList(const char *list, char separator)
48 size_t col = MAX_WIDTH, len;
49 const char *indent = " ";
50 const char *next;
52 if(!list || *list == '\0')
54 fprintf(stdout, "\n%s!!! none !!!\n", indent);
55 return;
58 do {
59 next = strchr(list, separator);
60 if(next)
62 len = next-list;
63 do {
64 next++;
65 } while(*next == separator);
67 else
68 len = strlen(list);
70 if(len + col + 2 >= MAX_WIDTH)
72 fprintf(stdout, "\n%s", indent);
73 col = strlen(indent);
75 else
77 fputc(' ', stdout);
78 col++;
81 len = fwrite(list, 1, len, stdout);
82 col += len;
84 if(!next || *next == '\0')
85 break;
86 fputc(',', stdout);
87 col++;
89 list = next;
90 } while(1);
91 fputc('\n', stdout);
94 static void printDeviceList(const char *list)
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');
105 static ALenum checkALErrors(int linenum)
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;
112 #define checkALErrors() checkALErrors(__LINE__)
114 static ALCenum checkALCErrors(ALCdevice *device, int linenum)
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;
121 #define checkALCErrors(x) checkALCErrors((x),__LINE__)
124 static void printALCInfo(ALCdevice *device)
126 ALCint major, minor;
128 alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
129 alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
130 if(checkALCErrors(device) == ALC_NO_ERROR)
131 printf("ALC version: %d.%d\n", major, minor);
132 if(device)
134 printf("ALC extensions:");
135 printList(alcGetString(device, ALC_EXTENSIONS), ' ');
136 checkALCErrors(device);
140 static void printALInfo(void)
142 printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
143 printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
144 printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
145 printf("OpenAL extensions:");
146 printList(alGetString(AL_EXTENSIONS), ' ');
147 checkALErrors();
150 static void printEFXInfo(ALCdevice *device)
152 ALCint major, minor, sends;
153 static const ALchar filters[][32] = {
154 "AL_FILTER_LOWPASS", "AL_FILTER_HIGHPASS", "AL_FILTER_BANDPASS", ""
156 char filterNames[] = "Low-pass,High-pass,Band-pass,";
157 static const ALchar effects[][32] = {
158 "AL_EFFECT_EAXREVERB", "AL_EFFECT_REVERB", "AL_EFFECT_CHORUS",
159 "AL_EFFECT_DISTORTION", "AL_EFFECT_ECHO", "AL_EFFECT_FLANGER",
160 "AL_EFFECT_FREQUENCY_SHIFTER", "AL_EFFECT_VOCAL_MORPHER",
161 "AL_EFFECT_PITCH_SHIFTER", "AL_EFFECT_RING_MODULATOR",
162 "AL_EFFECT_AUTOWAH", "AL_EFFECT_COMPRESSOR", "AL_EFFECT_EQUALIZER", ""
164 static const ALchar dedeffects[][64] = {
165 "AL_EFFECT_DEDICATED_DIALOGUE",
166 "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", ""
168 char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger,"
169 "Frequency Shifter,Vocal Morpher,Pitch Shifter,"
170 "Ring Modulator,Autowah,Compressor,Equalizer,"
171 "Dedicated Dialog,Dedicated LFE,";
172 char *current;
173 int i;
175 if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE)
177 printf("EFX not available\n");
178 return;
181 alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
182 alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
183 if(checkALCErrors(device) == ALC_NO_ERROR)
184 printf("EFX version: %d.%d\n", major, minor);
185 alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
186 if(checkALCErrors(device) == ALC_NO_ERROR)
187 printf("Max auxiliary sends: %d\n", sends);
189 current = filterNames;
190 for(i = 0;filters[i][0];i++)
192 char *next = strchr(current, ',');
193 ALenum val;
195 val = alGetEnumValue(filters[i]);
196 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
197 memmove(current, next+1, strlen(next));
198 else
199 current = next+1;
201 printf("Supported filters:");
202 printList(filterNames, ',');
204 current = effectNames;
205 for(i = 0;effects[i][0];i++)
207 char *next = strchr(current, ',');
208 ALenum val;
210 val = alGetEnumValue(effects[i]);
211 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
212 memmove(current, next+1, strlen(next));
213 else
214 current = next+1;
216 if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED"))
218 for(i = 0;dedeffects[i][0];i++)
220 char *next = strchr(current, ',');
221 ALenum val;
223 val = alGetEnumValue(dedeffects[i]);
224 if(alGetError() != AL_NO_ERROR || val == 0 || val == -1)
225 memmove(current, next+1, strlen(next));
226 else
227 current = next+1;
230 else
232 for(i = 0;dedeffects[i][0];i++)
234 char *next = strchr(current, ',');
235 memmove(current, next+1, strlen(next));
238 printf("Supported effects:");
239 printList(effectNames, ',');
242 int main(int argc, char *argv[])
244 ALCdevice *device;
245 ALCcontext *context;
247 if(argc > 1 && (strcmp(argv[1], "--help") == 0 ||
248 strcmp(argv[1], "-h") == 0))
250 printf("Usage: %s [playback device]\n", argv[0]);
251 return 0;
254 printf("Available playback devices:\n");
255 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
256 printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER));
257 else
258 printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
259 printf("Available capture devices:\n");
260 printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER));
262 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
263 printf("Default playback device: %s\n",
264 alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
265 else
266 printf("Default playback device: %s\n",
267 alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
268 printf("Default capture device: %s\n",
269 alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
271 printALCInfo(NULL);
273 device = alcOpenDevice((argc>1) ? argv[1] : NULL);
274 if(!device)
276 printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device"));
277 return 1;
280 printf("\n** Info for device \"%s\" **\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
281 printALCInfo(device);
283 context = alcCreateContext(device, NULL);
284 if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
286 if(context)
287 alcDestroyContext(context);
288 alcCloseDevice(device);
289 printf("\n!!! Failed to set a context !!!\n\n");
290 return 1;
293 printALInfo();
294 printEFXInfo(device);
296 alcMakeContextCurrent(NULL);
297 alcDestroyContext(context);
298 alcCloseDevice(device);
300 return 0;