Merge pull request #1955 from RadWolfie/fix-dsound-namespace

Fix Xbox DSound Namespace
This commit is contained in:
ergo720 2020-09-08 13:40:58 +02:00 committed by GitHub
commit fa6387a545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 190 additions and 44 deletions

View File

@ -117,6 +117,7 @@ file (GLOB CXBXR_HEADER_EMU
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/glextensions.h"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen.h"
"${CXBXR_ROOT_DIR}/src/common/XADPCM.h"
"${CXBXR_ROOT_DIR}/src/common/xbox/Logging.hpp"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/Direct3D9.h"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/VertexShader.h"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/VertexShaderSource.h"
@ -260,6 +261,7 @@ file (GLOB CXBXR_SOURCE_EMU
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/glextensions.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_common.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_wgl.cpp"
"${CXBXR_ROOT_DIR}/src/common/xbox/Logging.cpp"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/RenderStates.cpp"
"${CXBXR_ROOT_DIR}/src/core/hle/D3D8/Direct3D9/TextureStates.cpp"

View File

@ -0,0 +1,42 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 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 recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2020 RadWolfie
// *
// * All rights reserved
// *
// ******************************************************************
#include "common/Logging.h"
#include "Logging.hpp"
namespace xbox {
LOGRENDER(D3DVECTOR)
{
return os
LOGRENDER_MEMBER(x)
LOGRENDER_MEMBER(y)
LOGRENDER_MEMBER(z)
;
}
}

View File

@ -0,0 +1,34 @@
// ******************************************************************
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 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 recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2020 RadWolfie
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
#include "common/xbox_types.h"
#include "common/Logging.h"
namespace xbox {
LOGRENDER_HEADER(D3DVECTOR)
}

View File

@ -70,6 +70,10 @@ namespace xbox
typedef unsigned __int64 QUAD; // 8 byte aligned 8 byte long
typedef int BOOL;
typedef LONG HRESULT;
typedef float FLOAT;
// TODO: Remove __stdcall once lib86cpu is implemented.
#define XBOXAPI __stdcall
#define XCALLBACK XBOXAPI
// ******************************************************************
@ -107,4 +111,21 @@ namespace xbox
typedef WCHAR *LPWSTR, *PWSTR;
typedef /*_Null_terminated_*/ const WCHAR *LPCWSTR, *PCWSTR;
// ******************************************************************
// Misc
// ******************************************************************
typedef struct _XD3DVECTOR {
FLOAT x;
FLOAT y;
FLOAT z;
} D3DVECTOR;
template<typename A, typename B>
inline void CopyD3DVector(A& a, const B& b)
{
a.x = b.x;
a.y = b.y;
a.z = b.z;
}
}

View File

@ -1201,7 +1201,7 @@ HRESULT WINAPI xbox::EMUPATCH(IDirectSoundBuffer_SetMixBins)
LOG_FUNC_END;
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
hRet = HybridDirectSoundBuffer_SetMixBins(pThis->Xb_VoiceProperties, pMixBins, pThis->EmuBufferDesc.lpwfxFormat, pThis->EmuBufferDesc);
hRet = HybridDirectSoundBuffer_SetMixBins(pThis->Xb_VoiceProperties, pMixBins, pThis->EmuBufferDesc);
}
return hRet;

View File

