From 31b9c50721b9ab7e6faaf2f3ac866b3c46750427 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 10 Oct 2018 16:16:00 -0700 Subject: Use the common init/close functions for alffplay --- CMakeLists.txt | 3 ++- examples/alffplay.cpp | 47 ++++++++++++++--------------------------------- 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 \""<( - alcGetProcAddress(device, "alcGetInteger64vSOFT") - ); + { auto device = alcGetContextsDevice(alcGetCurrentContext()); + if(alcIsExtensionPresent(device, "ALC_SOFT_device_clock")) + { + std::cout<< "Found ALC_SOFT_device_clock" <( + 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; -- cgit v1.2.3