Announcement

Collapse
No announcement yet.

Help needed from VB expert !

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed from VB expert !

    taken up learning VB, just for the fun of it.. I'm trying to write a BMW i-bus steering wheel interface, that maps buttons to different apps and stuff.

    I'm doing ok, but can seem to grasp the API master volume control. I've been searching and searching and trying different code but failed to get anywhere with this section of the code.. in brief I want to adjust the master vol up and down and also mute it..

    So far what I have pieced together is the below code, but then I click on my up / down buttons I would expect the master volume slider to move on the windows mixer but it doesnt.. can anyone please advise what the hell i'm doing wrong.

    Code:
    Option Explicit
    
    'Types
        Private Type tVolume
            Volume As Long
        End Type
        
        Private Type tVolumeEx
            vLeft As Integer
            vRight As Integer
        End Type
    
    'Declares
        Private Declare Function waveOutGetVolume Lib "winmm.dll" _
            (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
        Private Declare Function waveOutSetVolume Lib "winmm.dll" _
            (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
    Sub ChangeVolume(iValue As Single)
        Dim DeviceID As Long
        
        Dim ActVolume As Long
        
        Dim Vol As tVolume
        Dim VolSplit As tVolumeEx
        
        'The wave level
        DeviceID = -0
        
        'Get current volume
        waveOutGetVolume DeviceID, ActVolume
        Vol.Volume = ActVolume
        
        'Split to stereo channels
        '(Long >> 2x Int)
        LSet VolSplit = Vol
        
        'Change volume
        VolSplit.vLeft = VolSplit.vLeft + iValue
        VolSplit.vRight = VolSplit.vRight + iValue
        
        'Combine back to one variable
        '(2x Int >> Long)
        LSet Vol = VolSplit
        
        'Apply new volume
        ActVolume = Vol.Volume
        waveOutSetVolume DeviceID, ActVolume
    End Sub
    
    
    Private Sub cmdDecrease_Click()
        ChangeVolume -2048
    End Sub
    
    Private Sub cmdIncrease_Click()
        ChangeVolume 2048
    End Sub
    cheers in advance
    CdRsKuLL
    Follow me on Twitter

    http://www.FreeICE.co.uk

  • #2
    I dont know if this is the smartest move
    VolSplit.vLeft = VolSplit.vLeft + iValue
    VolSplit.vRight = VolSplit.vRight + iValue
    because you dont know the current states of the vleft and vright, one could be overflowing positivly and the other can be overflowing negitively..... I would bypass this completly

    Code:
    Option Explicit
    
    'Types
        Private Type tVolume
            Volume As Long
        End Type
        
        Private Type tVolumeEx
            vLeft As Integer
            vRight As Integer
        End Type
    
    'Declares
        Private Declare Function waveOutGetVolume Lib "winmm.dll" _
            (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
        Private Declare Function waveOutSetVolume Lib "winmm.dll" _
            (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
    Sub ChangeVolume(iValue As Single)
        Dim DeviceID As Long
        
        Dim ActVolume As Long
        
        Dim Vol As tVolume
        Dim VolSplit As tVolumeEx
        
        'The wave level
        DeviceID = -0
        
        'Get current volume
        waveOutGetVolume DeviceID, ActVolume
        Vol.Volume = ActVolume
        Label1.Caption = ActVolume
        'Split to stereo channels
        '(Long >> 2x Int)
        LSet VolSplit = Vol
        
        'Change volume
        
        
        
        
        
        
        
        
        ActVolume = ActVolume + iValue
        
        
        
        'Apply new volume
        
        waveOutSetVolume DeviceID, ActVolume
    End Sub
    
    
    Private Sub cmdDecrease_Click()
        ChangeVolume -2024
    End Sub
    
    Private Sub cmdIncrease_Click()
        ChangeVolume 2024
    End Sub
    This changes your WAV volume settings. But be careful because it seems that it will loop through max and min volume, so if you keep making it quieter eventually it will start back at the top.

    I havent played with this stuff in a while, so i dont remember too much about the volume API calls, but this might help you a little bit.
    PC Components:
    Lilliput; XPC/FLEX mobo; 1.7 ghz P4 Mobile;512 DDR; 160 gb HDD; opus 150; slot usb dvd-rw
    My work log

    Comment


    • #3
      Originally posted by Peoples
      I dont know if this is the smartest move
      VolSplit.vLeft = VolSplit.vLeft + iValue
      VolSplit.vRight = VolSplit.vRight + iValue
      because you dont know the current states of the vleft and vright, one could be overflowing positivly and the other can be overflowing negitively..... I would bypass this completly
      Actually VolSplit is set by the LSet, after the waveOutGetVolume. My guess is that this value is actually the problem... either ActVolume is not returning (probably from the external call failing?) or it has some weird value that returns after the call. Best bet would probably be some debugging msgbox calls in there to see what's happening, or stepping through the code at runtime and putting some watches in there to see what the values are.

      For all intents and purposes it looks like it should work though...

      Only other thing that I can think of is that he renamed the buttons or something... since the subs are tied to cmdDecrease and cmdIncrease.

      * shrug *

      Comment


      • #4
        @CdrSkull,

        This is quick and dirty. Use this code. To keep from looping, the actVOlume should be between 0 and 65535.

        Code:
        Sub ChangeVolume(iValue As Single)
            Dim DeviceID As Long
            
            Dim ActVolume As Long
            
            Dim Vol As tVolume
            Dim VolSplit As tVolumeEx
            
            'The wave level
            DeviceID = -0
            
            'Get current volume
             waveOutGetVolume DeviceID, ActVolume
            
            Vol.Volume = ActVolume
            Label1.Caption = Int(ActVolume)
            'Split to stereo channels
            '(Long >> 2x Int)
           LSet VolSplit = Vol
            
            'Change volume
            
            
            
            
            
            
            
            
            ActVolume = ActVolume + iValue
            
            If Int(ActVolume) > 65535 Then
             ActVolume = 65535
          ElseIf Int(ActVolume) < 0 Then
             ActVolume = 0
          Else
             ActVolume = ActVolume
          End If
        
            
            'Apply new volume
            
            waveOutSetVolume DeviceID, ActVolume
        End Sub
        MyMedia Website

        Comment


        • #5
          thanks fella's for your input.. yep the code does work, I was expecting the mixer to update when I press the buttons, but it doesnt. I needed to shut it and re open it to notice the changes..

          Also as mentioned this alters the wav volume, but I was actual after altering the master volume.

          What would I need to add/change to get it to show update in the mixer like other volume programs to in realtime rather then closing it and starting it up again, and map it to the main volume rather then the wave

          cheers for all your help peeps..
          Follow me on Twitter

          http://www.FreeICE.co.uk

          Comment

          Working...
          X