Skip to content

OpenAL support #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions GeneralsMD/Code/GameEngineDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ set(GAMEENGINEDEVICE_SRC
Include/Win32Device/GameClient/Win32DIKeyboard.h
Include/Win32Device/GameClient/Win32DIMouse.h
Include/Win32Device/GameClient/Win32Mouse.h
Source/MilesAudioDevice/MilesAudioFileCache.h
Source/MilesAudioDevice/MilesAudioFileCache.cpp
Source/MilesAudioDevice/MilesAudioManager.cpp
Source/VideoDevice/Bink/BinkVideoPlayer.cpp
Source/W3DDevice/Common/System/W3DFunctionLexicon.cpp
Expand Down Expand Up @@ -245,4 +247,24 @@ if(RTS_BUILD_OPTION_FFMPEG)
target_link_libraries(z_gameenginedevice PRIVATE ${FFMPEG_LIBRARIES})
target_compile_definitions(z_gameenginedevice PUBLIC RTS_HAS_FFMPEG)
endif()
endif()

if(RTS_BUILD_OPTION_OPENAL)
find_package(OpenAL CONFIG REQUIRED)

if(OpenAL_FOUND)
target_sources(z_gameenginedevice PRIVATE
Include/OpenALDevice/FFmpegOpenALAudioStream.h
Include/OpenALDevice/OpenALAudioManager.h
Include/OpenALDevice/OpenALAudioStream.h
Source/OpenALDevice/FFmpegOpenALAudioStream.cpp
Source/OpenALDevice/OpenALAudioFileCache.h
Source/OpenALDevice/OpenALAudioFileCache.cpp
Source/OpenALDevice/OpenALAudioManager.cpp
Source/OpenALDevice/OpenALAudioStream.cpp
)

target_link_libraries(z_gameenginedevice PRIVATE OpenAL::OpenAL)
target_compile_definitions(z_gameenginedevice PUBLIC RTS_HAS_OPENAL)
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// FILE: MilesAudioManager.h //////////////////////////////////////////////////////////////////////////
// MilesAudioManager implementation
// Author: John K. McDonald, July 2002

#pragma once
#include "Common/AsciiString.h"
#include "Common/GameAudio.h"
#include "mss/mss.h"
Expand Down Expand Up @@ -51,87 +51,15 @@ enum PlayingWhich CPP_11(: Int)
PW_INVALID
};

struct PlayingAudio
{
union
{
HSAMPLE m_sample;
H3DSAMPLE m_3DSample;
HSTREAM m_stream;
};

PlayingAudioType m_type;
volatile PlayingStatus m_status; // This member is adjusted by another running thread.
AudioEventRTS *m_audioEventRTS;
void *m_file; // The file that was opened to play this
Bool m_requestStop;
Bool m_cleanupAudioEventRTS;
Int m_framesFaded;

PlayingAudio() :
m_type(PAT_INVALID),
m_audioEventRTS(NULL),
m_requestStop(false),
m_cleanupAudioEventRTS(true),
m_sample(NULL),
m_framesFaded(0)
{ }
};

struct ProviderInfo
{
AsciiString name;
HPROVIDER id;
Bool m_isValid;
};

struct OpenAudioFile
{
AILSOUNDINFO m_soundInfo;
void *m_file;
UnsignedInt m_openCount;
UnsignedInt m_fileSize;

Bool m_compressed; // if the file was compressed, then we need to free it with a miles function.

// Note: OpenAudioFile does not own this m_eventInfo, and should not delete it.
const AudioEventInfo *m_eventInfo; // Not mutable, unlike the one on AudioEventRTS.
};

typedef std::hash_map< AsciiString, OpenAudioFile, rts::hash<AsciiString>, rts::equal_to<AsciiString> > OpenFilesHash;
typedef OpenFilesHash::iterator OpenFilesHashIt;

class AudioFileCache
{
public:
AudioFileCache();

// Protected by mutex
virtual ~AudioFileCache();
void *openFile( AudioEventRTS *eventToOpenFrom );
void closeFile( void *fileToClose );
void setMaxSize( UnsignedInt size );
// End Protected by mutex

// Note: These functions should be used for informational purposes only. For speed reasons,
// they are not protected by the mutex, so they are not guarenteed to be valid if called from
// outside the audio cache. They should be used as a rough estimate only.
UnsignedInt getCurrentlyUsedSize() const { return m_currentlyUsedSize; }
UnsignedInt getMaxSize() const { return m_maxSize; }

protected:
void releaseOpenAudioFile( OpenAudioFile *fileToRelease );

// This function will return TRUE if it was able to free enough space, and FALSE otherwise.
Bool freeEnoughSpaceForSample(const OpenAudioFile& sampleThatNeedsSpace);

OpenFilesHash m_openFiles;
UnsignedInt m_currentlyUsedSize;
UnsignedInt m_maxSize;
HANDLE m_mutex;
const char *m_mutexName;
};

struct PlayingAudio;
class MilesAudioFileCache;
class MilesAudioManager : public AudioManager
{

Expand Down Expand Up @@ -315,7 +243,7 @@ class MilesAudioManager : public AudioManager
// in the sound engine
std::list<PlayingAudio *> m_stoppedAudio;

AudioFileCache *m_audioCache;
MilesAudioFileCache *m_audioCache;
PlayingAudio *m_binkHandle;
UnsignedInt m_num2DSamples;
UnsignedInt m_num3DSamples;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// FILE: FFmpegOpenALAudioStream.h //////////////////////////////////////////////////////////////////////////
// FFmpegOpenALAudioStream implementation
// Author: Stephan Vedder, May 2025
#pragma once

#include "OpenALAudioManager.h"
#include "OpenALAudioStream.h"

class FFmpegFile;
class FFmpegOpenALAudioStream : public OpenALAudioStream
{
public:
FFmpegOpenALAudioStream(FFmpegFile* file);
~FFmpegOpenALAudioStream();


protected:
FFmpegFile* m_ffmpegFile;
};
Loading
Loading