Solved

Get microphone state

Posted on 1997-07-04
2
518 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

17 Experts available now in Live!

Get 1:1 Help Now