static HRESULT WINAPI PrimaryBufferImpl_GetPan( LPDIRECTSOUNDBUFFER iface,LPLONG pan ) { IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface); DirectSoundDevice *device = This->device; float lvol, rvol; HRESULT hr; TRACE("(%p,%p)\n", iface, pan); if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) { WARN("control unavailable\n"); return DSERR_CONTROLUNAVAIL; } if (pan == NULL) { WARN("invalid parameter: pan == NULL\n"); return DSERR_INVALIDPARAM; } EnterCriticalSection(&device->mixlock); hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } if(device->pwfx->nChannels > 1){ hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } }else rvol = 1; device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF)); device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF)); DSOUND_AmpFactorToVolPan(&device->volpan); *pan = device->volpan.lPan; LeaveCriticalSection(&device->mixlock); return DS_OK; }
static HRESULT WINAPI PrimaryBufferImpl_SetPan(IDirectSoundBuffer *iface, LONG pan) { IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface); DirectSoundDevice *device = This->device; float fvol; HRESULT hr; int i; TRACE("(%p,%d)\n", iface, pan); if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) { WARN("control unavailable\n"); return DSERR_CONTROLUNAVAIL; } if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) { WARN("invalid parameter: pan = %d\n", pan); return DSERR_INVALIDPARAM; } /* **** */ EnterCriticalSection(&device->mixlock); for (i = 0; i < DS_MAX_CHANNELS; i++) { if (device->pwfx->nChannels > i){ hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol); if (FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } } else fvol = 1; device->volpan.dwTotalAmpFactor[i] = ((UINT16)(fvol * (DWORD)0xFFFF)); } DSOUND_AmpFactorToVolPan(&device->volpan); if (pan != device->volpan.lPan) { device->volpan.lPan=pan; DSOUND_RecalcVolPan(&device->volpan); for (i = 0; i < DS_MAX_CHANNELS; i++) { if (device->pwfx->nChannels > i) { fvol = (float)((DWORD)(device->volpan.dwTotalAmpFactor[i] & 0xFFFF) / (float)0xFFFF); hr = IAudioStreamVolume_SetChannelVolume(device->volume, i, fvol); if (FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("SetChannelVolume failed: %08x\n", hr); return hr; } } } } LeaveCriticalSection(&device->mixlock); /* **** */ return DS_OK; }
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(IDirectSoundBuffer *iface, LONG *vol) { IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface); DirectSoundDevice *device = This->device; float fvol; HRESULT hr; int i; TRACE("(%p,%p)\n", iface, vol); if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) { WARN("control unavailable\n"); return DSERR_CONTROLUNAVAIL; } if (vol == NULL) { WARN("invalid parameter: vol = NULL\n"); return DSERR_INVALIDPARAM; } EnterCriticalSection(&device->mixlock); for (i = 0; i < DS_MAX_CHANNELS; i++) { if (device->pwfx->nChannels > i){ hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol); if (FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } } else fvol = 1; device->volpan.dwTotalAmpFactor[i] = ((UINT16)(fvol * (DWORD)0xFFFF)); } DSOUND_AmpFactorToVolPan(&device->volpan); *vol = device->volpan.lVolume; LeaveCriticalSection(&device->mixlock); return DS_OK; }
static HRESULT WINAPI PrimaryBufferImpl_SetVolume( LPDIRECTSOUNDBUFFER iface,LONG vol ) { IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface); DirectSoundDevice *device = This->device; HRESULT hr; float lvol, rvol; TRACE("(%p,%d)\n", iface, vol); if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) { WARN("control unavailable\n"); return DSERR_CONTROLUNAVAIL; } if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) { WARN("invalid parameter: vol = %d\n", vol); return DSERR_INVALIDPARAM; } /* **** */ EnterCriticalSection(&device->mixlock); hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } if(device->pwfx->nChannels > 1){ hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("GetChannelVolume failed: %08x\n", hr); return hr; } }else rvol = 1; device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF)); device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF)); DSOUND_AmpFactorToVolPan(&device->volpan); if (vol != device->volpan.lVolume) { device->volpan.lVolume=vol; DSOUND_RecalcVolPan(&device->volpan); lvol = (float)((DWORD)(device->volpan.dwTotalLeftAmpFactor & 0xFFFF) / (float)0xFFFF); hr = IAudioStreamVolume_SetChannelVolume(device->volume, 0, lvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("SetChannelVolume failed: %08x\n", hr); return hr; } if(device->pwfx->nChannels > 1){ rvol = (float)((DWORD)(device->volpan.dwTotalRightAmpFactor & 0xFFFF) / (float)0xFFFF); hr = IAudioStreamVolume_SetChannelVolume(device->volume, 1, rvol); if(FAILED(hr)){ LeaveCriticalSection(&device->mixlock); WARN("SetChannelVolume failed: %08x\n", hr); return hr; } } } LeaveCriticalSection(&(device->mixlock)); /* **** */ return DS_OK; }
static void test_streamvolume(void) { IAudioClient *ac; IAudioStreamVolume *asv; WAVEFORMATEX *fmt; UINT32 chans, i; HRESULT hr; float vol, *vols; hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08x\n", hr); if(hr != S_OK) return; hr = IAudioClient_GetMixFormat(ac, &fmt); ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr); hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, fmt, NULL); ok(hr == S_OK, "Initialize failed: %08x\n", hr); hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&asv); ok(hr == S_OK, "GetService failed: %08x\n", hr); hr = IAudioStreamVolume_GetChannelCount(asv, NULL); ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetChannelCount(asv, &chans); ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr); ok(chans == fmt->nChannels, "GetChannelCount gave wrong number of channels: %d\n", chans); hr = IAudioStreamVolume_GetChannelVolume(asv, fmt->nChannels, NULL); ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetChannelVolume(asv, fmt->nChannels, &vol); ok(hr == E_INVALIDARG, "GetChannelCount gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetChannelVolume(asv, 0, NULL); ok(hr == E_POINTER, "GetChannelCount gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol); ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr); ok(vol == 1.f, "Channel volume was not 1: %f\n", vol); hr = IAudioStreamVolume_SetChannelVolume(asv, fmt->nChannels, -1.f); ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetChannelVolume(asv, 0, -1.f); ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 2.f); ok(hr == E_INVALIDARG, "SetChannelVolume gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 0.2f); ok(hr == S_OK, "SetChannelVolume failed: %08x\n", hr); hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol); ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr); ok(fabsf(vol - 0.2f) < 0.05f, "Channel volume wasn't 0.2: %f\n", vol); hr = IAudioStreamVolume_GetAllVolumes(asv, 0, NULL); ok(hr == E_POINTER, "GetAllVolumes gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels, NULL); ok(hr == E_POINTER, "GetAllVolumes gave wrong error: %08x\n", hr); vols = HeapAlloc(GetProcessHeap(), 0, fmt->nChannels * sizeof(float)); ok(vols != NULL, "HeapAlloc failed\n"); hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels - 1, vols); ok(hr == E_INVALIDARG, "GetAllVolumes gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_GetAllVolumes(asv, fmt->nChannels, vols); ok(hr == S_OK, "GetAllVolumes failed: %08x\n", hr); ok(fabsf(vols[0] - 0.2f) < 0.05f, "Channel 0 volume wasn't 0.2: %f\n", vol); for(i = 1; i < fmt->nChannels; ++i) ok(vols[i] == 1.f, "Channel %d volume is not 1: %f\n", i, vols[i]); hr = IAudioStreamVolume_SetAllVolumes(asv, 0, NULL); ok(hr == E_POINTER, "SetAllVolumes gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels, NULL); ok(hr == E_POINTER, "SetAllVolumes gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels - 1, vols); ok(hr == E_INVALIDARG, "SetAllVolumes gave wrong error: %08x\n", hr); hr = IAudioStreamVolume_SetAllVolumes(asv, fmt->nChannels, vols); ok(hr == S_OK, "SetAllVolumes failed: %08x\n", hr); HeapFree(GetProcessHeap(), 0, vols); IAudioStreamVolume_Release(asv); IAudioClient_Release(ac); CoTaskMemFree(fmt); }
static void test_volume_dependence(void) { IAudioClient *ac, *ac2; ISimpleAudioVolume *sav; IChannelAudioVolume *cav; IAudioStreamVolume *asv; WAVEFORMATEX *fmt; HRESULT hr; float vol; GUID session; UINT32 nch; hr = CoCreateGuid(&session); ok(hr == S_OK, "CoCreateGuid failed: %08x\n", hr); hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08x\n", hr); hr = IAudioClient_GetMixFormat(ac, &fmt); ok(hr == S_OK, "GetMixFormat failed: %08x\n", hr); hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, &session); ok(hr == S_OK, "Initialize failed: %08x\n", hr); hr = IAudioClient_GetService(ac, &IID_ISimpleAudioVolume, (void**)&sav); ok(hr == S_OK, "GetService (SimpleAudioVolume) failed: %08x\n", hr); hr = IAudioClient_GetService(ac, &IID_IChannelAudioVolume, (void**)&cav); ok(hr == S_OK, "GetService (ChannelAudioVolme) failed: %08x\n", hr); hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&asv); ok(hr == S_OK, "GetService (AudioStreamVolume) failed: %08x\n", hr); hr = IAudioStreamVolume_SetChannelVolume(asv, 0, 0.2f); ok(hr == S_OK, "ASV_SetChannelVolume failed: %08x\n", hr); hr = IChannelAudioVolume_SetChannelVolume(cav, 0, 0.4f, NULL); ok(hr == S_OK, "CAV_SetChannelVolume failed: %08x\n", hr); hr = ISimpleAudioVolume_SetMasterVolume(sav, 0.6f, NULL); ok(hr == S_OK, "SAV_SetMasterVolume failed: %08x\n", hr); hr = IAudioStreamVolume_GetChannelVolume(asv, 0, &vol); ok(hr == S_OK, "ASV_GetChannelVolume failed: %08x\n", hr); ok(fabsf(vol - 0.2) < 0.05f, "ASV_GetChannelVolume gave wrong volume: %f\n", vol); hr = IChannelAudioVolume_GetChannelVolume(cav, 0, &vol); ok(hr == S_OK, "CAV_GetChannelVolume failed: %08x\n", hr); ok(fabsf(vol - 0.4) < 0.05f, "CAV_GetChannelVolume gave wrong volume: %f\n", vol); hr = ISimpleAudioVolume_GetMasterVolume(sav, &vol); ok(hr == S_OK, "SAV_GetMasterVolume failed: %08x\n", hr); ok(fabsf(vol - 0.6) < 0.05f, "SAV_GetMasterVolume gave wrong volume: %f\n", vol); hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac2); if(SUCCEEDED(hr)){ IChannelAudioVolume *cav2; IAudioStreamVolume *asv2; hr = IAudioClient_Initialize(ac2, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST, 5000000, 0, fmt, &session); ok(hr == S_OK, "Initialize failed: %08x\n", hr); hr = IAudioClient_GetService(ac2, &IID_IChannelAudioVolume, (void**)&cav2); ok(hr == S_OK, "GetService failed: %08x\n", hr); hr = IAudioClient_GetService(ac2, &IID_IAudioStreamVolume, (void**)&asv2); ok(hr == S_OK, "GetService failed: %08x\n", hr); hr = IChannelAudioVolume_GetChannelVolume(cav2, 0, &vol); ok(hr == S_OK, "CAV_GetChannelVolume failed: %08x\n", hr); ok(fabsf(vol - 0.4) < 0.05f, "CAV_GetChannelVolume gave wrong volume: %f\n", vol); hr = IAudioStreamVolume_GetChannelVolume(asv2, 0, &vol); ok(hr == S_OK, "ASV_GetChannelVolume failed: %08x\n", hr); ok(vol == 1.f, "ASV_GetChannelVolume gave wrong volume: %f\n", vol); hr = IChannelAudioVolume_GetChannelCount(cav2, &nch); ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr); ok(nch == fmt->nChannels, "Got wrong channel count, expected %u: %u\n", fmt->nChannels, nch); hr = IAudioStreamVolume_GetChannelCount(asv2, &nch); ok(hr == S_OK, "GetChannelCount failed: %08x\n", hr); ok(nch == fmt->nChannels, "Got wrong channel count, expected %u: %u\n", fmt->nChannels, nch); IAudioStreamVolume_Release(asv2); IChannelAudioVolume_Release(cav2); IAudioClient_Release(ac2); }else skip("Unable to open the same device twice. Skipping session volume control tests\n"); hr = IChannelAudioVolume_SetChannelVolume(cav, 0, 1.f, NULL); ok(hr == S_OK, "CAV_SetChannelVolume failed: %08x\n", hr); hr = ISimpleAudioVolume_SetMasterVolume(sav, 1.f, NULL); ok(hr == S_OK, "SAV_SetMasterVolume failed: %08x\n", hr); CoTaskMemFree(fmt); ISimpleAudioVolume_Release(sav); IChannelAudioVolume_Release(cav); IAudioStreamVolume_Release(asv); IAudioClient_Release(ac); }