[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference abbott::visual_basic

Title:Microsoft Visual Basic
Moderator:TAMARA::DFEDOR::fedor
Created:Thu May 02 1991
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2565
Total number of notes:10453

2470.0. "WaveoutSetVolume - Multimedia - Sound volume setting problems." by CHEFS::TREVENNOR_A (A child of init) Thu Dec 12 1996 17:10

T.RTitleUserPersonal
Name
DateLines
2470.1How to declare unsigned long in VB?CHEFS::TREVENNOR_AA child of initThu Dec 19 1996 12:2013
2470.2ELIS::TOWERSFri Dec 20 1996 04:2012
2470.3waveoutSetVolume changed in Win95.CHEFS::TREVENNOR_AA child of initMon Mar 24 1997 05:5718
    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.
    
    
2470.4SetVolume function.CHEFS::TREVENNOR_AA child of initMon Mar 24 1997 06:0050
    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