aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--examples/alffplay.cpp47
2 files changed, 16 insertions, 34 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6d0037e..79df5c5f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1746,7 +1746,8 @@ IF(ALSOFT_EXAMPLES)
PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
TARGET_LINK_LIBRARIES(alffplay
- PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} common OpenAL)
+ PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common common
+ OpenAL)
IF(ALSOFT_INSTALL)
INSTALL(TARGETS alffplay
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
index 4b04efc1..27520a6d 100644
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -39,6 +39,8 @@ extern "C" {
#include "AL/al.h"
#include "AL/alext.h"
+#include "common/alhelpers.h"
+
extern "C" {
/* Undefine this to disable use of experimental extensions. Don't use for
* production code! Interfaces and behavior may change prior to being
@@ -1717,41 +1719,21 @@ int main(int argc, char *argv[])
SDL_RenderPresent(renderer);
/* Open an audio device */
- int fileidx = 1;
- ALCdevice *device = [argc,argv,&fileidx]() -> ALCdevice*
- {
- ALCdevice *dev = NULL;
- if(argc > 3 && strcmp(argv[1], "-device") == 0)
- {
- fileidx = 3;
- dev = alcOpenDevice(argv[2]);
- if(dev) return dev;
- std::cerr<< "Failed to open \""<<argv[2]<<"\" - trying default" <<std::endl;
- }
- return alcOpenDevice(nullptr);
- }();
- ALCcontext *context = alcCreateContext(device, nullptr);
- if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
+ ++argv; --argc;
+ if(InitAL(&argv, &argc))
{
std::cerr<< "Failed to set up audio device" <<std::endl;
- if(context)
- alcDestroyContext(context);
return 1;
}
- const ALCchar *name = nullptr;
- if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT"))
- name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
- if(!name || alcGetError(device) != AL_NO_ERROR)
- name = alcGetString(device, ALC_DEVICE_SPECIFIER);
- std::cout<< "Opened \""<<name<<"\"" <<std::endl;
-
- if(alcIsExtensionPresent(device, "ALC_SOFT_device_clock"))
- {
- std::cout<< "Found ALC_SOFT_device_clock" <<std::endl;
- alcGetInteger64vSOFT = reinterpret_cast<LPALCGETINTEGER64VSOFT>(
- alcGetProcAddress(device, "alcGetInteger64vSOFT")
- );
+ { auto device = alcGetContextsDevice(alcGetCurrentContext());
+ if(alcIsExtensionPresent(device, "ALC_SOFT_device_clock"))
+ {
+ std::cout<< "Found ALC_SOFT_device_clock" <<std::endl;
+ alcGetInteger64vSOFT = reinterpret_cast<LPALCGETINTEGER64VSOFT>(
+ alcGetProcAddress(device, "alcGetInteger64vSOFT")
+ );
+ }
}
if(alIsExtensionPresent("AL_SOFT_source_latency"))
@@ -1784,6 +1766,7 @@ int main(int argc, char *argv[])
}
#endif
+ int fileidx = 0;
for(;fileidx < argc;++fileidx)
{
if(strcmp(argv[fileidx], "-direct") == 0)
@@ -1912,9 +1895,7 @@ int main(int argc, char *argv[])
/* Nothing more to play. Shut everything down and quit. */
movState = nullptr;
- alcMakeContextCurrent(nullptr);
- alcDestroyContext(context);
- alcCloseDevice(device);
+ CloseAL();
SDL_DestroyRenderer(renderer);
renderer = nullptr;