Another multimedia question

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
LVL 1
mahnoAsked:
Who is Participating?
 
yzConnect With a Mentor Commented:
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
 
mahnoAuthor Commented:
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
 
mahnoAuthor Commented:
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
 
yzCommented:
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
 
mahnoAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.