Solved

Another multimedia question

Posted on 2000-05-16
5
522 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
  • 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

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

932 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

12 Experts available now in Live!

Get 1:1 Help Now