reword union data for better readability
This commit is contained in:
parent
06af046c13
commit
0c5117dc06
|
@ -150,60 +150,63 @@ void Init(T& settings, bool is3D)
|
||||||
|
|
||||||
XTL::CDirectSoundVoice::CDirectSoundVoice(bool is3D)
|
XTL::CDirectSoundVoice::CDirectSoundVoice(bool is3D)
|
||||||
{
|
{
|
||||||
u = { 0 };
|
settings = { 0 };
|
||||||
|
|
||||||
if (g_LibVersion_DSOUND < 4039) {
|
if (g_LibVersion_DSOUND < 4039) {
|
||||||
u.settings_4034_lower.p_audio_format = new XBOXADPCMWAVEFORMAT;
|
settings.r4034_lower.p_audio_format = new XBOXADPCMWAVEFORMAT;
|
||||||
memset(&u.settings_4034_lower.p_audio_format->wfx, 0, sizeof(XBOXADPCMWAVEFORMAT));
|
memset(&settings.r4034_lower.p_audio_format->wfx, 0, sizeof(XBOXADPCMWAVEFORMAT));
|
||||||
|
|
||||||
Init<_u::_settings_4034_lower>(u.settings_4034_lower, is3D);
|
using settings_template = _settings::_r4034_lower;
|
||||||
|
Init<settings_template>(settings.r4034_lower, is3D);
|
||||||
|
|
||||||
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4034_lower<_u::_settings_4034_lower>);
|
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4034_lower<settings_template>);
|
||||||
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4034_lower<_u::_settings_4034_lower>);
|
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4034_lower<settings_template>);
|
||||||
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4034_lower<_u::_settings_4034_lower>);
|
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4034_lower<settings_template>);
|
||||||
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<_u::_settings_4034_lower>);
|
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<settings_template>);
|
||||||
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<_u::_settings_4034_lower>);
|
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<settings_template>);
|
||||||
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<_u::_settings_4034_lower>);
|
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<settings_template>);
|
||||||
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<_u::_settings_4034_lower>);
|
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<settings_template>);
|
||||||
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<_u::_settings_4034_lower>);
|
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<settings_template>);
|
||||||
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<_u::_settings_4034_lower>);
|
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<settings_template>);
|
||||||
}
|
}
|
||||||
else if (g_LibVersion_DSOUND == 4039) {
|
else if (g_LibVersion_DSOUND == 4039) {
|
||||||
|
|
||||||
Init<_u::_settings_4039_only>(u.settings_4039_only, is3D);
|
using settings_template = _settings::_r4039_only;
|
||||||
|
Init<settings_template>(settings.r4039_only, is3D);
|
||||||
|
|
||||||
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4039_upper<_u::_settings_4039_only>);
|
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4039_upper<settings_template>);
|
||||||
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4039_only<_u::_settings_4039_only>);
|
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4039_only<settings_template>);
|
||||||
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4039_upper<_u::_settings_4039_only>);
|
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4039_upper<settings_template>);
|
||||||
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<_u::_settings_4039_only>);
|
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<settings_template>);
|
||||||
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<_u::_settings_4039_only>);
|
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<settings_template>);
|
||||||
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<_u::_settings_4039_only>);
|
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<settings_template>);
|
||||||
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<_u::_settings_4039_only>);
|
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<settings_template>);
|
||||||
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<_u::_settings_4039_only>);
|
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<settings_template>);
|
||||||
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<_u::_settings_4039_only>);
|
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<settings_template>);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Init<_u::_settings_4134_upper>(u.settings_4134_upper, is3D);
|
using settings_template = _settings::_r4134_upper;
|
||||||
|
Init<settings_template>(settings.r4134_upper, is3D);
|
||||||
|
|
||||||
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4039_upper<_u::_settings_4134_upper>);
|
funcs.GetFormat = reinterpret_cast<pGetFormat>(::GetFormat_4039_upper<settings_template>);
|
||||||
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4134_upper<_u::_settings_4134_upper>);
|
funcs.SetFormat = reinterpret_cast<pSetFormat>(::SetFormat_4134_upper<settings_template>);
|
||||||
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4039_upper<_u::_settings_4134_upper>);
|
funcs.GetFrequencyDefault = reinterpret_cast<pGetUint32>(::GetFrequencyDefault_4039_upper<settings_template>);
|
||||||
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<_u::_settings_4134_upper>);
|
funcs.GetPitch = reinterpret_cast<pGetInt32>(::GetPitch<settings_template>);
|
||||||
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<_u::_settings_4134_upper>);
|
funcs.SetPitch = reinterpret_cast<pSetInt32>(::SetPitch<settings_template>);
|
||||||
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<_u::_settings_4134_upper>);
|
funcs.GetVolume = reinterpret_cast<pGetInt32>(::GetVolume<settings_template>);
|
||||||
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<_u::_settings_4134_upper>);
|
funcs.SetVolume = reinterpret_cast<pSetInt32>(::SetVolume<settings_template>);
|
||||||
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<_u::_settings_4134_upper>);
|
funcs.GetHeadroom = reinterpret_cast<pGetUint32>(::GetHeadroom<settings_template>);
|
||||||
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<_u::_settings_4134_upper>);
|
funcs.SetHeadroom = reinterpret_cast<pSetUint32>(::SetHeadroom<settings_template>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::CDirectSoundVoice::~CDirectSoundVoice()
|
XTL::CDirectSoundVoice::~CDirectSoundVoice()
|
||||||
{
|
{
|
||||||
if (g_LibVersion_DSOUND < 4039) {
|
if (g_LibVersion_DSOUND < 4039) {
|
||||||
if (!u.settings_4034_lower.p_audio_format) {
|
if (!settings.r4034_lower.p_audio_format) {
|
||||||
delete u.settings_4034_lower.p_audio_format;
|
delete settings.r4034_lower.p_audio_format;
|
||||||
u.settings_4034_lower.p_audio_format = nullptr;
|
settings.r4034_lower.p_audio_format = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,22 +100,22 @@ struct CDirectSoundVoice : CUnknownGenericManager {
|
||||||
virtual ~CDirectSoundVoice();
|
virtual ~CDirectSoundVoice();
|
||||||
|
|
||||||
// CUnknownGenericManager // 0x00 - ???
|
// CUnknownGenericManager // 0x00 - ???
|
||||||
union _u {
|
union _settings {
|
||||||
struct _settings_interface
|
struct _unknown
|
||||||
{
|
{
|
||||||
uint32_t unknown_08[0x300 / 4]; // 0x000 - 0x300 (unknown size, likely over 0x200 size.
|
uint32_t unknown_08[0x300 / 4]; // 0x000 - 0x300 (unknown size, likely over 0x200 size.
|
||||||
} settings_interface;
|
} unknown;
|
||||||
|
|
||||||
struct _settings_4034_lower {
|
struct _r4034_lower {
|
||||||
xbaddr p_unknown_08; // 0x008
|
xbaddr p_unknown_08; // 0x008
|
||||||
uint16_t unknown_0C; // 0x00C // zero'd - unknown
|
uint16_t unknown_0C; // 0x00C // zero'd - unknown
|
||||||
XBOXADPCMWAVEFORMAT* p_audio_format; // 0x010 // Same as XBOXADPCMWAVEFORMAT / WAVEFORMATEX structure
|
XBOXADPCMWAVEFORMAT* p_audio_format; // 0x010 // Same as XBOXADPCMWAVEFORMAT / WAVEFORMATEX structure
|
||||||
int32_t pitch; // 0x014 // Always init and custom pitch from SetFrequency, SetPitch, SetFormat, etc calls.
|
int32_t pitch; // 0x014 // Always init and custom pitch from SetFrequency, SetPitch, SetFormat, etc calls.
|
||||||
int32_t volume; // 0x018 // default: (set volume - headroom)
|
int32_t volume; // 0x018 // default: (set volume - headroom)
|
||||||
uint32_t headroom; // 0x01C // default: (set headroom then update volume)
|
uint32_t headroom; // 0x01C // default: (set headroom then update volume)
|
||||||
} settings_4034_lower;
|
} r4034_lower;
|
||||||
|
|
||||||
struct _settings_4039_only {
|
struct _r4039_only {
|
||||||
uint32_t unknown_08; // 0x008
|
uint32_t unknown_08; // 0x008
|
||||||
uint32_t audio_codec; // 0x00C // Setter is 32 bit, yet getter is 16 bit integer reader
|
uint32_t audio_codec; // 0x00C // Setter is 32 bit, yet getter is 16 bit integer reader
|
||||||
uint32_t nChannels; // 0x010
|
uint32_t nChannels; // 0x010
|
||||||
|
@ -126,9 +126,9 @@ struct CDirectSoundVoice : CUnknownGenericManager {
|
||||||
int32_t volume; // 0x024 // (set volume - headroom)
|
int32_t volume; // 0x024 // (set volume - headroom)
|
||||||
uint32_t headroom; // 0x028 // (set headroom then update volume)
|
uint32_t headroom; // 0x028 // (set headroom then update volume)
|
||||||
uint32_t unknown_2C[(0x300 - 0x2C) / 4]; // 0x02C - 0x300 (unknown size, likely over 0x200 size.
|
uint32_t unknown_2C[(0x300 - 0x2C) / 4]; // 0x02C - 0x300 (unknown size, likely over 0x200 size.
|
||||||
} settings_4039_only;
|
} r4039_only;
|
||||||
|
|
||||||
struct _settings_4134_upper {
|
struct _r4134_upper {
|
||||||
uint32_t unknown_08; // 0x008
|
uint32_t unknown_08; // 0x008
|
||||||
uint16_t audio_codec; // 0x00C
|
uint16_t audio_codec; // 0x00C
|
||||||
uint8_t nChannels; // 0x00E
|
uint8_t nChannels; // 0x00E
|
||||||
|
@ -139,17 +139,17 @@ struct CDirectSoundVoice : CUnknownGenericManager {
|
||||||
int32_t volume; // 0x01C // (set volume - headroom)
|
int32_t volume; // 0x01C // (set volume - headroom)
|
||||||
uint32_t headroom; // 0x020 // (set headroom then update volume)
|
uint32_t headroom; // 0x020 // (set headroom then update volume)
|
||||||
uint32_t unknown_24[(0x300 - 0x24) / 4]; // 0x024 - 0x300 (unknown size, likely over 0x200 size.
|
uint32_t unknown_24[(0x300 - 0x24) / 4]; // 0x024 - 0x300 (unknown size, likely over 0x200 size.
|
||||||
} settings_4134_upper;
|
} r4134_upper;
|
||||||
} u;
|
} settings;
|
||||||
static_assert(sizeof(_u) == 0x300); // Not really require
|
static_assert(sizeof(_settings) == 0x300); // Not really require
|
||||||
|
|
||||||
// Generic interface without need to check xdk's build revision every time.
|
// Generic interface without need to check xdk's build revision every time.
|
||||||
typedef void (*pGetFormat)(_u& u, audio_format& format);
|
typedef void (*pGetFormat)(_settings& settings, audio_format& format);
|
||||||
typedef void (*pSetFormat)(_u& u, audio_format format);
|
typedef void (*pSetFormat)(_settings& settings, audio_format format);
|
||||||
typedef uint32_t (*pGetUint32)(_u& u);
|
typedef uint32_t (*pGetUint32)(_settings& settings);
|
||||||
typedef void (*pSetUint32)(_u& u, uint32_t value);
|
typedef void (*pSetUint32)(_settings& settings, uint32_t value);
|
||||||
typedef int32_t (*pGetInt32)(_u& u);
|
typedef int32_t (*pGetInt32)(_settings& settings);
|
||||||
typedef void (*pSetInt32)(_u& u, int32_t value);
|
typedef void (*pSetInt32)(_settings& settings, int32_t value);
|
||||||
struct {
|
struct {
|
||||||
pGetFormat GetFormat;
|
pGetFormat GetFormat;
|
||||||
pSetFormat SetFormat;
|
pSetFormat SetFormat;
|
||||||
|
@ -164,35 +164,35 @@ struct CDirectSoundVoice : CUnknownGenericManager {
|
||||||
static_assert(sizeof(funcs) == 0x24); // Not really require
|
static_assert(sizeof(funcs) == 0x24); // Not really require
|
||||||
|
|
||||||
inline void GetFormat(audio_format& format) {
|
inline void GetFormat(audio_format& format) {
|
||||||
funcs.GetFormat(u, format);
|
funcs.GetFormat(settings, format);
|
||||||
};
|
};
|
||||||
inline void SetFormat(audio_format format) {
|
inline void SetFormat(audio_format format) {
|
||||||
funcs.SetFormat(u, format);
|
funcs.SetFormat(settings, format);
|
||||||
};
|
};
|
||||||
inline uint32_t GetFrequencyDefault() {
|
inline uint32_t GetFrequencyDefault() {
|
||||||
return funcs.GetFrequencyDefault(u);
|
return funcs.GetFrequencyDefault(settings);
|
||||||
};
|
};
|
||||||
inline int32_t GetPitch() {
|
inline int32_t GetPitch() {
|
||||||
return funcs.GetPitch(u);
|
return funcs.GetPitch(settings);
|
||||||
};
|
};
|
||||||
inline void SetPitch(int32_t pitch) {
|
inline void SetPitch(int32_t pitch) {
|
||||||
funcs.SetPitch(u, pitch);
|
funcs.SetPitch(settings, pitch);
|
||||||
};
|
};
|
||||||
inline int32_t GetVolume() {
|
inline int32_t GetVolume() {
|
||||||
return funcs.GetVolume(u);
|
return funcs.GetVolume(settings);
|
||||||
};
|
};
|
||||||
inline void SetVolume(int32_t volume) {
|
inline void SetVolume(int32_t volume) {
|
||||||
funcs.SetVolume(u, volume);
|
funcs.SetVolume(settings, volume);
|
||||||
};
|
};
|
||||||
inline uint32_t GetHeadroom() {
|
inline uint32_t GetHeadroom() {
|
||||||
return funcs.GetHeadroom(u);
|
return funcs.GetHeadroom(settings);
|
||||||
};
|
};
|
||||||
inline void SetHeadroom(uint32_t headroom) {
|
inline void SetHeadroom(uint32_t headroom) {
|
||||||
funcs.SetHeadroom(u, headroom);
|
funcs.SetHeadroom(settings, headroom);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// Require to verify there is no other unknown additional data by compiler itself.
|
// Require to verify there is no other unknown additional data by compiler itself.
|
||||||
static_assert(sizeof(CDirectSoundVoice) == sizeof(CUnknownGenericManager) + sizeof(CDirectSoundVoice::_u) + sizeof(CDirectSoundVoice::funcs));
|
static_assert(sizeof(CDirectSoundVoice) == sizeof(CUnknownGenericManager) + sizeof(CDirectSoundVoice::_settings) + sizeof(CDirectSoundVoice::funcs));
|
||||||
|
|
||||||
struct DSBUFFER_S : CUnknownTemplate {
|
struct DSBUFFER_S : CUnknownTemplate {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue