Skip to content

Commit 6445d41

Browse files
committed
feature(openal): Implements OpenAL audio backend.
1 parent 7296c6a commit 6445d41

22 files changed

+1377
-44
lines changed

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ if(SYNTAX_CHECK_ONLY)
3939
endif(SYNTAX_CHECK_ONLY)
4040

4141
# Do we want to build with ffmpeg for audio/video decoding?
42-
option(W3D_BUILD_OPTION_FFMPEG "Build with ffmpeg." OFF)
42+
option(W3D_BUILD_OPTION_FFMPEG "Build with ffmpeg." ON)
4343
add_feature_info(FFMpegBuild W3D_BUILD_OPTION_FFMPEG "Build OpenW3D with FFMpeg")
4444

45+
# Do we want to build with OpenAL/ffmpeg for audio playback?
46+
cmake_dependent_option(W3D_BUILD_OPTION_OPENAL "Build with openal." ON W3D_BUILD_OPTION_FFMPEG OFF)
47+
add_feature_info(OpenALBuild W3D_BUILD_OPTION_OPENAL "Build OpenW3D with OpenAL")
48+
4549
if(NOT WIN32)
4650
add_compile_definitions(__cdecl=)
4751
add_compile_definitions(__stdcall=)
@@ -58,9 +62,13 @@ if(W3D_BUILD_OPTION_FFMPEG)
5862
include(ffmpeg)
5963
endif()
6064

65+
if(W3D_BUILD_OPTION_OPENAL)
66+
include(openal)
67+
endif()
68+
6169
if(WIN32)
6270
# Do we want to build with bink for video decoding?
63-
option(W3D_BUILD_OPTION_BINK "Build with bink." ON)
71+
cmake_dependent_option(W3D_BUILD_OPTION_BINK "Build with bink." ON NOT W3D_BUILD_OPTION_FFMPEG OFF)
6472
add_feature_info(BinkBuild W3D_BUILD_OPTION_BINK "Build OpenW3D with Bink")
6573

6674
if(W3D_BUILD_OPTION_BINK)
@@ -69,7 +77,7 @@ if(WIN32)
6977
endif()
7078

7179
# Do we want to build with miles for audio playback?
72-
option(W3D_BUILD_OPTION_MILES "Build with miles." ON)
80+
cmake_dependent_option(W3D_BUILD_OPTION_MILES "Build with miles." ON NOT W3D_BUILD_OPTION_OPENAL OFF)
7381
add_feature_info(MilesBuild W3D_BUILD_OPTION_MILES "Build OpenW3D with Miles Audio")
7482

7583
if(W3D_BUILD_OPTION_MILES)

Code/BinkMovie/FFMpegPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern "C" {
2929
#include <libswscale/swscale.h>
3030
}
3131

32-
void FFMpegMovieClass::On_Frame(AVFrame *frame, int stream_idx, int stream_type)
32+
void FFMpegMovieClass::On_Frame(AVFrame *frame, int /* stream_idx */, int stream_type)
3333
{
3434
if (stream_type == AVMEDIA_TYPE_VIDEO) {
3535
av_frame_free(&CurrentFrame);

Code/WWAudio/AudibleSound.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,13 @@ AudibleSoundClass::On_Frame_Update (unsigned int /* milliseconds */)
10591059
m_LogicalSound->Set_Transform (m_Transform);
10601060
}
10611061

1062+
//
1063+
// OpenAL addition, attempt to queue audio if the handle buffer is streaming.
1064+
//
1065+
if (m_SoundHandle != NULL) {
1066+
m_SoundHandle->Queue_Audio();
1067+
}
1068+
10621069
return true;
10631070
}
10641071

Code/WWAudio/AudibleSound.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class AudibleSoundClass : public SoundSceneObjClass
104104
//////////////////////////////////////////////////////////////////////
105105
friend class WWAudioClass;
106106
friend class MilesAudioClass;
107+
friend class OpenALAudioClass;
107108

108109
//////////////////////////////////////////////////////////////////////
109110
// Public data types

