diff options
87 files changed, 52710 insertions, 10 deletions
@@ -58,5 +58,3 @@ a license to everyone to use it as detailed in LICENSE.) * Felix H. Dahlke <fhd@ubercode.de> * Éloi Rivard <azmeuk@gmail.com> * Alexander Gladysh <ag@logiceditor.com> - - diff --git a/src/library_openal.js b/src/library_openal.js index 0b6e9b2f..6a97fce7 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -13,11 +13,30 @@ var LibraryOpenAL = { alcMakeContextCurrent: function(context) { if (context == 0) { AL.currentContext = null; + return 0; } else { AL.currentContext = AL.contexts[context - 1]; + return 1; } }, + alcGetContextsDevice: function(context) { + if (context <= AL.contexts.length && context > 0) { + // Returns the only one audio device + return 1; + } + return 0; + }, + + alcGetCurrentContext: function() { + for (var i = 0; i < AL.contexts.length; ++i) { + if (AL.contexts[i] == AL.currentContext) { + return i + 1; + } + } + return 0; + }, + alcDestroyContext: function(context) { // Stop playback, etc }, @@ -167,7 +186,9 @@ var LibraryOpenAL = { } switch (param) { case 0x100A /* AL_GAIN */: - AL.currentContext.src[source - 1].gain.gain.value = value; + if (AL.currentContext.src[source - 1]) { + AL.currentContext.src[source - 1].gain.gain.value = value; + } break; case 0x1003 /* AL_PITCH */: #if OPENAL_DEBUG @@ -291,14 +312,16 @@ var LibraryOpenAL = { } for (var i = 0; i < count; ++i) { var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1; - var buffer = AL.currentContext.buf[bufferIdx].buf; - for (var j = 0; j < AL.currentContext.src.length; ++j) { - if (buffer == AL.currentContext.src[j].buffer) { - AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */; - return; + if (bufferIdx < AL.currentContext.buf.length && AL.currentContext.buf[bufferIdx]) { + var buffer = AL.currentContext.buf[bufferIdx].buf; + for (var j = 0; j < AL.currentContext.src.length; ++j) { + if (buffer == AL.currentContext.src[j].buffer) { + AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */; + return; + } } + delete AL.currentContext.buf[bufferIdx]; } - delete AL.currentContext.buf[bufferIdx]; } }, @@ -424,7 +447,7 @@ var LibraryOpenAL = { #endif return; } - if ("src" in AL.currentContext.src[source - 1]) { + if (AL.currentContext.src[source - 1] && "src" in AL.currentContext.src[source - 1]) { AL.currentContext.src[source - 1]["src"].stop(0); delete AL.currentContext.src[source - 1]["src"]; } diff --git a/tests/freealut/AUTHORS b/tests/freealut/AUTHORS new file mode 100644 index 00000000..92890c93 --- /dev/null +++ b/tests/freealut/AUTHORS @@ -0,0 +1,14 @@ +Steve Baker <sjbaker1@airmail.net> + Initial version of the sources and the specification + +Sven Panne <sven.panne@aedion.de> + Build system + General hacking + Specification maintenance + +Erik Hofman <erik@ehofman.com> + Fixes and additions to the sound file loaders + playfile demo + +Prakash Punnoor <prakash@punnoor.de> + CMake build system diff --git a/tests/freealut/CMakeLists.txt b/tests/freealut/CMakeLists.txt new file mode 100644 index 00000000..640f35bf --- /dev/null +++ b/tests/freealut/CMakeLists.txt @@ -0,0 +1,208 @@ +# cmake project file by Prakash Punnoor +CMAKE_MINIMUM_REQUIRED(VERSION 2.0) + +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/admin/CMakeModules") +PROJECT(Alut C) +SET(PACKAGE "freealut") +SET(PACKAGE_TARNAME "freealut") +SET(PACKAGE_NAME "freealut library") +SET(PACKAGE_MAJOR_VERSION "1") +SET(PACKAGE_MINOR_VERSION "0") +SET(PACKAGE_BUILD_VERSION "1") +SET(PACKAGE_VERSION "${PACKAGE_MAJOR_VERSION}.${PACKAGE_MINOR_VERSION}.${PACKAGE_BUILD_VERSION}") +SET(MAJOR_VERSION "0") +SET(MINOR_VERSION "0") +SET(BUILD_VERSION "0") +SET(VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION}") +SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +SET(PACKAGE_BUGREPORT "openal-devel@opensource.creative.com") +SET(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}") + +INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) +INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake) +INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake) + +FIND_PACKAGE(ConfigHelper) + +SET(ALUT_SOURCES src/alutBufferData.c + src/alutCodec.c + src/alutError.c + src/alutInit.c + src/alutInputStream.c + src/alutInternal.h + src/alutLoader.c + src/alutOutputStream.c + src/alutUtil.c + src/alutVersion.c + src/alutWaveform.c) + +INCLUDE_DIRECTORIES(${Alut_SOURCE_DIR}/include) + +SET(ADD_WFLAGS "") +SET(ADD_CFLAGS "") +SET(ADD_LDFLAGS "") +SET(ADD_LIBS "") + +OPTION(BUILD_STATIC "build static library too" ON) +OPTION(PROFILE "enable profile" OFF) +OPTION(OPTIMIZATION "enable optimization" ON) +OPTION(WARNINGS "enable warnings" ON) +IF(WARNINGS) + OPTION(MORE_WARNINGS "enable more warnings" OFF) + OPTION(USE_WERROR "enable fail on all warning" OFF) +ENDIF(WARNINGS) + +#want test-suit? +OPTION(BUILD_TESTS "build the test-suite" OFF) + + +ADD_DEFINE(ALUT_BUILD_LIBRARY) +# We could possibly need struct timespec and random(), which are not ANSI. +# Define to 500 if Single Unix conformance is wanted, 600 for sixth revision. +ADD_DEFINE("_XOPEN_SOURCE 500") +# We might need nanosleep, which is a POSIX IEEE Std 1003.1b-1993 feature. +# Define to the POSIX version that should be used. +ADD_DEFINE("_POSIX_C_SOURCE 199309") +# Without __NO_CTYPE tolower and friends are macros which introduce a GLIBC 2.3 +# dependency. By defining this identifier we are currently backwards compatible +# to GLIBC 2.1.3, which is a good thing. In addition, the macros lead to code +# which triggers warnings with -Wunreachable-code. +ADD_DEFINE("__NO_CTYPE 1") + +ADD_DEFINITIONS(-DHAVE_CONFIG_H) +ADD_DEFINITIONS(-DNDEBUG) + +FIND_LIBRARY(OPENAL_LIB NAMES openal openal32 PATHS /usr/lib /usr/local/lib ${OPENAL_LIB_DIR}) +IF(OPENAL_LIB MATCHES "NOTFOUND") + MESSAGE(FATAL_ERROR "OpenAL not installed, cannot build alut - aborting.") +ENDIF(OPENAL_LIB MATCHES "NOTFOUND") + +IF(UNIX) + SET(ADD_LIBS ${ADD_LIBS} m) +ENDIF(UNIX) + +SET(CMAKE_REQUIRED_INCLUDES ${OPENAL_INCLUDE_DIR}) +CHECK_INCLUDE_FILES("AL/alc.h;AL/al.h" AL_HEADERS) +IF(NOT AL_HEADERS) + MESSAGE(FATAL_ERROR "OpenAL header files not found - aborting.") +ENDIF(NOT AL_HEADERS) + +IF(DEFINED OPENAL_INCLUDE_DIR) + INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) +ENDIF(DEFINED OPENAL_INCLUDE_DIR) + +FIND_PACKAGE(SleepFunction) + +CHECK_INCLUDE_FILE_DEFINE(stdint.h HAVE_STDINT_H) + +IF(WIN32) + CHECK_INCLUDE_FILE_DEFINE(basetsd.h HAVE_BASETSD_H) +ENDIF(WIN32) + +# FindSleepFunction will check for unistd.h if time.h wasn't found +IF(HAVE_TIME_H) + CHECK_INCLUDE_FILE_DEFINE(unistd.h HAVE_UNISTD_H) +ENDIF(HAVE_TIME_H) + +IF(HAVE_UNISTD_H) + CHECK_FUNCTION_DEFINE(" + #include <sys/types.h> + #include <sys/stat.h> + #include <unistd.h> + " stat "(\"\", (struct stat*)0)" HAVE_STAT) +ENDIF(HAVE_UNISTD_H) + +IF(NOT HAVE_STAT) + CHECK_FUNCTION_DEFINE(" + #include <sys/types.h> + #include <sys/stat.h> + " _stat "(\"\", (struct _stat*)0)" HAVE__STAT) +ENDIF(NOT HAVE_STAT) + +# compiler specific settings +FIND_PACKAGE(CompilerAttribute) +FIND_PACKAGE(CompilerVisibility) +FIND_PACKAGE(CompilerFlagsSet) + +GENERATE_CONFIG_H() + +SET(CMAKE_C_FLAGS "${ADD_WFLAGS} ${ADD_CFLAGS} ${CMAKE_C_FLAGS}") +SET(CMAKE_CXX_FLAGS "${ADD_CFLAGS} ${CMAKE_CXX_FLAGS}") +SET(CMAKE_SHARED_LINKER_FLAGS "${ADD_LDFLAGS} ${CMAKE_SHARED_LINKER_FLAGS}") +SET(CMAKE_MODULE_LINKER_FLAGS "${ADD_LDFLAGS} ${CMAKE_MODULE_LINKER_FLAGS}") + +IF(BUILD_STATIC) + # we can't create a static library with the same name + # as the shared one, so we copy it over after creation + ADD_LIBRARY(alut_static STATIC ${ALUT_SOURCES}) + TARGET_LINK_LIBRARIES(alut_static ${OPENAL_LIB} ${ADD_LIBS}) + IF(NOT WIN32) + ADD_CUSTOM_COMMAND( + TARGET alut_static + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy + ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}alut_static${CMAKE_STATIC_LIBRARY_SUFFIX} + ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}alut${CMAKE_STATIC_LIBRARY_SUFFIX}) + INSTALL_FILES(/lib FILES ${CMAKE_STATIC_LIBRARY_PREFIX}alut${CMAKE_STATIC_LIBRARY_SUFFIX}) + ENDIF(NOT WIN32) +ENDIF(BUILD_STATIC) + + +ADD_LIBRARY(alut SHARED ${ALUT_SOURCES}) +SET_TARGET_PROPERTIES(alut PROPERTIES VERSION ${VERSION} SOVERSION ${MAJOR_VERSION}) +TARGET_LINK_LIBRARIES(alut ${OPENAL_LIB} ${ADD_LIBS}) + +INSTALL_TARGETS(/lib alut) +INSTALL_FILES(/include/AL FILES include/AL/alut.h) + +# needed for openal.pc.in and openal-config.in +SET(prefix ${CMAKE_INSTALL_PREFIX}) +SET(exec_prefix "\${prefix}") +SET(libdir "\${exec_prefix}/lib") +SET(bindir "\${exec_prefix}/bin") +SET(includedir "\${prefix}/include") +SET(requirements "") +# static linking dependecies are broken, so pthread isn't needed currently +SET(PTHREAD_LIBS ${CMAKE_THREAD_LIBS_INIT}) + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/admin/pkgconfig/freealut.pc.in + ${CMAKE_BINARY_DIR}/admin/pkgconfig/freealut.pc @ONLY) +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/admin/pkgconfig/freealut-config.in + ${CMAKE_BINARY_DIR}/admin/pkgconfig/freealut-config @ONLY) +INSTALL_PROGRAMS(/bin FILES admin/pkgconfig/freealut-config) +INSTALL_FILES(/lib/pkgconfig FILES admin/pkgconfig/freealut.pc) + + +# test-suite +IF(BUILD_TESTS) + # examples + ADD_EXECUTABLE(hello_world examples/hello_world.c) + TARGET_LINK_LIBRARIES(hello_world ${OPENAL_LIB} ${ADD_LIBS} alut) + + ADD_EXECUTABLE(playfile examples/playfile.c) + TARGET_LINK_LIBRARIES(playfile ${OPENAL_LIB} ${ADD_LIBS} alut) + + + SET(TESTS errorstuff + fileloader + memoryloader + version + waveforms) + + FOREACH(TEST ${TESTS}) + SET(TEST_SRC test_suite/test_${TEST}.c) + SET_SOURCE_FILES_PROPERTIES(${TEST_SRC} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") + ADD_EXECUTABLE(test_${TEST} ${TEST_SRC}) + TARGET_LINK_LIBRARIES(test_${TEST} ${OPENAL_LIB} ${ADD_LIBS} alut) + ENDFOREACH(TEST) + + #copy over testdata, so test-suite can be used in binary dir + SET(TESTDATA file1.wav + file2.au + file3.raw) + + FOREACH(TESTDATUM ${TESTDATA}) + CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/test_suite/${TESTDATUM} ${CMAKE_BINARY_DIR}/${TESTDATUM} COPYONLY) + ENDFOREACH(TESTDATUM) +ENDIF(BUILD_TESTS) diff --git a/tests/freealut/COPYING b/tests/freealut/COPYING new file mode 100644 index 00000000..e463f462 --- /dev/null +++ b/tests/freealut/COPYING @@ -0,0 +1,483 @@ + + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source |