Skip to content

Commit 8ab9d1f

Browse files
BorisCarvajalSiegeLord
authored andcommitted
Opus codec support.
1 parent f42ef0e commit 8ab9d1f

File tree

8 files changed

+592
-2
lines changed

8 files changed

+592
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ before_install:
1313
export DISPLAY=:99.0;
1414
sh -e /etc/init.d/xvfb start;
1515
sudo apt-get update;
16-
sudo apt-get install -y libvorbis-dev libtheora-dev libphysfs-dev libdumb1-dev libflac-dev libpulse-dev libgtk2.0-dev pandoc;
16+
sudo apt-get install -y libopusfile-dev libvorbis-dev libtheora-dev libphysfs-dev libdumb1-dev libflac-dev libpulse-dev libgtk2.0-dev pandoc;
1717
elif [ `uname` = "Darwin" ]; then
18-
brew install cmake libvorbis freetype flac physfs;
18+
brew install cmake opusfile libvorbis freetype flac physfs;
1919
fi
2020

2121
env:

README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ These are the dependencies required for the addons:
110110
- Ogg Vorbis, a free lossy audio format. (libogg, libvorbis, libvorbisfile)
111111
Home page: <http://www.vorbis.com/>
112112

113+
- Opus, a free lossy audio codec. (libogg, libopus, libopusfile)
114+
Home page: <http://www.opus-codec.org/>
115+
113116
- FLAC, a free lossless audio codec. (libFLAC, libogg)
114117
Home page: <http://flac.sourceforge.net/>
115118

addons/acodec/CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if(WIN32)
66
endif()
77
option(WANT_VORBIS "Enable Ogg Vorbis support using libvorbis" on)
88
option(WANT_TREMOR "Enable Ogg Vorbis support using Tremor" off)
9+
option(WANT_OPUS "Enable Opus support using libopus" on)
910
option(WANT_MODAUDIO "Enable MOD Audio support" on)
1011
option(WANT_ACODEC_DYNAMIC_LOAD "Enable DLL loading in acodec (Windows)" off)
1112

@@ -268,6 +269,63 @@ if(SUPPORT_VORBIS)
268269
endif()
269270
endif(SUPPORT_VORBIS)
270271

