directsound: For channel counts > 2, generate a dwChannelMask for CreateSoundBuffer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c
index 19f1154..5db1b93 100644
--- a/src/audio/directsound/SDL_directsound.c
+++ b/src/audio/directsound/SDL_directsound.c
@@ -29,6 +29,7 @@
#include "SDL_audio.h"
#include "../SDL_audio_c.h"
#include "SDL_directsound.h"
+#include <mmreg.h>
#if HAVE_MMDEVICEAPI_H
#include "../../core/windows/SDL_immdevice.h"
#endif /* HAVE_MMDEVICEAPI_H */
@@ -53,6 +54,9 @@ static fnDirectSoundEnumerateW pDirectSoundEnumerateW = NULL;
static fnDirectSoundCaptureCreate8 pDirectSoundCaptureCreate8 = NULL;
static fnDirectSoundCaptureEnumerateW pDirectSoundCaptureEnumerateW = NULL;
+static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
+static const GUID SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = { 0x00000003, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
+
static void
DSOUND_Unload(void)
{
@@ -551,21 +555,57 @@ DSOUND_OpenDevice(_THIS, const char *devname)
(int) (DSBSIZE_MAX / numchunks));
} else {
int rc;
- WAVEFORMATEX wfmt;
+ WAVEFORMATEXTENSIBLE wfmt;
SDL_zero(wfmt);
- if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
- wfmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+ if (this->spec.channels > 2) {
+ wfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+ wfmt.Format.cbSize = sizeof(wfmt) - sizeof(WAVEFORMATEX);
+
+ if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
+ SDL_memcpy(&wfmt.SubFormat, &SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, sizeof(GUID));
+ } else {
+ wfmt.SubFormat = SDL_KSDATAFORMAT_SUBTYPE_PCM;
+ SDL_memcpy(&wfmt.SubFormat, &SDL_KSDATAFORMAT_SUBTYPE_PCM, sizeof(GUID));
+ }
+ wfmt.Samples.wValidBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
+
+ switch (this->spec.channels)
+ {
+ case 3: /* 3.0 (or 2.1) */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER;
+ break;
+ case 4: /* 4.0 */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
+ break;
+ case 5: /* 5.0 (or 4.1) */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
+ break;
+ case 6: /* 5.1 */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
+ break;
+ case 7: /* 6.1 */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_BACK_CENTER;
+ break;
+ case 8: /* 7.1 */
+ wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT;
+ break;
+ default:
+ SDL_assert(0 && "Unsupported channel count!");
+ break;
+ }
+ } else if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
+ wfmt.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
} else {
- wfmt.wFormatTag = WAVE_FORMAT_PCM;
+ wfmt.Format.wFormatTag = WAVE_FORMAT_PCM;
}
- wfmt.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
- wfmt.nChannels = this->spec.channels;
- wfmt.nSamplesPerSec = this->spec.freq;
- wfmt.nBlockAlign = wfmt.nChannels * (wfmt.wBitsPerSample / 8);
- wfmt.nAvgBytesPerSec = wfmt.nSamplesPerSec * wfmt.nBlockAlign;
+ wfmt.Format.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
+ wfmt.Format.nChannels = this->spec.channels;
+ wfmt.Format.nSamplesPerSec = this->spec.freq;
+ wfmt.Format.nBlockAlign = wfmt.Format.nChannels * (wfmt.Format.wBitsPerSample / 8);
+ wfmt.Format.nAvgBytesPerSec = wfmt.Format.nSamplesPerSec * wfmt.Format.nBlockAlign;
- rc = iscapture ? CreateCaptureBuffer(this, bufsize, &wfmt) : CreateSecondary(this, bufsize, &wfmt);
+ rc = iscapture ? CreateCaptureBuffer(this, bufsize, (WAVEFORMATEX*) &wfmt) : CreateSecondary(this, bufsize, (WAVEFORMATEX*) &wfmt);
if (rc == 0) {
this->hidden->num_buffers = numchunks;
break;