4 #include "devicemanager.h"
19 static inline void GetDeviceProc(T
**func
, ALCdevice
*device
, const char *name
)
20 { *func
= reinterpret_cast<T
*>(alcGetProcAddress(device
, name
)); }
23 ALCboolean (ALC_APIENTRY
*ALDeviceManager::SetThreadContext
)(ALCcontext
*);
25 DeviceManager
*DeviceManager::get()
27 return &ALDeviceManager::get();
31 ALDeviceManager
&ALDeviceManager::get()
33 static ALDeviceManager singleton
;
38 ALDeviceManager::ALDeviceManager()
40 if(alcIsExtensionPresent(0, "ALC_EXT_thread_local_context"))
41 GetDeviceProc(&SetThreadContext
, 0, "alcSetThreadContext");
44 bool ALDeviceManager::queryExtension(const char *extname
) const
46 return alcIsExtensionPresent(0, extname
);
49 std::vector
<std::string
> ALDeviceManager::enumerate(DeviceEnumeration type
) const
51 std::vector
<std::string
> list
;
52 if(type
== DevEnum_Complete
&& !alcIsExtensionPresent(0, "ALC_ENUMERATE_ALL_EXT"))
54 const ALCchar
*names
= alcGetString(0, type
);
55 while(names
&& *names
)
57 list
.push_back(names
);
58 names
+= strlen(names
)+1;
63 std::string
ALDeviceManager::defaultDeviceName(DefaultDeviceType type
) const
65 if(type
== DefaultDevType_Complete
&& !alcIsExtensionPresent(0, "ALC_ENUMERATE_ALL_EXT"))
66 type
= DefaultDevType_Basic
;
67 const ALCchar
*name
= alcGetString(0, type
);
68 return std::string(name
? name
: "");
72 Device
*ALDeviceManager::openPlayback(const std::string
&name
)
74 ALCdevice
*dev
= alcOpenDevice(name
.c_str());
78 throw std::runtime_error("Failed to open default device");
79 throw std::runtime_error("Failed to open device \""+name
+"\"");
81 return new ALDevice(dev
);