Author Topic: setting Master Volume and application Volume (Win 7 and up) [SOLVED]  (Read 320 times)

djwim

  • Posts: 33
How can I set the volume of the application that's using BASS24?
I use:
Code: [Select]
Call BASS_SetVolume (MasterVolume) ' for setting the master volume
Call BASS_ChannelSetAttribute(lHnd, BASS_ATTRIB_VOL, fVolume / 100) ' for setting volume per channel

But under windows, using the mixer, I can set the volume of the whole application separate from the master volume. More annoying is that this setting is remembered by windows, so even restarting the application will still use the old volume setting. My workaround is: don't touch this setting under windows ...  :) , but I wondered if there is a function in BASS24 which can handle this...
_Wim_
« Last Edit: 22 Aug '17 - 20:34 by djwim »

Ian @ un4seen

  • Administrator
  • Posts: 20401
It should be possible to adjust your app's mixer volume with the BASSWASAPI add-on, by using BASS_WASAPI_SetVolume with the BASS_WASAPI_VOL_SESSION option. Note that the BASSWASAPI device list is different to the BASS device list. You can find the corresponding device in both lists by looking for matching BASS_WASAPI_DEVICEINFO "id" and BASS_DEVICEINFO "driver" members.

djwim

  • Posts: 33
hmm, so it is not possible with BASS library only..!? I'll have a try with the BASSWASAPI add-on...

diystar

  • Posts: 41
Try Bass_SetConfig(BASS_CONFIG_GVOL_STREAM,LocalVol)

Ian @ un4seen

  • Administrator
  • Posts: 20401
The BASS_CONFIG_GVOL_STREAM setting won't affect the WASAPI session/mixer volume level. It is applied in the same way as the BASS_ATTRIB_VOL settings (see the BASS_CONFIG_GVOL_STREAM documentation for details).

djwim

  • Posts: 33
I tried BASSWASAPI add-on, but failed to use the "RecTest" example in the VB directory. I can elaborate on that, but I reckoned all I need is:
Code: [Select]
Declare Function BASS_WASAPI_SetVolume Lib "basswasapi.dll" (ByVal mode As Long, ByVal volume As Single) As Long
  Call BASS_WASAPI_SetVolume(0, 1)
But that causes an error message:
Quote
Unable to load function: BASS_ChannelGetLevelEx (BASS.dll)
and more surprising, it crashes my VB6 session..!!

However, for my purpose, setting the application volume at max at startup, I found that goold old winmm.dll is still available in win7 & win10, and "waveout volume" is apparently setting the application volume, so  I could use:
Code: [Select]
Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal wDeviceID As Integer, ByVal dwVolume As Long) As Integer
  Call waveOutSetVolume(0, &HFFFFFFFF) ' Set Application Volume for device 0 to max

.. the only thing missing now is setting the waveout channel to unmute incase it was set to mute...

Ian @ un4seen

  • Administrator
  • Posts: 20401
The "Unable to load function: BASS_ChannelGetLevelEx" error message sounds like you may currently be using an old BASS.DLL version. The BASS_ChannelGetLevelEx function was added in BASS 2.4.11.

Regarding the mute switch, that is accessible via BASS_WASAPI_SetMute. Note that before you can use BASS_WASAPI_SetVolume or BASS_WASAPI_SetMute, you will need to initialize the device via BASS_WASAPI_Init (should be shared mode). For example, you could do something like this:

Code: [Select]
BASS_WASAPI_Init(-1, 0, 0, 0, 0, 0, NULL, NULL); // initialize default output device
...
BASS_WASAPI_SetVolume(BASS_WASAPI_VOL_SESSION, 1); // set session volume to 100%
BASS_WASAPI_SetMute(BASS_WASAPI_VOL_SESSION, 0); // and unmute it

djwim

  • Posts: 33
Thanks Ian, I got it working now! I had BASS version 02040A00, guess that translates to 2.4.10. I copied the latest bass.dll and now got 02040C01 --> 2.4.12.1 
I only checked for HIword of bass_getversion being 2.4 ..
But I also forgot the BASS_WASAPI_Init,

So final (working) code for me is:
Code: [Select]
' BASS_WASAPI_Set/GetVolume modes
Global Const BASS_WASAPI_VOL_SESSION = 8

Declare Function BASS_WASAPI_Init Lib "basswasapi.dll" (ByVal device As Long, ByVal freq As Long, ByVal chans As Long, ByVal flags As Long, ByVal buffer As Single, ByVal period As Single, ByVal proc As Long, ByVal user As Long) As Long
Declare Function BASS_WASAPI_SetVolume Lib "basswasapi.dll" (ByVal mode As Long, ByVal volume As Single) As Long
Declare Function BASS_WASAPI_SetMute Lib "basswasapi.dll" (ByVal mode As Long, ByVal mute As Long) As Long

  Call BASS_WASAPI_Init(-1, 0, 0, 0, 0, 0, 0, 0)
  Call BASS_WASAPI_SetVolume(BASS_WASAPI_VOL_SESSION, 1)  'set application volume to max
  Call BASS_WASAPI_SetMute(BASS_WASAPI_VOL_SESSION, 0) 'unmute

So thanks again ... after so many years still active in your support!!
_Wim_