Results 1 to 5 of 5

Thread: Help needed from VB expert !

  1. #1
    FreeDrive Creator CdRsKuLL's Avatar
    Join Date
    Feb 2004
    Location
    Manchester
    Posts
    3,469

    Arrow 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

  2. #2
    My man uses Levitra. Peoples's Avatar
    Join Date
    Dec 2004
    Location
    Maryland
    Posts
    2,024
    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

  3. #3
    Constant Bitrate
    Join Date
    Nov 2004
    Location
    NY tri-state
    Posts
    189
    Quote 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 *

  4. #4
    Low Bitrate omar's Avatar
    Join Date
    Dec 2004
    Location
    San Diego
    Posts
    89
    @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

  5. #5
    FreeDrive Creator CdRsKuLL's Avatar
    Join Date
    Feb 2004
    Location
    Manchester
    Posts
    3,469
    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..

Similar Threads

  1. developing in VB
    By ShinkunoNamida in forum Software & Software Development
    Replies: 17
    Last Post: 07-27-2008, 10:13 AM
  2. VB & Winamp Help Needed
    By ST34LTH in forum Software & Software Development
    Replies: 7
    Last Post: 07-21-2004, 10:13 PM
  3. VB help needed - DVDplayer- Brushed metal
    By Custommx3 in forum MediaCar
    Replies: 2
    Last Post: 06-11-2004, 01:03 AM
  4. Programming help needed (DirectShow & VB)
    By All4Norway in forum Software & Software Development
    Replies: 0
    Last Post: 01-06-2003, 05:42 PM
  5. Developing a VB app with IR input???
    By mp3stang02 in forum Software & Software Development
    Replies: 8
    Last Post: 08-26-2002, 12:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •