JOAL v2.6.0-rc-20250706
JOAL, OpenAL® API Binding for Java™ (public API).
ALFactory.java
Go to the documentation of this file.
1/**
2 * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * -Redistribution of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * -Redistribution in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
15 * be used to endorse or promote products derived from this software without
16 * specific prior written permission.
17 *
18 * This software is provided "AS IS," without a warranty of any kind.
19 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
20 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
21 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS
22 * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
23 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
24 * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
25 * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
26 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
27 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
28 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
29 *
30 * You acknowledge that this software is not designed or intended for use in the
31 * design, construction, operation or maintenance of any nuclear facility.
32 */
33
34package com.jogamp.openal;
35
36import jogamp.openal.ALCImpl;
37import jogamp.openal.ALExtImpl;
38import jogamp.openal.ALImpl;
39import jogamp.openal.Debug;
40
41import com.jogamp.common.os.Platform;
42import com.jogamp.common.util.PropertyAccess;
43
44/**
45 * This class provides factory methods for generating AL and ALC objects.
46 *
47 * <p>
48 * Select preferred OpenAL native library type via system properties,
49 * i.e. System-OpenAL or bundled Soft-OpenAL.<br/>
50 * If the preferred choice fails, implementation falls back to the other.
51 * <PRE>
52 -Djoal.openal.lib=auto Prefer System-OpenAL over bundled Soft-OpenAL for OSX. Prefer bundled Soft-OpenAL over System-OpenAL for all others. This is the default.
53 -Djoal.openal.lib=system Prefer System-OpenAL over bundled Soft-OpenAL for all.
54 -Djoal.openal.lib=soft Prefer bundled Soft-OpenAL over System-OpenAL for all.
55 </PRE>
56 * Note: You may use the 'jnlp.' prefix, allowing using above property names w/ Applets and WebStart,
57 * e.g. 'jnlp.joal.openal.lib=system'.
58 * </p>
59 *
60 * @author Athomas Goldberg, Kenneth Russell, et.al.
61 */
62public class ALFactory {
63 public static final boolean DEBUG = Debug.debug("Factory");
64 /** If true, prefer System-OpenAL, otherwise bundled Soft-OpenAL (default). */
65 public static final boolean PREFER_SYSTEM_OPENAL;
66
67 static {
68 Platform.initSingleton();
69 final String choice = PropertyAccess.getProperty("joal.openal.lib", true);
70 boolean useSystem = false; // default on all systems
71 if( null != choice ) {
72 if( choice.equals("system") ) {
73 useSystem = true;
74 } else if( choice.equals("soft") ) {
75 useSystem = false;
76 }
77 }
78 PREFER_SYSTEM_OPENAL = useSystem;
79 }
80
81 private static boolean initialized = false;
82 private static AL al;
83 private static ALC alc;
84 private static ALExt alext;
85
86 private ALFactory() {}
87
88 private static synchronized void initialize() throws ALException {
89 try {
90 if (!initialized) {
91 if(null == ALImpl.getALProcAddressTable()) {
92 throw new ALException("AL not initialized (ProcAddressTable null)");
93 }
94 initialized = true;
95 if(DEBUG) {
96 System.err.println("AL initialized");
97 }
98 }
99 } catch (final UnsatisfiedLinkError e) {
100 throw new ALException(e);
101 } catch (final ExceptionInInitializerError er) {
102 throw new ALException(er);
103 }
104 }
105
106 /**
107 * If the system property <code>joal.SystemOpenAL</code> is set
108 * @return
109 * @throws ALException
110 */
111 public static boolean getPreferSystemOpenAL() throws ALException {
112 initialize();
114 }
115
116 /**
117 * Get the default AL object. This object is used to access most of the
118 * OpenAL functionality.
119 *
120 * @return the AL object
121 */
122 public static AL getAL() throws ALException {
123 initialize();
124 if (al == null) {
125 al = new ALImpl();
126 }
127 return al;
128 }
129
130 /**
131 * Get the default ALC object. This object is used to access most of the
132 * OpenAL context functionality.
133 *
134 * @return the ALC object
135 */
136 public static ALC getALC() throws ALException{
137 initialize();
138 if (alc == null) {
139 alc = new ALCImpl();
140 }
141 return alc;
142 }
143
144 /**
145 * Get the default ALExt object. This object is used to access most of the
146 * OpenAL extension functionality.
147 *
148 * @return the ALExt object
149 */
150 public static ALExt getALExt() throws ALException{
151 initialize();
152 if (alext == null) {
153 alext = new ALExtImpl();
154 }
155 return alext;
156 }
157}
A generic exception for OpenAL errors used throughout the binding as a substitute for RuntimeExceptio...
This class provides factory methods for generating AL and ALC objects.
Definition: ALFactory.java:62
static AL getAL()
Get the default AL object.
Definition: ALFactory.java:122
static boolean getPreferSystemOpenAL()
If the system property joal.SystemOpenAL is set.
Definition: ALFactory.java:111
static ALExt getALExt()
Get the default ALExt object.
Definition: ALFactory.java:150
static final boolean PREFER_SYSTEM_OPENAL
If true, prefer System-OpenAL, otherwise bundled Soft-OpenAL (default).
Definition: ALFactory.java:65
static final boolean DEBUG
Definition: ALFactory.java:63
static ALC getALC()
Get the default ALC object.
Definition: ALFactory.java:136