HACK fix for DSound's LOCDEFER flag

Due to title doesn't passdown specific channels, I am assuming it is relying on hardware level to output the mixin audio.
This commit is contained in:
RadWolfie 2019-01-22 13:22:07 -06:00
parent 78cabcef00
commit ddd2cd8bdd
1 changed files with 13 additions and 2 deletions

View File

@ -221,12 +221,23 @@ inline void GeneratePCMFormat(
if (DSBufferDesc.lpwfxFormat == nullptr) { if (DSBufferDesc.lpwfxFormat == nullptr) {
// Only allocate extra value for setting extra values later on. WAVEFORMATEXTENSIBLE is the highest size I had seen. // Only allocate extra value for setting extra values later on. WAVEFORMATEXTENSIBLE is the highest size I had seen.
DSBufferDesc.lpwfxFormat = (WAVEFORMATEX*)calloc(1, sizeof(WAVEFORMATEXTENSIBLE)); DSBufferDesc.lpwfxFormat = (WAVEFORMATEX*)calloc(1, sizeof(WAVEFORMATEXTENSIBLE));
} }
if (lpwfxFormat->wFormatTag == WAVE_FORMAT_PCM) { if (lpwfxFormat->wFormatTag == WAVE_FORMAT_PCM) {
// Test case: Hulk crash due to cbSize is not a valid size. // Test case: Hulk crash due to cbSize is not a valid size.
memcpy(DSBufferDesc.lpwfxFormat, lpwfxFormat, sizeof(WAVEFORMATEX)); memcpy(DSBufferDesc.lpwfxFormat, lpwfxFormat, sizeof(WAVEFORMATEX));
DSBufferDesc.lpwfxFormat->cbSize = 0; // Let's enforce this value to prevent any other exception later on. DSBufferDesc.lpwfxFormat->cbSize = 0; // Let's enforce this value to prevent any other exception later on.
} else { }
else if (lpwfxFormat->wFormatTag == 0 && (DSBufferDesc.dwFlags & DSBCAPS_LOCDEFER) > 0) {
// NOTE: This is currently a hack for ability to create buffer class with DSBCAPS_LOCDEFER flag.
DSBufferDesc.lpwfxFormat->wFormatTag = WAVE_FORMAT_PCM;
DSBufferDesc.lpwfxFormat->nChannels = 2;
DSBufferDesc.lpwfxFormat->nSamplesPerSec = 44100;
DSBufferDesc.lpwfxFormat->wBitsPerSample = 8;
DSBufferDesc.lpwfxFormat->nBlockAlign = (DSBufferDesc.lpwfxFormat->wBitsPerSample / 8 * DSBufferDesc.lpwfxFormat->nChannels);
DSBufferDesc.lpwfxFormat->nAvgBytesPerSec = DSBufferDesc.lpwfxFormat->nSamplesPerSec * DSBufferDesc.lpwfxFormat->nBlockAlign;
}
else {
memcpy(DSBufferDesc.lpwfxFormat, lpwfxFormat, sizeof(WAVEFORMATEX) + lpwfxFormat->cbSize); memcpy(DSBufferDesc.lpwfxFormat, lpwfxFormat, sizeof(WAVEFORMATEX) + lpwfxFormat->cbSize);
} }