diff options
Diffstat (limited to 'Alc/backends/dsound.c')
-rw-r--r-- | Alc/backends/dsound.c | 138 |
1 files changed, 64 insertions, 74 deletions
diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 3ca398ed..4db4b557 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -13,8 +13,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Or go to http://www.gnu.org/copyleft/lgpl.html */ @@ -43,6 +43,9 @@ #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 #endif +#ifndef DSSPEAKER_5POINT1_BACK +# define DSSPEAKER_5POINT1_BACK 0x00000006 +#endif #ifndef DSSPEAKER_7POINT1 # define DSSPEAKER_7POINT1 0x00000007 #endif @@ -57,6 +60,8 @@ DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); +#define DEVNAME_TAIL " on OpenAL Soft" + #ifdef HAVE_DYNLOAD static void *ds_handle; @@ -109,27 +114,23 @@ typedef struct { al_string name; GUID guid; } DevMap; -DECL_VECTOR(DevMap) +TYPEDEF_VECTOR(DevMap, vector_DevMap) -vector_DevMap PlaybackDevices; -vector_DevMap CaptureDevices; +static vector_DevMap PlaybackDevices; +static vector_DevMap CaptureDevices; static void clear_devlist(vector_DevMap *list) { - DevMap *iter, *end; - - iter = VECTOR_ITER_BEGIN(*list); - end = VECTOR_ITER_END(*list); - for(;iter != end;++iter) - AL_STRING_DEINIT(iter->name); +#define DEINIT_STR(i) AL_STRING_DEINIT((i)->name) + VECTOR_FOR_EACH(DevMap, *list, DEINIT_STR); VECTOR_RESIZE(*list, 0); +#undef DEINIT_STR } static BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHAR* UNUSED(drvname), void *data) { vector_DevMap *devices = data; OLECHAR *guidstr = NULL; - DevMap *iter, *end; DevMap entry; HRESULT hr; int count; @@ -140,24 +141,26 @@ static BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHA AL_STRING_INIT(entry.name); count = 0; - do { + while(1) + { + const DevMap *iter; + al_string_copy_wcstr(&entry.name, desc); - if(count != 0) + if(count == 0) + al_string_append_cstr(&entry.name, DEVNAME_TAIL); + else { char str[64]; - snprintf(str, sizeof(str), " #%d", count+1); + snprintf(str, sizeof(str), " #%d"DEVNAME_TAIL, count+1); al_string_append_cstr(&entry.name, str); } - count++; - iter = VECTOR_ITER_BEGIN(*devices); - end = VECTOR_ITER_END(*devices); - for(;iter != end;++iter) - { - if(al_string_cmp(entry.name, iter->name) == 0) - break; - } - } while(iter != end); +#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0) + VECTOR_FIND_IF(iter, const DevMap, *devices, MATCH_ENTRY); + if(iter == VECTOR_ITER_END(*devices)) break; +#undef MATCH_ENTRY + count++; + } entry.guid = *guid; hr = StringFromCLSID(guid, &guidstr); @@ -323,7 +326,7 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr) static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *deviceName) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - GUID *guid = NULL; + const GUID *guid = NULL; HRESULT hr, hrcom; if(VECTOR_SIZE(PlaybackDevices) == 0) @@ -344,20 +347,14 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de } else { - DevMap *iter, *end; + const DevMap *iter; - iter = VECTOR_ITER_BEGIN(PlaybackDevices); - end = VECTOR_ITER_END(PlaybackDevices); - for(;iter != end;++iter) - { - if(al_string_cmp_cstr(iter->name, deviceName) == 0) - { - guid = &iter->guid; - break; - } - } - if(iter == end) +#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0) + VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME); +#undef MATCH_NAME + if(iter == VECTOR_ITER_END(PlaybackDevices)) return ALC_INVALID_VALUE; + guid = &iter->guid; } hr = DS_OK; @@ -450,28 +447,35 @@ static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self) hr = IDirectSound_GetSpeakerConfig(self->DS, &speakers); if(SUCCEEDED(hr)) { + speakers = DSSPEAKER_CONFIG(speakers); if(!(device->Flags&DEVICE_CHANNELS_REQUEST)) { - speakers = DSSPEAKER_CONFIG(speakers); if(speakers == DSSPEAKER_MONO) device->FmtChans = DevFmtMono; else if(speakers == DSSPEAKER_STEREO || speakers == DSSPEAKER_HEADPHONE) device->FmtChans = DevFmtStereo; else if(speakers == DSSPEAKER_QUAD) device->FmtChans = DevFmtQuad; - else if(speakers == DSSPEAKER_5POINT1 || speakers == DSSPEAKER_5POINT1_SURROUND) + else if(speakers == DSSPEAKER_5POINT1_SURROUND) device->FmtChans = DevFmtX51; + else if(speakers == DSSPEAKER_5POINT1_BACK) + device->FmtChans = DevFmtX51Rear; else if(speakers == DSSPEAKER_7POINT1 || speakers == DSSPEAKER_7POINT1_SURROUND) device->FmtChans = DevFmtX71; else ERR("Unknown system speaker config: 0x%lx\n", speakers); } + device->IsHeadphones = (device->FmtChans == DevFmtStereo && + speakers == DSSPEAKER_HEADPHONE); switch(device->FmtChans) { case DevFmtMono: OutputType.dwChannelMask = SPEAKER_FRONT_CENTER; break; + case DevFmtBFormat3D: + device->FmtChans = DevFmtStereo; + /*fall-through*/ case DevFmtStereo: OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; @@ -487,16 +491,16 @@ static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self) SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | - SPEAKER_BACK_LEFT | - SPEAKER_BACK_RIGHT; + SPEAKER_SIDE_LEFT | + SPEAKER_SIDE_RIGHT; break; - case DevFmtX51Side: + case DevFmtX51Rear: OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | - SPEAKER_SIDE_LEFT | - SPEAKER_SIDE_RIGHT; + SPEAKER_BACK_LEFT | + SPEAKER_BACK_RIGHT; break; case DevFmtX61: OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | @@ -681,7 +685,7 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; WAVEFORMATEXTENSIBLE InputType; DSCBUFFERDESC DSCBDescription; - GUID *guid = NULL; + const GUID *guid = NULL; HRESULT hr, hrcom; ALuint samples; @@ -703,20 +707,14 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi } else { - DevMap *iter, *end; + const DevMap *iter; - iter = VECTOR_ITER_BEGIN(CaptureDevices); - end = VECTOR_ITER_END(CaptureDevices); - for(;iter != end;++iter) - { - if(al_string_cmp_cstr(iter->name, deviceName) == 0) - { - guid = &iter->guid; - break; - } - } - if(iter == end) +#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0) + VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME); +#undef MATCH_NAME + if(iter == VECTOR_ITER_END(CaptureDevices)) return ALC_INVALID_VALUE; + guid = &iter->guid; } switch(device->FmtType) @@ -760,16 +758,16 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | - SPEAKER_BACK_LEFT | - SPEAKER_BACK_RIGHT; + SPEAKER_SIDE_LEFT | + SPEAKER_SIDE_RIGHT; break; - case DevFmtX51Side: + case DevFmtX51Rear: InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | - SPEAKER_SIDE_LEFT | - SPEAKER_SIDE_RIGHT; + SPEAKER_BACK_LEFT | + SPEAKER_BACK_RIGHT; break; case DevFmtX61: InputType.dwChannelMask = SPEAKER_FRONT_LEFT | @@ -790,6 +788,8 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; break; + case DevFmtBFormat3D: + break; } InputType.Format.wFormatTag = WAVE_FORMAT_PCM; @@ -1042,26 +1042,16 @@ static ALCbackend* ALCdsoundBackendFactory_createBackend(ALCdsoundBackendFactory if(type == ALCbackend_Playback) { ALCdsoundPlayback *backend; - - backend = ALCdsoundPlayback_New(sizeof(*backend)); + NEW_OBJ(backend, ALCdsoundPlayback)(device); if(!backend) return NULL; - memset(backend, 0, sizeof(*backend)); - - ALCdsoundPlayback_Construct(backend, device); - return STATIC_CAST(ALCbackend, backend); } if(type == ALCbackend_Capture) { ALCdsoundCapture *backend; - - backend = ALCdsoundCapture_New(sizeof(*backend)); + NEW_OBJ(backend, ALCdsoundCapture)(device); if(!backend) return NULL; - memset(backend, 0, sizeof(*backend)); - - ALCdsoundCapture_Construct(backend, device); - return STATIC_CAST(ALCbackend, backend); } |