| Well, got there eventually. In .+1 I provide the routine I came up
with. The documentation for waveoutSetVolume is now wrong (since
Win95 I spose) in that the layout of the parameters is not a
word n which each byte contains the volume to set for each channel,
it is a longword where the highest byte of each word is the 8 bit
volume setting for each channel - thus the problem with VB not having
an unsigned datatypes.
Anyway, the routine which I provide in the next reply will work. I'd
like to get this stuff to Microsoft to included on their web pages,
but not being a signed up developer etc I cannot. Can anyone do it for
me?
Thanks in any case
Alan Trevennor
UK NSIS Multimedia group.
|
| Public Function SetVolume(ByVal V As Variant) As Integer
'
Static LoWord, HiWord, ResultWord As Long
'
' In general what we do here is use the value of V (0-255)
' to fill the high order bytes of two 16 bit values HiWord and
' LoWord. Then we place the first of these values into the low
' 16 bits of a VB longword (32 bits) called ResultWord. If the
' value of HiWord has the top bit set then we clear that top bit
' before placing the value into the high 16 bits of ResultWord.
' If the highest bit WAS dropped, we set the value of result
' to the max minus number available in a VB Long and add our
' 32 bit value to make it into something Vb can deal with, but
' which (in hex value terms) is still correct for our purposes.
' I wonder why VB can't deal with unsigned values? What an
' omission.
'
Debug.Print "Volume being set to " & V
'
' Calculate the lower 16 bits
LoWord = (V * 256)
' And the higher 16 bits are the same for now....
HiWord = LoWord
'
' When these two values are made up into a 32 bit
' longword as described above, Would the result set
' bit 31 (ie &H80000000)?
If ((LoWord + (HiWord * (2 ^ 16))) > &H7FFFFFFF) Then
' Yes. Need to convert to a minus number here
' Strip the top bit from the higher word.
HiWord = HiWord And &H7FFF
' Make the whole thing a negative number to accomodate
' VBs lack of unsigned longword datatype
ResultWord = (0 - (2 ^ 31) + (HiWord * 2 ^ 16) + LoWord)
Else
' No, the top bit remains as zero.
ResultWord = LoWord + (HiWord * (2 ^ 16))
End If
Debug.Print "Sending " & Hex(ResultWord) & " to waveOutSetVolume"
' Set the value.
HiWord = waveOutSetVolume(ByVal 0, ByVal ResultWord)
' Processing here to check return from call .... etc etc.
End Function
|