Link to home
Start Free TrialLog in
Avatar of Grailman
Grailman

asked on

mixerGetLineControls failure

I'm trying to open a mixer to monitor audio levels but am getting a MIXERR_INVALCONTROL failure on mixerGetLineControls(). Here is the code I'm using:

    MMRESULT rc;              // Return code.
    MIXERCONTROL mxc;         // Holds the mixer control data.
    MIXERLINE mxl;            // Holds the mixer line data.
    MIXERLINECONTROLS mxlc;   // Obtains the mixer control.
      MIXERCAPS mxrcaps;
      HMIXER hMixer = NULL;

      int nNumDevs = ::mixerGetNumDevs();

      ::ZeroMemory(&m_mxrcaps, sizeof(MIXERCAPS));

      if(!nNumDevs)
      {
            GetMMError(rc);
            return;
      }

      rc = ::mixerOpen(&m_hMixer, 0, 0, NULL, MIXER_OBJECTF_MIXER );
      if(rc != MMSYSERR_NOERROR )
      {
            GetMMError(rc);
            return;
      }

      if(m_hMixer == NULL)
      {
            GetMMError(rc);
            return;
      }

    // Initialize MIXERLINE structure.
    ZeroMemory(&mxl,sizeof(mxl));
    mxl.cbStruct = sizeof(mxl);

    mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;

    rc = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxl,
                           MIXER_GETLINEINFOF_COMPONENTTYPE);
      if(rc != MMSYSERR_NOERROR )
      {
            GetMMError(rc);
      }

    // Get the control.
    ZeroMemory(&mxlc, sizeof(mxlc));
    mxlc.cbStruct = sizeof(mxlc);
    mxlc.dwLineID = mxl.dwLineID;
    mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_PEAKMETER;
    mxlc.cControls = 1;
    mxlc.cbmxctrl = sizeof(mxc);
    mxlc.pamxctrl = &mxc;
    ZeroMemory(&mxc, sizeof(mxc));
    mxc.cbStruct = sizeof(mxc);
    rc = mixerGetLineControls((HMIXEROBJ)m_hMixer,&mxlc,
                               MIXER_GETLINECONTROLSF_ONEBYTYPE);
    if (MMSYSERR_NOERROR != rc)
      {
            GetMMError(rc);
    }

    MIXERCONTROLDETAILS mxcd;             // Gets the control values.
    MIXERCONTROLDETAILS_SIGNED volStruct; // Gets the control values.

    // Initialize the MIXERCONTROLDETAILS structure
    ZeroMemory(&mxcd, sizeof(mxcd));
    mxcd.cbStruct = sizeof(mxcd);
    mxcd.cbDetails = sizeof(volStruct);
    mxcd.dwControlID = mxc.dwControlID;
    mxcd.paDetails = &volStruct;
    mxcd.cChannels = 1;

    rc = mixerGetControlDetails((HMIXEROBJ)m_hMixer, &mxcd,
                                 MIXER_GETCONTROLDETAILSF_VALUE);
    if (MMSYSERR_NOERROR != rc)
      {
            GetMMError(rc);
      }

      ... use MIXERCONTROLDETAILS structure


Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Grailman
Grailman

ASKER

I tried your Audio Mixer Functions Demo and it worked fine but only for playing wav files. How do you use it to get the cd play or the microphone input?
I tried using MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC and MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE for mxl.dwComponentType but still could not get any response...?
The controls you are trying to get are unlikely to be supported by the audio driver. Check out the Windows Volume Control utility and the following Win32 sample to see if the controls are there.
The win32 sample & volume controls show the mixer so it should be there. I don't have time to dig into it for now but it looks like I should be able t find it.
Good luck.