@ -133,7 +133,7 @@ static inline void InitVoiceProperties(xbox::X_DSVOICEPROPS& Xb_VoiceProperties)
static inline void GenerateMixBinDefault(
xbox::X_DSVOICEPROPS &Xb_VoiceProperties,
LPCWAVEFORMATEX lpwfxFormat,
::LPCWAVEFORMATEX lpwfxFormat,
xbox::X_LPDSMIXBINS mixbins_output,
bool is3D)
{
@ -247,7 +247,7 @@ static inline void GenerateMixBinDefault(
static inline void GeneratePCMFormat(
DSBUFFERDESC &DSBufferDesc,
LPCWAVEFORMATEX Xb_lpwfxFormat,
xbox::LPCWAVEFORMATEX Xb_lpwfxFormat,
DWORD &Xb_flags,
DWORD &dwEmuFlags,
DWORD X_BufferSizeRequest,
@ -259,8 +259,6 @@ static inline void GeneratePCMFormat(
{
bool bIsSpecial = false;
GenerateMixBinDefault(Xb_VoiceProperties, Xb_lpwfxFormat, mixbins_output, ((DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) > 0));
// convert from Xbox to PC DSound
{
DSBufferDesc.dwReserved = 0;
@ -326,6 +324,8 @@ static inline void GeneratePCMFormat(
if (X_BufferCacheSize > 0) {
DSBufferDesc.dwBufferBytes = DSoundBufferGetPCMBufferSize(dwEmuFlags, X_BufferCacheSize);
}
GenerateMixBinDefault(Xb_VoiceProperties, DSBufferDesc.lpwfxFormat, mixbins_output, ((DSBufferDesc.dwFlags& DSBCAPS_CTRL3D) > 0));
}
static inline void DSoundGenericUnlock(
@ -951,13 +951,13 @@ static inline HRESULT HybridDirectSound3DBuffer_SetAllParameters(
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
DS3DBUFFER pDS3DBufferParamsTemp;
::DS3DBUFFER pDS3DBufferParamsTemp;
pDS3DBufferParamsTemp.dwSize = sizeof(DS3DBUFFER);
pDS3DBufferParamsTemp.vPosition = pDS3DBufferParams->vPosition;
pDS3DBufferParamsTemp.vVelocity = pDS3DBufferParams->vVelocity;
CopyD3DVector(pDS3DBufferParamsTemp.vPosition, pDS3DBufferParams->vPosition);
CopyD3DVector(pDS3DBufferParamsTemp.vVelocity, pDS3DBufferParams->vVelocity);
pDS3DBufferParamsTemp.dwInsideConeAngle = pDS3DBufferParams->dwInsideConeAngle;
pDS3DBufferParamsTemp.dwOutsideConeAngle = pDS3DBufferParams->dwOutsideConeAngle;
pDS3DBufferParamsTemp.vConeOrientation = pDS3DBufferParams->vConeOrientation;
CopyD3DVector(pDS3DBufferParamsTemp.vConeOrientation, pDS3DBufferParams->vConeOrientation);
pDS3DBufferParamsTemp.lConeOutsideVolume = pDS3DBufferParams->lConeOutsideVolume;
pDS3DBufferParamsTemp.flMinDistance = pDS3DBufferParams->flMinDistance;
pDS3DBufferParamsTemp.flMaxDistance = pDS3DBufferParams->flMaxDistance;
@ -1109,7 +1109,7 @@ static inline HRESULT HybridDirectSoundBuffer_SetFilter(
//IDirectSoundBuffer
static inline HRESULT HybridDirectSoundBuffer_SetFormat(
LPDIRECTSOUNDBUFFER8 &pDSBuffer,
LPCWAVEFORMATEX Xb_pwfxFormat,
xbox::LPCWAVEFORMATEX Xb_pwfxFormat,
DWORD Xb_flags,
DSBUFFERDESC &BufferDesc,
DWORD &dwEmuFlags,
@ -1255,17 +1255,21 @@ static inline HRESULT HybridDirectSound3DBuffer_SetMinDistance(
RETURN_RESULT_CHECK(hRet);
}
/*
//TODO: PC DirectSound does not have SetMixBins method function.
//IDirectSoundStream
//IDirectSoundBuffer
static inline HRESULT HybridDirectSoundBuffer_SetMixBins(
LPDIRECTSOUNDBUFFER8 pDSBuffer,
PVOID pMixBins)
xbox::X_DSVOICEPROPS& Xb_VoiceProperties,
xbox::X_LPDSMIXBINS in_MixBins,
DSBUFFERDESC& BufferDesc
)
{
HRESULT ret = DS_OK;
return DS_OK;
}*/
GenerateMixBinDefault(Xb_VoiceProperties, BufferDesc.lpwfxFormat, in_MixBins, ((BufferDesc.dwFlags & DSBCAPS_CTRL3D) > 0));
return ret;
}
//IDirectSoundStream x2
//IDirectSoundBuffer x2
@ -1522,17 +1526,3 @@ static inline HRESULT HybridDirectSoundBuffer_GetVoiceProperties(
return ret;
}
static inline HRESULT HybridDirectSoundBuffer_SetMixBins(
xbox::X_DSVOICEPROPS& Xb_VoiceProperties,
xbox::X_LPDSMIXBINS in_MixBins,
LPCWAVEFORMATEX pwfxFormat,
DSBUFFERDESC& BufferDesc
)
{
HRESULT ret = DS_OK;
GenerateMixBinDefault(Xb_VoiceProperties, pwfxFormat, in_MixBins, ((BufferDesc.dwFlags & DSBCAPS_CTRL3D) > 0));
return ret;
}

View File

@ -1125,7 +1125,7 @@ HRESULT WINAPI xbox::EMUPATCH(CDirectSoundStream_SetMixBins)
LOG_FUNC_ARG(pMixBins)
LOG_FUNC_END;
hRet = HybridDirectSoundBuffer_SetMixBins(pThis->Xb_VoiceProperties, pMixBins, pThis->EmuBufferDesc.lpwfxFormat, pThis->EmuBufferDesc);
hRet = HybridDirectSoundBuffer_SetMixBins(pThis->Xb_VoiceProperties, pMixBins, pThis->EmuBufferDesc);
}

View File

@ -25,6 +25,7 @@
#include <dsound.h> // Temporary placeholder until XbDSoundTypes.h is cross-platform + filled in the blanks
#include "Logging.h"
#include "common/xbox/Logging.hpp"
#include "XbDSoundLogging.hpp"
#include "common/Settings.hpp"
@ -303,6 +304,43 @@ LOGRENDER(DSLFODESC)
;
}
ENUM2STR_START(WAVEFORMAT_TAG)
ENUM2STR_CASE(0)
ENUM2STR_CASE(WAVE_FORMAT_PCM)
ENUM2STR_CASE(WAVE_FORMAT_ADPCM)
ENUM2STR_CASE(WAVE_FORMAT_XBOX_ADPCM)
ENUM2STR_CASE(WAVE_FORMAT_EXTENSIBLE)
ENUM2STR_END_and_LOGRENDER(WAVEFORMAT_TAG)
#define WFC_MONO 1
#define WFC_STEREO 2
#define WFC_2POINT1 3
#define WFC_QUAD 4
#define WFC_5POINT0 5
#define WFC_5POINT1 6
ENUM2STR_START(WAVEFORMAT_CHANNEL)
ENUM2STR_CASE(WFC_MONO)
ENUM2STR_CASE(WFC_STEREO)
ENUM2STR_CASE(WFC_2POINT1)
ENUM2STR_CASE(WFC_QUAD)
ENUM2STR_CASE(WFC_5POINT0)
ENUM2STR_CASE(WFC_5POINT1)
ENUM2STR_END_and_LOGRENDER(WAVEFORMAT_CHANNEL)
LOGRENDER(WAVEFORMATEX)
{
return os
LOGRENDER_MEMBER_TYPE(WAVEFORMAT_TAG, wFormatTag)
LOGRENDER_MEMBER_TYPE(WAVEFORMAT_CHANNEL, nChannels)
LOGRENDER_MEMBER(nSamplesPerSec)
LOGRENDER_MEMBER(nAvgBytesPerSec)
LOGRENDER_MEMBER(nBlockAlign)
LOGRENDER_MEMBER(wBitsPerSample)
LOGRENDER_MEMBER(cbSize)
;
}
LOGRENDER(XBOXADPCMWAVEFORMAT)
{
return os

View File

@ -32,6 +32,8 @@ namespace xbox {
// TODO: Everything, only small portions had been implemented.
enum WAVEFORMAT_CHANNEL : int;
enum WAVEFORMAT_TAG : int;
// DSound flag/enum
enum DSMIXBIN_SPEAKER : int;
enum DSSPEAKER_FLAG : int;
@ -82,6 +84,7 @@ LOGRENDER_HEADER(X_DSI3DL2BUFFER)
LOGRENDER_HEADER(X_DSI3DL2OBSTRUCTION)
LOGRENDER_HEADER(X_DSI3DL2OCCLUSION)
LOGRENDER_HEADER(DSLFODESC)
LOGRENDER_HEADER(WAVEFORMATEX)
LOGRENDER_HEADER(XBOXADPCMWAVEFORMAT)
// DSound Buffer class usage
LOGRENDER_HEADER(X_DSBUFFERDESC)

View File

@ -30,12 +30,28 @@
namespace xbox {
#include <dsound.h> // TODO: FIXME after global namespace xbox issue is resolved.
// TODO: Port PC dsound.h to xbox edition here base on previous research.
// TODO: Also need to use fixed size to able support cross-platform without extra work.
// Such as uint32_t, uint16_t, etc.
typedef struct _XWAVEFORMATEX
{
uint16_t wFormatTag;
uint16_t nChannels;
uint32_t nSamplesPerSec;
uint32_t nAvgBytesPerSec;
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
uint16_t cbSize;
} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX;
typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
#define WAVE_FORMAT_ADPCM 0x0002
#define WAVE_FORMAT_XBOX_ADPCM 0x0069
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
// Xbox SGE Memory layout
#define XTL_DS_SGE_COUNT_MAX 2047
@ -162,7 +178,7 @@ struct X_DSENVOLOPEDESC
#define XTL_DSSCAPS_NOMERGE 0x20000000
#define XTL_DSSCAPS_ACCURATENOTIFY 0x40000000
typedef VOID(CALLBACK *LPFNXMOCALLBACK)(LPVOID pStreamContext, LPVOID pPacketContext, DWORD dwStatus);
typedef VOID(XCALLBACK *LPFNXMOCALLBACK)(LPVOID pStreamContext, LPVOID pPacketContext, DWORD dwStatus);
// ******************************************************************
// * X_DSSTREAMDESC

View File

@ -52,8 +52,8 @@ struct CUnknownGenericManager {
// all VMT (Virtual Method Table) are stored in local offset 0x00's pointer
// TODO: Implement to use derived's override AddRef/Release. Also, each class has its own ref counter and is not shareable.
virtual ~CUnknownGenericManager() {}; // 0x00
virtual uint32_t WINAPI AddRef() { return ref_count++; }; // 0x04
virtual uint32_t WINAPI Release() { return ref_count--; }; // 0x08
virtual uint32_t XBOXAPI AddRef() { return ref_count++; }; // 0x04
virtual uint32_t XBOXAPI Release() { return ref_count--; }; // 0x08
uint32_t ref_count; // 0x04
};
@ -65,13 +65,13 @@ struct CUnknownTemplate {
CUnknownTemplate();
virtual ~CUnknownTemplate() {}; // 0x00
virtual void WINAPI pUnknown_04() { throw std::exception("pUnknown_04"); }; // 0x04
virtual void WINAPI pUnknown_08() { throw std::exception("pUnknown_08"); }; // 0x08
virtual void WINAPI pUnknown_0C() { throw std::exception("pUnknown_0C"); }; // 0x0C
virtual void WINAPI pUnknown_10() { throw std::exception("pUnknown_10"); }; // 0x10
virtual void WINAPI pUnknown_14() { throw std::exception("pUnknown_14"); }; // 0x14
virtual void WINAPI pUnknown_18() { throw std::exception("pUnknown_18"); }; // 0x18
virtual void WINAPI pUnknown_1C() { throw std::exception("pUnknown_1C"); }; // 0x1C
virtual void XBOXAPI pUnknown_04() { throw std::exception("pUnknown_04"); }; // 0x04
virtual void XBOXAPI pUnknown_08() { throw std::exception("pUnknown_08"); }; // 0x08
virtual void XBOXAPI pUnknown_0C() { throw std::exception("pUnknown_0C"); }; // 0x0C
virtual void XBOXAPI pUnknown_10() { throw std::exception("pUnknown_10"); }; // 0x10
virtual void XBOXAPI pUnknown_14() { throw std::exception("pUnknown_14"); }; // 0x14
virtual void XBOXAPI pUnknown_18() { throw std::exception("pUnknown_18"); }; // 0x18
virtual void XBOXAPI pUnknown_1C() { throw std::exception("pUnknown_1C"); }; // 0x1C
// If need to add more VMT (Virtual Method Table), add them above here.
uint32_t ref_count; // 0x04
};