Solved

Setting Win32 mixer volumes

Posted on 1997-07-21
2
365 Views
Last Modified: 2013-12-03
How do I set mixer volumes under program control in Win32?  I figured out how to do it for a Sound Blaster 16 in Win 3.1 by accessing the hardware ports directly, but this is not allowed for 32 bit programs.

I need my program to do everything the Windows 95 volume control application does.
0
Comment
Question by:Keysoft
2 Comments
 
LVL 1

Accepted Solution

by:
pcs071997 earned 100 total points
ID: 1401600
ShowVolume() Code to Be Added to the Generic Sample

// Link with mmsystem.lib for 16-bit applications and // link with winmm.lib for 32-bit applications.
#include <mmsystem.h> #include <stdlib.h>


void ShowVolume(void);   //Prototype the function early in the app

void ShowVolume(void) {
    // This is the function that can be added to the Generic Sample to
    // illustrate the use of waveOutGetVolume() and waveOutSetVolume().

    char buffer[40];
    char printbuf[80];
    UINT uRetVal, uNumDevs;
    DWORD volume;
    long lLeftVol, lRightVol;

    WAVEOUTCAPS waveCaps;

    // Make sure there is at least one
    // wave output device to work with.
    if (uNumDevs = waveOutGetNumDevs())
    {
   itoa((int)uNumDevs, buffer, 10);
   wsprintf(printbuf, "Number of devices is %s\n", (LPSTR)buffer);
   MessageBox(GetFocus(), printbuf, "NumDevs", MB_OK);
    }

    // This sample uses a hard-coded 0 as the device ID, but retail
    // applications should loop on devices 0 through N-1, where N is the
    // number of devices returned by waveOutGetNumDevs().
    if (!waveOutGetDevCaps(0,(LPWAVEOUTCAPS)&waveCaps,
       sizeof(WAVEOUTCAPS)))

    {
   // Verify the device supports volume changes
   if(waveCaps.dwSupport & WAVECAPS_VOLUME)
   {
       // The low word is the left volume, the high word is the right.
       // Set left channel: 2000h is one-eighth volume (8192 base ten).
       // Set right channel: 4000h is quarter volume (16384 base ten).
       uRetVal = waveOutSetVolume(0, (DWORD)0x40002000UL);

       // Now get and display the volumes.
       uRetVal = waveOutGetVolume(0, (LPDWORD)&volume);

       lLeftVol = (long)LOWORD(volume);
       lRightVol = (long)HIWORD(volume);

       ltoa(lLeftVol, buffer, 10);
       wsprintf(printbuf, "Left Volume is %s\n", (LPSTR)buffer);
       MessageBox(GetFocus(), printbuf, "Left Volume", MB_OK);

       ltoa(lRightVol, buffer, 10);
       wsprintf(printbuf, "Right Volume is %s\n", (LPSTR)buffer);
       MessageBox(GetFocus(), printbuf, "Right Volume", MB_OK);

       // The low word is the left volume, the high word is the right.
       // Set left channel: 8000h is half volume (32768 base ten).
       // Set right channel: 4000h is quarter volume (16384 base ten).
       uRetVal = waveOutSetVolume(0, (DWORD)0x40008000UL);

       // Now get and display the volumes.
       uRetVal = waveOutGetVolume(0, (LPDWORD)&volume);

       lLeftVol = (long)LOWORD(volume);
       lRightVol = (long)HIWORD(volume);

       ltoa(lLeftVol, buffer, 10);
       wsprintf(printbuf, "Left Volume is %s\n", (LPSTR)buffer);
       MessageBox(GetFocus(), printbuf, "Left Volume", MB_OK);

       ltoa(lRightVol, buffer, 10);
       wsprintf(printbuf, "Right Volume is %s\n", (LPSTR)buffer);
       MessageBox(GetFocus(), printbuf, "Right Volume", MB_OK);

   }
 }
}
Audio Mixer Reference
This section describes the functions, structures, and messages associated with audio mixers. These elements are grouped as follows.

Querying Devices
MIXERCAPS
mixerGetDevCaps
mixerGetNumDevs

Opening and Closing
mixerClose
mixerOpen

Retrieving Mixer Identifiers
mixerGetID

Retrieving Line Controls
MIXERCONTROL
mixerGetLineControls
MIXERLINECONTROLS

Changing Control Attributes
MIXERCONTROLDETAILS
MIXERCONTROLDETAILS_BOOLEAN
MIXERCONTROLDETAILS_LISTTEXT
MIXERCONTROLDETAILS_SIGNED
MIXERCONTROLDETAILS_UNSIGNED
mixerGetControlDetails
mixerSetControlDetails

Retrieving Line Information
mixerGetLineInfo
MIXERLINE
MM_MIXM_CONTROL_CHANGE
MM_MIXM_LINE_CHANGE

Sending User-Defined Messages
mixerMessage

0
 

Author Comment

by:Keysoft
ID: 1401601
I didn't even realize there were mixer specific functions!  Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

16 Experts available now in Live!

Get 1:1 Help Now