Skip to content

Commit

Permalink
Enabled support of network sources in audio stream opcodes. (#158)
Browse files Browse the repository at this point in the history
Enabled support of network sources in audio stream opcodes.
Added network sources support as option in settings
  • Loading branch information
MiranDMC authored Jun 23, 2024
1 parent 0c368da commit 65eca0c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cleo_plugins/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ class Audio
//0AAC=2, %2d% = load_audiostream %1d% // IF and SET
static OpcodeResult __stdcall opcode_0AAC(CScriptThread* thread)
{
OPCODE_READ_PARAM_FILEPATH(path);
OPCODE_READ_PARAM_STRING_LEN(path, 511);

if (!isNetworkSource(path))
CLEO_ResolvePath(thread, _buff_path, sizeof(_buff_path));

auto ptr = soundSystem.CreateStream(path);

Expand Down Expand Up @@ -207,7 +210,10 @@ class Audio
//0AC1=2,%2d% = load_audiostream_with_3d_support %1d% //IF and SET
static OpcodeResult __stdcall opcode_0AC1(CScriptThread* thread)
{
OPCODE_READ_PARAM_FILEPATH(path);
OPCODE_READ_PARAM_STRING_LEN(path, 511);

if (!isNetworkSource(path))
CLEO_ResolvePath(thread, _buff_path, sizeof(_buff_path));

auto ptr = soundSystem.CreateStream(path, true);

Expand Down Expand Up @@ -414,4 +420,3 @@ class Audio
} audioInstance;

CSoundSystem Audio::soundSystem;

8 changes: 7 additions & 1 deletion cleo_plugins/Audio/C3DAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ using namespace CLEO;

C3DAudioStream::C3DAudioStream(const char* filepath) : CAudioStream()
{
if (isNetworkSource(filepath) && !CSoundSystem::allowNetworkSources)
{
TRACE("Loading of 3d-audiostream '%s' failed. Support of network sources was disabled in SA.Audio.ini", filepath);
return;
}

unsigned flags = BASS_SAMPLE_3D | BASS_SAMPLE_MONO | BASS_SAMPLE_SOFTWARE;
if (CSoundSystem::useFloatAudio) flags |= BASS_SAMPLE_FLOAT;

if (!(streamInternal = BASS_StreamCreateFile(FALSE, filepath, 0, 0, flags)) &&
!(streamInternal = BASS_StreamCreateURL(filepath, 0, flags, nullptr, nullptr)))
{
LOG_WARNING(0, "Loading 3d-audiostream %s failed. Error code: %d", filepath, BASS_ErrorGetCode());
LOG_WARNING(0, "Loading of 3d-audiostream '%s' failed. Error code: %d", filepath, BASS_ErrorGetCode());
return;
}

Expand Down
8 changes: 7 additions & 1 deletion cleo_plugins/Audio/CAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ using namespace CLEO;

CAudioStream::CAudioStream(const char* filepath)
{
if (isNetworkSource(filepath) && !CSoundSystem::allowNetworkSources)
{
TRACE("Loading of audiostream '%s' failed. Support of network sources was disabled in SA.Audio.ini", filepath);
return;
}

unsigned flags = BASS_SAMPLE_SOFTWARE;
if (CSoundSystem::useFloatAudio) flags |= BASS_SAMPLE_FLOAT;

if (!(streamInternal = BASS_StreamCreateFile(FALSE, filepath, 0, 0, flags)) &&
!(streamInternal = BASS_StreamCreateURL(filepath, 0, flags, 0, nullptr)))
{
LOG_WARNING(0, "Loading audiostream %s failed. Error code: %d", filepath, BASS_ErrorGetCode());
LOG_WARNING(0, "Loading of audiostream '%s' failed. Error code: %d", filepath, BASS_ErrorGetCode());
return;
}

Expand Down
8 changes: 8 additions & 0 deletions cleo_plugins/Audio/CSoundSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace CLEO
{
bool CSoundSystem::useFloatAudio = false;
bool CSoundSystem::allowNetworkSources = true;
BASS_3DVECTOR CSoundSystem::pos(0.0, 0.0, 0.0);
BASS_3DVECTOR CSoundSystem::vel(0.0, 0.0, 0.0);
BASS_3DVECTOR CSoundSystem::front(0.0, -1.0, 0.0);
Expand All @@ -29,6 +30,12 @@ namespace CLEO
}
}

bool isNetworkSource(const char* path)
{
return _strnicmp("http:", path, 5) == 0 ||
_strnicmp("https:", path, 6) == 0;
}

CSoundSystem::~CSoundSystem()
{
TRACE("Finalizing SoundSystem...");
Expand All @@ -49,6 +56,7 @@ namespace CLEO

auto config = GetConfigFilename();
defaultStreamType = (eStreamType)GetPrivateProfileInt("General", "DefaultStreamType", 0, config.c_str());
allowNetworkSources = GetPrivateProfileInt("General", "AllowNetworkSources", 1, config.c_str()) != 0;

int default_device, total_devices, enabled_devices;
EnumerateBassDevices(total_devices, enabled_devices, default_device);
Expand Down
3 changes: 3 additions & 0 deletions cleo_plugins/Audio/CSoundSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace CLEO
bool paused = false;

static bool useFloatAudio;
static bool CSoundSystem::allowNetworkSources;

static BASS_3DVECTOR pos;
static BASS_3DVECTOR vel;
Expand Down Expand Up @@ -52,4 +53,6 @@ namespace CLEO
void Resume();
void Process();
};

bool isNetworkSource(const char* path);
}
3 changes: 3 additions & 0 deletions cleo_plugins/Audio/SA.Audio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
; Manually select audio device. Visit `.cleo.log` file to check list of available options. -1 for automatic
AudioDevice=-1

; Allow playing streams from http(s) locations
AllowNetworkSources=1

; Which game's volume settings CLEO sounds should use by default: 0 - None, 1 - SFX, 2 - Music
DefaultStreamType=1

0 comments on commit 65eca0c

Please sign in to comment.