Migrate from OpenAL/ALUT to SDL2_mixer
This commit is contained in:
parent
4401c1d6a5
commit
3e83967bf2
17 changed files with 272 additions and 639 deletions
24
README.md
24
README.md
|
@ -8,15 +8,11 @@ shoot-em-up games set in an isolated world full of Japanese folklore.
|
|||
## Installation
|
||||
|
||||
Dependencies:
|
||||
* SDL2, SDL2\_ttf
|
||||
* SDL2, SDL2\_ttf, SDL2\_mixer
|
||||
* libpng, ZLIB
|
||||
* OpenGL
|
||||
* OpenAL, ALUT
|
||||
* CMake (build system)
|
||||
|
||||
Optional:
|
||||
* libogg, libvorbis, libvorbisfile (to play .ogg BGMs)
|
||||
|
||||
To build and install Taisei just follow these steps.
|
||||
|
||||
```
|
||||
|
@ -50,11 +46,11 @@ your replays if you really want to publish them.
|
|||
|
||||
Currently Taisei does not include any background music. To use this feature,
|
||||
you should have required audio files in `bgm/` subdirectory.
|
||||
BGM may either be in `.wav` format, or in `.ogg`; last one apply only if you have
|
||||
compiled Taisei with libogg, libvorbis and libvorbisfile (automatically enabled
|
||||
if cmake is able to find them).
|
||||
BGM (as well as SFX) may be in `.wav`, `.flac`, or `.ogg` format; additionally
|
||||
you may try another formats such as `.mp3`, `.aiff`, `.mod`, `.xm`, etc. if
|
||||
your build of SDL2_mixer supports these formats.
|
||||
|
||||
Complete music pack consists of 16 bgm\_\*.ogg or bgm\_\*.wav files, where ‘\*’ mean:
|
||||
Complete music pack consists of 16 bgm\_\*.(ogg/wav/flac) files, where ‘\*’ mean:
|
||||
```
|
||||
credits BGM for credits screen
|
||||
ending BGM for ending
|
||||
|
@ -70,6 +66,16 @@ consists of bgm filename (without extension), space of tab, and theme name.
|
|||
No space/tab allowed either in beginning of line or BGM filenames listed in
|
||||
this file; theme names may contain them.
|
||||
|
||||
## Sound problems
|
||||
|
||||
If your sound becomes glitchy, and you encounter lot of console messages like:
|
||||
`ALSA lib pcm.c:7234:(snd_pcm_recover) underrun occurred`,
|
||||
it seems like you possibly have broken ALSA configuration.
|
||||
This may be fixed by playing with parameter values of `pcm.dmixer.slave` option
|
||||
group in `/etc/asound.conf` or wherever you have your ALSA configuration.
|
||||
Commenting `period_time`, `period_size`, `buffer_size`, `rate` may give you
|
||||
the first approach to what to do.
|
||||
|
||||
## Contact
|
||||
|
||||
http://taisei-project.org/
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
# Locate ALUT
|
||||
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
|
||||
#
|
||||
# $ALUTDIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$ALUTDIR
|
||||
# used in building ALUT.
|
||||
#
|
||||
# Created by Sukender (Benoit Neil). Based on FindOpenAL.cmake module. (taken from osgaudio)
|
||||
|
||||
IF(ALUT_USE_AL_SUBDIR)
|
||||
SET(ALUT_HEADER_NAMES "AL/alut.h")
|
||||
SET(ALUT_HEADER_SUFFIXES include)
|
||||
ELSE()
|
||||
SET(ALUT_HEADER_NAMES "alut.h")
|
||||
SET(ALUT_HEADER_SUFFIXES include/AL include/OpenAL include)
|
||||
ENDIF()
|
||||
|
||||
SET(ALUT_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_PATH(ALUT_INCLUDE_DIR NAMES ${ALUT_HEADER_NAMES}
|
||||
HINTS
|
||||
$ENV{ALUTDIR}
|
||||
$ENV{ALUT_PATH}
|
||||
PATH_SUFFIXES ${ALUT_HEADER_SUFFIXES}
|
||||
PATHS ${ALUT_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(ALUT_LIBRARY
|
||||
NAMES alut libalut
|
||||
HINTS
|
||||
$ENV{ALUTDIR}
|
||||
$ENV{ALUT_PATH}
|
||||
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 Release
|
||||
PATHS ${ALUT_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
# First search for d-suffixed libs
|
||||
FIND_LIBRARY(ALUT_LIBRARY_DEBUG
|
||||
NAMES alutd libalutd
|
||||
HINTS
|
||||
$ENV{ALUTDIR}
|
||||
$ENV{ALUT_PATH}
|
||||
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 Debug
|
||||
PATHS ${ALUT_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF(NOT ALUT_LIBRARY_DEBUG)
|
||||
# Then search for non suffixed libs if necessary, but only in debug dirs
|
||||
FIND_LIBRARY(ALUT_LIBRARY_DEBUG
|
||||
NAMES alut libalut
|
||||
HINTS
|
||||
$ENV{ALUTDIR}
|
||||
$ENV{ALUT_PATH}
|
||||
PATH_SUFFIXES Debug
|
||||
PATHS ${ALUT_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
IF(ALUT_LIBRARY)
|
||||
IF(ALUT_LIBRARY_DEBUG)
|
||||
SET(ALUT_LIBRARIES optimized "${ALUT_LIBRARY}" debug "${ALUT_LIBRARY_DEBUG}")
|
||||
ELSE()
|
||||
SET(ALUT_LIBRARIES "${ALUT_LIBRARY}") # Could add "general" keyword, but it is optional
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG ALUT_LIBRARIES ALUT_INCLUDE_DIR)
|
|
@ -1,77 +0,0 @@
|
|||
# Locate OGG
|
||||
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
|
||||
#
|
||||
# $OGGDIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$OGGDIR
|
||||
# used in building OGG.
|
||||
#
|
||||
# Taken from OALWrapper made by FrictionalGames https://github.com/FrictionalGames/OALWrapper
|
||||
|
||||
SET(OGG_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(MSVC_YEAR_NAME)
|
||||
IF (MSVC_VERSION GREATER 1599) # >= 1600
|
||||
SET(MSVC_YEAR_NAME VS2010)
|
||||
ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500
|
||||
SET(MSVC_YEAR_NAME VS2008)
|
||||
ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400
|
||||
SET(MSVC_YEAR_NAME VS2005)
|
||||
ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300
|
||||
SET(MSVC_YEAR_NAME VS2003)
|
||||
ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200
|
||||
SET(MSVC_YEAR_NAME VS6)
|
||||
ENDIF()
|
||||
|
||||
FIND_PATH(OGG_INCLUDE_DIR
|
||||
NAMES ogg/ogg.h ogg/os_types.h
|
||||
HINTS ENV OGGDIR
|
||||
PATH_SUFFIXES include
|
||||
PATHS ${OGG_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(OGG_LIBRARY
|
||||
NAMES ogg libogg
|
||||
HINTS ENV OGGDIR
|
||||
PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
|
||||
PATHS ${OGG_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
# First search for d-suffixed libs
|
||||
FIND_LIBRARY(OGG_LIBRARY_DEBUG
|
||||
NAMES oggd ogg_d liboggd libogg_d
|
||||
HINTS ENV OGGDIR
|
||||
PATH_SUFFIXES lib lib64 win32/Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${OGG_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF(NOT OGG_LIBRARY_DEBUG)
|
||||
# Then search for non suffixed libs if necessary, but only in debug dirs
|
||||
FIND_LIBRARY(OGG_LIBRARY_DEBUG
|
||||
NAMES ogg libogg
|
||||
HINTS ENV OGGDIR
|
||||
PATH_SUFFIXES win32/Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${OGG_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF(OGG_LIBRARY)
|
||||
IF(OGG_LIBRARY_DEBUG)
|
||||
SET(OGG_LIBRARIES optimized "${OGG_LIBRARY}" debug "${OGG_LIBRARY_DEBUG}")
|
||||
ELSE()
|
||||
SET(OGG_LIBRARIES "${OGG_LIBRARY}") # Could add "general" keyword, but it is optional
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGG DEFAULT_MSG OGG_LIBRARIES OGG_INCLUDE_DIR)
|
|
@ -1,85 +0,0 @@
|
|||
# Locate Vorbis
|
||||
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
|
||||
#
|
||||
# $VORBISDIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$VORBISDIR
|
||||
# used in building Vorbis.
|
||||
#
|
||||
# Taken from OALWrapper made by FrictionalGames https://github.com/FrictionalGames/OALWrapper
|
||||
|
||||
SET(VORBIS_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(MSVC_YEAR_NAME)
|
||||
IF (MSVC_VERSION GREATER 1599) # >= 1600
|
||||
SET(MSVC_YEAR_NAME VS2010)
|
||||
ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500
|
||||
SET(MSVC_YEAR_NAME VS2008)
|
||||
ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400
|
||||
SET(MSVC_YEAR_NAME VS2005)
|
||||
ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300
|
||||
SET(MSVC_YEAR_NAME VS2003)
|
||||
ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200
|
||||
SET(MSVC_YEAR_NAME VS6)
|
||||
ENDIF()
|
||||
|
||||
FIND_PATH(VORBIS_INCLUDE_DIR
|
||||
NAMES vorbis/codec.h
|
||||
HINTS
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES include
|
||||
PATHS ${VORBIS_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(VORBIS_LIBRARY
|
||||
NAMES vorbis libvorbis
|
||||
HINTS
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES lib lib64 win32/Vorbis_Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
|
||||
PATHS ${VORBIS_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
# First search for d-suffixed libs
|
||||
FIND_LIBRARY(VORBIS_LIBRARY_DEBUG
|
||||
NAMES vorbisd vorbis_d libvorbisd libvorbis_d
|
||||
HINTS
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES lib lib64 win32/Vorbis_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${VORBIS_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF(NOT VORBIS_LIBRARY_DEBUG)
|
||||
# Then search for non suffixed libs if necessary, but only in debug dirs
|
||||
FIND_LIBRARY(VORBIS_LIBRARY_DEBUG
|
||||
NAMES vorbis libvorbis
|
||||
HINTS
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES win32/Vorbis_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${VORBIS_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF(VORBIS_LIBRARY)
|
||||
IF(VORBIS_LIBRARY_DEBUG)
|
||||
SET(VORBIS_LIBRARIES optimized "${VORBIS_LIBRARY}" debug "${VORBIS_LIBRARY_DEBUG}")
|
||||
ELSE()
|
||||
SET(VORBIS_LIBRARIES "${VORBIS_LIBRARY}") # Could add "general" keyword, but it is optional
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBIS DEFAULT_MSG VORBIS_LIBRARIES VORBIS_INCLUDE_DIR)
|
|
@ -1,93 +0,0 @@
|
|||
# Locate VorbisFile
|
||||
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
|
||||
#
|
||||
# $VORBISDIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$VORBISDIR
|
||||
# used in building Vorbis.
|
||||
#
|
||||
# Taken from OALWrapper made by FrictionalGames https://github.com/FrictionalGames/OALWrapper
|
||||
|
||||
SET(VORBISFILE_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
SET(MSVC_YEAR_NAME)
|
||||
IF (MSVC_VERSION GREATER 1599) # >= 1600
|
||||
SET(MSVC_YEAR_NAME VS2010)
|
||||
ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500
|
||||
SET(MSVC_YEAR_NAME VS2008)
|
||||
ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400
|
||||
SET(MSVC_YEAR_NAME VS2005)
|
||||
ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300
|
||||
SET(MSVC_YEAR_NAME VS2003)
|
||||
ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200
|
||||
SET(MSVC_YEAR_NAME VS6)
|
||||
ENDIF()
|
||||
|
||||
FIND_PATH(VORBISFILE_INCLUDE_DIR
|
||||
NAMES vorbis/vorbisfile.h
|
||||
HINTS
|
||||
$ENV{VORBISFILEDIR}
|
||||
$ENV{VORBISFILE_PATH}
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES include
|
||||
PATHS ${VORBISFILE_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(VORBISFILE_LIBRARY
|
||||
NAMES vorbisfile libvorbisfile
|
||||
HINTS
|
||||
$ENV{VORBISFILEDIR}
|
||||
$ENV{VORBISFILE_PATH}
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
|
||||
PATHS ${VORBISFILE_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
# First search for d-suffixed libs
|
||||
FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG
|
||||
NAMES vorbisfiled vorbisfile_d libvorbisfiled libvorbisfile_d
|
||||
HINTS
|
||||
$ENV{VORBISFILEDIR}
|
||||
$ENV{VORBISFILE_PATH}
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${VORBISFILE_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF(NOT VORBISFILE_LIBRARY_DEBUG)
|
||||
# Then search for non suffixed libs if necessary, but only in debug dirs
|
||||
FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG
|
||||
NAMES vorbisfile libvorbisfile
|
||||
HINTS
|
||||
$ENV{VORBISFILEDIR}
|
||||
$ENV{VORBISFILE_PATH}
|
||||
$ENV{VORBISDIR}
|
||||
$ENV{VORBIS_PATH}
|
||||
PATH_SUFFIXES win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
|
||||
PATHS ${VORBISFILE_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF(VORBISFILE_LIBRARY)
|
||||
IF(VORBISFILE_LIBRARY_DEBUG)
|
||||
SET(VORBISFILE_LIBRARIES optimized "${VORBISFILE_LIBRARY}" debug "${VORBISFILE_LIBRARY_DEBUG}")
|
||||
ELSE()
|
||||
SET(VORBISFILE_LIBRARIES "${VORBISFILE_LIBRARY}") # Could add "general" keyword, but it is optional
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBISFILE DEFAULT_MSG VORBISFILE_LIBRARIES VORBISFILE_INCLUDE_DIR)
|
109
cmake/sdl2/FindSDL2_mixer.cmake
Normal file
109
cmake/sdl2/FindSDL2_mixer.cmake
Normal file
|
@ -0,0 +1,109 @@
|
|||
# - Locate SDL_mixer library
|
||||
# This module defines:
|
||||
# SDL2_MIXER_LIBRARIES, the name of the library to link against
|
||||
# SDL2_MIXER_INCLUDE_DIRS, where to find the headers
|
||||
# SDL2_MIXER_FOUND, if false, do not try to link against
|
||||
# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_mixer
|
||||
#
|
||||
# For backward compatiblity the following variables are also set:
|
||||
# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES)
|
||||
# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS)
|
||||
# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND)
|
||||
#
|
||||
# $SDLDIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$SDLDIR
|
||||
# used in building SDL.
|
||||
#
|
||||
# Created by Eric Wing. This was influenced by the FindSDL.cmake
|
||||
# module, but with modifications to recognize OS X frameworks and
|
||||
# additional Unix paths (FreeBSD, etc).
|
||||
|
||||
#=============================================================================
|
||||
# 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.)
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(SDL2_ARCH_64 TRUE)
|
||||
set(SDL2_PROCESSOR_ARCH "x64")
|
||||
else()
|
||||
set(SDL2_ARCH_64 FALSE)
|
||||
set(SDL2_PROCESSOR_ARCH "x86")
|
||||
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
|
||||
SET(SDL2_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
if(NOT SDL2_MIXER_INCLUDE_DIR AND SDL2MIXER_INCLUDE_DIR)
|
||||
set(SDL2_MIXER_INCLUDE_DIR ${SDL2MIXER_INCLUDE_DIR} CACHE PATH "directory cache
|
||||
entry initialized from old variable name")
|
||||
endif()
|
||||
find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h
|
||||
HINTS
|
||||
ENV SDL2MIXERDIR
|
||||
ENV SDL2DIR
|
||||
PATH_SUFFIXES include include/SDL2
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
if(NOT SDL2_MIXER_LIBRARY AND SDL2MIXER_LIBRARY)
|
||||
set(SDL2_MIXER_LIBRARY ${SDL2MIXER_LIBRARY} CACHE FILEPATH "file cache entry
|
||||
initialized from old variable name")
|
||||
endif()
|
||||
find_library(SDL2_MIXER_LIBRARY
|
||||
NAMES SDL2_mixer
|
||||
HINTS
|
||||
ENV SDL2MIXERDIR
|
||||
ENV SDL2DIR
|
||||
PATH_SUFFIXES lib64 lib lib/${SDL2_PROCESSOR_ARCH}
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h")
|
||||
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}")
|
||||
set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH})
|
||||
unset(SDL2_MIXER_VERSION_MAJOR_LINE)
|
||||
unset(SDL2_MIXER_VERSION_MINOR_LINE)
|
||||
unset(SDL2_MIXER_VERSION_PATCH_LINE)
|
||||
unset(SDL2_MIXER_VERSION_MAJOR)
|
||||
unset(SDL2_MIXER_VERSION_MINOR)
|
||||
unset(SDL2_MIXER_VERSION_PATCH)
|
||||
endif()
|
||||
|
||||
set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY})
|
||||
set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer
|
||||
REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS
|
||||
VERSION_VAR SDL2_MIXER_VERSION_STRING)
|
||||
|
||||
# for backward compatiblity
|
||||
set(SDL2MIXER_LIBRARY ${SDL2_MIXER_LIBRARIES})
|
||||
set(SDL2MIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS})
|
||||
set(SDL2MIXER_FOUND ${SDL2_MIXER_FOUND})
|
||||
|
||||
mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR)
|
|
@ -1 +1,5 @@
|
|||
FindSDL2, FindSDL2_ttf:
|
||||
https://github.com/tcbrindle/sdl2-cmake-scripts
|
||||
|
||||
FindSDL2_mixer:
|
||||
https://github.com/Gear2D/gear2d-components/blob/master/cmake/
|
||||
|
|
|
@ -2,21 +2,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
|
|||
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(OpenAL REQUIRED)
|
||||
find_package(ALUT REQUIRED)
|
||||
find_package(SDL2_mixer REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
find_package(SDL2_ttf REQUIRED)
|
||||
find_package(Freetype)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OGG)
|
||||
|
||||
if(OGG_FOUND)
|
||||
find_package(Vorbis)
|
||||
endif()
|
||||
|
||||
if(VORBIS_FOUND)
|
||||
find_package(VorbisFile)
|
||||
endif()
|
||||
|
||||
set(SRCs
|
||||
main.c
|
||||
|
@ -77,11 +67,6 @@ set(SRCs
|
|||
resource/model.c
|
||||
)
|
||||
|
||||
if(VORBISFILE_FOUND)
|
||||
set(SRCs ${SRCs} resource/ogg.c)
|
||||
add_definitions(-DOGG_SUPPORT_ENABLED)
|
||||
endif()
|
||||
|
||||
if(USE_SDL2_PATHS)
|
||||
set(SRCs ${SRCs} paths/sdl.c)
|
||||
elseif(RELATIVE)
|
||||
|
@ -94,7 +79,7 @@ if(WIN32)
|
|||
set(SRCs ${SRCs} taisei_err.c)
|
||||
endif()
|
||||
|
||||
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}" -Wall -Wno-parentheses)
|
||||
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}" -Wall -Wno-parentheses -std=gnu99)
|
||||
|
||||
if(RELATIVE)
|
||||
add_definitions(-DRELATIVE)
|
||||
|
@ -114,22 +99,16 @@ endif()
|
|||
|
||||
set(LIBs ${LIBs}
|
||||
${SDL2_LIBRARY}
|
||||
${SDL2_TTF_LIBRARIES}
|
||||
${PNG_LIBRARY}
|
||||
${OPENAL_LIBRARY}
|
||||
${ALUT_LIBRARY}
|
||||
${SDL2_TTF_LIBRARIES}
|
||||
${PNG_LIBRARY}
|
||||
${SDL2_MIXER_LIBRARY}
|
||||
${OPENGL_LIBRARY}
|
||||
m)
|
||||
|
||||
|
||||
if(FREETYPE_FOUND)
|
||||
set(LIBs ${LIBs} ${FREETYPE_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(VORBISFILE_FOUND)
|
||||
set(LIBs ${LIBs} ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(ZLIB_FOUND)
|
||||
set(LIBs ${LIBs} ${ZLIB_LIBRARY})
|
||||
endif()
|
||||
|
@ -149,7 +128,7 @@ if(TAISEI_WIN32_CONSOLE)
|
|||
add_definitions(-D__WINDOWS_CONSOLE__)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SDL2_INCLUDE_DIR} ${ALUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SDL2_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
|
||||
|
||||
unset(POSIX CACHE)
|
||||
check_symbol_exists(_POSIX_VERSION "unistd.h" POSIX)
|
||||
|
|
|
@ -104,7 +104,7 @@ int main(int argc, char** argv) {
|
|||
config_load(CONFIG_FILE);
|
||||
|
||||
printf("initialize:\n");
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0)
|
||||
errx(-1, "Error initializing SDL: %s", SDL_GetError());
|
||||
printf("-- SDL_Init\n");
|
||||
|
||||
|
@ -123,8 +123,8 @@ int main(int argc, char** argv) {
|
|||
gamepad_init();
|
||||
|
||||
// Order DOES matter: init_global, then sfx/bgm, then load_resources.
|
||||
init_sfx(&argc, argv);
|
||||
init_bgm(&argc, argv);
|
||||
init_sfx();
|
||||
init_bgm();
|
||||
load_resources();
|
||||
printf("initialization complete.\n");
|
||||
|
||||
|
|
|
@ -11,55 +11,44 @@
|
|||
#include "list.h"
|
||||
#include "taisei_err.h"
|
||||
|
||||
#ifdef OGG_SUPPORT_ENABLED
|
||||
#include <vorbis/vorbisfile.h>
|
||||
#include "ogg.h"
|
||||
#endif
|
||||
int mixer_loaded = 0;
|
||||
|
||||
int alut_loaded = 0;
|
||||
void unload_mixer_if_needed(void) {
|
||||
// mixer will be unloaded only if there are no audio AND no music enabled
|
||||
if(!config_get_int(CONFIG_NO_AUDIO) || !config_get_int(CONFIG_NO_MUSIC) || !mixer_loaded) return;
|
||||
|
||||
int warn_alut_error(const char *when) {
|
||||
ALenum error = alGetError();
|
||||
|
||||
if(error != AL_NO_ERROR) {
|
||||
warnx("AL error %d while %s", error, when);
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = alutGetError();
|
||||
if (error == ALUT_ERROR_NO_ERROR) return 0;
|
||||
warnx("ALUT error %d while %s: %s", error, when, alutGetErrorString(error));
|
||||
return 1;
|
||||
Mix_CloseAudio();
|
||||
Mix_Quit();
|
||||
mixer_loaded = 0;
|
||||
printf("-- Unloaded SDL2_mixer\n");
|
||||
}
|
||||
|
||||
void unload_alut_if_needed() {
|
||||
// ALUT will be unloaded only if there are no audio AND no music enabled
|
||||
if(!config_get_int(CONFIG_NO_AUDIO) || !config_get_int(CONFIG_NO_MUSIC) || !alut_loaded) return;
|
||||
int init_mixer_if_needed(void) {
|
||||
// mixer will not be loaded if there are no audio AND no music enabled
|
||||
if((config_get_int(CONFIG_NO_AUDIO) && config_get_int(CONFIG_NO_MUSIC)) || mixer_loaded) return 1;
|
||||
|
||||
warn_alut_error("preparing to shutdown");
|
||||
alutExit();
|
||||
warn_alut_error("shutting down");
|
||||
alut_loaded = 0;
|
||||
printf("-- Unloaded ALUT\n");
|
||||
}
|
||||
|
||||
int init_alut_if_needed(int *argc, char *argv[]) {
|
||||
// ALUT will not be loaded if there are no audio AND no music enabled
|
||||
if((config_get_int(CONFIG_NO_AUDIO) && config_get_int(CONFIG_NO_MUSIC)) || alut_loaded) return 1;
|
||||
|
||||
if(!alutInit(argc, argv))
|
||||
int formats_mask = Mix_Init(MIX_INIT_OGG | MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3);
|
||||
if(!formats_mask)
|
||||
{
|
||||
warn_alut_error("initializing");
|
||||
alutExit(); // Try to shutdown ALUT if it was partly initialized
|
||||
warn_alut_error("shutting down");
|
||||
Mix_Quit(); // Try to shutdown mixer if it was partly initialized
|
||||
config_set_int(CONFIG_NO_AUDIO, 1);
|
||||
config_set_int(CONFIG_NO_MUSIC, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("-- ALUT\n");
|
||||
printf("-- SDL2_mixer\n\tSupported formats:%s%s%s%s\n",
|
||||
(formats_mask & MIX_INIT_OGG ? " OGG": ""),
|
||||
(formats_mask & MIX_INIT_FLAC ? " FLAC": ""),
|
||||
(formats_mask & MIX_INIT_MOD ? " MOD": ""),
|
||||
(formats_mask & MIX_INIT_MP3 ? " MP3": "")
|
||||
);
|
||||
|
||||
alut_loaded = 1;
|
||||
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
|
||||
{
|
||||
warnx("Mix_OpenAudio(): %s.\n", Mix_GetError());
|
||||
}
|
||||
|
||||
mixer_loaded = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -71,7 +60,7 @@ static void sfx_cfg_noaudio_callback(ConfigIndex idx, ConfigValue v) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(!init_sfx(NULL, NULL)) {
|
||||
if(!init_sfx()) {
|
||||
config_set_int(idx, true);
|
||||
return;
|
||||
}
|
||||
|
@ -84,7 +73,7 @@ static void sfx_cfg_volume_callback(ConfigIndex idx, ConfigValue v) {
|
|||
set_sfx_volume(config_set_float(idx, v.f));
|
||||
}
|
||||
|
||||
int init_sfx(int *argc, char *argv[])
|
||||
int init_sfx(void)
|
||||
{
|
||||
static bool callbacks_set_up = false;
|
||||
|
||||
|
@ -95,88 +84,84 @@ int init_sfx(int *argc, char *argv[])
|
|||
}
|
||||
|
||||
if (config_get_int(CONFIG_NO_AUDIO)) return 1;
|
||||
if (!init_alut_if_needed(argc, argv)) return 0;
|
||||
|
||||
alGenSources(SNDSRC_COUNT, resources.sndsrc);
|
||||
if(warn_alut_error("creating sfx sources"))
|
||||
if (!init_mixer_if_needed()) return 0;
|
||||
|
||||
int channels = Mix_AllocateChannels(SNDCHAN_COUNT);
|
||||
if (!channels)
|
||||
{
|
||||
warnx("init_sfx(): unable to allocate any channels.\n");
|
||||
config_set_int(CONFIG_NO_AUDIO, 1);
|
||||
unload_alut_if_needed();
|
||||
unload_mixer_if_needed();
|
||||
return 0;
|
||||
}
|
||||
if (channels < SNDCHAN_COUNT) warnx("init_sfx(): allocated only %d of %d channels.\n", channels, SNDCHAN_COUNT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void shutdown_sfx(void)
|
||||
{
|
||||
alDeleteSources(SNDSRC_COUNT, resources.sndsrc);
|
||||
warn_alut_error("deleting sfx sources");
|
||||
if(resources.state & RS_SfxLoaded)
|
||||
{
|
||||
printf("-- freeing sounds\n");
|
||||
delete_sounds();
|
||||
resources.state &= ~RS_SfxLoaded;
|
||||
}
|
||||
unload_alut_if_needed();
|
||||
unload_mixer_if_needed();
|
||||
}
|
||||
|
||||
Sound *load_sound_or_bgm(char *filename, Sound **dest, const char *res_directory, const char *type) {
|
||||
ALuint sound = 0;
|
||||
Sound *load_sound_or_bgm(char *filename, Sound **dest, sound_type_t type) {
|
||||
Mix_Chunk *sound = NULL;
|
||||
Mix_Music *music = NULL;
|
||||
|
||||
#ifdef OGG_SUPPORT_ENABLED
|
||||
// Try to load ogg file
|
||||
if(strcmp(type, "ogg") == 0)
|
||||
switch(type)
|
||||
{
|
||||
ALenum format;
|
||||
char *buffer;
|
||||
ALsizei size;
|
||||
ALsizei freq;
|
||||
|
||||
int ogg_err;
|
||||
if((ogg_err = load_ogg(filename, &format, &buffer, &size, &freq)) != 0)
|
||||
errx(-1,"load_sound_or_bgm():\n!- cannot load '%s' through load_ogg: error %d", filename, ogg_err);
|
||||
|
||||
alGenBuffers(1, &sound);
|
||||
warn_alut_error("generating audio buffer");
|
||||
|
||||
alBufferData(sound, format, buffer, size, freq);
|
||||
warn_alut_error("filling buffer with data");
|
||||
|
||||
free(buffer);
|
||||
if(!sound)
|
||||
errx(-1,"load_sound_or_bgm():\n!- cannot forward loaded '%s' to alut: %s", filename, alutGetErrorString(alutGetError()));
|
||||
case ST_SOUND:
|
||||
sound = Mix_LoadWAV(filename);
|
||||
if (!sound) {
|
||||
warnx("load_sound_or_bgm():\n!- cannot load sound from '%s': %s", filename, Mix_GetError());
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case ST_MUSIC:
|
||||
music = Mix_LoadMUS(filename);
|
||||
if (!music) {
|
||||
warnx("load_sound_or_bgm():\n!- cannot load BGM from '%s': %s", filename, Mix_GetError());
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errx(-1,"load_sound_or_bgm():\n!- incorrect sound type specified");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Fallback to standard ALUT wrapper
|
||||
if(!sound)
|
||||
{
|
||||
sound = alutCreateBufferFromFile(filename);
|
||||
warn_alut_error("creating buffer from .wav file");
|
||||
}
|
||||
if(!sound)
|
||||
errx(-1,"load_sound_or_bgm():\n!- cannot load '%s' through alut: %s", filename, alutGetErrorString(alutGetError()));
|
||||
|
||||
Sound *snd = create_element((void **)dest, sizeof(Sound));
|
||||
|
||||
snd->alsnd = sound;
|
||||
snd->type = type;
|
||||
if (sound)
|
||||
snd->sound = sound;
|
||||
else
|
||||
snd->music = music;
|
||||
snd->lastplayframe = 0;
|
||||
|
||||
// res_directory should have trailing slash
|
||||
char *beg = strstr(filename, res_directory) + strlen(res_directory);
|
||||
char *beg = strrchr(filename, '/'); // TODO: check portability of '/'
|
||||
char *end = strrchr(filename, '.');
|
||||
if (!beg || !end)
|
||||
errx(-1,"load_sound_or_bgm():\n!- incorrect filename format");
|
||||
|
||||
++beg; // skip '/' between last path element and file name
|
||||
int sz = end - beg + 1;
|
||||
snd->name = malloc(sz);
|
||||
if (!snd->name)
|
||||
errx(-1,"load_sound_or_bgm():\n!- failed to allocate memory for sound name (is it empty?)");
|
||||
strlcpy(snd->name, beg, sz);
|
||||
|
||||
printf("-- loaded '%s' as '%s', type %s\n", filename, snd->name, type);
|
||||
printf("-- loaded '%s' as %s '%s'\n", filename, ((type==ST_SOUND) ? "SFX" : "BGM"), snd->name);
|
||||
|
||||
return snd;
|
||||
}
|
||||
|
||||
Sound *load_sound(char *filename, const char *type) {
|
||||
return load_sound_or_bgm(filename, &resources.sounds, "sfx/", type);
|
||||
Sound *load_sound(char *filename) {
|
||||
return load_sound_or_bgm(filename, &resources.sounds, ST_SOUND);
|
||||
}
|
||||
|
||||
Sound *get_snd(Sound *source, char *name) {
|
||||
|
@ -205,42 +190,22 @@ void play_sound_p(char *name, int unconditional)
|
|||
snd->lastplayframe = global.frames;
|
||||
}
|
||||
|
||||
ALuint i,res = -1;
|
||||
ALint play;
|
||||
for(i = 0; i < SNDSRC_COUNT; i++) {
|
||||
alGetSourcei(resources.sndsrc[i],AL_SOURCE_STATE,&play);
|
||||
warn_alut_error("checking state of sfx source");
|
||||
if(play != AL_PLAYING) {
|
||||
res = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(res != -1) {
|
||||
alSourcei(resources.sndsrc[res],AL_BUFFER, snd->alsnd);
|
||||
warn_alut_error("changing buffer of sfx source");
|
||||
alSourcePlay(resources.sndsrc[res]);
|
||||
warn_alut_error("starting playback of sfx source");
|
||||
} else {
|
||||
warnx("play_sound_p():\n!- not enough sources");
|
||||
}
|
||||
if(Mix_PlayChannel(-1, snd->sound, 0) == -1)
|
||||
warnx("play_sound_p(): error playing sound: %s", Mix_GetError());
|
||||
}
|
||||
|
||||
void set_sfx_volume(float gain)
|
||||
{
|
||||
if(config_get_int(CONFIG_NO_AUDIO)) return;
|
||||
printf("SFX volume: %f\n", gain);
|
||||
int i;
|
||||
for(i = 0; i < SNDSRC_COUNT; i++) {
|
||||
alSourcef(resources.sndsrc[i],AL_GAIN, gain);
|
||||
warn_alut_error("changing gain of sfx source");
|
||||
}
|
||||
Mix_Volume(-1, gain * MIX_MAX_VOLUME);
|
||||
}
|
||||
|
||||
void delete_sound(void **snds, void *snd) {
|
||||
free(((Sound *)snd)->name);
|
||||
alDeleteBuffers(1, &((Sound *)snd)->alsnd);
|
||||
warn_alut_error("deleting source buffer");
|
||||
Sound *ssnd = (Sound *)snd;
|
||||
free(ssnd->name);
|
||||
if(ssnd->type == ST_MUSIC) Mix_FreeMusic(ssnd->music);
|
||||
else Mix_FreeChunk(ssnd->sound);
|
||||
delete_element(snds, snd);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,14 @@
|
|||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#include <AL/alut.h>
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
#define SNDCHAN_COUNT 100
|
||||
|
||||
typedef enum {
|
||||
ST_SOUND,
|
||||
ST_MUSIC
|
||||
} sound_type_t;
|
||||
|
||||
struct Sound;
|
||||
|
||||
|
@ -17,13 +24,16 @@ typedef struct Sound {
|
|||
struct Sound *prev;
|
||||
|
||||
int lastplayframe;
|
||||
|
||||
ALuint alsnd;
|
||||
sound_type_t type;
|
||||
union {
|
||||
Mix_Chunk *sound;
|
||||
Mix_Music *music;
|
||||
};
|
||||
char *name;
|
||||
} Sound;
|
||||
|
||||
Sound *load_sound(char *filename, const char *type);
|
||||
Sound *load_sound_or_bgm(char *filename, Sound **dest, const char *res_directory, const char *type);
|
||||
Sound *load_sound(char *filename);
|
||||
Sound *load_sound_or_bgm(char *filename, Sound **dest, sound_type_t type);
|
||||
|
||||
#define play_sound(name) play_sound_p(name, 0);
|
||||
#define play_ui_sound(name) play_sound_p(name, 1);
|
||||
|
@ -37,11 +47,10 @@ void delete_sounds(void);
|
|||
|
||||
void set_sfx_volume(float gain);
|
||||
|
||||
int init_sfx(int *argc, char *argv[]);
|
||||
int init_sfx(void);
|
||||
void shutdown_sfx(void);
|
||||
|
||||
int init_alut_if_needed(int *argc, char *argv[]);
|
||||
void unload_alut_if_needed();
|
||||
int warn_alut_error(const char *when);
|
||||
int init_mixer_if_needed(void);
|
||||
void unload_mixer_if_needed(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,11 +12,6 @@
|
|||
#include "taisei_err.h"
|
||||
#include "bgm.h"
|
||||
|
||||
#ifdef OGG_SUPPORT_ENABLED
|
||||
#include <vorbis/vorbisfile.h>
|
||||
#include "ogg.h"
|
||||
#endif
|
||||
|
||||
struct current_bgm_t current_bgm = { .name = NULL };
|
||||
|
||||
char *saved_bgm;
|
||||
|
@ -29,7 +24,7 @@ static void bgm_cfg_nomusic_callback(ConfigIndex idx, ConfigValue v) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(!init_bgm(NULL, NULL)) {
|
||||
if(!init_bgm()) {
|
||||
config_set_int(idx, true);
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +38,7 @@ static void bgm_cfg_volume_callback(ConfigIndex idx, ConfigValue v) {
|
|||
set_bgm_volume(config_set_float(idx, v.f));
|
||||
}
|
||||
|
||||
int init_bgm(int *argc, char *argv[])
|
||||
int init_bgm(void)
|
||||
{
|
||||
static bool callbacks_set_up = false;
|
||||
|
||||
|
@ -54,30 +49,20 @@ int init_bgm(int *argc, char *argv[])
|
|||
}
|
||||
|
||||
if (config_get_int(CONFIG_NO_MUSIC)) return 1;
|
||||
if (!init_alut_if_needed(argc, argv)) return 0;
|
||||
|
||||
alGenSources(1, &resources.bgmsrc);
|
||||
if(warn_alut_error("creating music sources"))
|
||||
{
|
||||
config_set_int(CONFIG_NO_MUSIC, 1);
|
||||
unload_alut_if_needed();
|
||||
return 0;
|
||||
}
|
||||
if (!init_mixer_if_needed()) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void shutdown_bgm(void)
|
||||
{
|
||||
current_bgm.name = NULL;
|
||||
alDeleteSources(1, &resources.bgmsrc);
|
||||
warn_alut_error("deleting music sources");
|
||||
if(resources.state & RS_BgmLoaded)
|
||||
{
|
||||
printf("-- freeing music\n");
|
||||
delete_music();
|
||||
resources.state &= ~RS_BgmLoaded;
|
||||
}
|
||||
unload_alut_if_needed();
|
||||
unload_mixer_if_needed();
|
||||
}
|
||||
|
||||
char *get_bgm_desc(Bgm_desc *source, char *name) {
|
||||
|
@ -139,13 +124,14 @@ void load_bgm_descriptions(const char *path) {
|
|||
return;
|
||||
}
|
||||
|
||||
Sound *load_bgm(char *filename, const char *type) {
|
||||
return load_sound_or_bgm(filename, &resources.music, "bgm/", type);
|
||||
Sound *load_bgm(char *filename) {
|
||||
return load_sound_or_bgm(filename, &resources.music, ST_MUSIC);
|
||||
}
|
||||
|
||||
void start_bgm(char *name) {
|
||||
if(config_get_int(CONFIG_NO_MUSIC)) return;
|
||||
|
||||
// start_bgm(NULL) or start_bgm("") would be equivalent to stop_bgm().
|
||||
if(!name || strcmp(name, "") == 0)
|
||||
{
|
||||
stop_bgm();
|
||||
|
@ -155,11 +141,11 @@ void start_bgm(char *name) {
|
|||
// if BGM has changed, change it and start from beginning
|
||||
if (!current_bgm.name || strcmp(name, current_bgm.name))
|
||||
{
|
||||
Mix_HaltMusic();
|
||||
|
||||
current_bgm.name = realloc(current_bgm.name, strlen(name) + 1);
|
||||
|
||||
if(current_bgm.name == NULL)
|
||||
errx(-1,"start_bgm():\n!- realloc error with music '%s'", name);
|
||||
|
||||
strcpy(current_bgm.name, name);
|
||||
if((current_bgm.data = get_snd(resources.music, name)) == NULL)
|
||||
{
|
||||
|
@ -169,20 +155,14 @@ void start_bgm(char *name) {
|
|||
current_bgm.name = NULL;
|
||||
return;
|
||||
}
|
||||
alSourceRewind(resources.bgmsrc);
|
||||
warn_alut_error("rewinding music source");
|
||||
alSourcei(resources.bgmsrc, AL_BUFFER, current_bgm.data->alsnd);
|
||||
warn_alut_error("changing buffer of music source");
|
||||
alSourcei(resources.bgmsrc, AL_LOOPING, AL_TRUE);
|
||||
warn_alut_error("looping music source");
|
||||
}
|
||||
|
||||
// otherwise, do not change anything and continue
|
||||
ALint play;
|
||||
alGetSourcei(resources.bgmsrc,AL_SOURCE_STATE,&play);
|
||||
warn_alut_error("checking state of music source");
|
||||
|
||||
// Support drawing BGM title in game loop
|
||||
if(Mix_PausedMusic()) Mix_ResumeMusic(); // Unpause music if paused
|
||||
if(Mix_PlayingMusic()) return; // Do nothing if music already playing (or was just unpaused)
|
||||
|
||||
if(Mix_PlayMusic(current_bgm.data->music, -1) == -1) // Start playing otherwise
|
||||
printf("Failed starting BGM %s: %s.\n", current_bgm.name, Mix_GetError());
|
||||
// Support drawing BGM title in game loop (only when music changed!)
|
||||
if ((current_bgm.title = get_bgm_desc(resources.bgm_descriptions, current_bgm.name)) != NULL)
|
||||
{
|
||||
current_bgm.started_at = global.frames;
|
||||
|
@ -193,30 +173,21 @@ void start_bgm(char *name) {
|
|||
{
|
||||
current_bgm.started_at = -1;
|
||||
}
|
||||
|
||||
if(play != AL_PLAYING)
|
||||
{
|
||||
alSourcePlay(resources.bgmsrc);
|
||||
warn_alut_error("starting playback of music source");
|
||||
printf("Started %s\n", (current_bgm.title ? current_bgm.title : current_bgm.name));
|
||||
}
|
||||
|
||||
printf("Started %s\n", (current_bgm.title ? current_bgm.title : current_bgm.name));
|
||||
}
|
||||
|
||||
void continue_bgm(void)
|
||||
{
|
||||
start_bgm(current_bgm.name);
|
||||
start_bgm(current_bgm.name); // In most cases it's just unpausing existing music.
|
||||
}
|
||||
|
||||
void stop_bgm(void) {
|
||||
if (config_get_int(CONFIG_NO_MUSIC) || !current_bgm.name) return;
|
||||
|
||||
ALint play;
|
||||
alGetSourcei(resources.bgmsrc,AL_SOURCE_STATE,&play);
|
||||
warn_alut_error("checking state of music source");
|
||||
if(play == AL_PLAYING)
|
||||
if(Mix_PlayingMusic() && !Mix_PausedMusic())
|
||||
{
|
||||
alSourcePause(resources.bgmsrc);
|
||||
warn_alut_error("pausing music source");
|
||||
Mix_PauseMusic(); // Pause, not halt - to be unpaused in continue_bgm() if needed.
|
||||
printf("BGM stopped.\n");
|
||||
}
|
||||
else
|
||||
|
@ -242,8 +213,7 @@ void set_bgm_volume(float gain)
|
|||
{
|
||||
if(config_get_int(CONFIG_NO_MUSIC)) return;
|
||||
printf("BGM volume: %f\n", gain);
|
||||
alSourcef(resources.bgmsrc,AL_GAIN, gain);
|
||||
warn_alut_error("changing gain of music source");
|
||||
Mix_VolumeMusic(gain * MIX_MAX_VOLUME);
|
||||
}
|
||||
|
||||
void delete_music(void) {
|
||||
|
|
|
@ -26,7 +26,7 @@ struct current_bgm_t {
|
|||
int started_at;
|
||||
};
|
||||
|
||||
Sound *load_bgm(char *filename, const char *type);
|
||||
Sound *load_bgm(char *filename);
|
||||
|
||||
extern struct current_bgm_t current_bgm;
|
||||
|
||||
|
@ -36,7 +36,7 @@ void continue_bgm(void);
|
|||
void save_bgm(void);
|
||||
void restore_bgm(void);
|
||||
|
||||
int init_bgm(int *argc, char *argv[]);
|
||||
int init_bgm(void);
|
||||
void shutdown_bgm(void);
|
||||
|
||||
void load_bgm_descriptions(const char *path);
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
// Based on "Introduction to Ogg Vorbis" example code
|
||||
// by Anthony "TangentZ" Yuen
|
||||
//
|
||||
// https://www.gamedev.net/resources/_/technical/game-programming/introduction-to-ogg-vorbis-r2031
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
static int detect_endianness(void)
|
||||
{
|
||||
// Returns 0 for little endian, 1 for big endian.
|
||||
union { uint16_t patterns; uint8_t endianness; } test_endianness = { .patterns = 0x0100 };
|
||||
return test_endianness.endianness;
|
||||
}
|
||||
|
||||
#define BUFFER_SIZE 32768 // 32 KB buffers
|
||||
|
||||
int load_ogg(char *filename, ALenum *format, char **buffer, ALsizei *size, ALsizei *freq)
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen(filename, "rb");
|
||||
if (f == NULL) return -1; // Error opening for reading
|
||||
|
||||
OggVorbis_File oggFile;
|
||||
if (ov_open(f, &oggFile, NULL, 0) != 0)
|
||||
{
|
||||
fclose(f);
|
||||
return -2; // Error opening for decoding
|
||||
}
|
||||
|
||||
vorbis_info *pInfo;
|
||||
pInfo = ov_info(&oggFile, -1);
|
||||
*format = (pInfo->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
||||
*freq = pInfo->rate;
|
||||
|
||||
int bitstream;
|
||||
long bytes;
|
||||
char array[BUFFER_SIZE];
|
||||
*buffer = NULL; *size = 0;
|
||||
do
|
||||
{
|
||||
bytes = ov_read(&oggFile, array, BUFFER_SIZE, detect_endianness(), 2, 1, &bitstream);
|
||||
if (bytes < 0)
|
||||
{
|
||||
fclose(f);
|
||||
ov_clear(&oggFile);
|
||||
return -3; // Error decoding
|
||||
}
|
||||
|
||||
*buffer = realloc(*buffer, *size + bytes);
|
||||
if(*buffer == NULL)
|
||||
{
|
||||
fclose(f);
|
||||
ov_clear(&oggFile);
|
||||
return -4; // Memory limit exceeded
|
||||
}
|
||||
|
||||
memcpy(*buffer + *size, array, bytes);
|
||||
*size += bytes;
|
||||
}
|
||||
while (bytes > 0);
|
||||
|
||||
ov_clear(&oggFile);
|
||||
return 0;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef OGG_H
|
||||
#define OGG_H
|
||||
|
||||
#include <AL/al.h>
|
||||
|
||||
int load_ogg(char *filename, ALenum *format, char **buffer, ALsizei *size, ALsizei *freq);
|
||||
|
||||
#endif
|
|
@ -39,18 +39,26 @@ void recurse_dir(char *path) {
|
|||
else
|
||||
load_texture(buf);
|
||||
} else
|
||||
#ifdef OGG_SUPPORT_ENABLED
|
||||
if( (strcmp(dp->d_name + strlen(dp->d_name)-4, ".wav") == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".ogg") == 0))
|
||||
#else
|
||||
if (strcmp(dp->d_name + strlen(dp->d_name)-4, ".wav") == 0)
|
||||
#endif
|
||||
// A some kind of 'indian code', but...
|
||||
if( (strcmp(dp->d_name + strlen(dp->d_name)-4, ".wav" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".ogg" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".mp3" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".mod" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".xm" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".s3m" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".669" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".it" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".med" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".mid" ) == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".flac") == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".aiff") == 0)
|
||||
|| (strcmp(dp->d_name + strlen(dp->d_name)-4, ".voc" ) == 0))
|
||||
{
|
||||
// BGMs should have "bgm_" prefix!
|
||||
if(strncmp(dp->d_name, "bgm_", 4) == 0)
|
||||
load_bgm(buf, dp->d_name + strlen(dp->d_name)-3);
|
||||
load_bgm(buf);
|
||||
else
|
||||
load_sound(buf, dp->d_name + strlen(dp->d_name)-3);
|
||||
load_sound(buf);
|
||||
} else if(strcmp(dp->d_name + strlen(dp->d_name)-4, ".sha") == 0) {
|
||||
load_shader_file(buf);
|
||||
} else if(strcmp(dp->d_name + strlen(dp->d_name)-4, ".obj") == 0) {
|
||||
|
|
|
@ -28,10 +28,6 @@ typedef enum ResourceState {
|
|||
RS_BgmLoaded = 16
|
||||
} ResourceState;
|
||||
|
||||
enum {
|
||||
SNDSRC_COUNT = 35
|
||||
};
|
||||
|
||||
struct Resources {
|
||||
ResourceState state;
|
||||
|
||||
|
@ -43,9 +39,6 @@ struct Resources {
|
|||
Model *models;
|
||||
Bgm_desc *bgm_descriptions;
|
||||
|
||||
ALuint sndsrc[SNDSRC_COUNT];
|
||||
ALuint bgmsrc;
|
||||
|
||||
FBO fbg[2];
|
||||
FBO fsec;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue