1 /* 2 * Copyright (c) 2002-2008 LWJGL Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'LWJGL' nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.lwjgl.test.openal; 33 34 import java.nio.IntBuffer; 35 import java.util.HashMap; 36 import java.util.Iterator; 37 import java.util.Map; 38 import java.util.Set; 39 import java.util.Map.Entry; 40 41 import org.lwjgl.BufferUtils; 42 import org.lwjgl.LWJGLException; 43 import org.lwjgl.openal.AL; 44 import org.lwjgl.openal.AL10; 45 import org.lwjgl.openal.ALC10; 46 import org.lwjgl.openal.ALC11; 47 import org.lwjgl.openal.ALCdevice; 48 import org.lwjgl.openal.EFX10; 49 import org.lwjgl.openal.EFXUtil; 50 51 /** 52 * 53 * idea from openal-info 54 * 55 * @author Brian Matzon <brian@matzon.dk> 56 * @version $Revision: 2983 $ 57 * $Id$ 58 */ 59 public class OpenALInfo { 60 61 /** 62 * Creates an instance of OpenALInfo 63 */ OpenALInfo()64 public OpenALInfo() { 65 } 66 67 /** 68 * Runs the actual test, using supplied arguments 69 */ execute(String[] args)70 protected void execute(String[] args) { 71 try { 72 AL.create(null, -1, 60, false); 73 checkForErrors(); 74 } catch (LWJGLException le) { 75 die("Init", le.getMessage()); 76 } 77 78 printALCInfo(); 79 printALInfo(); 80 printEFXInfo(); 81 82 checkForErrors(); 83 84 AL.destroy(); 85 } 86 printALCInfo()87 private void printALCInfo() { 88 IntBuffer version = BufferUtils.createIntBuffer(2); 89 ALCdevice device; 90 91 if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATION_EXT")) { 92 if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATE_ALL_EXT")) { 93 printDevices(ALC11.ALC_ALL_DEVICES_SPECIFIER, "playback"); 94 } else { 95 printDevices(ALC10.ALC_DEVICE_SPECIFIER, "playback"); 96 } 97 printDevices(ALC11.ALC_CAPTURE_DEVICE_SPECIFIER, "capture"); 98 } else { 99 System.out.println("No device enumeration available"); 100 } 101 102 device = ALC10.alcGetContextsDevice(ALC10.alcGetCurrentContext()); 103 checkForErrors(); 104 105 System.out.println("Default playback device: " + ALC10.alcGetString(device, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER)); 106 107 System.out.println("Default capture device: " + ALC10.alcGetString(device, ALC11.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); 108 109 ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, version); 110 ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, (IntBuffer) version.position(1)); 111 checkForErrors(); 112 113 System.out.println("ALC version: " + version.get(0) + "." + version.get(1)); 114 115 System.out.println("ALC extensions:"); 116 String[] extensions = ALC10.alcGetString(device, ALC10.ALC_EXTENSIONS).split(" "); 117 for ( String extension : extensions ) { 118 if ( extension.trim().length() == 0 ) { 119 continue; 120 } 121 System.out.println(" " + extension); 122 } 123 checkForErrors(); 124 } 125 printALInfo()126 private void printALInfo() { 127 System.out.println("OpenAL vendor string: " + AL10.alGetString(AL10.AL_VENDOR)); 128 System.out.println("OpenAL renderer string: " + AL10.alGetString(AL10.AL_RENDERER)); 129 System.out.println("OpenAL version string: " + AL10.alGetString(AL10.AL_VERSION)); 130 System.out.println("AL extensions:"); 131 String[] extensions = AL10.alGetString(AL10.AL_EXTENSIONS).split(" "); 132 for ( String extension : extensions ) { 133 if ( extension.trim().length() == 0 ) { 134 continue; 135 } 136 System.out.println(" " + extension); 137 } 138 checkForErrors(); 139 } 140 printEFXInfo()141 private void printEFXInfo() { 142 if(!EFXUtil.isEfxSupported()) { 143 System.out.println("EFX not available"); 144 return; 145 } 146 147 ALCdevice device = AL.getDevice(); 148 IntBuffer major = BufferUtils.createIntBuffer(1); 149 IntBuffer minor = BufferUtils.createIntBuffer(1); 150 IntBuffer sends = BufferUtils.createIntBuffer(1); 151 ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, major); 152 ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, minor); 153 if(ALC10.alcGetError(device) == ALC10.ALC_NO_ERROR) { 154 System.out.println("EFX version: " + major.get() + "." + minor.get()); 155 } 156 157 ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, sends); 158 if(ALC10.alcGetError(device) == ALC10.ALC_NO_ERROR) { 159 System.out.println("Max auxiliary sends: " + sends.get()); 160 } 161 162 System.out.println("Supported filters: "); 163 HashMap<String, Integer> filters = new HashMap<String, Integer>(); 164 filters.put("Low-pass", EFX10.AL_FILTER_LOWPASS); 165 filters.put("High-pass", EFX10.AL_FILTER_HIGHPASS); 166 filters.put("Band-pass", EFX10.AL_FILTER_BANDPASS); 167 168 Set<Entry<String, Integer>> entries = filters.entrySet(); 169 for ( final Entry<String, Integer> entry : entries ) { 170 String key = entry.getKey(); 171 if ( EFXUtil.isFilterSupported(entry.getValue()) ) 172 System.out.println(" " + entry.getKey()); 173 } 174 175 System.out.println("Supported effects: "); 176 HashMap<String, Integer> effects = new HashMap<String, Integer>(); 177 effects.put("EAX Reverb", EFX10.AL_EFFECT_EAXREVERB); 178 effects.put("Reverb", EFX10.AL_EFFECT_REVERB); 179 effects.put("Chorus", EFX10.AL_EFFECT_CHORUS); 180 effects.put("Distortion", EFX10.AL_EFFECT_DISTORTION); 181 effects.put("Echo", EFX10.AL_EFFECT_ECHO); 182 effects.put("Flanger", EFX10.AL_EFFECT_FLANGER); 183 effects.put("Frequency Shifter", EFX10.AL_EFFECT_FREQUENCY_SHIFTER); 184 effects.put("Vocal Morpher", EFX10.AL_EFFECT_VOCAL_MORPHER); 185 effects.put("Pitch Shifter", EFX10.AL_EFFECT_PITCH_SHIFTER); 186 effects.put("Ring Modulator", EFX10.AL_EFFECT_RING_MODULATOR); 187 effects.put("Autowah", EFX10.AL_EFFECT_AUTOWAH); 188 effects.put("Compressor", EFX10.AL_EFFECT_COMPRESSOR); 189 effects.put("Equalizer", EFX10.AL_EFFECT_EQUALIZER); 190 191 entries = effects.entrySet(); 192 for ( final Entry<String, Integer> entry : entries ) { 193 if ( EFXUtil.isEffectSupported(entry.getValue()) ) 194 System.out.println(" " + entry.getKey()); 195 } 196 } 197 printDevices(int which, String kind)198 private void printDevices(int which, String kind) { 199 String[] devices = ALC10.alcGetString(null, which).split("\0"); 200 checkForErrors(); 201 202 System.out.println("Available " + kind + " devices: "); 203 for ( String device : devices ) { 204 System.out.println(" " + device); 205 } 206 } 207 die(String kind, String description)208 private void die(String kind, String description) { 209 System.out.println(kind + " error " + description + " occured"); 210 } 211 checkForErrors()212 private void checkForErrors() { 213 { 214 ALCdevice device = ALC10.alcGetContextsDevice(ALC10.alcGetCurrentContext()); 215 int error = ALC10.alcGetError(device); 216 if(error != ALC10.ALC_NO_ERROR) { 217 die("ALC", ALC10.alcGetString(device, error)); 218 } 219 } 220 { 221 int error = AL10.alGetError(); 222 if(error != AL10.AL_NO_ERROR) { 223 die("AL", AL10.alGetString(error)); 224 } 225 } 226 } 227 228 /** 229 * main entry point 230 * 231 * @param args String array containing arguments 232 */ main(String[] args)233 public static void main(String[] args) { 234 OpenALInfo openalInfo = new OpenALInfo(); 235 openalInfo.execute(args); 236 System.exit(0); 237 } 238 }