272+
#
273+
# Opus
274+
#
275+
276+
if(WANT_OPUS)
277+
find_package(Opus)
278+
if(OPUS_FOUND)
279+
set(CMAKE_REQUIRED_INCLUDES ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
280+
if(COMPILER_GCC_OR_CLANG)
281+
# libm is required when linking statically.
282+
set(CMAKE_REQUIRED_LIBRARIES "${OPUS_LIBRARIES};m")
283+
else()
284+
set(CMAKE_REQUIRED_LIBRARIES "${OPUS_LIBRARIES}")
285+
endif(COMPILER_GCC_OR_CLANG)
286+
run_c_compile_test("
287+
#include <opus/opusfile.h>
288+
int main(void)
289+
{
290+
OggOpusFile *f;
291+
OpusHead *v = 0;
292+
(void)v;
293+
op_free(f);
294+
return 0;
295+
}"
296+
OPUS_COMPILES)
297+
set(CMAKE_REQUIRED_INCLUDES)
298+
set(CMAKE_REQUIRED_LIBRARIES)
299+
if(OPUS_COMPILES)
300+
set(SUPPORT_OPUS 1)
301+
endif()
302+
endif(OPUS_FOUND)
303+
if(NOT SUPPORT_OPUS)
304+
message("WARNING: libopus not found or compile test failed, disabling support.")
305+
endif(NOT SUPPORT_OPUS)
306+
endif()
307+
308+
if(SUPPORT_OPUS)
309+
include_directories(SYSTEM ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
310+
set(ALLEGRO_CFG_ACODEC_OPUS 1)
311+
list(APPEND ACODEC_SOURCES opus.c)
312+
313+
list(APPEND ACODEC_INCLUDE_DIRECTORIES ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
314+
315+
if(WIN32 AND WANT_ACODEC_DYNAMIC_LOAD)
316+
if(OPUSFILE_LIBRARY MATCHES "${WIN32_STATIC_LIB_REGEX}")
317+
message("WARNING: Dynamic loading will be disabled for Opus"
318+
" as static library was found: ${OPUSFILE_LIBRARY}")
319+
else()
320+
get_dll_name(${OPUSFILE_LIBRARY} ALLEGRO_CFG_ACODEC_OPUSFILE_DLL)
321+
endif()
322+
endif()
323+
324+
if(NOT ALLEGRO_CFG_ACODEC_OPUSFILE_DLL)
325+
list(APPEND ACODEC_LIBRARIES ${OPUS_LIBRARIES})
326+
endif()
327+
endif(SUPPORT_OPUS)
328+
271329
configure_file(
272330
allegro5/internal/aintern_acodec_cfg.h.cmake
273331
${PROJECT_BINARY_DIR}/include/allegro5/internal/aintern_acodec_cfg.h

addons/acodec/acodec.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ bool al_init_acodec_addon(void)
5555
ret &= al_register_audio_stream_loader_f(".ogg", _al_load_ogg_vorbis_audio_stream_f);
5656
#endif
5757

58+
#ifdef ALLEGRO_CFG_ACODEC_OPUS
59+
ret &= al_register_sample_loader(".opus", _al_load_ogg_opus);
60+
ret &= al_register_audio_stream_loader(".opus", _al_load_ogg_opus_audio_stream);
61+
ret &= al_register_sample_loader_f(".opus", _al_load_ogg_opus_f);
62+
ret &= al_register_audio_stream_loader_f(".opus", _al_load_ogg_opus_audio_stream_f);
63+
#endif
64+
5865
return ret;
5966
}
6067

addons/acodec/acodec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ ALLEGRO_AUDIO_STREAM *_al_load_ogg_vorbis_audio_stream_f(ALLEGRO_FILE* file,
5858
size_t buffer_count, unsigned int samples);
5959
#endif
6060

61+
#ifdef ALLEGRO_CFG_ACODEC_OPUS
62+
ALLEGRO_SAMPLE *_al_load_ogg_opus(const char *filename);
63+
ALLEGRO_SAMPLE *_al_load_ogg_opus_f(ALLEGRO_FILE *file);
64+
ALLEGRO_AUDIO_STREAM *_al_load_ogg_opus_audio_stream(const char *filename,
65+
size_t buffer_count, unsigned int samples);
66+
ALLEGRO_AUDIO_STREAM *_al_load_ogg_opus_audio_stream_f(ALLEGRO_FILE* file,
67+
size_t buffer_count, unsigned int samples);
68+
#endif
6169

6270

6371
#endif

addons/acodec/allegro5/internal/aintern_acodec_cfg.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#cmakedefine ALLEGRO_CFG_ACODEC_MODAUDIO
33
#cmakedefine ALLEGRO_CFG_ACODEC_VORBIS
44
#cmakedefine ALLEGRO_CFG_ACODEC_TREMOR
5+
#cmakedefine ALLEGRO_CFG_ACODEC_OPUS
56

67

78
/* Define if the library should be loaded dynamically. */
89
#cmakedefine ALLEGRO_CFG_ACODEC_FLAC_DLL "@ALLEGRO_CFG_ACODEC_FLAC_DLL@"
910
#cmakedefine ALLEGRO_CFG_ACODEC_DUMB_DLL "@ALLEGRO_CFG_ACODEC_DUMB_DLL@"
1011
#cmakedefine ALLEGRO_CFG_ACODEC_VORBISFILE_DLL "@ALLEGRO_CFG_ACODEC_VORBISFILE_DLL@"
12+
#cmakedefine ALLEGRO_CFG_ACODEC_OPUSFILE_DLL "@ALLEGRO_CFG_ACODEC_OPUSFILE_DLL@"

0 commit comments

Comments
 (0)