Skip to content

Commit

Permalink
Refactor xrSound
Browse files Browse the repository at this point in the history
Code cleanup and formatting
LPCSTR to pcstr
BOOL to bool
and others...
  • Loading branch information
Xottab-DUTY committed Aug 18, 2017
1 parent de46442 commit ab80503
Show file tree
Hide file tree
Showing 30 changed files with 489 additions and 519 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/CarSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CCar::SCarSound::Init()

snd_engine.create(ini->r_string("car_sound", "snd_name"), st_Effect, sg_SourceType); //
snd_engine_start.create(READ_IF_EXISTS(ini, r_string, "car_sound", "engine_start", "car\\test_car_start"),
st_Effect, sg_SourceType);
st_Effect, sg_SourceType);
snd_engine_stop.create(
READ_IF_EXISTS(ini, r_string, "car_sound", "engine_stop", "car\\test_car_stop"), st_Effect, sg_SourceType);
float fengine_start_delay = READ_IF_EXISTS(ini, r_float, "car_sound", "engine_sound_start_dellay", 0.25f);
Expand Down
10 changes: 5 additions & 5 deletions src/xrMisc/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ ref_sound_data::ref_sound_data() throw() :
g_object(0)
{}

ref_sound_data::ref_sound_data(LPCSTR fName, esound_type sound_type, int game_type)
ref_sound_data::ref_sound_data(pcstr fName, esound_type sound_type, int game_type)
{ ::Sound->_create_data(*this, fName, sound_type, game_type); }

ref_sound_data::~ref_sound_data()
{ ::Sound->_destroy_data(*this); }

void ref_sound::create(LPCSTR name, esound_type sound_type, int game_type)
void ref_sound::create(pcstr name, esound_type sound_type, int game_type)
{
VerSndUnlocked();
::Sound->create(*this, name, sound_type, game_type);
}

void ref_sound::attach_tail(LPCSTR name)
void ref_sound::attach_tail(pcstr name)
{
VerSndUnlocked();
::Sound->attach_tail(*this, name);
Expand Down Expand Up @@ -132,14 +132,14 @@ void ref_sound::stop()
{
VerSndUnlocked();
if (_feedback())
_feedback()->stop(FALSE);
_feedback()->stop(false);
}

void ref_sound::stop_deferred()
{
VerSndUnlocked();
if (_feedback())
_feedback()->stop(TRUE);
_feedback()->stop(true);
}

const CSound_params* ref_sound::get_params()
Expand Down
54 changes: 24 additions & 30 deletions src/xrSound/OpenALDeviceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#pragma warning(pop)

#ifdef _EDITOR
log_fn_ptr_type* pLog = NULL;
log_fn_ptr_type* pLog = nullptr;
#endif

void __cdecl al_log(char* msg) { Log(msg); }
ALDeviceList::ALDeviceList()
{
pLog = al_log;
snd_device_id = u32(-1);
snd_device_id = (u32)-1;
Enumerate();
}

Expand All @@ -48,18 +48,17 @@ ALDeviceList::ALDeviceList()
ALDeviceList::~ALDeviceList()
{
for (int i = 0; snd_devices_token[i].name; i++)
{
xr_free(snd_devices_token[i].name);
}

xr_free(snd_devices_token);
snd_devices_token = NULL;
snd_devices_token = nullptr;
}

void ALDeviceList::Enumerate()
{
char* devices;
pstr devices;
int major, minor, index;
LPCSTR actualDeviceName;
pcstr actualDeviceName;

Msg("SOUND: OpenAL: enumerate devices...");
// have a set of vectors storing the device list, selection status, spec version #, and XRAM support status
Expand All @@ -68,13 +67,13 @@ void ALDeviceList::Enumerate()

CoUninitialize();
// grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
{
Msg("SOUND: OpenAL: EnumerationExtension Present");

devices = (char*)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
devices = (pstr)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
Msg("devices %s", devices);
xr_strcpy(m_defaultDeviceName, (char*)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
xr_strcpy(m_defaultDeviceName, (pstr)alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER));
Msg("SOUND: OpenAL: system default SndDevice name is %s", m_defaultDeviceName);

// ManowaR
Expand All @@ -99,14 +98,14 @@ void ALDeviceList::Enumerate()
ALCdevice* device = alcOpenDevice(devices);
if (device)
{
ALCcontext* context = alcCreateContext(device, NULL);
ALCcontext* context = alcCreateContext(device, nullptr);
if (context)
{
alcMakeContextCurrent(context);
// if new actual device name isn't already in the list, then add it...
actualDeviceName = alcGetString(device, ALC_DEVICE_SPECIFIER);

if ((actualDeviceName != NULL) && xr_strlen(actualDeviceName) > 0)
if (actualDeviceName != nullptr && xr_strlen(actualDeviceName) > 0)
{
alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &major);
alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &minor);
Expand All @@ -121,26 +120,22 @@ void ALDeviceList::Enumerate()
if (alIsExtensionPresent("EAX5.0"))
m_devices.back().props.eax = 5;

m_devices.back().props.efx = (alIsExtensionPresent("ALC_EXT_EFX") == TRUE);
m_devices.back().props.xram = (alIsExtensionPresent("EAX_RAM") == TRUE);
m_devices.back().props.efx = alIsExtensionPresent("ALC_EXT_EFX") == true;
m_devices.back().props.xram = alIsExtensionPresent("EAX_RAM") == true;

m_devices.back().props.eax_unwanted =
((0 == xr_strcmp(actualDeviceName, AL_GENERIC_HARDWARE)) ||
(0 == xr_strcmp(actualDeviceName, AL_GENERIC_SOFTWARE)));
0 == xr_strcmp(actualDeviceName, AL_GENERIC_HARDWARE) ||
0 == xr_strcmp(actualDeviceName, AL_GENERIC_SOFTWARE);
++index;
}
alcDestroyContext(context);
}
else
{
Msg("SOUND: OpenAL: cant create context for %s", device);
}
alcCloseDevice(device);
}
else
{
Msg("SOUND: OpenAL: cant open device %s", devices);
}

devices += xr_strlen(devices) + 1;
}
Expand All @@ -152,7 +147,7 @@ void ALDeviceList::Enumerate()
u32 _cnt = GetNumDevices();
snd_devices_token = xr_alloc<xr_token>(_cnt + 1);
snd_devices_token[_cnt].id = -1;
snd_devices_token[_cnt].name = NULL;
snd_devices_token[_cnt].name = nullptr;
for (u32 i = 0; i < _cnt; ++i)
{
snd_devices_token[i].id = i;
Expand All @@ -169,23 +164,23 @@ void ALDeviceList::Enumerate()
{
GetDeviceVersion(j, &majorVersion, &minorVersion);
Msg("%d. %s, Spec Version %d.%d %s eax[%d] efx[%s] xram[%s]", j + 1, GetDeviceName(j), majorVersion,
minorVersion, (_stricmp(GetDeviceName(j), m_defaultDeviceName) == 0) ? "(default)" : "",
minorVersion, _stricmp(GetDeviceName(j), m_defaultDeviceName) == 0 ? "(default)" : "",
GetDeviceDesc(j).props.eax, GetDeviceDesc(j).props.efx ? "yes" : "no",
GetDeviceDesc(j).props.xram ? "yes" : "no");
}
if (!strstr(GetCommandLine(), "-editor"))
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
}

