Skip to content

Commit

Permalink
dsound: Reject WAVEFORMATEX formats with more than two channels.
Browse files Browse the repository at this point in the history
Formats with more than two channels require WAVEFORMATEXTENSIBLE according to tests.

Fix Viking: Battle for Asgard (211160) audio cracking in its intro video.
  • Loading branch information
zzhiyi authored and julliard committed Feb 20, 2024
1 parent b3ec5bc commit 7c7b2e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dlls/dsound/dsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ static HRESULT DirectSoundDevice_CreateSoundBuffer(
return DSERR_INVALIDPARAM;
}

if (dsbd->lpwfxFormat->nChannels > 2 && dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
return DSERR_INVALIDPARAM;

if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
{
WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
Expand Down
3 changes: 3 additions & 0 deletions dlls/dsound/primary.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passe
return DSERR_INVALIDPARAM;
}

if (passed_fmt->nChannels > 2 && passed_fmt->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
return DSERR_ALLOCATED;

/* **** */
AcquireSRWLockExclusive(&device->buffer_list_lock);
EnterCriticalSection(&(device->mixlock));
Expand Down
2 changes: 0 additions & 2 deletions dlls/dsound/tests/dsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,6 @@ static void perform_invalid_fmt_tests(const char *testname, IDirectSound *dso, I
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
todo_wine
ok(rc == (buf ? DSERR_ALLOCATED : DSERR_INVALIDPARAM), "%s: SetFormat: %08lx\n", testname, rc);

wfx.wFormatTag = WAVE_FORMAT_PCM;
Expand All @@ -1510,7 +1509,6 @@ static void perform_invalid_fmt_tests(const char *testname, IDirectSound *dso, I
wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rc = do_invalid_fmt_test(dso, buf, &wfx, &got_buf);
todo_wine
ok(rc == (buf ? DSERR_ALLOCATED : DSERR_INVALIDPARAM), "%s: SetFormat: %08lx\n", testname, rc);

fmtex.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
Expand Down

0 comments on commit 7c7b2e8

Please sign in to comment.