Mercurial > audio-send
diff utils/openal-info.c @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/utils/openal-info.c Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,365 @@ 1.4 +/* 1.5 + * OpenAL Info Utility 1.6 + * 1.7 + * Copyright (c) 2010 by Chris Robinson <chris.kcat@gmail.com> 1.8 + * 1.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy 1.10 + * of this software and associated documentation files (the "Software"), to deal 1.11 + * in the Software without restriction, including without limitation the rights 1.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1.13 + * copies of the Software, and to permit persons to whom the Software is 1.14 + * furnished to do so, subject to the following conditions: 1.15 + * 1.16 + * The above copyright notice and this permission notice shall be included in 1.17 + * all copies or substantial portions of the Software. 1.18 + * 1.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1.25 + * THE SOFTWARE. 1.26 + */ 1.27 + 1.28 +#include <stdio.h> 1.29 +#include <string.h> 1.30 + 1.31 +#include "AL/alc.h" 1.32 +#include "AL/al.h" 1.33 +#include "AL/alext.h" 1.34 + 1.35 +#ifndef ALC_ENUMERATE_ALL_EXT 1.36 +#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012 1.37 +#define ALC_ALL_DEVICES_SPECIFIER 0x1013 1.38 +#endif 1.39 + 1.40 +#ifndef ALC_EXT_EFX 1.41 +#define ALC_EFX_MAJOR_VERSION 0x20001 1.42 +#define ALC_EFX_MINOR_VERSION 0x20002 1.43 +#define ALC_MAX_AUXILIARY_SENDS 0x20003 1.44 +#define AL_FILTER_TYPE 0x8001 1.45 +#define AL_FILTER_NULL 0x0000 1.46 +#define AL_FILTER_LOWPASS 0x0001 1.47 +#define AL_FILTER_HIGHPASS 0x0002 1.48 +#define AL_FILTER_BANDPASS 0x0003 1.49 +#define AL_EFFECT_TYPE 0x8001 1.50 +#define AL_EFFECT_NULL 0x0000 1.51 +#define AL_EFFECT_EAXREVERB 0x8000 1.52 +#define AL_EFFECT_REVERB 0x0001 1.53 +#define AL_EFFECT_CHORUS 0x0002 1.54 +#define AL_EFFECT_DISTORTION 0x0003 1.55 +#define AL_EFFECT_ECHO 0x0004 1.56 +#define AL_EFFECT_FLANGER 0x0005 1.57 +#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006 1.58 +#define AL_EFFECT_VOCAL_MORPHER 0x0007 1.59 +#define AL_EFFECT_PITCH_SHIFTER 0x0008 1.60 +#define AL_EFFECT_RING_MODULATOR 0x0009 1.61 +#define AL_EFFECT_AUTOWAH 0x000A 1.62 +#define AL_EFFECT_COMPRESSOR 0x000B 1.63 +#define AL_EFFECT_EQUALIZER 0x000C 1.64 +typedef void (AL_APIENTRY *LPALGENFILTERS)(ALsizei, ALuint*); 1.65 +typedef void (AL_APIENTRY *LPALDELETEFILTERS)(ALsizei, ALuint*); 1.66 +typedef void (AL_APIENTRY *LPALFILTERI)(ALuint, ALenum, ALint); 1.67 +typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*); 1.68 +typedef void (AL_APIENTRY *LPALDELETEEFFECTS)(ALsizei, ALuint*); 1.69 +typedef void (AL_APIENTRY *LPALEFFECTI)(ALuint, ALenum, ALint); 1.70 +#endif 1.71 +static LPALGENFILTERS palGenFilters; 1.72 +static LPALDELETEFILTERS palDeleteFilters; 1.73 +static LPALFILTERI palFilteri; 1.74 +static LPALGENEFFECTS palGenEffects; 1.75 +static LPALDELETEEFFECTS palDeleteEffects; 1.76 +static LPALEFFECTI palEffecti; 1.77 + 1.78 +#ifndef ALC_EXT_DEDICATED 1.79 +#define AL_EFFECT_DEDICATED_DIALOGUE 0x9001 1.80 +#define AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT 0x9000 1.81 +#endif 1.82 + 1.83 + 1.84 +#define MAX_WIDTH 80 1.85 + 1.86 +static void printList(const char *list, char separator) 1.87 +{ 1.88 + size_t col = MAX_WIDTH, len; 1.89 + const char *indent = " "; 1.90 + const char *next; 1.91 + 1.92 + if(!list || *list == '\0') 1.93 + { 1.94 + fprintf(stdout, "\n%s!!! none !!!\n", indent); 1.95 + return; 1.96 + } 1.97 + 1.98 + do { 1.99 + next = strchr(list, separator); 1.100 + if(next) 1.101 + { 1.102 + len = next-list; 1.103 + do { 1.104 + next++; 1.105 + } while(*next == separator); 1.106 + } 1.107 + else 1.108 + len = strlen(list); 1.109 + 1.110 + if(len + col + 2 >= MAX_WIDTH) 1.111 + { 1.112 + fprintf(stdout, "\n%s", indent); 1.113 + col = strlen(indent); 1.114 + } 1.115 + else 1.116 + { 1.117 + fputc(' ', stdout); 1.118 + col++; 1.119 + } 1.120 + 1.121 + len = fwrite(list, 1, len, stdout); 1.122 + col += len; 1.123 + 1.124 + if(!next || *next == '\0') 1.125 + break; 1.126 + fputc(',', stdout); 1.127 + col++; 1.128 + 1.129 + list = next; 1.130 + } while(1); 1.131 + fputc('\n', stdout); 1.132 +} 1.133 + 1.134 +static void printDeviceList(const char *list) 1.135 +{ 1.136 + if(!list || *list == '\0') 1.137 + printf(" !!! none !!!\n"); 1.138 + else do { 1.139 + printf(" %s\n", list); 1.140 + list += strlen(list) + 1; 1.141 + } while(*list != '\0'); 1.142 +} 1.143 + 1.144 + 1.145 +static ALenum checkALErrors(int linenum) 1.146 +{ 1.147 + ALenum err = alGetError(); 1.148 + if(err != AL_NO_ERROR) 1.149 + printf("OpenAL Error: %s (0x%x), @ %d\n", alGetString(err), err, linenum); 1.150 + return err; 1.151 +} 1.152 +#define checkALErrors() checkALErrors(__LINE__) 1.153 + 1.154 +static ALCenum checkALCErrors(ALCdevice *device, int linenum) 1.155 +{ 1.156 + ALCenum err = alcGetError(device); 1.157 + if(err != ALC_NO_ERROR) 1.158 + printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum); 1.159 + return err; 1.160 +} 1.161 +#define checkALCErrors(x) checkALCErrors((x),__LINE__) 1.162 + 1.163 + 1.164 +static void printALCInfo(ALCdevice *device) 1.165 +{ 1.166 + ALCint major, minor; 1.167 + 1.168 + alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); 1.169 + alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor); 1.170 + if(checkALCErrors(device) == ALC_NO_ERROR) 1.171 + printf("ALC version: %d.%d\n", major, minor); 1.172 + if(device) 1.173 + { 1.174 + printf("ALC extensions:"); 1.175 + printList(alcGetString(device, ALC_EXTENSIONS), ' '); 1.176 + checkALCErrors(device); 1.177 + } 1.178 +} 1.179 + 1.180 +static void printALInfo(void) 1.181 +{ 1.182 + printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR)); 1.183 + printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER)); 1.184 + printf("OpenAL version string: %s\n", alGetString(AL_VERSION)); 1.185 + printf("OpenAL extensions:"); 1.186 + printList(alGetString(AL_EXTENSIONS), ' '); 1.187 + checkALErrors(); 1.188 +} 1.189 + 1.190 +static void printEFXInfo(ALCdevice *device) 1.191 +{ 1.192 + ALCint major, minor, sends; 1.193 + ALuint obj; 1.194 + int i; 1.195 + const ALenum filters[] = { 1.196 + AL_FILTER_LOWPASS, AL_FILTER_HIGHPASS, AL_FILTER_BANDPASS, 1.197 + AL_FILTER_NULL 1.198 + }; 1.199 + char filterNames[] = "Low-pass,High-pass,Band-pass,"; 1.200 + const ALenum effects[] = { 1.201 + AL_EFFECT_EAXREVERB, AL_EFFECT_REVERB, AL_EFFECT_CHORUS, 1.202 + AL_EFFECT_DISTORTION, AL_EFFECT_ECHO, AL_EFFECT_FLANGER, 1.203 + AL_EFFECT_FREQUENCY_SHIFTER, AL_EFFECT_VOCAL_MORPHER, 1.204 + AL_EFFECT_PITCH_SHIFTER, AL_EFFECT_RING_MODULATOR, AL_EFFECT_AUTOWAH, 1.205 + AL_EFFECT_COMPRESSOR, AL_EFFECT_EQUALIZER, AL_EFFECT_NULL 1.206 + }; 1.207 + const ALenum dedeffects[] = { 1.208 + AL_EFFECT_DEDICATED_DIALOGUE, 1.209 + AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, AL_EFFECT_NULL 1.210 + }; 1.211 + char effectNames[] = "EAX Reverb,Reverb,Chorus,Distortion,Echo,Flanger," 1.212 + "Frequency Shifter,Vocal Morpher,Pitch Shifter," 1.213 + "Ring Modulator,Autowah,Compressor,Equalizer," 1.214 + "Dedicated Dialog,Dedicated LFE,"; 1.215 + char *current; 1.216 + 1.217 + if(alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_FALSE) 1.218 + { 1.219 + printf("EFX not available\n"); 1.220 + return; 1.221 + } 1.222 + 1.223 + alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major); 1.224 + alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor); 1.225 + if(checkALCErrors(device) == ALC_NO_ERROR) 1.226 + printf("EFX version: %d.%d\n", major, minor); 1.227 + alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends); 1.228 + if(checkALCErrors(device) == ALC_NO_ERROR) 1.229 + printf("Max auxiliary sends: %d\n", sends); 1.230 + 1.231 + palGenFilters = alGetProcAddress("alGenFilters"); 1.232 + palDeleteFilters = alGetProcAddress("alDeleteFilters"); 1.233 + palFilteri = alGetProcAddress("alFilteri"); 1.234 + palGenEffects = alGetProcAddress("alGenEffects"); 1.235 + palDeleteEffects = alGetProcAddress("alDeleteEffects"); 1.236 + palEffecti = alGetProcAddress("alEffecti"); 1.237 + if(checkALErrors() != AL_NO_ERROR || 1.238 + !palGenFilters || !palDeleteFilters || !palFilteri || 1.239 + !palGenEffects || !palDeleteEffects || !palEffecti) 1.240 + { 1.241 + printf("!!! Missing EFX functions !!!\n"); 1.242 + return; 1.243 + } 1.244 + 1.245 + palGenFilters(1, &obj); 1.246 + if(checkALErrors() == AL_NO_ERROR) 1.247 + { 1.248 + current = filterNames; 1.249 + for(i = 0;filters[i] != AL_FILTER_NULL;i++) 1.250 + { 1.251 + char *next = strchr(current, ','); 1.252 + 1.253 + palFilteri(obj, AL_FILTER_TYPE, filters[i]); 1.254 + if(alGetError() == AL_NO_ERROR) 1.255 + current = next+1; 1.256 + else 1.257 + memmove(current, next+1, strlen(next)); 1.258 + } 1.259 + palDeleteFilters(1, &obj); 1.260 + checkALErrors(); 1.261 + 1.262 + printf("Supported filters:"); 1.263 + printList(filterNames, ','); 1.264 + } 1.265 + 1.266 + palGenEffects(1, &obj); 1.267 + if(checkALErrors() == AL_NO_ERROR) 1.268 + { 1.269 + current = effectNames; 1.270 + for(i = 0;effects[i] != AL_EFFECT_NULL;i++) 1.271 + { 1.272 + char *next = strchr(current, ','); 1.273 + 1.274 + palEffecti(obj, AL_EFFECT_TYPE, effects[i]); 1.275 + if(alGetError() == AL_NO_ERROR) 1.276 + current = next+1; 1.277 + else 1.278 + memmove(current, next+1, strlen(next)); 1.279 + } 1.280 + if(alcIsExtensionPresent(device, "ALC_EXT_DEDICATED")) 1.281 + { 1.282 + for(i = 0;dedeffects[i] != AL_EFFECT_NULL;i++) 1.283 + { 1.284 + char *next = strchr(current, ','); 1.285 + 1.286 + palEffecti(obj, AL_EFFECT_TYPE, dedeffects[i]); 1.287 + if(alGetError() == AL_NO_ERROR) 1.288 + current = next+1; 1.289 + else 1.290 + memmove(current, next+1, strlen(next)); 1.291 + } 1.292 + } 1.293 + else 1.294 + { 1.295 + for(i = 0;dedeffects[i] != AL_EFFECT_NULL;i++) 1.296 + { 1.297 + char *next = strchr(current, ','); 1.298 + memmove(current, next+1, strlen(next)); 1.299 + } 1.300 + } 1.301 + palDeleteEffects(1, &obj); 1.302 + checkALErrors(); 1.303 + 1.304 + printf("Supported effects:"); 1.305 + printList(effectNames, ','); 1.306 + } 1.307 +} 1.308 + 1.309 +int main(int argc, char *argv[]) 1.310 +{ 1.311 + ALCdevice *device; 1.312 + ALCcontext *context; 1.313 + 1.314 + if(argc > 1 && (strcmp(argv[1], "--help") == 0 || 1.315 + strcmp(argv[1], "-h") == 0)) 1.316 + { 1.317 + printf("Usage: %s [playback device]\n", argv[0]); 1.318 + return 0; 1.319 + } 1.320 + 1.321 + printf("Available playback devices:\n"); 1.322 + if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) 1.323 + printDeviceList(alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER)); 1.324 + else 1.325 + printDeviceList(alcGetString(NULL, ALC_DEVICE_SPECIFIER)); 1.326 + printf("Available capture devices:\n"); 1.327 + printDeviceList(alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER)); 1.328 + 1.329 + if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) 1.330 + printf("Default playback device: %s\n", 1.331 + alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER)); 1.332 + else 1.333 + printf("Default playback device: %s\n", 1.334 + alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER)); 1.335 + printf("Default capture device: %s\n", 1.336 + alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); 1.337 + 1.338 + printALCInfo(NULL); 1.339 + 1.340 + device = alcOpenDevice((argc>1) ? argv[1] : NULL); 1.341 + if(!device) 1.342 + { 1.343 + printf("\n!!! Failed to open %s !!!\n\n", ((argc>1) ? argv[1] : "default device")); 1.344 + return 1; 1.345 + } 1.346 + 1.347 + printf("\n** Info for device \"%s\" **\n", alcGetString(device, ALC_DEVICE_SPECIFIER)); 1.348 + printALCInfo(device); 1.349 + 1.350 + context = alcCreateContext(device, NULL); 1.351 + if(!context || alcMakeContextCurrent(context) == ALC_FALSE) 1.352 + { 1.353 + if(context) 1.354 + alcDestroyContext(context); 1.355 + alcCloseDevice(device); 1.356 + printf("\n!!! Failed to set a context !!!\n\n"); 1.357 + return 1; 1.358 + } 1.359 + 1.360 + printALInfo(); 1.361 + printEFXInfo(device); 1.362 + 1.363 + alcMakeContextCurrent(NULL); 1.364 + alcDestroyContext(context); 1.365 + alcCloseDevice(device); 1.366 + 1.367 + return 0; 1.368 +}