Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

left-right audio control

Posted on 1997-10-09
4
612 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

789 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