mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 15:22:16 +00:00
Remove use of SDL_sound
This commit is contained in:
parent
b38589e2dc
commit
14618cbf30
5 changed files with 6 additions and 1140 deletions
|
@ -1,382 +0,0 @@
|
||||||
# - Locates the SDL_sound library
|
|
||||||
#
|
|
||||||
# This module depends on SDL being found and
|
|
||||||
# must be called AFTER FindSDL.cmake is called.
|
|
||||||
#
|
|
||||||
# This module defines
|
|
||||||
# SDL_SOUND_INCLUDE_DIR, where to find SDL_sound.h
|
|
||||||
# SDL_SOUND_FOUND, if false, do not try to link to SDL_sound
|
|
||||||
# SDL_SOUND_LIBRARIES, this contains the list of libraries that you need
|
|
||||||
# to link against. This is a read-only variable and is marked INTERNAL.
|
|
||||||
# SDL_SOUND_EXTRAS, this is an optional variable for you to add your own
|
|
||||||
# flags to SDL_SOUND_LIBRARIES. This is prepended to SDL_SOUND_LIBRARIES.
|
|
||||||
# This is available mostly for cases this module failed to anticipate for
|
|
||||||
# and you must add additional flags. This is marked as ADVANCED.
|
|
||||||
# SDL_SOUND_VERSION_STRING, human-readable string containing the version of SDL_sound
|
|
||||||
#
|
|
||||||
# This module also defines (but you shouldn't need to use directly)
|
|
||||||
# SDL_SOUND_LIBRARY, the name of just the SDL_sound library you would link
|
|
||||||
# against. Use SDL_SOUND_LIBRARIES for you link instructions and not this one.
|
|
||||||
# And might define the following as needed
|
|
||||||
# MIKMOD_LIBRARY
|
|
||||||
# MODPLUG_LIBRARY
|
|
||||||
# OGG_LIBRARY
|
|
||||||
# VORBIS_LIBRARY
|
|
||||||
# SMPEG_LIBRARY
|
|
||||||
# FLAC_LIBRARY
|
|
||||||
# SPEEX_LIBRARY
|
|
||||||
#
|
|
||||||
# Typically, you should not use these variables directly, and you should use
|
|
||||||
# SDL_SOUND_LIBRARIES which contains SDL_SOUND_LIBRARY and the other audio libraries
|
|
||||||
# (if needed) to successfully compile on your system.
|
|
||||||
#
|
|
||||||
# Created by Eric Wing.
|
|
||||||
# This module is a bit more complicated than the other FindSDL* family modules.
|
|
||||||
# The reason is that SDL_sound can be compiled in a large variety of different ways
|
|
||||||
# which are independent of platform. SDL_sound may dynamically link against other 3rd
|
|
||||||
# party libraries to get additional codec support, such as Ogg Vorbis, SMPEG, ModPlug,
|
|
||||||
# MikMod, FLAC, Speex, and potentially others.
|
|
||||||
# Under some circumstances which I don't fully understand,
|
|
||||||
# there seems to be a requirement
|
|
||||||
# that dependent libraries of libraries you use must also be explicitly
|
|
||||||
# linked against in order to successfully compile. SDL_sound does not currently
|
|
||||||
# have any system in place to know how it was compiled.
|
|
||||||
# So this CMake module does the hard work in trying to discover which 3rd party
|
|
||||||
# libraries are required for building (if any).
|
|
||||||
# This module uses a brute force approach to create a test program that uses SDL_sound,
|
|
||||||
# and then tries to build it. If the build fails, it parses the error output for
|
|
||||||
# known symbol names to figure out which libraries are needed.
|
|
||||||
#
|
|
||||||
# Responds to the $SDLDIR and $SDLSOUNDDIR environmental variable that would
|
|
||||||
# correspond to the ./configure --prefix=$SDLDIR used in building SDL.
|
|
||||||
#
|
|
||||||
# On OSX, this will prefer the Framework version (if found) over others.
|
|
||||||
# People will have to manually change the cache values of
|
|
||||||
# SDL_LIBRARY to override this selectionor set the CMake environment
|
|
||||||
# CMAKE_INCLUDE_PATH to modify the search paths.
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Copyright 2005-2009 Kitware, Inc.
|
|
||||||
# Copyright 2012 Benjamin Eikel
|
|
||||||
#
|
|
||||||
# Distributed under the OSI-approved BSD License (the "License");
|
|
||||||
# see accompanying file Copyright.txt for details.
|
|
||||||
#
|
|
||||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
||||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the License for more information.
|
|
||||||
#=============================================================================
|
|
||||||
# (To distribute this file outside of CMake, substitute the full
|
|
||||||
# License text for the above reference.)
|
|
||||||
|
|
||||||
set(SDL_SOUND_EXTRAS "" CACHE STRING "SDL_sound extra flags")
|
|
||||||
mark_as_advanced(SDL_SOUND_EXTRAS)
|
|
||||||
|
|
||||||
# Find SDL_sound.h
|
|
||||||
find_path(SDL_SOUND_INCLUDE_DIR SDL_sound.h
|
|
||||||
HINTS
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
PATH_SUFFIXES SDL SDL12 SDL11
|
|
||||||
)
|
|
||||||
|
|
||||||
find_library(SDL_SOUND_LIBRARY
|
|
||||||
NAMES SDL_sound
|
|
||||||
HINTS
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
)
|
|
||||||
|
|
||||||
if(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
|
|
||||||
|
|
||||||
# CMake is giving me problems using TRY_COMPILE with the CMAKE_FLAGS
|
|
||||||
# for the :STRING syntax if I have multiple values contained in a
|
|
||||||
# single variable. This is a problem for the SDL_LIBRARY variable
|
|
||||||
# because it does just that. When I feed this variable to the command,
|
|
||||||
# only the first value gets the appropriate modifier (e.g. -I) and
|
|
||||||
# the rest get dropped.
|
|
||||||
# To get multiple single variables to work, I must separate them with a "\;"
|
|
||||||
# I could go back and modify the FindSDL.cmake module, but that's kind of painful.
|
|
||||||
# The solution would be to try something like:
|
|
||||||
# set(SDL_TRY_COMPILE_LIBRARY_LIST "${SDL_TRY_COMPILE_LIBRARY_LIST}\;${CMAKE_THREAD_LIBS_INIT}")
|
|
||||||
# Instead, it was suggested on the mailing list to write a temporary CMakeLists.txt
|
|
||||||
# with a temporary test project and invoke that with TRY_COMPILE.
|
|
||||||
# See message thread "Figuring out dependencies for a library in order to build"
|
|
||||||
# 2005-07-16
|
|
||||||
# try_compile(
|
|
||||||
# MY_RESULT
|
|
||||||
# ${CMAKE_BINARY_DIR}
|
|
||||||
# ${PROJECT_SOURCE_DIR}/DetermineSoundLibs.c
|
|
||||||
# CMAKE_FLAGS
|
|
||||||
# -DINCLUDE_DIRECTORIES:STRING=${SDL_INCLUDE_DIR}\;${SDL_SOUND_INCLUDE_DIR}
|
|
||||||
# -DLINK_LIBRARIES:STRING=${SDL_SOUND_LIBRARY}\;${SDL_LIBRARY}
|
|
||||||
# OUTPUT_VARIABLE MY_OUTPUT
|
|
||||||
# )
|
|
||||||
|
|
||||||
# To minimize external dependencies, create a sdlsound test program
|
|
||||||
# which will be used to figure out if additional link dependencies are
|
|
||||||
# required for the link phase.
|
|
||||||
file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/DetermineSoundLibs.c
|
|
||||||
"#include \"SDL_sound.h\"
|
|
||||||
#include \"SDL.h\"
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
Sound_AudioInfo desired;
|
|
||||||
Sound_Sample* sample;
|
|
||||||
|
|
||||||
SDL_Init(0);
|
|
||||||
Sound_Init();
|
|
||||||
|
|
||||||
/* This doesn't actually have to work, but Init() is a no-op
|
|
||||||
* for some of the decoders, so this should force more symbols
|
|
||||||
* to be pulled in.
|
|
||||||
*/
|
|
||||||
sample = Sound_NewSampleFromFile(argv[1], &desired, 4096);
|
|
||||||
|
|
||||||
Sound_Quit();
|
|
||||||
SDL_Quit();
|
|
||||||
return 0;
|
|
||||||
}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Calling
|
|
||||||
# target_link_libraries(DetermineSoundLibs "${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
|
|
||||||
# causes problems when SDL_LIBRARY looks like
|
|
||||||
# /Library/Frameworks/SDL.framework;-framework Cocoa
|
|
||||||
# The ;-framework Cocoa seems to be confusing CMake once the OS X
|
|
||||||
# framework support was added. I was told that breaking up the list
|
|
||||||
# would fix the problem.
|
|
||||||
set(TMP_TRY_LIBS)
|
|
||||||
foreach(lib ${SDL_SOUND_LIBRARY} ${SDL_LIBRARY})
|
|
||||||
set(TMP_TRY_LIBS "${TMP_TRY_LIBS} \"${lib}\"")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# message("TMP_TRY_LIBS ${TMP_TRY_LIBS}")
|
|
||||||
|
|
||||||
# Write the CMakeLists.txt and test project
|
|
||||||
# Weird, this is still sketchy. If I don't quote the variables
|
|
||||||
# in the TARGET_LINK_LIBRARIES, I seem to loose everything
|
|
||||||
# in the SDL_LIBRARY string after the "-framework".
|
|
||||||
# But if I quote the stuff in INCLUDE_DIRECTORIES, it doesn't work.
|
|
||||||
file(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/CMakeLists.txt
|
|
||||||
"cmake_minimum_required(VERSION 2.8)
|
|
||||||
project(DetermineSoundLibs C)
|
|
||||||
include_directories(${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
|
|
||||||
add_executable(DetermineSoundLibs DetermineSoundLibs.c)
|
|
||||||
target_link_libraries(DetermineSoundLibs ${TMP_TRY_LIBS})"
|
|
||||||
)
|
|
||||||
|
|
||||||
try_compile(
|
|
||||||
MY_RESULT
|
|
||||||
${PROJECT_BINARY_DIR}/CMakeTmp
|
|
||||||
${PROJECT_BINARY_DIR}/CMakeTmp
|
|
||||||
DetermineSoundLibs
|
|
||||||
OUTPUT_VARIABLE MY_OUTPUT
|
|
||||||
)
|
|
||||||
|
|
||||||
# message("${MY_RESULT}")
|
|
||||||
# message(${MY_OUTPUT})
|
|
||||||
|
|
||||||
if(NOT MY_RESULT)
|
|
||||||
|
|
||||||
# I expect that MPGLIB, VOC, WAV, AIFF, and SHN are compiled in statically.
|
|
||||||
# I think Timidity is also compiled in statically.
|
|
||||||
# I've never had to explcitly link against Quicktime, so I'll skip that for now.
|
|
||||||
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY})
|
|
||||||
|
|
||||||
# Find MikMod
|
|
||||||
if("${MY_OUTPUT}" MATCHES "MikMod_")
|
|
||||||
find_library(MIKMOD_LIBRARY
|
|
||||||
NAMES libmikmod-coreaudio mikmod
|
|
||||||
PATHS
|
|
||||||
ENV MIKMODDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(MIKMOD_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MIKMOD_LIBRARY})
|
|
||||||
endif(MIKMOD_LIBRARY)
|
|
||||||
endif("${MY_OUTPUT}" MATCHES "MikMod_")
|
|
||||||
|
|
||||||
# Find ModPlug
|
|
||||||
if("${MY_OUTPUT}" MATCHES "MODPLUG_")
|
|
||||||
find_library(MODPLUG_LIBRARY
|
|
||||||
NAMES modplug
|
|
||||||
PATHS
|
|
||||||
ENV MODPLUGDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(MODPLUG_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${MODPLUG_LIBRARY})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Find Ogg and Vorbis
|
|
||||||
if("${MY_OUTPUT}" MATCHES "ov_")
|
|
||||||
find_library(VORBIS_LIBRARY
|
|
||||||
NAMES vorbis Vorbis VORBIS
|
|
||||||
PATHS
|
|
||||||
ENV VORBISDIR
|
|
||||||
ENV OGGDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(VORBIS_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${VORBIS_LIBRARY})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_library(OGG_LIBRARY
|
|
||||||
NAMES ogg Ogg OGG
|
|
||||||
PATHS
|
|
||||||
ENV OGGDIR
|
|
||||||
ENV VORBISDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(OGG_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Find SMPEG
|
|
||||||
if("${MY_OUTPUT}" MATCHES "SMPEG_")
|
|
||||||
find_library(SMPEG_LIBRARY
|
|
||||||
NAMES smpeg SMPEG Smpeg SMpeg
|
|
||||||
PATHS
|
|
||||||
ENV SMPEGDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(SMPEG_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SMPEG_LIBRARY})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Find FLAC
|
|
||||||
if("${MY_OUTPUT}" MATCHES "FLAC_")
|
|
||||||
find_library(FLAC_LIBRARY
|
|
||||||
NAMES flac FLAC
|
|
||||||
PATHS
|
|
||||||
ENV FLACDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(FLAC_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${FLAC_LIBRARY})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Hmmm...Speex seems to depend on Ogg. This might be a problem if
|
|
||||||
# the TRY_COMPILE attempt gets blocked at SPEEX before it can pull
|
|
||||||
# in the Ogg symbols. I'm not sure if I should duplicate the ogg stuff
|
|
||||||
# above for here or if two ogg entries will screw up things.
|
|
||||||
if("${MY_OUTPUT}" MATCHES "speex_")
|
|
||||||
find_library(SPEEX_LIBRARY
|
|
||||||
NAMES speex SPEEX
|
|
||||||
PATHS
|
|
||||||
ENV SPEEXDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib
|
|
||||||
)
|
|
||||||
if(SPEEX_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${SPEEX_LIBRARY})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Find OGG (needed for Speex)
|
|
||||||
# We might have already found Ogg for Vorbis, so skip it if so.
|
|
||||||
if(NOT OGG_LIBRARY)
|
|
||||||
find_library(OGG_LIBRARY
|
|
||||||
NAMES ogg Ogg OGG
|
|
||||||
PATHS
|
|
||||||
ENV OGGDIR
|
|
||||||
ENV VORBISDIR
|
|
||||||
ENV SPEEXDIR
|
|
||||||
ENV SDLSOUNDDIR
|
|
||||||
ENV SDLDIR
|
|
||||||
/sw
|
|
||||||
/opt/local
|
|
||||||
/opt/csw
|
|
||||||
/opt
|
|
||||||
PATH_SUFFIXES lib
|
|
||||||
)
|
|
||||||
if(OGG_LIBRARY)
|
|
||||||
set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP} CACHE INTERNAL "SDL_sound and dependent libraries")
|
|
||||||
else()
|
|
||||||
set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARY} CACHE INTERNAL "SDL_sound and dependent libraries")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(SDL_SOUND_INCLUDE_DIR AND EXISTS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h")
|
|
||||||
file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SOUND_VER_MAJOR[ \t]+[0-9]+$")
|
|
||||||
file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_MINOR_LINE REGEX "^#define[ \t]+SOUND_VER_MINOR[ \t]+[0-9]+$")
|
|
||||||
file(STRINGS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h" SDL_SOUND_VERSION_PATCH_LINE REGEX "^#define[ \t]+SOUND_VER_PATCH[ \t]+[0-9]+$")
|
|
||||||
string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MAJOR "${SDL_SOUND_VERSION_MAJOR_LINE}")
|
|
||||||
string(REGEX REPLACE "^#define[ \t]+SOUND_VER_MINOR[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_MINOR "${SDL_SOUND_VERSION_MINOR_LINE}")
|
|
||||||
string(REGEX REPLACE "^#define[ \t]+SOUND_VER_PATCH[ \t]+([0-9]+)$" "\\1" SDL_SOUND_VERSION_PATCH "${SDL_SOUND_VERSION_PATCH_LINE}")
|
|
||||||
set(SDL_SOUND_VERSION_STRING ${SDL_SOUND_VERSION_MAJOR}.${SDL_SOUND_VERSION_MINOR}.${SDL_SOUND_VERSION_PATCH})
|
|
||||||
unset(SDL_SOUND_VERSION_MAJOR_LINE)
|
|
||||||
unset(SDL_SOUND_VERSION_MINOR_LINE)
|
|
||||||
unset(SDL_SOUND_VERSION_PATCH_LINE)
|
|
||||||
unset(SDL_SOUND_VERSION_MAJOR)
|
|
||||||
unset(SDL_SOUND_VERSION_MINOR)
|
|
||||||
unset(SDL_SOUND_VERSION_PATCH)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
|
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_sound
|
|
||||||
REQUIRED_VARS SDL_SOUND_LIBRARY SDL_SOUND_INCLUDE_DIR
|
|
||||||
VERSION_VAR SDL_SOUND_VERSION_STRING)
|
|
|
@ -222,22 +222,11 @@ else( WIN32 )
|
||||||
endif( WIN32 )
|
endif( WIN32 )
|
||||||
|
|
||||||
|
|
||||||
set( OAL_SOURCES sound/oalsound.cpp )
|
|
||||||
if( NOT NO_OPENAL )
|
if( NOT NO_OPENAL )
|
||||||
find_package( OpenAL )
|
find_package( OpenAL )
|
||||||
if( OPENAL_FOUND )
|
if( OPENAL_FOUND )
|
||||||
include_directories( ${OPENAL_INCLUDE_DIR} )
|
include_directories( ${OPENAL_INCLUDE_DIR} )
|
||||||
set( ZDOOM_LIBS ${OPENAL_LIBRARY} ${ZDOOM_LIBS} )
|
set( ZDOOM_LIBS ${OPENAL_LIBRARY} ${ZDOOM_LIBS} )
|
||||||
find_package( SDL )
|
|
||||||
if( SDL_FOUND )
|
|
||||||
find_package( SDL_sound )
|
|
||||||
if( SDL_SOUND_FOUND )
|
|
||||||
set_source_files_properties( sound/oalsound.cpp PROPERTIES COMPILE_FLAGS "-DWITH_SDL_SOUND=1" )
|
|
||||||
set( OAL_SOURCES ${OAL_SOURCES} sound/oalsdlsound.cpp )
|
|
||||||
include_directories( ${SDL_SOUND_INCLUDE_DIR} )
|
|
||||||
set( ZDOOM_LIBS ${SDL_SOUND_LIBRARIES} ${ZDOOM_LIBS} )
|
|
||||||
endif( SDL_SOUND_FOUND )
|
|
||||||
endif( SDL_FOUND )
|
|
||||||
else( OPENAL_FOUND )
|
else( OPENAL_FOUND )
|
||||||
set( NO_OPENAL ON )
|
set( NO_OPENAL ON )
|
||||||
endif( OPENAL_FOUND )
|
endif( OPENAL_FOUND )
|
||||||
|
@ -1065,7 +1054,7 @@ add_executable( zdoom WIN32
|
||||||
sound/music_softsynth_mididevice.cpp
|
sound/music_softsynth_mididevice.cpp
|
||||||
sound/music_timidity_mididevice.cpp
|
sound/music_timidity_mididevice.cpp
|
||||||
sound/music_win_mididevice.cpp
|
sound/music_win_mididevice.cpp
|
||||||
${OAL_SOURCES}
|
sound/oalsound.cpp
|
||||||
sound/music_pseudo_mididevice.cpp
|
sound/music_pseudo_mididevice.cpp
|
||||||
textures/animations.cpp
|
textures/animations.cpp
|
||||||
textures/anim_switches.cpp
|
textures/anim_switches.cpp
|
||||||
|
|
|
@ -1,593 +0,0 @@
|
||||||
/*
|
|
||||||
** oalsdlsound.cpp
|
|
||||||
** Interface for SDL_sound; uses OpenAL
|
|
||||||
**
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
** Copyright 2008-2010 Chris Robinson
|
|
||||||
** All rights reserved.
|
|
||||||
**
|
|
||||||
** Redistribution and use in source and binary forms, with or without
|
|
||||||
** modification, are permitted provided that the following conditions
|
|
||||||
** are met:
|
|
||||||
**
|
|
||||||
** 1. Redistributions of source code must retain the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer.
|
|
||||||
** 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
|
||||||
** documentation and/or other materials provided with the distribution.
|
|
||||||
** 3. The name of the author may not be used to endorse or promote products
|
|
||||||
** derived from this software without specific prior written permission.
|
|
||||||
**
|
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
**---------------------------------------------------------------------------
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#define USE_WINDOWS_DWORD
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "doomstat.h"
|
|
||||||
#include "templates.h"
|
|
||||||
#include "oalsound.h"
|
|
||||||
#include "oalsdlsound.h"
|
|
||||||
#include "c_cvars.h"
|
|
||||||
#include "c_dispatch.h"
|
|
||||||
#include "i_system.h"
|
|
||||||
#include "v_text.h"
|
|
||||||
#include "gi.h"
|
|
||||||
#include "actor.h"
|
|
||||||
#include "r_state.h"
|
|
||||||
#include "w_wad.h"
|
|
||||||
#include "i_music.h"
|
|
||||||
#include "i_musicinterns.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
|
||||||
struct RWSubFile {
|
|
||||||
private:
|
|
||||||
FILE *fp;
|
|
||||||
size_t start;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RWSubFile(FILE *f, size_t offset, size_t len)
|
|
||||||
: fp(f), start(offset), length(len)
|
|
||||||
{
|
|
||||||
fseek(fp, start, SEEK_SET);
|
|
||||||
}
|
|
||||||
~RWSubFile()
|
|
||||||
{ fclose(fp); }
|
|
||||||
|
|
||||||
static int seek(SDL_RWops *context, int offset, int whence)
|
|
||||||
{
|
|
||||||
RWSubFile *self = static_cast<RWSubFile*>(context->hidden.unknown.data1);
|
|
||||||
|
|
||||||
if(whence == SEEK_END)
|
|
||||||
{
|
|
||||||
if(offset <= 0)
|
|
||||||
offset = self->length + offset;
|
|
||||||
}
|
|
||||||
else if(whence == SEEK_CUR)
|
|
||||||
offset = offset + ftell(self->fp) - self->start;
|
|
||||||
else if(whence != SEEK_SET)
|
|
||||||
{
|
|
||||||
SDL_SetError("Invalid seek mode");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(offset >= 0 && size_t(offset) <= self->length)
|
|
||||||
{
|
|
||||||
if(fseek(self->fp, offset + self->start, SEEK_SET) == 0)
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetError("Invalid file seek");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read(SDL_RWops *context, void *ptr, int size, int maxnum)
|
|
||||||
{
|
|
||||||
RWSubFile *self = static_cast<RWSubFile*>(context->hidden.unknown.data1);
|
|
||||||
return fread(ptr, size, maxnum, self->fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int write(SDL_RWops *context, const void *ptr, int size, int num)
|
|
||||||
{
|
|
||||||
RWSubFile *self = static_cast<RWSubFile*>(context->hidden.unknown.data1);
|
|
||||||
return fwrite(ptr, size, num, self->fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int close(SDL_RWops *context)
|
|
||||||
{
|
|
||||||
RWSubFile *self = static_cast<RWSubFile*>(context->hidden.unknown.data1);
|
|
||||||
if(context->type != 0xdeadbeef)
|
|
||||||
{
|
|
||||||
SDL_SetError("Wrong kind of RWops for RWSubfile::close");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete self;
|
|
||||||
SDL_FreeRW(context);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ALenum checkALError(const char *fn, unsigned int ln)
|
|
||||||
{
|
|
||||||
ALenum err = alGetError();
|
|
||||||
if(err != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
if(strchr(fn, '/'))
|
|
||||||
fn = strrchr(fn, '/')+1;
|
|
||||||
else if(strchr(fn, '\\'))
|
|
||||||
fn = strrchr(fn, '\\')+1;
|
|
||||||
Printf(">>>>>>>>>>>> Received AL error %s (%#x), %s:%u\n", alGetString(err), err, fn, ln);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
#define getALError() checkALError(__FILE__, __LINE__)
|
|
||||||
|
|
||||||
|
|
||||||
bool OpenALSoundStream::SetupSource()
|
|
||||||
{
|
|
||||||
if(Renderer->FreeSfx.size() == 0)
|
|
||||||
{
|
|
||||||
FSoundChan *lowest = Renderer->FindLowestChannel();
|
|
||||||
if(lowest) Renderer->StopChannel(lowest);
|
|
||||||
|
|
||||||
if(Renderer->FreeSfx.size() == 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Source = Renderer->FreeSfx.back();
|
|
||||||
Renderer->FreeSfx.pop_back();
|
|
||||||
|
|
||||||
alSource3f(Source, AL_DIRECTION, 0.f, 0.f, 0.f);
|
|
||||||
alSource3f(Source, AL_VELOCITY, 0.f, 0.f, 0.f);
|
|
||||||
alSource3f(Source, AL_POSITION, 0.f, 0.f, 0.f);
|
|
||||||
alSourcef(Source, AL_MAX_GAIN, Renderer->MusicVolume);
|
|
||||||
alSourcef(Source, AL_GAIN, Volume*Renderer->MusicVolume);
|
|
||||||
alSourcef(Source, AL_PITCH, 1.f);
|
|
||||||
alSourcef(Source, AL_ROLLOFF_FACTOR, 0.f);
|
|
||||||
alSourcef(Source, AL_SEC_OFFSET, 0.f);
|
|
||||||
alSourcei(Source, AL_SOURCE_RELATIVE, AL_TRUE);
|
|
||||||
alSourcei(Source, AL_LOOPING, AL_FALSE);
|
|
||||||
if(Renderer->EnvSlot)
|
|
||||||
{
|
|
||||||
alSourcef(Source, AL_ROOM_ROLLOFF_FACTOR, 0.f);
|
|
||||||
alSourcef(Source, AL_AIR_ABSORPTION_FACTOR, 0.f);
|
|
||||||
alSourcei(Source, AL_DIRECT_FILTER, AL_FILTER_NULL);
|
|
||||||
alSource3i(Source, AL_AUXILIARY_SEND_FILTER, 0, 0, AL_FILTER_NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
alGenBuffers(Buffers.size(), &Buffers[0]);
|
|
||||||
return (getALError() == AL_NO_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenALSoundStream::OpenALSoundStream(OpenALSoundRenderer *renderer)
|
|
||||||
: Renderer(renderer), Sample(NULL), Source(0), Playing(false),
|
|
||||||
Looping(false), Buffers(4), SampleRate(0), Format(0),
|
|
||||||
NeedSwab(false), NeedS8Conv(false), NeedS16Conv(false),
|
|
||||||
Volume(1.f)
|
|
||||||
{
|
|
||||||
for(size_t i = 0;i < Buffers.size();i++)
|
|
||||||
Buffers[i] = 0;
|
|
||||||
Renderer->Streams.push_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenALSoundStream::~OpenALSoundStream()
|
|
||||||
{
|
|
||||||
Playing = false;
|
|
||||||
|
|
||||||
Sound_FreeSample(Sample);
|
|
||||||
Sample = NULL;
|
|
||||||
|
|
||||||
if(Source)
|
|
||||||
{
|
|
||||||
alSourceRewind(Source);
|
|
||||||
alSourcei(Source, AL_BUFFER, 0);
|
|
||||||
|
|
||||||
Renderer->FreeSfx.push_back(Source);
|
|
||||||
Source = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Buffers.size() > 0)
|
|
||||||
{
|
|
||||||
alDeleteBuffers(Buffers.size(), &Buffers[0]);
|
|
||||||
Buffers.clear();
|
|
||||||
}
|
|
||||||
getALError();
|
|
||||||
|
|
||||||
Renderer->Streams.erase(std::find(Renderer->Streams.begin(),
|
|
||||||
Renderer->Streams.end(), this));
|
|
||||||
Renderer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::Play(bool looping, float vol)
|
|
||||||
{
|
|
||||||
if(Playing)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
alSourceRewind(Source);
|
|
||||||
alSourcei(Source, AL_BUFFER, 0);
|
|
||||||
|
|
||||||
Looping = looping;
|
|
||||||
SetVolume(vol);
|
|
||||||
|
|
||||||
for(size_t i = 0;i < Buffers.size();i++)
|
|
||||||
{
|
|
||||||
size_t count = Sound_Decode(Sample);
|
|
||||||
if(count == 0 && Looping)
|
|
||||||
{
|
|
||||||
Sound_Seek(Sample, 0);
|
|
||||||
count = Sound_Decode(Sample);
|
|
||||||
}
|
|
||||||
alBufferData(Buffers[i], Format, GetData(count), count, SampleRate);
|
|
||||||
}
|
|
||||||
Playing = (getALError() == AL_NO_ERROR);
|
|
||||||
if(Playing)
|
|
||||||
{
|
|
||||||
alSourceQueueBuffers(Source, Buffers.size(), &Buffers[0]);
|
|
||||||
alSourcePlay(Source);
|
|
||||||
Playing = (getALError() == AL_NO_ERROR);
|
|
||||||
}
|
|
||||||
return Playing;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenALSoundStream::Stop()
|
|
||||||
{
|
|
||||||
alSourceRewind(Source);
|
|
||||||
alSourcei(Source, AL_BUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::SetPaused(bool paused)
|
|
||||||
{
|
|
||||||
if(paused) alSourcePause(Source);
|
|
||||||
else alSourcePlay(Source);
|
|
||||||
return (getALError() == AL_NO_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenALSoundStream::SetVolume(float vol)
|
|
||||||
{
|
|
||||||
if(vol >= 0.f) Volume = vol;
|
|
||||||
alSourcef(Source, AL_GAIN, Volume*Renderer->MusicVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int OpenALSoundStream::GetPosition()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::SetPosition(unsigned int val)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::IsEnded()
|
|
||||||
{
|
|
||||||
if(!Playing)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
ALint processed, state, queued;
|
|
||||||
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
while(processed-- > 0)
|
|
||||||
{
|
|
||||||
ALuint buf = 0;
|
|
||||||
alSourceUnqueueBuffers(Source, 1, &buf);
|
|
||||||
queued--;
|
|
||||||
|
|
||||||
size_t count = Sound_Decode(Sample);
|
|
||||||
if(count == 0 && Looping)
|
|
||||||
{
|
|
||||||
Sound_Seek(Sample, 0);
|
|
||||||
count = Sound_Decode(Sample);
|
|
||||||
}
|
|
||||||
if(count > 0)
|
|
||||||
{
|
|
||||||
alBufferData(buf, Format, GetData(count), count, SampleRate);
|
|
||||||
alSourceQueueBuffers(Source, 1, &buf);
|
|
||||||
queued++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Playing = (getALError() == AL_NO_ERROR && queued > 0);
|
|
||||||
if(Playing && state != AL_PLAYING && state != AL_PAUSED)
|
|
||||||
{
|
|
||||||
alSourcePlay(Source);
|
|
||||||
Playing = (getALError() == AL_NO_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Playing;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *OpenALSoundStream::GetData(size_t bytes)
|
|
||||||
{
|
|
||||||
void *data = Sample->buffer;
|
|
||||||
if(NeedSwab)
|
|
||||||
{
|
|
||||||
short *samples = reinterpret_cast<short*>(data);
|
|
||||||
size_t count = bytes >> 1;
|
|
||||||
for(size_t i = 0;i < count;i++)
|
|
||||||
{
|
|
||||||
short smp = *samples;
|
|
||||||
*(samples++) = ((smp>>8)&0x00FF) | ((smp<<8)&0xFF00);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(NeedS8Conv)
|
|
||||||
{
|
|
||||||
char *samples = reinterpret_cast<char*>(data);
|
|
||||||
for(size_t i = 0;i < bytes;i++)
|
|
||||||
samples[i] = samples[i]^0x80;
|
|
||||||
}
|
|
||||||
if(NeedS16Conv)
|
|
||||||
{
|
|
||||||
short *samples = reinterpret_cast<short*>(data);
|
|
||||||
size_t count = bytes >> 1;
|
|
||||||
for(size_t i = 0;i < count;i++)
|
|
||||||
samples[i] = samples[i]^0x8000;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
FString OpenALSoundStream::GetStats()
|
|
||||||
{
|
|
||||||
FString stats;
|
|
||||||
ALfloat volume;
|
|
||||||
ALint processed;
|
|
||||||
ALint queued;
|
|
||||||
ALint state;
|
|
||||||
ALenum err;
|
|
||||||
|
|
||||||
alGetSourcef(Source, AL_GAIN, &volume);
|
|
||||||
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
|
|
||||||
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
if((err=alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
stats = "Error getting stats: ";
|
|
||||||
stats += alGetString(err);
|
|
||||||
return stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
stats = (state == AL_INITIAL) ? "Buffering" : (state == AL_STOPPED) ? "Underrun" :
|
|
||||||
(state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state";
|
|
||||||
stats.AppendFormat(",%3d%% buffered", (queued ? 100-(processed*100/queued) : 0));
|
|
||||||
stats.AppendFormat(", %d%%", int(volume * 100));
|
|
||||||
if(state == AL_PAUSED)
|
|
||||||
stats += ", paused";
|
|
||||||
if(state == AL_PLAYING)
|
|
||||||
stats += ", playing";
|
|
||||||
stats.AppendFormat(", %uHz", SampleRate);
|
|
||||||
if(!Playing)
|
|
||||||
stats += " XX";
|
|
||||||
return stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool OpenALSoundStream::InitSample()
|
|
||||||
{
|
|
||||||
UInt32 smpsize = 0;
|
|
||||||
SampleRate = Sample->actual.rate;
|
|
||||||
|
|
||||||
Format = AL_NONE;
|
|
||||||
if(Sample->actual.format == AUDIO_S8)
|
|
||||||
{
|
|
||||||
NeedS8Conv = true;
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
Format = AL_FORMAT_MONO8;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
Format = AL_FORMAT_STEREO8;
|
|
||||||
smpsize = 1 * Sample->actual.channels;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_U8)
|
|
||||||
{
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
Format = AL_FORMAT_MONO8;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
Format = AL_FORMAT_STEREO8;
|
|
||||||
smpsize = 1 * Sample->actual.channels;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_S16LSB || Sample->actual.format == AUDIO_S16MSB)
|
|
||||||
{
|
|
||||||
NeedSwab = (Sample->actual.format != AUDIO_S16SYS);
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
Format = AL_FORMAT_MONO16;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
Format = AL_FORMAT_STEREO16;
|
|
||||||
smpsize = 2 * Sample->actual.channels;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_U16LSB || Sample->actual.format == AUDIO_U16MSB)
|
|
||||||
{
|
|
||||||
NeedS16Conv = true;
|
|
||||||
NeedSwab = (Sample->actual.format != AUDIO_U16SYS);
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
Format = AL_FORMAT_MONO16;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
Format = AL_FORMAT_STEREO16;
|
|
||||||
smpsize = 2 * Sample->actual.channels;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Format == AL_NONE)
|
|
||||||
{
|
|
||||||
Printf("Unsupported sound format (0x%04x, %d channels)\n", Sample->actual.format, Sample->actual.channels);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint32 bufsize = (UInt32)(BufferTime*SampleRate) * smpsize;
|
|
||||||
if(Sound_SetBufferSize(Sample, bufsize) == 0)
|
|
||||||
{
|
|
||||||
Printf("Failed to set buffer size to %u bytes: %s\n", bufsize, Sound_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::Init(const char *filename, int offset, int length)
|
|
||||||
{
|
|
||||||
if(!SetupSource())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(offset == 0)
|
|
||||||
Sample = Sound_NewSampleFromFile(filename, NULL, 0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FILE *fp = fopen(filename, "rb");
|
|
||||||
if(!fp)
|
|
||||||
{
|
|
||||||
Printf("Failed to open %s\n", filename);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *ext = strrchr(filename, '.');
|
|
||||||
if(ext) ext++;
|
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_AllocRW();
|
|
||||||
ops->seek = RWSubFile::seek;
|
|
||||||
ops->read = RWSubFile::read;
|
|
||||||
ops->write = RWSubFile::write;
|
|
||||||
ops->close = RWSubFile::close;
|
|
||||||
ops->type = 0xdeadbeef;
|
|
||||||
ops->hidden.unknown.data1 = new RWSubFile(fp, offset, length);
|
|
||||||
|
|
||||||
Sample = Sound_NewSample(ops, ext, NULL, 0);
|
|
||||||
}
|
|
||||||
if(!Sample)
|
|
||||||
{
|
|
||||||
Printf("Could not open audio in %s (%s)\n", filename, Sound_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InitSample();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenALSoundStream::Init(const BYTE *data, unsigned int datalen)
|
|
||||||
{
|
|
||||||
if(!SetupSource())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Sample = Sound_NewSample(SDL_RWFromConstMem(data, datalen), NULL, NULL, 0);
|
|
||||||
if(!Sample)
|
|
||||||
{
|
|
||||||
Printf("Could not read audio: %s\n", Sound_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InitSample();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Decoder::Decoder(const void* data, unsigned int datalen)
|
|
||||||
: Sample(NULL), NeedSwab(false), NeedS8Conv(false), NeedS16Conv(false)
|
|
||||||
{
|
|
||||||
Sample = Sound_NewSample(SDL_RWFromConstMem(data, datalen), NULL, NULL, 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Decoder::~Decoder()
|
|
||||||
{
|
|
||||||
Sound_FreeSample(Sample);
|
|
||||||
Sample = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Decoder::GetFormat(ALenum *format, ALuint *rate)
|
|
||||||
{
|
|
||||||
ALenum fmt = AL_NONE;
|
|
||||||
if(Sample->actual.format == AUDIO_S8)
|
|
||||||
{
|
|
||||||
NeedS8Conv = true;
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
fmt = AL_FORMAT_MONO8;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
fmt = AL_FORMAT_STEREO8;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_U8)
|
|
||||||
{
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
fmt = AL_FORMAT_MONO8;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
fmt = AL_FORMAT_STEREO8;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_S16LSB || Sample->actual.format == AUDIO_S16MSB)
|
|
||||||
{
|
|
||||||
NeedSwab = (Sample->actual.format != AUDIO_S16SYS);
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
fmt = AL_FORMAT_MONO16;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
fmt = AL_FORMAT_STEREO16;
|
|
||||||
}
|
|
||||||
else if(Sample->actual.format == AUDIO_U16LSB || Sample->actual.format == AUDIO_U16MSB)
|
|
||||||
{
|
|
||||||
NeedS16Conv = true;
|
|
||||||
NeedSwab = (Sample->actual.format != AUDIO_U16SYS);
|
|
||||||
if(Sample->actual.channels == 1)
|
|
||||||
fmt = AL_FORMAT_MONO16;
|
|
||||||
else if(Sample->actual.channels == 2)
|
|
||||||
fmt = AL_FORMAT_STEREO16;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fmt == AL_NONE)
|
|
||||||
{
|
|
||||||
Printf("Unsupported sound format (0x%04x, %d channels)\n", Sample->actual.format, Sample->actual.channels);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*format = fmt;
|
|
||||||
*rate = Sample->actual.rate;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Decoder::GetData(ALsizei *size)
|
|
||||||
{
|
|
||||||
UInt32 got = Sound_DecodeAll(Sample);
|
|
||||||
if(got == 0)
|
|
||||||
{
|
|
||||||
*size = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *data = Sample->buffer;
|
|
||||||
if(NeedSwab)
|
|
||||||
{
|
|
||||||
short *samples = reinterpret_cast<short*>(data);
|
|
||||||
size_t count = got >> 1;
|
|
||||||
for(size_t i = 0;i < count;i++)
|
|
||||||
{
|
|
||||||
short smp = *samples;
|
|
||||||
*(samples++) = ((smp>>8)&0x00FF) | ((smp<<8)&0xFF00);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NeedS8Conv)
|
|
||||||
{
|
|
||||||
char *samples = reinterpret_cast<char*>(data);
|
|
||||||
for(size_t i = 0;i < got;i++)
|
|
||||||
samples[i] = samples[i]^0x80;
|
|
||||||
}
|
|
||||||
if(NeedS16Conv)
|
|
||||||
{
|
|
||||||
short *samples = reinterpret_cast<short*>(data);
|
|
||||||
size_t count = got >> 1;
|
|
||||||
for(size_t i = 0;i < count;i++)
|
|
||||||
samples[i] = samples[i]^0x8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
*size = got;
|
|
||||||
return data;
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
#ifndef OALSDLSOUND_H
|
|
||||||
#define OALSDLSOUND_H
|
|
||||||
|
|
||||||
#include "oalsound.h"
|
|
||||||
#include "tempfiles.h"
|
|
||||||
|
|
||||||
#include "SDL_sound.h"
|
|
||||||
|
|
||||||
class OpenALSoundStream : public SoundStream
|
|
||||||
{
|
|
||||||
OpenALSoundRenderer *Renderer;
|
|
||||||
Sound_Sample *Sample;
|
|
||||||
ALuint Source;
|
|
||||||
|
|
||||||
bool Playing;
|
|
||||||
bool Looping;
|
|
||||||
|
|
||||||
static const ALfloat BufferTime = 0.2f;
|
|
||||||
std::vector<ALuint> Buffers;
|
|
||||||
|
|
||||||
ALuint SampleRate;
|
|
||||||
ALenum Format;
|
|
||||||
|
|
||||||
bool NeedSwab;
|
|
||||||
bool NeedS8Conv;
|
|
||||||
bool NeedS16Conv;
|
|
||||||
void *GetData(size_t bytes);
|
|
||||||
|
|
||||||
// General methods
|
|
||||||
bool SetupSource();
|
|
||||||
bool InitSample();
|
|
||||||
|
|
||||||
ALfloat Volume;
|
|
||||||
|
|
||||||
public:
|
|
||||||
OpenALSoundStream(OpenALSoundRenderer *renderer);
|
|
||||||
virtual ~OpenALSoundStream();
|
|
||||||
|
|
||||||
virtual bool Play(bool looping, float vol);
|
|
||||||
virtual void Stop();
|
|
||||||
virtual bool SetPaused(bool paused);
|
|
||||||
|
|
||||||
virtual void SetVolume(float vol);
|
|
||||||
|
|
||||||
virtual unsigned int GetPosition();
|
|
||||||
virtual bool SetPosition(unsigned int val);
|
|
||||||
|
|
||||||
virtual bool IsEnded();
|
|
||||||
|
|
||||||
virtual FString GetStats();
|
|
||||||
|
|
||||||
bool Init(const char *filename, int offset, int length);
|
|
||||||
bool Init(const BYTE *data, unsigned int datalen);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Decoder
|
|
||||||
{
|
|
||||||
Sound_Sample *Sample;
|
|
||||||
bool NeedSwab;
|
|
||||||
bool NeedS8Conv;
|
|
||||||
bool NeedS16Conv;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Decoder(const void *data, unsigned int datalen);
|
|
||||||
virtual ~Decoder();
|
|
||||||
|
|
||||||
bool GetFormat(ALenum *format, ALuint *rate);
|
|
||||||
void *GetData(ALsizei *size);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* OALSDLSOUND_H */
|
|
|
@ -88,9 +88,6 @@ void I_BuildALDeviceList(FOptionValues *opt)
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef WITH_SDL_SOUND
|
|
||||||
#include "SDL_sound.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXTERN_CVAR (Int, snd_channels)
|
EXTERN_CVAR (Int, snd_channels)
|
||||||
EXTERN_CVAR (Int, snd_samplerate)
|
EXTERN_CVAR (Int, snd_samplerate)
|
||||||
|
@ -134,68 +131,8 @@ static ALCenum checkALCError(ALCdevice *device, const char *fn, unsigned int ln)
|
||||||
}
|
}
|
||||||
#define getALCError(d) checkALCError((d), __FILE__, __LINE__)
|
#define getALCError(d) checkALCError((d), __FILE__, __LINE__)
|
||||||
|
|
||||||
#ifdef WITH_SDL_SOUND
|
|
||||||
#include "oalsdlsound.h"
|
|
||||||
#else
|
|
||||||
|
|
||||||
class OpenALSoundStream : public SoundStream
|
class OpenALSoundStream : public SoundStream
|
||||||
{
|
|
||||||
OpenALSoundRenderer *Renderer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ALfloat Volume;
|
|
||||||
|
|
||||||
OpenALSoundStream(OpenALSoundRenderer *renderer)
|
|
||||||
: Renderer(renderer), Volume(1.0f)
|
|
||||||
{ Renderer->Streams.push_back(this); }
|
|
||||||
|
|
||||||
virtual ~OpenALSoundStream()
|
|
||||||
{
|
|
||||||
Renderer->Streams.erase(std::find(Renderer->Streams.begin(),
|
|
||||||
Renderer->Streams.end(), this));
|
|
||||||
Renderer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool Play(bool, float)
|
|
||||||
{ return false; }
|
|
||||||
|
|
||||||
virtual void Stop()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
virtual void SetVolume(float vol)
|
|
||||||
{ Volume = vol; }
|
|
||||||
|
|
||||||
virtual bool SetPaused(bool)
|
|
||||||
{ return false; }
|
|
||||||
|
|
||||||
virtual unsigned int GetPosition()
|
|
||||||
{ return 0; }
|
|
||||||
|
|
||||||
virtual bool IsEnded()
|
|
||||||
{ return true; }
|
|
||||||
|
|
||||||
bool Init(const char*)
|
|
||||||
{ return false; }
|
|
||||||
|
|
||||||
bool Init(const BYTE*, unsigned int)
|
|
||||||
{ return false; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class Decoder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Decoder(const void*, unsigned int) { }
|
|
||||||
virtual ~Decoder() { }
|
|
||||||
|
|
||||||
bool GetFormat(ALenum*, ALuint*)
|
|
||||||
{ return false; }
|
|
||||||
void *GetData(ALsizei *size)
|
|
||||||
{ *size = 0; return NULL; }
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class OpenALCallbackStream : public SoundStream
|
|
||||||
{
|
{
|
||||||
OpenALSoundRenderer *Renderer;
|
OpenALSoundRenderer *Renderer;
|
||||||
|
|
||||||
|
@ -220,7 +157,7 @@ class OpenALCallbackStream : public SoundStream
|
||||||
std::auto_ptr<SoundDecoder> Decoder;
|
std::auto_ptr<SoundDecoder> Decoder;
|
||||||
static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user)
|
static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user)
|
||||||
{
|
{
|
||||||
OpenALCallbackStream *self = static_cast<OpenALCallbackStream*>(_sstream);
|
OpenALSoundStream *self = static_cast<OpenALSoundStream*>(_sstream);
|
||||||
if(length < 0) return false;
|
if(length < 0) return false;
|
||||||
|
|
||||||
size_t got = self->Decoder->read((char*)ptr, length);
|
size_t got = self->Decoder->read((char*)ptr, length);
|
||||||
|
@ -273,14 +210,14 @@ class OpenALCallbackStream : public SoundStream
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenALCallbackStream(OpenALSoundRenderer *renderer)
|
OpenALSoundStream(OpenALSoundRenderer *renderer)
|
||||||
: Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f)
|
: Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f)
|
||||||
{
|
{
|
||||||
Renderer->Streams.push_back(this);
|
Renderer->Streams.push_back(this);
|
||||||
memset(Buffers, 0, sizeof(Buffers));
|
memset(Buffers, 0, sizeof(Buffers));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~OpenALCallbackStream()
|
virtual ~OpenALSoundStream()
|
||||||
{
|
{
|
||||||
if(Source)
|
if(Source)
|
||||||
{
|
{
|
||||||
|
@ -658,19 +595,6 @@ OpenALSoundRenderer::OpenALSoundRenderer()
|
||||||
|
|
||||||
Printf("I_InitSound: Initializing OpenAL\n");
|
Printf("I_InitSound: Initializing OpenAL\n");
|
||||||
|
|
||||||
#ifdef WITH_SDL_SOUND
|
|
||||||
static bool sdl_sound_inited = false;
|
|
||||||
if(!sdl_sound_inited)
|
|
||||||
{
|
|
||||||
if(Sound_Init() == 0)
|
|
||||||
{
|
|
||||||
Printf(TEXTCOLOR_RED" Failed to init SDL_sound: %s\n", Sound_GetError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sdl_sound_inited = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(strcmp(snd_aldevice, "Default") != 0)
|
if(strcmp(snd_aldevice, "Default") != 0)
|
||||||
{
|
{
|
||||||
Device = alcOpenDevice(*snd_aldevice);
|
Device = alcOpenDevice(*snd_aldevice);
|
||||||
|
@ -1154,7 +1078,7 @@ short *OpenALSoundRenderer::DecodeSample(int outlen, const void *coded, int size
|
||||||
|
|
||||||
SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
|
SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
|
||||||
{
|
{
|
||||||
std::auto_ptr<OpenALCallbackStream> stream(new OpenALCallbackStream(this));
|
std::auto_ptr<OpenALSoundStream> stream(new OpenALSoundStream(this));
|
||||||
if(!stream->Init(callback, buffbytes, flags, samplerate, userdata))
|
if(!stream->Init(callback, buffbytes, flags, samplerate, userdata))
|
||||||
return NULL;
|
return NULL;
|
||||||
return stream.release();
|
return stream.release();
|
||||||
|
@ -1162,7 +1086,7 @@ SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int
|
||||||
|
|
||||||
SoundStream *OpenALSoundRenderer::OpenStream(const char *filename, int flags, int offset, int length)
|
SoundStream *OpenALSoundRenderer::OpenStream(const char *filename, int flags, int offset, int length)
|
||||||
{
|
{
|
||||||
std::auto_ptr<OpenALCallbackStream> stream(new OpenALCallbackStream(this));
|
std::auto_ptr<OpenALSoundStream> stream(new OpenALSoundStream(this));
|
||||||
|
|
||||||
bool loop = (flags&SoundStream::Loop);
|
bool loop = (flags&SoundStream::Loop);
|
||||||
bool ok = ((offset == -1) ? stream->Init((const BYTE*)filename, length, loop) :
|
bool ok = ((offset == -1) ? stream->Init((const BYTE*)filename, length, loop) :
|
||||||
|
|
Loading…
Reference in a new issue