Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

waveOutSetVolume()

Posted on 1997-04-10
2
Medium Priority
?
2,751 Views
Last Modified: 2008-03-03
I've got a problem when setting the volume of the wave output. waveOutSetVolume takes 2 arguments; the first is the  id of the sounddevice and the second is the volume. The problem is that the second argument should be a unsigned long, but VB can just handle signed longs.
Anyone got a solution of how to solve this problem?

The code i have today (that doesnt fully work) is:
(left & right are the volume in percent)

Function SetVolume(left As Integer, right As Integer)
    Dim i As Integer
    Dim BothVolumes As Long
    Dim tt As Currency
    Dim tt2 As Currency
   
    CurrentVolLeft = (left * 65535) / 100
    CurrentVolRight = ((right * 65535) / 100) And &HFFFF&
    tt2 = CurrentVolRight
    If tt2 > 32767 Then
        tt = tt2 * 32768#
        tt = -tt
        tt = tt + 32767 * 65535
    Else
        tt = tt2 * 65535#
    End If
    tt = tt And &HFFFF0000
    CurrentVolRight = tt
    i = waveOutSetVolume(0, CurrentVolRight Or CurrentVolLeft)
End Function

/johan
0
Comment
Question by:coq
2 Comments
 

Expert Comment

by:Msoft
ID: 1425199
Hi !

Long and Unsigned Long are same 32 bit data types.
the difference is only in that how Visual Basic Or C++ Interpritates (Convert) it into a number.

So If you write in Visual Basic:

dim a as long
a = &HFFFFFFFF  
msgbox a

So In Visual Basic You`ll Get -1
But In C++ When you Print it Using Printf you'll get
Number: 2^32 -1 (  4294967295 )


Function that Inputs ( L as Long) and Returns (L*2 as Long)
( So Windows function ( Not VB function) would get it as   UnsignedLong)

(0 <= L < 2^31)

Function L2UL(L As long) As Long
 Dim TL As Long
  If L < &H40000000 Then
   L2UL = L * 2
  Else
   TL = L Xor &H40000000
   L2UL = TL * 2 - 2 ^ 31
  End If
 End Function

Now You Can make Your Sub:

' Inputs Volume as long ( 0 <= Valume < 2^31)
Sub MywaveOutSetVolume ( Volume as long )
 dim NewValue as long
 NewValue = L2UL(Volume)
 waveOutSetVolume(0, NewValue)
End Sub

so MywaveOutSetVolume (17) same to waveOutSetVolume(0,34)
and MywaveOutSetVolume(2^31-1)same to waveOutSetVolume(0,2^32-2)

PS:
   I think that waveOutSetVolume is not Linear Function
   ( Volume of waveOutSetVolume(2*k) is not twice than  waveOutSetVolume(k), I think that the function is proportional to Log)
 !!! I haven't read the Help its only depends of my
     Physics Knowledge !!!!
             
     
I Hope it's will help you !!!




 









 
0
 

Accepted Solution

by:
syberdyne earned 140 total points
ID: 1425200
When I have worked with setting the wave volume, I used the following function to combine the left and right volumes into the DoubleWord that is required.

Function MakeDWord(wHi As Long, wLo As Long) As Long
    If wHi And &H8000& Then
        MakeDWord = (((wHi And &H7FFF&) * 65536) Or (wLo And &HFFFF&)) Or &H80000000
    Else
        MakeDWord = (wHi * &H10000) + (wLo And &HFFFF&)
    End If
End Function

With this your function could be coded as follows:

Function SetVolume(left As Integer, right As Integer)
  Dim i As Integer
  Dim BothVolumes As Long
  Dim CurrentVolLeft As Long
  Dim CurrentVolRight As Long
  Dim tt As Currency
  Dim tt2 As Currency
                         
  CurrentVolLeft = (left * 65535) / 100
  CurrentVolRight = (right * 65535) / 100
  BothVolumes = MakeDWord(CurrentVolLeft, CurrentVolRight)
  i = waveOutSetVolume(0, BothVolumes)
End Function

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question