Solved

Get microphone state

Posted on 1997-07-04
2
519 Views
Last Modified: 2013-11-20
I would know if there are MFC (or API) in Windows 95 that retrieve the microphone state when I switch on/off it by hand. My input is only by microphone and not by mouse or keyboard.
How can I do ? Thanks a lot
0
Comment
Question by:grimaldi
2 Comments
 

Author Comment

by:grimaldi
ID: 1302454
Adjusted points to 100
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1302455
If I understand correctly, you mean the switch on the microphone. Some microphones have such switches, some don't have. There is no way to retrieve the state. What you can do is to detect the audio signal coming into the microphone. I copied the following PAQ answered by me in Microsoft Windows Programming Topic Area. You can also use Audio Mixers functions to select or deselect the microphone (switch on/off by software control, it is different from the phisical switch).

Question:
I want to capture the realtime amplitude of the microphone using the mixer functions in
                  Win32. I would like to to have this value returned in the range of 0 to 255. How do I do
                  this?

        Answer:
                   Use Audio Mixers functions. The following are some sample codes.

                   // open the first mixer
                   ::mixerOpen(&m_hMixer, 0, (DWORD)this->GetSafeHwnd(), NULL,
                   MIXER_OBJECTF_MIXER | CALLBACK_WINDOW);

                   ...

                   // get the mixer control
                   if (m_hMixer == NULL)
                   return FALSE;

                   // get dwLineID
                   MIXERLINE mxl;
                   mxl.cbStruct = sizeof(MIXERLINE);
                   mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
                   if (::mixerGetLineInfo((HMIXEROBJ)m_hMixer,
                   &mxl,
                   MIXER_OBJECTF_HMIXER |
                   MIXER_GETLINEINFOF_COMPONENTTYPE)
                   != MMSYSERR_NOERROR)
                   return FALSE;

                   // get dwControlID
                   MIXERCONTROL mxc;
                   MIXERLINECONTROLS mxlc;
                   mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
                   mxlc.dwLineID = mxl.dwLineID;
                   mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_PEAKMETER;
                   mxlc.cControls = 1;
                   mxlc.cbmxctrl = sizeof(MIXERCONTROL);
                   mxlc.pamxctrl = &mxc;
                   if (::mixerGetLineControls((HMIXEROBJ)m_hMixer,
                   &mxlc,
                   MIXER_OBJECTF_HMIXER |
                   MIXER_GETLINECONTROLSF_ONEBYTYPE)
                   != MMSYSERR_NOERROR)
                   return FALSE;

                       m_dwMeterControlID = mxc.dwControlID;


                   // get the value, lVal is in the range of -32768 to 32767, you can convert it to 0-255.
                   BOOL GetMeterValue(LONG &lVal)
                   {
                   if (m_hMixer == NULL)
                   return FALSE;

                   MIXERCONTROLDETAILS_SIGNED mxcdMeter;
                       MIXERCONTROLDETAILS mxcd;
                   mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
                       mxcd.dwControlID = m_dwMeterControlID;
                       mxcd.cChannels = 1;
                       mxcd.cMultipleItems = 0;
                       mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_SIGNED);
                       mxcd.paDetails = &mxcdMeter;
                   if (::mixerGetControlDetails((HMIXEROBJ)m_hMixer,
                   &mxcd,
                   MIXER_OBJECTF_HMIXER |
                   MIXER_GETCONTROLDETAILSF_VALUE)
                   != MMSYSERR_NOERROR)
                   return FALSE;

                   lVal = mxcdMeter.lValue;

                   return TRUE;
                   }


                   ::mixerClose(m_hMixer);
                   m_hMixer = NULL;


                   You can call GetMeterValue() with a timer.

                   For more information, see Win32 SDK documentations about Audio Mixers.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

863 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