Skip to content

Commit

Permalink
Cygwin: mixer: Fix volume control for no WAVECAPS_LRVOLUME device
Browse files Browse the repository at this point in the history
Currently, if the device does not have capability WAVECAPS_LRVOLUME,
the volume control does not work properly. This patch fixes that.

Fixes: 2a4af36 ("Cygwin: Implement sound mixer device.")
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 committed Jun 1, 2024
1 parent 2c338fd commit abfa508
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions winsup/cygwin/autoload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0, 1)
LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0, 1)
LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0, 1)
LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0, 1)
LoadDLLfuncEx3 (waveOutMessage, winmm, 1, 0, 1)
LoadDLLfuncEx3 (waveOutGetDevCapsA, winmm, 1, 0, 1)

LoadDLLfunc (accept, ws2_32)
LoadDLLfunc (bind, ws2_32)
Expand Down
14 changes: 13 additions & 1 deletion winsup/cygwin/fhandler/mixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ details. */
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include <mmddk.h>

ssize_t
fhandler_dev_mixer::write (const void *ptr, size_t len)
Expand Down Expand Up @@ -88,7 +89,9 @@ int
fhandler_dev_mixer::ioctl (unsigned int cmd, void *buf)
{
int ret = 0;
DWORD id, flag;
DWORD vol;
WAVEOUTCAPS woc;
switch (cmd)
{
case SOUND_MIXER_READ_DEVMASK:
Expand All @@ -115,21 +118,30 @@ fhandler_dev_mixer::ioctl (unsigned int cmd, void *buf)
*(int *) buf = 1 << rec_source;
break;
case MIXER_WRITE (SOUND_MIXER_VOLUME):
waveOutMessage ((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET,
(DWORD_PTR)&id, (DWORD_PTR)&flag);
waveOutGetDevCaps ((UINT)id, &woc, sizeof (woc));
vol = volume_oss_to_winmm (*(int *) buf);
if (!(woc.dwSupport & WAVECAPS_LRVOLUME))
vol = max(vol & 0xffff, (vol >> 16) & 0xffff);
if (waveOutSetVolume ((HWAVEOUT)WAVE_MAPPER, vol) != MMSYSERR_NOERROR)
{
set_errno (EINVAL);
ret = -1;
}
break;
case MIXER_READ (SOUND_MIXER_VOLUME):
DWORD vol;
waveOutMessage ((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET,
(DWORD_PTR)&id, (DWORD_PTR)&flag);
waveOutGetDevCaps ((UINT)id, &woc, sizeof (woc));
if (waveOutGetVolume ((HWAVEOUT)WAVE_MAPPER, &vol) != MMSYSERR_NOERROR)
{
set_errno (EINVAL);
ret = -1;
break;
}
if (!(woc.dwSupport & WAVECAPS_LRVOLUME))
vol |= (vol & 0xffff) << 16;
*(int *) buf = volume_winmm_to_oss (vol);
break;
default:
Expand Down

0 comments on commit abfa508

Please sign in to comment.