Skip to content

Commit

Permalink
Updates for headset compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jan 14, 2017
1 parent 3b203f2 commit 6e5ce13
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 1
#define TBF_BUILD 4
#define TBF_BUILD 5
#define TBF_REV 0


Expand Down
30 changes: 13 additions & 17 deletions src/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,21 @@ IAudioClient_GetMixFormat_Detour (IAudioClient *This,

#define TARGET_SAMPLE_RATE config.audio.sample_hz

if (pMixFormat->nSamplesPerSec != TARGET_SAMPLE_RATE) {
if (TARGET_SAMPLE_RATE != -1 && pMixFormat->nSamplesPerSec != TARGET_SAMPLE_RATE) {
audio_log->Log ( L" ** Resampling Audiostream from %lu Hz to %lu Hz",
pMixFormat->nSamplesPerSec, TARGET_SAMPLE_RATE );
pMixFormat->nSamplesPerSec = TARGET_SAMPLE_RATE;
}

pMixFormat->nAvgBytesPerSec = (pMixFormat->nSamplesPerSec * pMixFormat->nChannels * pMixFormat->wBitsPerSample) >> 3;
pMixFormat->nBlockAlign = (pMixFormat->wBitsPerSample * pMixFormat->nChannels) >> 3;

g_DeviceFormat.Format.cbSize = 22;
g_DeviceFormat.Format.nSamplesPerSec = pMixFormat->nSamplesPerSec;
g_DeviceFormat.Format.nChannels = pMixFormat->nChannels;
g_DeviceFormat.Format.nBlockAlign = pMixFormat->nBlockAlign;
g_DeviceFormat.Format.nAvgBytesPerSec = pMixFormat->nAvgBytesPerSec;
g_DeviceFormat.Format.wBitsPerSample = pMixFormat->wBitsPerSample;
//g_DeviceFormat.Format.wBitsPerSample = ((PWAVEFORMATEXTENSIBLE)pMixFormat)->Samples.wValidBitsPerSample;

// We may have gotten an extensible wave format, but... we need to
// truncate this sucker to a plain old WAVEFORMATEX
Expand Down Expand Up @@ -509,7 +509,6 @@ IAudioClient_Initialize_Detour (IAudioClient *This,
L" >> Channels: %lu, Samples Per Sec: %lu, Bits Per Sample: %hu\n",
pFormat->nChannels, pFormat->nSamplesPerSec, pFormat->wBitsPerSample );

#if 0
WAVEFORMATEX format;

format.cbSize = pFormat->cbSize;
Expand All @@ -520,16 +519,15 @@ IAudioClient_Initialize_Detour (IAudioClient *This,
format.wBitsPerSample = pFormat->wBitsPerSample;
format.wFormatTag = pFormat->wFormatTag;

WAVEFORMATEX *pClosestMatch =
(PWAVEFORMATEX)CoTaskMemAlloc (sizeof (WAVEFORMATEXTENSIBLE));

#if 0
if (This->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, pFormat, &pClosestMatch) == S_OK) {
CoTaskMemFree (pClosestMatch);
pClosestMatch = &format;
}
#endif

WAVEFORMATEX *pClosestMatch = (WAVEFORMATEX *)pFormat;
WAVEFORMATEX *pClosestMatch =
(PWAVEFORMATEX)CoTaskMemAlloc (sizeof (WAVEFORMATEXTENSIBLE));

#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY 0x08000000
Expand All @@ -551,14 +549,12 @@ IAudioClient_Initialize_Detour (IAudioClient *This,
AUDCLNT_STREAMFLAGS_UNKNOWN4000000 );
}

if (g_DeviceFormat.Format.cbSize == 22) {
pClosestMatch->nChannels = g_DeviceFormat.Format.nChannels;
pClosestMatch->nSamplesPerSec = g_DeviceFormat.Format.nSamplesPerSec;
//pClosestMatch->nBlockAlign = g_DeviceFormat.Format.nBlockAlign;
//pClosestMatch->nAvgBytesPerSec = g_DeviceFormat.Format.nAvgBytesPerSec;
//pClosestMatch->wBitsPerSample = g_DeviceFormat.Format.wBitsPerSample;
if (This->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, &format, &pClosestMatch) != S_OK) {
CoTaskMemFree (pClosestMatch);
pClosestMatch = (WAVEFORMATEX *)pFormat;
}


HRESULT ret =
IAudioClient_Initialize_Original (This, AUDCLNT_SHAREMODE_SHARED,
StreamFlags, hnsBufferDuration,
Expand All @@ -570,15 +566,13 @@ IAudioClient_Initialize_Detour (IAudioClient *This,

_com_error error (ret);

#if 0
if (pClosestMatch != &format)
if (pClosestMatch != pFormat)
CoTaskMemFree (pClosestMatch);
#endif

audio_log->Log ( L" Result: 0x%04X (%s)\n", ret - AUDCLNT_ERR (0x0000),
error.ErrorMessage () );

//new_session = false;
new_session = false;
//DSOUND_VIRTUAL_OVERRIDE ( ppAudioClient, 8, "IAudioClient::GetMixFormat",
//IAudioClient_GetMixFormat_Original,
//IAudioClient_GetMixFormat_Original,
Expand Down Expand Up @@ -755,6 +749,7 @@ tbf::SoundFix::Init (void)
dsound_dll = LoadLibrary (L"dsound.dll");
ole32_dll = LoadLibrary (L"Ole32.dll");

#if 0
audio_log->LogEx (true, L"@ Hooking DirectSoundCreate... ");

TBF_CreateDLLHook ( L"dsound.dll", "DirectSoundCreate",
Expand All @@ -770,6 +765,7 @@ tbf::SoundFix::Init (void)
// when the code was originally written -- test this in the future.
DirectSoundCreate_Detour (NULL, &g_pDS, NULL);
g_pDS->SetCooperativeLevel (NULL, DSSCL_EXCLUSIVE);
#endif

new_session = true;

Expand Down
Binary file modified tbf.VC.db
Binary file not shown.
Binary file modified version.ini
Binary file not shown.

0 comments on commit 6e5ce13

Please sign in to comment.