Solved

Another multimedia question

Posted on 2000-05-16
5
526 Views
Last Modified: 2008-07-03
Hi,

Please tell me, how can I using API functions (mixerXXX) set selection(wave input) to microphone? (Volume control->options->properties->recording)

PS: I'm using VC60 (OS Win9x/NT/2k)

Thanks,
  mahno
0
Comment
Question by:mahno
[X]
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
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
yz earned 100 total points
ID: 2816632
yes, pls check the code below, It changes the current input line to microphone.

In the previous question about Mic Boost, accturally it's better to use MIXERCONTROL_CONTROLTYPE_ONOFF than string "Mic Boost", if the name of this control is not the same.

But I think, MIXERCONTROL_CONTROLTYPE_ONOFF is a type of control, if there are two or more same type controls, how to identify them?

As in this program, I identify the index of microphone control from it's name. because I cannot make sure that the order of items in array pMixerControlDetails_Boolean is the same as thr order of controls in WaveIn line device.

There is no unique ID for every control of audio device, the manufactory of the device can make their own control ID and name I guess, such as Mic Boost control, it has no unique ID defined in mmsystem.h, so I feel it's not easy to write a program which can run in ALL computers. Enum all controls and ask user to select maybe a good way.

Do you have MixApp example from platform SDK, the related APIs is explained quite clearly in its code I think.

#include <windows.h>
#include <mmsystem.h>

HMIXER                                          hMixer;
MIXERLINE                                    MixerLine;
MIXERCONTROL                              MixerControl;
MIXERLINECONTROLS                        MixerLineControls;
PMIXERCONTROL                              paMixerControls;
MIXERCONTROLDETAILS                        MixerControlDetails;
PMIXERCONTROLDETAILS_BOOLEAN      pMixerControlDetails_Boolean;
PMIXERCONTROLDETAILS_LISTTEXT      pMixerControlDetails_Listtext;
MIXERCAPS                                    MixerCaps;
MMRESULT                                    mmr;

void main()
      {
      UINT u,v;

    mmr = mixerOpen(&hMixer, 0, 0, 0L, MIXER_OBJECTF_MIXER);

    mmr = mixerGetDevCaps((UINT)hMixer, &MixerCaps, sizeof(MixerCaps));

    for (u = 0; u < MixerCaps.cDestinations; u++)
            {
                  MixerLine.cbStruct      = sizeof(MixerLine);
                  MixerLine.dwDestination = u;

                  mmr = mixerGetLineInfo((HMIXEROBJ)hMixer, &MixerLine, MIXER_GETLINEINFOF_DESTINATION);

                  if (MIXERLINE_COMPONENTTYPE_DST_WAVEIN == MixerLine.dwComponentType)
                        break;
            }

    paMixerControls = (PMIXERCONTROL)malloc(sizeof(MIXERCONTROL) * MixerLine.cControls);
      
    MixerLineControls.cbStruct       = sizeof(MixerLineControls);
    MixerLineControls.dwLineID       = MixerLine.dwLineID;
    MixerLineControls.cControls      = MixerLine.cControls;
    MixerLineControls.cbmxctrl       = sizeof(MIXERCONTROL);
    MixerLineControls.pamxctrl       = paMixerControls;
   
    mmr = mixerGetLineControls((HMIXEROBJ)hMixer, &MixerLineControls, MIXER_GETLINECONTROLSF_ALL);      
      
      for (u = 0; u < MixerLine.cControls; u++)
            if (MIXERCONTROL_CONTROLTYPE_MUX == paMixerControls[u].dwControlType)
                  break;
      
    MixerLineControls.cbStruct    = sizeof(MixerLineControls);
    MixerLineControls.dwControlID = paMixerControls[u].dwControlID;
    MixerLineControls.cbmxctrl    = sizeof(MixerControl);
    MixerLineControls.pamxctrl    = &MixerControl;

    mmr = mixerGetLineControls((HMIXEROBJ)hMixer, &MixerLineControls, MIXER_GETLINECONTROLSF_ONEBYID);
      
      free(paMixerControls);

      pMixerControlDetails_Listtext = (PMIXERCONTROLDETAILS_LISTTEXT)malloc(MixerLine.cChannels * MixerControl.cMultipleItems * sizeof(MIXERCONTROLDETAILS_LISTTEXT));

      MixerControlDetails.cbStruct       = sizeof(MixerControlDetails);
    MixerControlDetails.dwControlID    = MixerControl.dwControlID;
    MixerControlDetails.cChannels      = MixerLine.cChannels;
    MixerControlDetails.cMultipleItems = MixerControl.cMultipleItems;
    MixerControlDetails.cbDetails      = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
    MixerControlDetails.paDetails      = pMixerControlDetails_Listtext;

    mmr = mixerGetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, MIXER_GETCONTROLDETAILSF_LISTTEXT);

      for(u = 0; u < MixerControl.cMultipleItems; u++)
            if (0 == strcmp(pMixerControlDetails_Listtext[u].szName, "Microphone"))
                  break;

      pMixerControlDetails_Boolean = (PMIXERCONTROLDETAILS_BOOLEAN)malloc(MixerLine.cChannels * MixerControl.cMultipleItems * sizeof(MIXERCONTROLDETAILS_BOOLEAN));
 
      MixerControlDetails.cbStruct       = sizeof(MixerControlDetails);
    MixerControlDetails.dwControlID    = MixerControl.dwControlID;
    MixerControlDetails.cChannels      = MixerLine.cChannels;
    MixerControlDetails.cMultipleItems = MixerControl.cMultipleItems;
    MixerControlDetails.cbDetails      = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    MixerControlDetails.paDetails      = pMixerControlDetails_Boolean;

    mmr = mixerGetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, 0L);
      
      for (v = 0; v < MixerControl.cMultipleItems; v++)
            pMixerControlDetails_Boolean[v].fValue = false;                                    // Clear all selections

      pMixerControlDetails_Boolean[u].fValue = true;                                          // Select Microphone

    mmr = mixerSetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, 0L);

      free(pMixerControlDetails_Listtext);
      free(pMixerControlDetails_Boolean);
      }      
