Solved

Another multimedia question

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 97
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 91
How to convert MFC::CString to UTF8 wchar_t* 10 388
Problem with SqlConnection 4 184
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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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