Code/WWAudio/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ set(WWAUDIO_SRC
3535
WWAudio.h
3636
)
3737

38-
if(W3D_BUILD_OPTION_MILES)
38+
if(W3D_BUILD_OPTION_OPENAL)
39+
list(APPEND WWAUDIO_SRC
40+
openal/OpenALAudio.h
41+
openal/OpenALAudio.cpp
42+
openal/FFMpegBuffer.cpp
43+
openal/FFMpegBuffer.h
44+
openal/OpenALHandle.cpp
45+
openal/OpenALHandle.h
46+
null/NullUtils.cpp
47+
)
48+
elseif(W3D_BUILD_OPTION_MILES)
3949
list(APPEND WWAUDIO_SRC
4050
miles/MilesAudio.h
4151
miles/MilesAudio.cpp
@@ -70,6 +80,10 @@ if(TARGET milesstub)
7080
target_link_libraries(wwaudio PRIVATE milesstub)
7181
endif()
7282

83+
if(TARGET OpenAL::OpenAL)
84+
target_link_libraries(wwaudio PRIVATE OpenAL::OpenAL)
85+
endif()
86+
7387
# This module needs building differently for the level editor
7488
if (W3D_TOOLS)
7589
# Targets to build.
@@ -87,6 +101,10 @@ if (W3D_TOOLS)
87101
target_compile_definitions(wwaudioe PRIVATE W3D_HAS_MILES)
88102
endif()
89103

104+
if(TARGET OpenAL::OpenAL)
105+
target_link_libraries(wwaudioe PRIVATE OpenAL::OpenAL)
106+
endif()
107+
90108
if(TARGET milesstub)
91109
target_link_libraries(wwaudioe PRIVATE milesstub)
92110
endif()

Code/WWAudio/SoundScene.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ class SoundSceneClass
161161
// Debugging
162162
//////////////////////////////////////////////////////////////////////
163163
bool Is_Sound_In_Scene (AudibleSoundClass *sound_obj, bool all = true);
164-
164+
165+
virtual void Initialize (void);
165166
protected:
166167

167168
//////////////////////////////////////////////////////////////////////
168169
// Protected methods
169170
//////////////////////////////////////////////////////////////////////
170171
virtual void On_Frame_Update (unsigned int milliseconds = 0);
171-
virtual void Initialize (void);
172172

173173
virtual bool Is_Logical_Sound_In_Scene (LogicalSoundClass *sound_obj, bool single_shot = false);
174174

Code/WWAudio/WWAudio.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ WWAudioClass::WWAudioClass(bool lite)
134134

135135
WWAudioClass::~WWAudioClass (void)
136136
{
137+
//
138+
// Free the list of logical "types".
139+
//
140+
Reset_Logical_Types ();
141+
137142
delete AudioIni;
138143
_theInstance = NULL;
139144
}

Code/WWAudio/miles/MilesAudio.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ MilesAudioClass::~MilesAudioClass (void)
122122
WWAudioThreadsClass::End_Delayed_Release_Thread ();
123123

124124
Shutdown ();
125-
126-
//
127-
// Free the list of logical "types".
128-
//
129-
Reset_Logical_Types ();
130-
131-
return;
132125
}
133126

134127

Code/WWAudio/miles/sound2dhandle.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ class Sound2DHandleClass : public SoundHandleClass
6464
// Public methods
6565
///////////////////////////////////////////////////////////////////
6666

67-
//
68-
// RTTI
69-
//
70-
Sound2DHandleClass * As_Sound2DHandleClass (void) override { return this; }
71-
7267
//
7368
// Inherited
7469
//

Code/WWAudio/miles/sound3dhandle.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ class Sound3DHandleClass : public SoundHandleClass
6464
// Public methods
6565
///////////////////////////////////////////////////////////////////
6666

67-
//
68-
// RTTI
69-
//
70-
Sound3DHandleClass * As_Sound3DHandleClass (void) override { return this; }
71-
7267
//
7368
// Inherited
7469
//

0 commit comments

Comments
 (0)