0
 
LVL 1

Author Comment

by:mahno
ID: 2817272
Hi yz,

Something wrong in:

MixerControlDetails.cbStruct       = sizeof(MixerControlDetails);
                        MixerControlDetails.dwControlID    = MixerControl.dwControlID;
                        MixerControlDetails.cChannels      = MixerLine.cChannels;
                        MixerControlDetails.cMultipleItems = MixerControl.cMultipleItems;
                        MixerControlDetails.cbDetails      = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
                        MixerControlDetails.paDetails      = pMixerControlDetails_Listtext;

                        mmr = mixerGetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails,
                    MIXER_GETCONTROLDETAILSF_LISTTEXT);

mmr is equal to MMSYSERR_INVALPARAM

May be the reason is dwControlID (It's equal to 0)

Regards,
  mahno
0
 
LVL 1

Author Comment

by:mahno
ID: 2832527
Ur code doesn't work corretly, but I find way how to solve my problem. Ur code helps me. That is why I can't give grade "A".

Thanks,
  mahno
0
 
LVL 1

Expert Comment

by:yz
ID: 2833258
I don't know why, these code runs ok in my computer, and the dwControlID of MixerLine is acturally zero, and the
mixerGetControlDetails returns S_OK, what happens in ur computer? could you tell me more? and how you solve it?
0
 
LVL 1

Author Comment

by:mahno
ID: 2833356
As I said on my computer mmr is equal to MMSYSERR_INVALPARAM.

>and how you solve it?
see bellow:
{
  HMIXER hMixer;
  MIXERLINE MixerLine;
  MIXERLINECONTROLS MixerLineControls;
  PMIXERCONTROL paMixerControls;
  MIXERCONTROLDETAILS MixerControlDetails;
  PMIXERCONTROLDETAILS_BOOLEAN pMixerControlDetails_Boolean;
  PMIXERCONTROLDETAILS_LISTTEXT pMixerControlDetails_Listtext;
  MIXERCAPS MixerCaps;
  MMRESULT mmr;
 
  UINT u,v;
  BOOL bFindDst = FALSE;
  BOOL bFindCtrl = FALSE;

  // Check if mixer exists
  if(mixerGetNumDevs() < 1) {
    return FALSE;
  }

  mmr = mixerOpen(&hMixer, 0, 0, 0L, MIXER_OBJECTF_MIXER);
  if (mmr != MMSYSERR_NOERROR) {
    return FALSE;
  }

  mmr = mixerGetDevCaps((UINT)hMixer, &MixerCaps, sizeof(MixerCaps));
  if (mmr != MMSYSERR_NOERROR) {
    mixerClose(hMixer);
    return FALSE;
  }

  for (u = 0; u < MixerCaps.cDestinations; u++) {
    MixerLine.cbStruct      = sizeof(MixerLine);
    MixerLine.dwDestination = u;
    MixerLine.dwSource      = 0;
   
    // Get information on this line
    mmr = mixerGetLineInfo((HMIXEROBJ)hMixer, &MixerLine, MIXER_GETLINEINFOF_DESTINATION);
    if (mmr != MMSYSERR_NOERROR) {
      mixerClose(hMixer);
      return FALSE;
    }

    if (MixerLine.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_WAVEIN) { //(MixerLine.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_VOICEIN)
      bFindDst = TRUE;
      break;
    }
  }

  if (!bFindDst) {
    mixerClose(hMixer);
    return FALSE;
  }

  paMixerControls = new MIXERCONTROL[MixerLine.cControls];

  MixerLineControls.cbStruct       = sizeof(MIXERLINECONTROLS);
  MixerLineControls.dwLineID       = MixerLine.dwLineID;
  MixerLineControls.cControls      = MixerLine.cControls;
  MixerLineControls.cbmxctrl       = sizeof(MIXERCONTROL);
  MixerLineControls.pamxctrl       = paMixerControls;
 
  // Get the controls for the current destination mixer line
  mmr = mixerGetLineControls((HMIXEROBJ)hMixer, &MixerLineControls, MIXER_GETLINECONTROLSF_ALL);
  if (mmr != MMSYSERR_NOERROR) {
    delete paMixerControls;
    mixerClose(hMixer);
    return FALSE;
  }

  for (u = 0; u < MixerLine.cControls; u++) {
    if ((paMixerControls[u].dwControlType == MIXERCONTROL_CONTROLTYPE_MUX) ||
      (paMixerControls[u].dwControlType == MIXERCONTROL_CONTROLTYPE_MIXER)) {
      bFindCtrl = TRUE;
      break;
    }
  }

  if (!bFindCtrl) {
    delete paMixerControls;
    mixerClose(hMixer);
    return FALSE;
  }

  pMixerControlDetails_Listtext = new MIXERCONTROLDETAILS_LISTTEXT[MixerLine.cChannels * paMixerControls[u].cMultipleItems];

  MixerControlDetails.cbStruct       = sizeof(MIXERCONTROLDETAILS);
  MixerControlDetails.dwControlID    = paMixerControls[u].dwControlID;
  MixerControlDetails.cChannels      = 1;//MixerLine.cChannels;
  MixerControlDetails.hwndOwner      = (HWND)paMixerControls[u].cMultipleItems;
  MixerControlDetails.cbDetails      = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
  MixerControlDetails.paDetails      = pMixerControlDetails_Listtext;

  mmr = mixerGetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, MIXER_GETCONTROLDETAILSF_LISTTEXT);
  if (mmr != MMSYSERR_NOERROR) {
    delete paMixerControls;
    delete pMixerControlDetails_Listtext;
    mixerClose(hMixer);
    return FALSE;
  }

  pMixerControlDetails_Boolean = new MIXERCONTROLDETAILS_BOOLEAN[MixerLine.cChannels * paMixerControls[u].cMultipleItems];

  MixerControlDetails.cbStruct       = sizeof(MIXERCONTROLDETAILS);
  MixerControlDetails.dwControlID    = paMixerControls[u].dwControlID;
  MixerControlDetails.cChannels      = 1;//MixerLine.cChannels;
  MixerControlDetails.hwndOwner      = (HWND)paMixerControls[u].cMultipleItems;
  MixerControlDetails.cbDetails      = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
  MixerControlDetails.paDetails      = pMixerControlDetails_Boolean;

  mmr = mixerGetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE);
  if (mmr != MMSYSERR_NOERROR) {
    delete paMixerControls;
    delete pMixerControlDetails_Listtext;
    delete pMixerControlDetails_Boolean;
    mixerClose(hMixer);
    return FALSE;
  }

  //Set only the microphone or line as input sources
  for(v = 0; v < paMixerControls[u].cMultipleItems; v++) {
    pMixerControlDetails_Boolean[v].fValue = FALSE;
    if (pMixerControlDetails_Listtext[v].dwParam2 == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE)
      pMixerControlDetails_Boolean[v].fValue = TRUE;
  }

  mmr = mixerSetControlDetails((HMIXEROBJ)hMixer, &MixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE);
  if (mmr != MMSYSERR_NOERROR) {
    delete paMixerControls;
    delete pMixerControlDetails_Listtext;
    delete pMixerControlDetails_Boolean;
    mixerClose(hMixer);
    return FALSE;
  }

  delete paMixerControls;
  delete pMixerControlDetails_Listtext;
  delete pMixerControlDetails_Boolean;
  mixerClose(hMixer);
  return TRUE;
}

Regards,
  mahno


0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

696 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