?
Solved

Another multimedia question

Posted on 2000-05-16
5
Medium Priority
?
527 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

764 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