BOOL getCurrentChannelConfig() { IDirectSound8* ds; DWORD speakerConfig; LPGUID guid = NULL; DirectSoundEnumerate((LPDSENUMCALLBACK)DSEnumProc, (VOID*)&guid); if (DirectSoundCreate8(guid, &ds, NULL) != S_OK) { return FALSE; } ds->Initialize(NULL); if (ds->GetSpeakerConfig(&speakerConfig) != S_OK) { PrintLastError("GetSpeakerConfig()"); return FALSE; } if (ds) { ds->Release(); } if (guid) { LocalFree(guid); } switch (DSSPEAKER_CONFIG(speakerConfig)) { case DSSPEAKER_STEREO: currentChannelCount = 2; return TRUE; case DSSPEAKER_QUAD: currentChannelCount = 4; return TRUE; case DSSPEAKER_5POINT1: currentChannelCount = 6; return TRUE; case DSSPEAKER_7POINT1: currentChannelCount = 8; return TRUE; } return FALSE; }
BOOL setCurrentChannelConfig() { IDirectSound8* ds; DWORD speakerConfig; LPGUID guid = NULL; DirectSoundEnumerate((LPDSENUMCALLBACK)DSEnumProc, (VOID*)&guid); if (DirectSoundCreate8(guid, &ds, NULL) != S_OK) { PrintLastError("DirectSoundCreate8()"); return FALSE; } ds->Initialize(NULL); switch (currentChannelCount) { case 2: speakerConfig = DSSPEAKER_STEREO; break; case 4: speakerConfig = DSSPEAKER_QUAD; break; case 6: speakerConfig = DSSPEAKER_5POINT1; break; case 8: speakerConfig = DSSPEAKER_7POINT1; break; default: speakerConfig = DSSPEAKER_STEREO; break; } if (ds->SetSpeakerConfig(speakerConfig) != S_OK) { PrintLastError("SetSpeakerConfig()"); return FALSE; } if (ds) { ds->Release(); } if (guid) { LocalFree(guid); } return FALSE; }