> 音量だけでなくミュートの操作も行なう予定ですので、
hspdsp.dllは Vista以降でのミュート操作にも対応しています。
とりあえず、hspdsp.dllのボリューム操作部分をHSPに移植してみました。
#module
#define CLSID_IMMDeviceEnumerator "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
#define IID_IMMDeviceEnumerator "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
#define IID_IMMDevice "{D666063F-1587-4E43-81F1-B948E807363F}"
#define IID_IAudioEndpointVolume "{5CDF2C82-841E-4546-9722-0CF74078229A}"
#define ERender 0x00000000
#define Console 0x00000000
#usecom IMMDeviceEnumerator IID_IMMDeviceEnumerator CLSID_IMMDeviceEnumerator
#comfunc Enumerator_GetDefaultAudioEndpoint 4 int,int,var
#usecom IMMDevice IID_IMMDevice CLSID_IMMDeviceEnumerator
#comfunc Device_Activate 3 var,int,int,var
#usecom IAudioEndpointVolume IID_IAudioEndpointVolume CLSID_IMMDeviceEnumerator
#comfunc Volume_SetMasterVolumeLevelScalar 7 float,var
#comfunc Volume_GetMasterVolumeLevelScalar 9 var
#comfunc Volume_SetMute 14 int,int
#comfunc Volume_GetMute 15 var
#defcfunc todouble int p1
temp = 0.0
lpoke temp, 4, (p1 & 0x80000000) | (((p1 & 0x7fffffff) >> 3) + ((p1 & 0x7fffffff) ! 0) * 0x38000000)
lpoke temp, 0, p1 << 29
return temp
#deffunc _OpenDevice
newcom pMMDeviceEnumerator,IMMDeviceEnumerator
if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1
newcom pMMDevice,IMMDevice,-1,0
newcom pAudioEndpointVolume,IAudioEndpointVolume,-1,0
Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator,ERender,Console,pMMDevice
if varuse(pMMDevice) = 0 : _CloseDevice : return -2
uuid = 0x5CDF2C82 , 0x4546841E , 0xF70C2297 , 0x9A227840
Device_Activate pMMDevice,uuid,1,0,pAudioEndpointVolume
if varuse(pAudioEndpointVolume) = 0 : _CloseDevice : return -3
return 0
#deffunc _CloseDevice
if vartype(pAudioEndpointVolume) = 6{
if varuse(pAudioEndpointVolume) != 0{
delcom pAudioEndpointVolume
}
}
if vartype(pMMDevice) = 6{
if varuse(pMMDevice) != 0{
delcom pMMDevice
}
}
if vartype(pMMDeviceEnumerator) = 6{
if varuse(pMMDeviceEnumerator) != 0{
delcom pMMDeviceEnumerator
}
}
return
#deffunc SetMasterVolumeVista int vol
_OpenDevice
if stat<0 : return stat
uuid = 0,0,0,0
Volume_SetMasterVolumeLevelScalar pAudioEndpointVolume,1.0f*(double(vol)/100.0f),uuid
_CloseDevice
return
#defcfunc GetMasterVolumeVista
_OpenDevice
if stat<0 : return stat
vol = 0
Volume_GetMasterVolumeLevelScalar pAudioEndpointVolume,vol
_CloseDevice
return int(todouble(vol)*100.0f)
#deffunc SetMuteVista int flag
_OpenDevice
if stat<0 : return stat
Volume_SetMute pAudioEndpointVolume,flag,0
_CloseDevice
return
#defcfunc GetMuteVista
_OpenDevice
if stat<0 : return stat
res = 0
Volume_GetMute pAudioEndpointVolume,res
_CloseDevice
return res
#global
// ミュートに設定
SetMuteVista 1
mes GetMuteVista()
// ミュート解除
SetMuteVista 0
mes GetMuteVista()
// ボリュームを30にセット(0〜100)
SetMasterVolumeVista 30
mes GetMasterVolumeVista()