Solved

left-right audio control

Posted on 1997-10-09
4
575 Views
Last Modified: 2008-03-10
How can I control the left channel (left speaker) or the right channel (right speaker) for the audio(wavesound?) or
Mpeg1 file in Visual Basic?
Could you give me some program codes for VB4 or VB5?
thank you
0
Comment
Question by:hokman
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
lmarceau earned 50 total points
ID: 1437111
If you would have told us which final result you needed a could give you a more precide answer.
But I know you can't play two diffenrent files into each speaker. Since the data is played at the same time, it must be bundled at the same place. You will need to mix it in memory or to create a files with want you need on the hard disk before starting the playback.

The only thing you can do is to use the waveOutSetVolume. It will allow you to independently set the left and the rigth volume.
Syntax

UINT waveOutSetVolume(wDeviceID, dwVolume)

This function sets the volume of a waveform output device.

Parameters

UINT  wDeviceID

Identifies the waveform output device.

DWORD  dwVolume

Specifies the new volume setting. The low-order word contains the left channel volume setting, and the high-order word contains the right channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.

If a device does not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and the high-order word is ignored.

Return Value

Returns zero if the function was successful. Otherwise, it returns an error number. Possible error returns are:

MMSYSERR_INVALHANDLE

Specified device handle is invalid.

MMSYSERR_NOTSUPPORTED

Function isn't supported.

MMSYSERR_NODRIVER

The driver was not installed.

Comments

Not all devices support volume changes. To determine whether the device supports volume control, use the WAVECAPS_VOLUME flag to test the dwSupport field of the WAVEOUTCAPSstructure (filled by waveOutGetDevCaps).


0
 

Author Comment

by:hokman
ID: 1437112
what is low order word? what is high order word?
how to write this program code?
how do I know my DeviceID?
0
 
LVL 1

Expert Comment

by:lmarceau
ID: 1437113
For your first question:
A byte is made up of 8 bits.
A word is made up of 16 bits. -> This is what Vb calls an Integer
And a pack of 32 bits is called a long word, or simply long in Vb.
A long can be divided into two part:
The first 16 bits in a long, those at right, those which has the lowest impact on the numerical value, are called the low order word.
And the orders 16 bits in the long, those at left, those which has te higest impact on the numerical value, are called the high order word

waveOutSetVolume function want you to pack two information in the long, one in each word that make it up. You can do that this way:

dim LeftVolume as integer
dim RightVolume as integer
dim ToBeSend as long
ToBeSend = LeftVolume + RightVolume * 2^16

And this line in a module in your code: (vb4 16bit)
Declare Function waveOutSetVolume Lib "MMSYSTEM" (ByVal udeviceid As Integer, ByVal dwVolume As Long) As Integer

You can look up for the corect line for your vb version with the API text viewer that came with vb. Open the file vb\winapi\winmmsys.txt and search for waveOutSetVolume.

The DeviceId is the number of the sound card driver. Usually this is zero since most computer only have one sound card. But if a computer have many, then the first card has the number 0, the second has #1, the third has #2 and so on.
You can ask for the number of devices with the call waveOutGetNumDevs and ask the user for which he want to set the volume.
You could want to ask Windows for the name of the differents sound cards with waveOutGetDevCaps() to be able to show them to the user rather than only the number. Most user will not know which sound card has which number.
0
 

Author Comment

by:hokman
ID: 1437114
thank you for your patience.
But I still have problem because I am a beginner
what kind of command buttoms should I use e.g. slider or VScroll or HScroll?(or two slider to have right and left volume control, then how to disturbute the program code into two fields of sliders)
Should I also use waveOutGetVolume in order to make waveOutSetVolume have effect?
wDeviceID = 0
and dwVolume = ToBeSend
right?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now