LPCSTR ALDeviceList::GetDeviceName(u32 index) { return snd_devices_token[index].name; }
pcstr ALDeviceList::GetDeviceName(u32 index) const { return snd_devices_token[index].name; }
void ALDeviceList::SelectBestDevice()
{
int best_majorVersion = -1;
int best_minorVersion = -1;
int majorVersion;
int minorVersion;

if (snd_device_id == u32(-1))
if (snd_device_id == (u32)-1)
{
// select best
u32 new_device_id = snd_device_id;
Expand All @@ -195,19 +190,19 @@ void ALDeviceList::SelectBestDevice()
continue;

GetDeviceVersion(i, &majorVersion, &minorVersion);
if ((majorVersion > best_majorVersion) ||
(majorVersion == best_majorVersion && minorVersion > best_minorVersion))
if (majorVersion > best_majorVersion ||
majorVersion == best_majorVersion && minorVersion > best_minorVersion)
{
best_majorVersion = majorVersion;
best_minorVersion = minorVersion;
new_device_id = i;
}
}
if (new_device_id == u32(-1))
if (new_device_id == (u32)-1)
{
R_ASSERT(GetNumDevices() != 0);
new_device_id = 0; // first
};
}
snd_device_id = new_device_id;
}
if (GetNumDevices() == 0)
Expand All @@ -223,5 +218,4 @@ void ALDeviceList::GetDeviceVersion(u32 index, int* major, int* minor)
{
*major = m_devices[index].major_ver;
*minor = m_devices[index].minor_ver;
return;
}
14 changes: 7 additions & 7 deletions src/xrSound/OpenALDeviceList.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once
#ifndef ALDEVICELIST_H
#define ALDEVICELIST_H

#include "openal/al.h"
#include "openal/alc.h"

#define AL_GENERIC_HARDWARE "Generic Hardware"
#define AL_GENERIC_SOFTWARE "Generic Software"
constexpr pcstr AL_GENERIC_HARDWARE = "Generic Hardware";
constexpr pcstr AL_GENERIC_SOFTWARE = "Generic Software";

struct ALDeviceDesc
{
Expand All @@ -27,7 +28,7 @@ struct ALDeviceDesc
u16 storage;
};
ESndProps props;
ALDeviceDesc(LPCSTR nm, int mn, int mj)
ALDeviceDesc(pcstr nm, int mn, int mj)
{
xr_strcpy(name, nm);
minor_ver = mn;
Expand All @@ -39,18 +40,17 @@ struct ALDeviceDesc

class ALDeviceList
{
private:
xr_vector<ALDeviceDesc> m_devices;
string256 m_defaultDeviceName;
void Enumerate();

public:
ALDeviceList();
~ALDeviceList();

u32 GetNumDevices() { return m_devices.size(); }
u32 GetNumDevices() const { return m_devices.size(); }
const ALDeviceDesc& GetDeviceDesc(u32 index) { return m_devices[index]; }
LPCSTR GetDeviceName(u32 index);
pcstr GetDeviceName(u32 index) const;
void GetDeviceVersion(u32 index, int* major, int* minor);
void SelectBestDevice();
};
Expand Down
Loading

0 comments on commit ab80503

Please sign in to comment.