void WindowsAudioInputDevice::initializeIfNecessary() {
  if (ourMixers != NULL) return; // we've already been initialized
  numMixers = mixerGetNumDevs();
  ourMixers = new Mixer[numMixers];

  // Initialize each mixer:
  numInputPortsTotal = 0;
  for (unsigned i = 0; i < numMixers; ++i) {
    Mixer& mixer = ourMixers[i];
    mixer.index = i;
    mixer.open();
    if (mixer.hMixer != NULL) {
      // This device has a valid mixer.  Get information about its ports:
      mixer.getPortsInfo();
      mixer.close();

      if (mixer.numPorts == 0) continue;

      numInputPortsTotal += mixer.numPorts;
    } else {
      mixer.ports = NULL;
      mixer.numPorts = 0;
    }
  }
}
/* Given a DirectX device identified by "lpszDesc", find the corresponding wave device ID and return it in "waveID".
   This is a hack that we use because GetWaveDeviceIDFromGUID() only works for playback devices (not capture devices). */
HRESULT GetWaveDeviceIDFromName(LPCTSTR lpszDesc, DWORD* waveID)
{
	UINT totalDevices = mixerGetNumDevs();
	UINT currentDevice;
	MIXERCAPS mmCaps;
	MMRESULT mmResult;

	for (currentDevice = 0; currentDevice < totalDevices; currentDevice++) {
		mmResult = mixerGetDevCaps(currentDevice, &mmCaps, sizeof(mmCaps));
		if (mmFAILED(mmResult)) {
			// We couldn't get mixer-caps for this device.  This isn't good, but
			// let's persevere and try the rest of the devices.
			DPRINTF(("ERROR GetWaveDeviceIDFromName() failed to get dev-caps for index %d\n", currentDevice));
		}
		else if (stringMatchIn(lpszDesc, mmCaps.szPname)) {
			// Success!!  We've found a device with a matching name, so grab its
			// device-ID and return triumphantly.
			*waveID = currentDevice;
			return S_OK;
		}
	}
	// Failure.  We couldn't find a matching device.
	*waveID = -1;
	return ERROR_INVALID_DATA;
}
Esempio n. 3
0
BOOL CMixOut::OpenMixer()
{
	m_iDevNum = mixerGetNumDevs();
	if (m_iDevNum == 0)
	{
		TRACE("There (is) are no device mixer.\n");
		return FALSE;
	}

	WAVEFORMATEX wfx;
	memset( &wfx, 0, sizeof(WAVEFORMATEX) );
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 1;
	wfx.nSamplesPerSec = 8000;
	wfx.nAvgBytesPerSec = 1 * 8000 * 16 / 8;
	wfx.nBlockAlign = 16 * 1 / 8;
	wfx.wBitsPerSample = 16;
	wfx.cbSize = 0;

	HWAVEOUT hwaveOut;
	m_mmr = waveOutOpen( &hwaveOut, WAVE_MAPPER, &wfx, 0L, 0L, CALLBACK_NULL );
	if ( m_mmr != MMSYSERR_NOERROR )
	{
		return false;
	}
	else
	{
		m_mmr = mixerGetID( (HMIXEROBJ)hwaveOut, &m_uiMixerId, MIXER_OBJECTF_HWAVEOUT );
		waveOutClose( hwaveOut );
		if (m_mmr != MMSYSERR_NOERROR )
		{
			return false;
		}
	}

	WNDCLASSEX wcx;
	memset( &wcx, 0, sizeof(WNDCLASSEX) );	
	wcx.cbSize = sizeof(WNDCLASSEX);
	wcx.lpszClassName = WND_CLASS_NAME;
	wcx.lpfnWndProc = (WNDPROC)MixerWndProc;
	::RegisterClassEx(&wcx);
	m_hWnd = CreateWindow(	WND_CLASS_NAME,
							WND_NAME,
							WS_POPUP | WS_DISABLED,
							0, 0, 0, 0,
							NULL, NULL, NULL, NULL );
	if ( !m_hWnd )
	{
	
		return false;
	}
	::ShowWindow(m_hWnd, SW_HIDE);
	m_mmr = mixerOpen( (LPHMIXER)&m_hMixer, m_uiMixerId, (DWORD)m_hWnd, 0L, CALLBACK_WINDOW );
	if (m_mmr != MMSYSERR_NOERROR )
	{
		::DestroyWindow( m_hWnd );
		return false;
	}
	return true;
}
//##################################################
//agenttype_mixer_menu_devices
//##################################################
void agenttype_mixer_menu_devices(Menu *menu, control *c, char *action, char *agentname, int format)
{
	//Variables
	MIXERCAPS       mixer_capabilities;
	HMIXER          mixer_handle;

	//Count the devices
	UINT count_devices = mixerGetNumDevs();
	if (count_devices < 1)
	{
		make_menuitem_nop(menu, "No audio devices present.");
		return;
	}

	//For every device...
	for (UINT device = 0; device < count_devices; device++)
	{
		//Open the mixer
		if (MMSYSERR_NOERROR == mixerOpen(  &mixer_handle, device, 0, 0, 0)
			&& MMSYSERR_NOERROR == mixerGetDevCaps(device, &mixer_capabilities, sizeof(MIXERCAPS)))
		{
			//Create a submenu for destination lines
			Menu *submenu;
			submenu = make_menu(mixer_capabilities.szPname, c);
			agenttype_mixer_menu_destlines(submenu, c, action, agentname, format, device, mixer_handle, mixer_capabilities);
			make_submenu_item(menu, mixer_capabilities.szPname, submenu);

			//Close the mixer
			mixerClose(mixer_handle);
		}
	}
	return;
}
Esempio n. 5
0
static HWND
CreateApplicationWindow(VOID)
{
    HWND hWnd;

    PMIXER_WINDOW MixerWindow = HeapAlloc(hAppHeap,
                                          HEAP_ZERO_MEMORY,
                                          sizeof(MIXER_WINDOW));
    if (MixerWindow == NULL)
    {
        return NULL;
    }

    if (mixerGetNumDevs() > 0)
    {
        hWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT,
                              SZ_APP_CLASS,
                              lpAppTitle,
                              WS_DLGFRAME | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, 
                              0, 0, 300, 315,
                              NULL,
                              LoadMenu(hAppInstance,
                                       MAKEINTRESOURCE(IDM_MAINMENU)),
                              hAppInstance,
                              MixerWindow);
    }
    else
    {
        LPTSTR lpErrMessage;

        /*
         * no mixer devices are available!
         */

        hWnd = NULL;
        if (AllocAndLoadString(&lpErrMessage,
                               hAppInstance,
                               IDS_NOMIXERDEVICES))
        {
            MessageBox(NULL,
                       lpErrMessage,
                       lpAppTitle,
                       MB_ICONINFORMATION);
            LocalFree(lpErrMessage);
        }
    }

    if (hWnd == NULL)
    {
        HeapFree(hAppHeap,
                 0,
                 MixerWindow);
    }

    return hWnd;
}
Esempio n. 6
0
bool CVolumeOutMaster::Init()
{
	if ( !mixerGetNumDevs() )
		return false;
	// Getting Mixer ID
	HWAVEOUT hwaveOut;
	MMRESULT mmResult;
	WAVEFORMATEX WaveFmt;
	SetDeviceType( &WaveFmt );
	mmResult = waveOutOpen( &hwaveOut, WAVE_MAPPER, &WaveFmt, 0L, 0L, CALLBACK_NULL );
	if ( mmResult != MMSYSERR_NOERROR )
	{
		qDebug(".MasterOutputVolume: FAILURE: Could not open WaveOut Mapper. mmResult=%d\n", mmResult );
		return false;
	} else {
		mmResult = mixerGetID( (HMIXEROBJ)hwaveOut, &m_uMixerID, MIXER_OBJECTF_HWAVEOUT );
		waveOutClose( hwaveOut );
		if ( mmResult != MMSYSERR_NOERROR )
		{
			qDebug(".MasterOutputVolume: FAILURE: WaveOut Mapper in Mixer is not available. mmResult=%d\n", mmResult );
			return false;
		}
	}

	//////////////// Exposing Window to Mixer
	//////////////WNDCLASSEX wcx;
	//////////////memset( &wcx, 0, sizeof(WNDCLASSEX) );
	//////////////wcx.cbSize = sizeof(WNDCLASSEX);
	//////////////wcx.lpszClassName = _T(WND_CLASS_NAME);
	//////////////wcx.lpfnWndProc = (WNDPROC)MixerWndProc;
	//////////////::RegisterClassEx(&wcx);
	//////////////m_hWnd = CreateWindow(_T(WND_CLASS_NAME),
	//////////////						_T(WND_NAME),
	//////////////						WS_POPUP | WS_DISABLED,
	//////////////						0, 0, 0, 0,
	//////////////						NULL, NULL, NULL, NULL );
	//////////////if ( !m_hWnd )
	//////////////{
	//////////////	qDebug(".MasterOutputVolume: FAILURE: Could not create internal window.\n" );
	//////////////	return false;
	//////////////}
	//////////////::ShowWindow(m_hWnd, SW_HIDE);
	//////////////mmResult = mixerOpen( (LPHMIXER)&m_dwMixerHandle, m_uMixerID, (DWORD)m_hWnd, 0L, CALLBACK_WINDOW );
	mmResult = mixerOpen( (LPHMIXER)&m_dwMixerHandle, m_uMixerID, NULL, 0L, CALLBACK_NULL );
	if ( mmResult != MMSYSERR_NOERROR )
	{
		qDebug(".MasterOutputVolume: FAILURE: Could not open Mixer. mmResult=%d\n", mmResult );
		//////////////::DestroyWindow( m_hWnd );
		return false;
	}
	return true;
}
Esempio n. 7
0
/**
 * A ridiculous amount of code to do something this simple.
 * But mixers are pretty abstract a subject, I guess...
 * (No, the API just sucks.)
 */
static int initMixer(void)
{
    MIXERCAPS   mixerCaps;
    int         num = mixerGetNumDevs(); // Number of mixer devices.

    if(initMixerOk || CommandLine_Check("-nomixer"))
        return true;

    if(verbose)
    {
        // In verbose mode, print a lot of extra information.
        Con_Message("dsWinMM::initMixer: Number of mixer devices: %i", num);
    }

    // Open the mixer device.
    res = mixerOpen(&mixer, 0, 0, 0, MIXER_OBJECTF_MIXER);
    if(res != MMSYSERR_NOERROR)
    {
        if(verbose)
            Con_Message("  Error opening mixer: Error %i", res);
        return 0;
    }

    // Get the device caps.
    mixerGetDevCaps((UINT_PTR) mixer, &mixerCaps, sizeof(mixerCaps));

    Con_Message("dsWinMM::initMixer: %s", mixerCaps.szPname);
    if(verbose)
        Con_Message("  Audio line destinations: %i",
                    mixerCaps.cDestinations);

    // Init CD mixer.
    if(verbose)
        Con_Message("Init CD audio line:");
    initMixerLine(&mixCD, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC);
    if(verbose)
        Con_Message("Init synthesizer line:");
    initMixerLine(&mixMidi, MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER);

    // We're successful.
    initMixerOk = true;

    // Get the original mixer volume settings (restored at shutdown).
    origVol = mixer3i(MIX_MIDI, MIX_GET, MIX_VOLUME);
    origCDVol = mixer3i(MIX_CDAUDIO, MIX_GET, MIX_VOLUME);

    return true;
}
Esempio n. 8
0
    PLUGIN_FUNCTION_ARG3(GetDeviceName,unsigned,index, char *,buffer, unsigned,bufsize)
    {
      if (buffer == NULL || bufsize < 4)
        return PluginLID_InvalidParameter;

      if (index >= 1)
        return PluginLID_NoMoreNames;

      UINT numDevs = mixerGetNumDevs();
      for(UINT i = 0; i < numDevs; i++){
        MIXERCAPS caps;
	mixerGetDevCaps(i, &caps, sizeof(caps));
        if (strstr(caps.szPname, "USB Audio") != NULL) {
          strcpy(buffer, "HID");
          return PluginLID_NoError;
        }
      }

      return PluginLID_NoMoreNames;
    }
/* If the PROP_DEVICE_NAME is set, find the mixer related to device;
 * otherwise we get the default input mixer. */
static gboolean
gst_directsound_src_mixer_find (GstDirectSoundSrc * dsoundsrc,
    MIXERCAPS * mixer_caps)
{
  MMRESULT mmres;
  guint i, num_mixers;

  num_mixers = mixerGetNumDevs ();
  for (i = 0; i < num_mixers; i++) {
    mmres = mixerOpen (&dsoundsrc->mixer, i, 0L, 0L,
        MIXER_OBJECTF_MIXER | MIXER_OBJECTF_WAVEIN);

    if (mmres != MMSYSERR_NOERROR)
      continue;

    mmres = mixerGetDevCaps (GPOINTER_TO_UINT (dsoundsrc->mixer),
        mixer_caps, sizeof (MIXERCAPS));

    if (mmres != MMSYSERR_NOERROR) {
      mixerClose (dsoundsrc->mixer);
      continue;
    }

    /* Get default mixer */
    if (dsoundsrc->device_name == NULL) {
      GST_DEBUG ("Got default input mixer: %s", mixer_caps->szPname);
      return TRUE;
    }

    if (g_strstr_len (dsoundsrc->device_name, -1, mixer_caps->szPname) != NULL) {
      GST_DEBUG ("Got requested input mixer: %s", mixer_caps->szPname);
      return TRUE;
    }

    /* Wrong mixer */
    mixerClose (dsoundsrc->mixer);
  }

  GST_DEBUG ("Can't find input mixer");
  return FALSE;
}
Esempio n. 10
0
PSND_MIXER
SndMixerCreate(HWND hWndNotification)
{
    PSND_MIXER Mixer = (PSND_MIXER) HeapAlloc(GetProcessHeap(),
                                 HEAP_ZERO_MEMORY,
                                 sizeof(SND_MIXER));
    if (Mixer != NULL)
    {
        Mixer->hWndNotification = hWndNotification;
        Mixer->MixersCount = mixerGetNumDevs();
        Mixer->MixerId = NO_MIXER_SELECTED;

        if (Mixer->MixersCount > 0)
        {
            /* select the first mixer by default */
            SndMixerSelect(Mixer, 0);
        }
    }

    return Mixer;
}
Esempio n. 11
0
static void winsnd_detect(MSSndCardManager *m){
    MMRESULT mr = NOERROR;
    unsigned int nInDevices = waveInGetNumDevs ();
    unsigned int item;
	char pcmdev[1024];
	char mixdev[1024];

    for (item = 0; item < nInDevices; item++)
    {
        WAVEINCAPS caps;
        mr = waveInGetDevCaps (item, &caps, sizeof (WAVEINCAPS));
        if (mr == MMSYSERR_NOERROR)
        {
            MSSndCard *card;
	        snprintf(pcmdev,sizeof(pcmdev),"%s",caps.szPname);
	        snprintf(mixdev,sizeof(mixdev),"%s",caps.szPname);
            if (item == 0)
            {
		        card=winsnd_card_new(pcmdev,mixdev, item-1);
		        ms_snd_card_manager_add_card(m,card);
            }
			card=winsnd_card_new(pcmdev,mixdev, item);
			ms_snd_card_manager_add_card(m,card);
        }
    }
#if 0
	nInDevices = mixerGetNumDevs ();
    for (item = 0; item < nInDevices; item++)
    {
        MIXERCAPS caps;
        mr = mixerGetDevCaps (item, &caps, sizeof (MIXERCAPS));
        if (mr == MMSYSERR_NOERROR)
        {
	        snprintf(pcmdev,sizeof(pcmdev),"%s",caps.szPname);
	        snprintf(mixdev,sizeof(mixdev),"%s",caps.szPname);
        }
    }
#endif
}
BOOL MicMute::openMixer()
{
int n;

	//Get the no of mixer devices
	n=mixerGetNumDevs();
	
	m_mixer=NULL;
	::ZeroMemory(&mixcap,sizeof(MIXERCAPS));

	if(n==0)
	return FALSE;

		//Open the first mixer device
		if(mixerOpen(&m_mixer,0,NULL,NULL,MIXER_OBJECTF_MIXER)!=MMSYSERR_NOERROR)
		return FALSE;
		
		//Get mixer properties
		if( ::mixerGetDevCaps((UINT)m_mixer,&mixcap, sizeof(MIXERCAPS) )!=MMSYSERR_NOERROR)
		return FALSE;
		
 	    return TRUE;
}
Esempio n. 13
0
unsigned int iKX::get_winmm_device(int what,int subdevice)
{
 UINT ret=0xffffffff;

 const char *device=get_winmm_name((what==KX_WINMM_MIXER)?KX_WINMM_WAVE:what);
 if(device==0)
  return ret;

 if(subdevice==0)
 {
      switch(what)
      {
       case KX_WINMM_MIXER:
             if(mixerGetNumDevs()) // else causes unsigned infinite loop
               for(UINT i=0;i<mixerGetNumDevs();i++)
               {
                MIXERCAPS caps;
                if(mixerGetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR)
                {
                  if(strcmp(caps.szPname,device)==NULL)
                  {
                   ret=i;
                   break;
                  }
                } else break;
               }
             break;
       case KX_WINMM_WAVE:
       case KX_WINMM_WAVE23:
       case KX_WINMM_WAVE45:
       case KX_WINMM_WAVE67:
       case KX_WINMM_WAVEHQ:
             if(waveInGetNumDevs()) // else causes unsigned infinite loop
               for(UINT i=0;i<waveInGetNumDevs();i++)
               {
                WAVEINCAPS caps;
                if(waveInGetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR)
                {
                  if(strcmp(caps.szPname,device)==NULL)
                  {
                   ret=i;
                   break;
                  }
                } else break;
               }
             break;
       case KX_WINMM_SYNTH:
       case KX_WINMM_SYNTH2:
       case KX_WINMM_UART:
       case KX_WINMM_UART2:
       case KX_WINMM_CTRL:
             if(midiInGetNumDevs()) // else causes unsigned infinite loop
               for(UINT i=0;i<midiInGetNumDevs();i++)
               {
                MIDIINCAPS caps;
                if(midiInGetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR)
                {
                  if(strcmp(caps.szPname,device)==NULL)
                  {
                   ret=i;
                   break;
                  }
                } else break;
               }
             break;
      }
 }
 else
 {
      switch(what)
      {
       case KX_WINMM_MIXER:
            debug("kxapi: incorrect get_winmm call(mixer)\n");
            break;
       case KX_WINMM_WAVE:
       case KX_WINMM_WAVE23:
       case KX_WINMM_WAVE45:
       case KX_WINMM_WAVE67:
       case KX_WINMM_WAVEHQ:
             if(waveOutGetNumDevs()) // else causes unsigned infinite loop
               for(UINT i=0;i<waveOutGetNumDevs();i++)
               {
                WAVEOUTCAPS caps;
                if(waveOutGetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR)
                {
                  if(strcmp(caps.szPname,device)==NULL)
                  {
                   ret=i;
                   break;
                  }
                } else break;
               }
             break;
       case KX_WINMM_SYNTH:
       case KX_WINMM_SYNTH2:
       case KX_WINMM_UART:
       case KX_WINMM_UART2:
       case KX_WINMM_CTRL:
             if(midiOutGetNumDevs()) // else causes unsigned infinite loop
               for(UINT i=0;i<midiOutGetNumDevs();i++)
               {
                MIDIOUTCAPS caps;
                if(midiOutGetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR)
                {
                  if(strcmp(caps.szPname,device)==NULL)
                  {
                   ret=i;
                   break;
                  }
                } else break;
               }
             break;
      }
 }
 return ret;
}
Esempio n. 14
0
int iKX::init_winmm()
{
    // check for Vista and Windows7:
    OSVERSIONINFOEX ver;
    memset(&ver,0,sizeof(ver));
    ver.dwOSVersionInfoSize=sizeof(ver);

    if(GetVersionEx((OSVERSIONINFO *)&ver)) // ok?
    {
     if(ver.dwPlatformId==VER_PLATFORM_WIN32_NT && ver.dwMajorVersion>=6)
     {
      debug("iKX(): init_winmm: mixers are not supported. Vista+ workaround\n");
      return 0;
     }
    }

    int ret=-1;

    for(unsigned int i=0;i<mixerGetNumDevs();i++)
    {
        HMIXER mixer=0;
        int to_close=1;

        // open mixer
        if(mixerOpen(&mixer,i,0,0,MIXER_OBJECTF_MIXER)!=MMSYSERR_NOERROR)
        {
            debug("iKX(): mixerOpen failed [%x]\n",GetLastError());
            continue; // next mixer
        }
        // get mixer caps
        MIXERCAPS mc; memset(&mc,0,sizeof(mc));
        if(mixerGetDevCaps(i,&mc,sizeof(mc))!=MMSYSERR_NOERROR)
        {
            debug("iKX(): mixerGetDevCaps() failed [%x]\n",GetLastError());
            mixerClose(mixer);
            continue;
        }

        // debug("iKX(): init_winmm: looking for '%s': '%s' [#%d out of %d]\n",wave_name,mc.szPname,i,mixerGetNumDevs());

        if(strncmp(mc.szPname,wave_name,strlen(wave_name)-4)!=NULL) // yes, this should be 'wave_name', not 'mixer_name';
        { mixerClose(mixer); continue; }

        if(strcmp(mc.szPname,wave_name)==0)
         { mixer_handler[0]=(uintptr_t)mixer; to_close=0; ret=0; }
        else
         if(strcmp(mc.szPname,wave23_name)==0)
          { mixer_handler[1]=(uintptr_t)mixer; to_close=0;  ret=0; }
         else
          if(strcmp(mc.szPname,wave45_name)==0)
           { mixer_handler[2]=(uintptr_t)mixer; to_close=0;  ret=0; }
          else
           if(strcmp(mc.szPname,wave67_name)==0)
            { mixer_handler[3]=(uintptr_t)mixer; to_close=0;  ret=0; }
           else
           if(strcmp(mc.szPname,waveHQ_name)==0)
             { mixer_handler[4]=(uintptr_t)mixer; to_close=0; ret=0; }
            else
            {
             debug("kXAPI: WARNING: incorrect init_winmm() code: %s\n",mc.szPname);
            }
        if(to_close)
         mixerClose(mixer);
//      break;
    }
    if(ret==-1)
    {
     debug("iKX(): init_winmm: number of mixers: %d\n",mixerGetNumDevs());
    }

    return ret;
}
INT32 PORT_GetPortMixerCount() {
    return (INT32) mixerGetNumDevs();
}
Esempio n. 16
0
BOOL CVolumeCtrl::Init()
{
	if (!mixerGetNumDevs())
	{
		return FALSE;
	}

	HWAVEIN hwaveIn;
	MMRESULT mmResult;
	WAVEFORMATEX WaveFmt;
	SetDeviceType( &WaveFmt );
	mmResult = waveInOpen(&hwaveIn, m_dwDeviceID, &WaveFmt, 0L, 0L, CALLBACK_NULL);
	if (mmResult != MMSYSERR_NOERROR)
	{
		return FALSE;
	}
	else
	{
		// 得到混响器的标识号
		mmResult = mixerGetID((HMIXEROBJ)hwaveIn, &m_uMixerID, MIXER_OBJECTF_HWAVEIN);
		waveInClose(hwaveIn);
		if (mmResult != MMSYSERR_NOERROR )
		{
			return FALSE;
		}
	}

	// Exposing Window to Mixer
	WNDCLASSEX wcx;
	memset( &wcx, 0, sizeof(WNDCLASSEX) );	
	wcx.cbSize = sizeof(WNDCLASSEX);
	wcx.lpszClassName = WND_CLASS_NAME;
	wcx.lpfnWndProc = (WNDPROC)MixerWndProc;
	::RegisterClassEx(&wcx);
	m_hWnd = CreateWindow(WND_CLASS_NAME,
		                  WND_NAME, 
						  WS_POPUP | WS_DISABLED,
						  0, 0, 0, 0,
						  NULL, NULL, NULL, NULL );
	if (!m_hWnd)
	{
		return FALSE;
	}
	::ShowWindow(m_hWnd, SW_HIDE);
	::UpdateWindow(m_hWnd);

	//
	// 打开混响器设备
	// 参数:
	//      m_dwMixerHandle--混响器设备的句柄  
	//      m_uMixerID--为混响器的标识号,用于指定要打开的混响器设备
	//	
	mmResult = mixerOpen( (LPHMIXER)&m_dwMixerHandle, m_uMixerID, (DWORD)m_hWnd, 0L, CALLBACK_WINDOW );
	if (mmResult != MMSYSERR_NOERROR || m_uMixerID == -1)
	{
		::DestroyWindow( m_hWnd );
		return FALSE;
	}

	return TRUE;
}
Esempio n. 17
0
VOID
InitVolumeControls(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
    UINT NumMixers;
    MIXERCAPS mxc;
    TCHAR szNoDevices[256];

    CheckDlgButton(hwndDlg,
                   IDC_ICON_IN_TASKBAR,
                   GetSystrayVolumeIconState() ? BST_CHECKED : BST_UNCHECKED);

    LoadString(hApplet, IDS_NO_DEVICES, szNoDevices, _countof(szNoDevices));

    NumMixers = mixerGetNumDevs();
    if (!NumMixers)
    {
        EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME_TRACKBAR), FALSE);
        EnableWindow(GetDlgItem(hwndDlg, IDC_MUTE_CHECKBOX),   FALSE);
        EnableWindow(GetDlgItem(hwndDlg, IDC_ADVANCED_BTN),    FALSE);
        EnableWindow(GetDlgItem(hwndDlg, IDC_SPEAKER_VOL_BTN), FALSE);
        EnableWindow(GetDlgItem(hwndDlg, IDC_ADVANCED2_BTN),   FALSE);
        SendDlgItemMessage(hwndDlg, IDC_MUTE_ICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)pGlobalData->hIconNoHW);
        SetDlgItemText(hwndDlg, IDC_DEVICE_NAME, szNoDevices);
        return;
    }

    if (mixerOpen(&pGlobalData->hMixer, 0, PtrToUlong(hwndDlg), 0, MIXER_OBJECTF_MIXER | CALLBACK_WINDOW) != MMSYSERR_NOERROR)
    {
        MessageBox(hwndDlg, _T("Cannot open mixer"), NULL, MB_OK);
        return;
    }

    ZeroMemory(&mxc, sizeof(MIXERCAPS));
    if (mixerGetDevCaps(PtrToUint(pGlobalData->hMixer), &mxc, sizeof(MIXERCAPS)) != MMSYSERR_NOERROR)
    {
        MessageBox(hwndDlg, _T("mixerGetDevCaps failed"), NULL, MB_OK);
        return;
    }

    GetMuteControl(pGlobalData);
    GetMuteState(pGlobalData);
    if (pGlobalData->muteVal)
    {
        SendDlgItemMessage(hwndDlg, IDC_MUTE_CHECKBOX, BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0);
        SendDlgItemMessage(hwndDlg, IDC_MUTE_ICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)pGlobalData->hIconMuted);
    }
    else
    {
        SendDlgItemMessage(hwndDlg, IDC_MUTE_CHECKBOX, BM_SETCHECK, (WPARAM)BST_UNCHECKED, (LPARAM)0);
        SendDlgItemMessage(hwndDlg, IDC_MUTE_ICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)pGlobalData->hIconUnMuted);
    }

    GetVolumeControl(pGlobalData);
    GetVolumeValue(pGlobalData);

    SendDlgItemMessage(hwndDlg, IDC_DEVICE_NAME, WM_SETTEXT, 0, (LPARAM)mxc.szPname);
    SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETRANGE, (WPARAM)TRUE,
        (LPARAM)MAKELONG(pGlobalData->volumeMinimum, pGlobalData->volumeMaximum/VOLUME_DIVIDER));
    SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETPAGESIZE, (WPARAM)FALSE, (LPARAM)1);
    SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETSEL, (WPARAM)FALSE,
        (LPARAM)MAKELONG(pGlobalData->volumeMinimum, pGlobalData->volumeValue/VOLUME_DIVIDER));
    SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pGlobalData->volumeValue/VOLUME_DIVIDER);
}
Esempio n. 18
0
/* ------------------------------------------------------------------------------------ */
CMixer::CMixer(HWND hwnd, DWORD DstType, DWORD SrcType, DWORD ControlType) :
    m_HMixer(NULL),
    m_iMixerControlID(0),
    mmr(MMSYSERR_NOERROR),
    m_dwChannels(0),
    m_bSuccess(FALSE)
{
    if(mixerGetNumDevs() < 1)
        return;

    mmr = mixerOpen(&m_HMixer, 0, reinterpret_cast<DWORD>(hwnd), 0L, CALLBACK_WINDOW);

    if(mmr != MMSYSERR_NOERROR)
        return;

    // get dwLineID
    MIXERLINE mxl;
    mxl.cbStruct = sizeof(MIXERLINE);

    // DstType
    mxl.dwComponentType = DstType;

    if(mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(m_HMixer), &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
        return;

    // SrcType
    if(SrcType != NO_SOURCE)
    {
        UINT nconn = mxl.cConnections;
        DWORD DstIndex = mxl.dwDestination;

        for(UINT j=0; j<nconn; ++j)
        {
            mxl.cbStruct = sizeof(MIXERLINE);
            mxl.dwSource = j;
            mxl.dwDestination = DstIndex;

            if(mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(m_HMixer), &mxl, MIXER_GETLINEINFOF_SOURCE) != MMSYSERR_NOERROR)
                return;

            if(mxl.dwComponentType == SrcType)
                break;
        }
    }

    // get dwControlID
    MIXERCONTROL mxc;
    MIXERLINECONTROLS mxlc;

    mxlc.cbStruct		= sizeof(MIXERLINECONTROLS);
    mxlc.dwLineID		= mxl.dwLineID;
    mxlc.dwControlType	= ControlType;
    mxlc.cControls		= 1;
    mxlc.cbmxctrl		= sizeof(MIXERCONTROL);
    mxlc.pamxctrl		= &mxc;

    if(mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(m_HMixer), &mxlc, MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR)
        return;

    m_iMixerControlID = mxc.dwControlID;
    m_dwChannels = mxl.cChannels;

    if(MIXERCONTROL_CONTROLF_UNIFORM & mxc.fdwControl)
        m_dwChannels = 1;

    m_bSuccess = TRUE;
}
bool setVolume(DWORD volume) {
	HMIXER mixer;
	int mixerNum ;//总的混音器数量
	bool is_find_mic;

	//获取当前系统总的混音器数量
	mixerNum= mixerGetNumDevs(); 	
	is_find_mic = false;
	for(int i=0;i<mixerNum;i++)
	{

		if (mixerOpen(&mixer, i, 0, 0, 0) != MMSYSERR_NOERROR) {   //这里修改麦克风音量是没有问题的,第一个你要找出那个混音器是麦克风啊
			printf("mixer open failed ...\n");
			MessageBoxW(NULL, L"Error: mixerOpen()", NULL, MB_ICONHAND);
			return false;
		}

		// Get the line info
		MIXERCAPS mixcaps;
		MIXERLINE mixerLine;
		mixerGetDevCaps(i, &mixcaps, sizeof(MIXERCAPS));
		mixerLine.cbStruct = sizeof(MIXERLINE);
		mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;  //用MIXERLINE_COMPONENTTYPE_DST_WAVEIN 作参数可得到所有录音的Connection
		mixerLine.dwSource = 0;
		mixerLine.dwDestination = 0;

		if (mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLine, MIXER_GETLINEINFOF_SOURCE)
			!= MMSYSERR_NOERROR) {
				MessageBoxW(NULL, L"Error: mixerGetLineInfo()", NULL, MB_ICONHAND);
				return false;
		}

		if(mixerLine.dwComponentType !=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ){
			printf("i = %d ,this device is not microphone \n" ,i);
			mixerClose(mixer);
			continue;
		}

		is_find_mic = true;
		printf("mixerLine.dwComponentType = %xH ,MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = %xH \n" ,mixerLine.dwComponentType ,MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);

		//下面的代码只有是耳麦的时候才去执行
		// Get control for mixerline
		MIXERCONTROL mixerCtrl;
		MIXERLINECONTROLS mixerLineCtrl;

		mixerLineCtrl.cbStruct = sizeof(MIXERLINECONTROLS);
		mixerLineCtrl.dwLineID = mixerLine.dwLineID;
		mixerLineCtrl.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
		mixerLineCtrl.cControls = 1;
		mixerLineCtrl.pamxctrl = &mixerCtrl;
		mixerLineCtrl.cbmxctrl = sizeof(MIXERCONTROL);
		mixerLineCtrl.cControls = 5;

		if (mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLineCtrl, MIXER_GETLINECONTROLSF_ONEBYTYPE)
			!= MMSYSERR_NOERROR) {
				MessageBoxW(NULL, L"Error: mixerGetLineControls()", NULL, MB_ICONHAND);
				return false;
		}

		// Volume..
		MIXERCONTROLDETAILS mixerCtrlDetails;
		MIXERCONTROLDETAILS_UNSIGNED mixerCtrlDetailsUnsigned;

		mixerCtrlDetailsUnsigned.dwValue = volume;		//volume size 
		mixerCtrlDetails.dwControlID = mixerCtrl.dwControlID;
		mixerCtrlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
		mixerCtrlDetails.cMultipleItems = 0;
		mixerCtrlDetails.paDetails = &mixerCtrlDetailsUnsigned;
		mixerCtrlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
		mixerCtrlDetails.cChannels = 1;

		if (mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer), &mixerCtrlDetails, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE)
			!= MMSYSERR_NOERROR) {
				MessageBoxW(NULL, L"Error: mixerSetControlDetails()", NULL, MB_ICONHAND);
				return false;
		}

		mixerClose(mixer);
	}//for loop

	return is_find_mic;
}
Esempio n. 20
0
BOOL AudioInput::SetMicrPhoneVolume(DWORD dwVolume)
{
	BOOL bResult = FALSE;
	try
	{
		int mixerNum = (int)mixerGetNumDevs();
		for(int i = 0; i < mixerNum; i ++)
		{
			DWORD dwSource = 0;
			HMIXER m_hMixer = NULL;   
			MMRESULT mr = NULL;
			//打开Mixer设备   
			if(mixerOpen(&m_hMixer, i, 0, 0, MIXER_OBJECTF_MIXER) != MMSYSERR_NOERROR)
				continue; 

			MIXERLINE MixerLine;   
			//结构体的大小   
			MixerLine.cbStruct = sizeof(MixerLine);   
			//录制设备总线   
			MixerLine.dwComponentType   =   MIXERLINE_COMPONENTTYPE_DST_WAVEIN;   
			//得到录制总线中的连接数   
			if(mixerGetLineInfo((HMIXEROBJ)m_hMixer, &MixerLine,
				MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
				continue; 

			//将连接数保存   
			DWORD dwConnections = MixerLine.cConnections;   
			//准备获取麦克风设备的ID   
			DWORD dwLineID = 0;   
			for(DWORD i = 0; i < dwConnections; i++ )   
			{   
				//枚举每一个设备,当Source的ID等于当前的迭代记数   
				MixerLine.dwSource = i;   
				//根据SourceID获得连接的信息   
				if(mixerGetLineInfo((HMIXEROBJ)m_hMixer, &MixerLine,   
					MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE) != MMSYSERR_NOERROR) 
					//判断函数执行错误   
					break;  

				//如果当前设备类型是麦克风,则跳出循环。   
				if(MixerLine.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE)   
				{   
					dwLineID = MixerLine.dwLineID;
					dwSource = MixerLine.dwSource;
					break;   
				}   
			}

			//如果没有找到,返回失败。   
			if(dwLineID == 0)   
				continue;   

			//get line id of destination line   
			MIXERLINE lineinfo_Dest;   
			::ZeroMemory(&lineinfo_Dest, sizeof(MIXERLINE));   
			lineinfo_Dest.cbStruct = sizeof(MIXERLINE);   
			lineinfo_Dest.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;   
			if(::mixerGetLineInfo(   
				(HMIXEROBJ)m_hMixer,   
				&lineinfo_Dest,   
				MIXER_OBJECTF_HMIXER   |     
				MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
				continue;  

			//get id of specified connector   
			MIXERLINE lineinfo_Connector;   
			::ZeroMemory(&lineinfo_Connector, sizeof(MIXERLINE));  

			lineinfo_Connector.cbStruct = sizeof(MIXERLINE);   
			lineinfo_Connector.dwDestination = lineinfo_Dest.dwLineID;   
			lineinfo_Connector.dwSource = dwSource;   
			if(::mixerGetLineInfo(   
				(HMIXEROBJ)m_hMixer,   
				&lineinfo_Connector,     
				MIXER_GETLINEINFOF_SOURCE) != MMSYSERR_NOERROR)
				continue;  

			MIXERCONTROL mxc;   
			MIXERLINECONTROLS mxlc;   
			mxlc.cbStruct = sizeof(MIXERLINECONTROLS);   
			mxlc.dwLineID = lineinfo_Connector.dwLineID;   
			mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;   
			mxlc.cControls = 1;   
			mxlc.cbmxctrl = sizeof(MIXERCONTROL);   
			mxlc.pamxctrl = &mxc;   
			if(::mixerGetLineControls(   
				reinterpret_cast<HMIXEROBJ>(m_hMixer),   
				&mxlc,   
				MIXER_OBJECTF_HMIXER|MIXER_GETLINECONTROLSF_ONEBYTYPE)!= MMSYSERR_NOERROR)
				continue;  

			//get volume value range now   
			MIXERCONTROLDETAILS_UNSIGNED mxcdVolume;   
			MIXERCONTROLDETAILS mxcd;   
			mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);   
			mxcd.dwControlID = mxc.dwControlID;   
			mxcd.cChannels = 1;   
			mxcd.cMultipleItems = 0;   
			mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);   
			mxcd.paDetails = &mxcdVolume;   
			if(mixerGetControlDetails(   
				reinterpret_cast<HMIXEROBJ>(m_hMixer),   
				&mxcd,   
				MIXER_GETCONTROLDETAILSF_VALUE)!= MMSYSERR_NOERROR)
				continue;  

			//set volume   
			MIXERCONTROLDETAILS_UNSIGNED mxcdVolume_Set = { mxc.Bounds.dwMaximum * dwVolume / 255 };   
			MIXERCONTROLDETAILS mxcd_Set;   
			mxcd_Set.cbStruct = sizeof(MIXERCONTROLDETAILS);   
			mxcd_Set.dwControlID = mxc.dwControlID;   
			mxcd_Set.cChannels = 1;   
			mxcd_Set.cMultipleItems = 0;   
			mxcd_Set.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);   
			mxcd_Set.paDetails = &mxcdVolume_Set;   
			if(mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(m_hMixer),   
				&mxcd_Set,   
				MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
				continue;   

			::mixerClose(m_hMixer);
			m_hMixer = NULL;
			bResult = TRUE;;
		}
	}
	catch(...){ return FALSE; }
	return bResult;
}
Esempio n. 21
0
BOOL CALLBACK MixerPlus_OptionsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static PMIXERPLUS_INFO pinfo = NULL;

	UINT i;
	MIXERCAPS mxcaps;

	switch(uMsg)
	{
		case WM_COMMAND:

			switch(LOWORD(wParam))
			{
				case IDOK:

					pinfo->dwMixerID = (DWORD) SendDlgItemMessage(hDlg,
																	IDC_DEVICE,
																	CB_GETCURSEL, 0, 0);

					if(IsDlgButtonChecked(hDlg, IDC_MODE_PLAYBACK) == BST_CHECKED)
						pinfo->mode = MIXERPLUS_MODE_PLAYBACK;

					else pinfo->mode = MIXERPLUS_MODE_RECORDING;

					EndDialog(hDlg, IDOK);
					return TRUE;

				case IDCANCEL:

					EndDialog(hDlg, IDCANCEL);
					return TRUE;
			}

			break;

		case WM_INITDIALOG:

			pinfo = (PMIXERPLUS_INFO) lParam;

			for(i = 0; i < mixerGetNumDevs(); i++)
				if(!MMERROR(mixerGetDevCaps(i, &mxcaps, sizeof(mxcaps))))
				{
					SendDlgItemMessage(hDlg,
										IDC_DEVICE,
										CB_ADDSTRING,
										0,
										(LPARAM) mxcaps.szPname);
				}

			SendDlgItemMessage(hDlg,
								IDC_DEVICE,
								CB_SETCURSEL,
								pinfo->dwMixerID,
								0);

			if(pinfo->mode == MIXERPLUS_MODE_PLAYBACK)
				CheckDlgButton(hDlg, IDC_MODE_PLAYBACK, BST_CHECKED);

			else CheckDlgButton(hDlg, IDC_MODE_RECORDING, BST_CHECKED);

			return TRUE;
	}

	return FALSE;
}
Esempio n. 22
0
    CDVolume()
    {
        UINT uMaxDevices = mixerGetNumDevs();  //Fix memory leak -Imago 8/2/09
        
        // find all of the CD line controls and store their ID and starting volume
        for (UINT uDeviceID = 0; uDeviceID < uMaxDevices; ++uDeviceID)
        {
            HMIXEROBJ hmixer;
            
            //
            // open the mixer in question
            //
            if (MMSYSERR_NOERROR != mixerOpen((LPHMIXER)&hmixer, uDeviceID, NULL, NULL, MIXER_OBJECTF_MIXER))
            {
                debugf("Failed to open mixer %d\n", uDeviceID);
                continue;
            }

            //
            // look for a mixer line attached to a CD
            //
            MIXERLINE mixerline;

            mixerline.cbStruct = sizeof(mixerline);
            mixerline.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
            if (MMSYSERR_NOERROR != mixerGetLineInfo(hmixer, &mixerline, MIXER_GETLINEINFOF_COMPONENTTYPE)
                || mixerline.cControls == 0)
            {
                debugf("Failed to find CD line on mixer %d\n", uDeviceID);
                mixerClose((HMIXER)hmixer);
                continue;
            }

            //
            // look for a volume control for that mixer line
            //
            MIXERLINECONTROLS mixerlinecontrols; 
            MixerLineData mixerlinedata;

            mixerlinecontrols.cbStruct = sizeof(mixerlinecontrols);
            mixerlinecontrols.dwLineID = mixerline.dwLineID;
            mixerlinecontrols.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
            mixerlinecontrols.cControls = 1;
            mixerlinecontrols.cbmxctrl = sizeof(MIXERCONTROL);
            mixerlinecontrols.pamxctrl = &(mixerlinedata.mixercontrol);

            mixerlinedata.hmixer = hmixer;
            mixerlinedata.cChannels = mixerline.cChannels;

            if (MMSYSERR_NOERROR != 
                mixerGetLineControls(hmixer, &mixerlinecontrols, MIXER_GETLINECONTROLSF_ONEBYTYPE))
            {
                debugf("Failed to find CD volume fader on mixer %d\n", uDeviceID);
                mixerClose((HMIXER)hmixer);
                continue;
            }
            
            // don't try to use more than 8 channels (not likely to be a problem)
            if (mixerlinedata.cChannels > c_nMaxChannels)
                mixerlinedata.cChannels = 1;

            //
            // Get the initial volume settings (so we can restore them when we are done)
            //
            MIXERCONTROLDETAILS mixercontroldetails;

            mixercontroldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
            mixercontroldetails.dwControlID = mixerlinedata.mixercontrol.dwControlID;
            mixercontroldetails.cChannels = mixerlinedata.cChannels;
            mixercontroldetails.cMultipleItems = 0;
            mixercontroldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
            mixercontroldetails.paDetails = &(mixerlinedata.vmixercontrolsOld);
            
            if (MMSYSERR_NOERROR !=
                mixerGetControlDetails(hmixer, &mixercontroldetails, MIXER_GETCONTROLDETAILSF_VALUE))
            {
                debugf("Failed to get previous volume levels for mixer %d\n", uDeviceID);
                mixerClose((HMIXER)hmixer);
                continue;
            }

            // add this to the list of volume controls
            m_listMixerLines.push_back(mixerlinedata);
        }
    }
void Win32RedBookDevice::openVolume()
{
   setLastError("");

   // first attempt to get the volume control through the mixer API
   S32 i;
   for(i = mixerGetNumDevs() - 1; i >= 0; i--)
   {
      // open the mixer
      if(mixerOpen((HMIXER*)&mVolumeDeviceId, i, 0, 0, 0) == MMSYSERR_NOERROR)
      {
         MIXERLINE lineInfo;
         memset(&lineInfo, 0, sizeof(lineInfo));
         lineInfo.cbStruct = sizeof(lineInfo);
         lineInfo.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;

         // get the cdaudio line
         if(mixerGetLineInfo(mVolumeDeviceId, &lineInfo, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
         {
            MIXERLINECONTROLS lineControls;
            MIXERCONTROL volumeControl;

            memset(&lineControls, 0, sizeof(lineControls));
            lineControls.cbStruct = sizeof(lineControls);
            lineControls.dwLineID = lineInfo.dwLineID;
            lineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
            lineControls.cControls = 1;
            lineControls.cbmxctrl = sizeof(volumeControl);
            lineControls.pamxctrl = &volumeControl;

            memset(&volumeControl, 0, sizeof(volumeControl));
            volumeControl.cbStruct = sizeof(volumeControl);

            // get the volume control
            if(mixerGetLineControls(mVolumeDeviceId, &lineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
            {
               memset(&mMixerVolumeDetails, 0, sizeof(mMixerVolumeDetails));
               mMixerVolumeDetails.cbStruct = sizeof(mMixerVolumeDetails);
               mMixerVolumeDetails.dwControlID = volumeControl.dwControlID;
               mMixerVolumeDetails.cChannels = 1;
               mMixerVolumeDetails.cbDetails = sizeof(mMixerVolumeValue);
               mMixerVolumeDetails.paDetails = &mMixerVolumeValue;

               memset(&mMixerVolumeValue, 0, sizeof(mMixerVolumeValue));

               // query the current value
               if(mixerGetControlDetails(mVolumeDeviceId, &mMixerVolumeDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR)
               {
                  mUsingMixer = true;
                  mVolumeInitialized = true;
                  mOriginalVolume = mMixerVolumeValue.dwValue;
                  return;
               }
            }
         }
      }

      mixerClose((HMIXER)mVolumeDeviceId);
   }

   // try aux
   for(i = auxGetNumDevs() - 1; i >= 0; i--)
   {
      AUXCAPS caps;
      auxGetDevCaps(i, &caps, sizeof(AUXCAPS));
      if((caps.wTechnology == AUXCAPS_CDAUDIO) && (caps.dwSupport & AUXCAPS_VOLUME))
      {
         mAuxVolumeDeviceId = i;
         mVolumeInitialized = true;
         mUsingMixer = false;
         auxGetVolume(i, (unsigned long *)&mOriginalVolume);
         return;
      }
   }

   setLastError("Volume failed to initialize");
}
Esempio n. 24
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_CREATE: 
	  {
	    RECT rc;
	    GetWindowRect(hWnd, &rc);
            hwndList = CreateWindow(TEXT("listbox"), NULL, WS_CHILD | WS_VISIBLE,
              0, 0, rc.right-rc.left, rc.bottom-rc.top,
              hWnd, (HMENU)1, hInst, NULL);
	    break;
	  }
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
		  {
		    //DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
		    SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
		    int numDevs = mixerGetNumDevs();
		    if (numDevs == 0) {
		      MessageBox(hWnd, TEXT("No audio mixer devices found."), NULL, MB_OK);
		      break;
		    }
#define MSG_LEN 1024
		    TCHAR msg[MSG_LEN+1];
		    TCHAR lpszComponent[MSG_LEN];
		    UINT nDevId = 0, uDest, uConnect, uConnections;
		    MIXERCAPS mxcaps;
		    MMRESULT rc;
		    HMIXER hmx = NULL;
		    for (int i=0; i<numDevs; i++) {
		      mixerGetDevCaps(i, &mxcaps, sizeof(MIXERCAPS));
		      wsprintf(msg, TEXT("Device name: %s\t#Destinations: %ld"), mxcaps.szPname, mxcaps.cDestinations);
		      SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)msg);
		      rc = mixerOpen(&hmx, i, (DWORD_PTR)hWnd, NULL, CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
		      if (rc != MMSYSERR_NOERROR) {
		        MessageBox(hWnd, TEXT("Error opening mixer deivce"), NULL, MB_OK);
			mixerClose(hmx);
		        continue;
		      }
		      lstrcpy(msg, TEXT("Type\tComponent\tName\tLine ID\tFlags\tCtls\tConnections"));
		      SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)msg);
		      MIXERLINE mxl;
		      for (uDest = 0; uDest < mxcaps.cDestinations; uDest++) {
			mxl.cbStruct = sizeof(mxl);
			mxl.dwDestination = uDest;
			rc = mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_DESTINATION);
			if (rc != MMSYSERR_NOERROR) {
			  wsprintf(msg, TEXT("mixerGetLineInfo(dst=%u) failed. rc=%u!"), uDest, rc);
			  MessageBox(hWnd, msg, NULL, MB_OK);
			  continue;
			}
			GetComponentType(&mxl, lpszComponent);
			wsprintf(msg, TEXT("%s\t%-25s\t%-25s\t%.08lXh\t%.08lXh\t%lu\t%lu"), 
			  (MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) 
			    ? TEXT("Dest Active") : TEXT("Dest Inactive"),
			  lpszComponent, mxl.szName, mxl.dwLineID, mxl.fdwLine, mxl.cControls, mxl.cConnections);
			SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)msg);
			uConnections = mxl.cConnections;
			for (uConnect = 0; uConnect < uConnections; uConnect++) {
			  mxl.cbStruct = sizeof(mxl);
			  mxl.dwDestination = uDest;
			  mxl.dwSource = uConnect;
			  rc = mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
			  if (rc != MMSYSERR_NOERROR) {
			    wsprintf(msg, TEXT("mixerGetLineInfo(src=%u) failed. rc=%u!"), uConnect, rc);
			    MessageBox(hWnd, msg, NULL, MB_OK);
			    continue;
			  }
			  GetComponentType(&mxl, lpszComponent);
			  wsprintf(msg, TEXT("%s\t%-25s\t%-25s\t%.08lXh\t%.08lXh\t%lu\t%lu"), 
			    (MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) 
			      ? TEXT("Src Active") : TEXT("Src Inactive"),
			    lpszComponent, mxl.szName, mxl.dwLineID, mxl.fdwLine, mxl.cControls, mxl.cConnections);
			  SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)msg);
			}
		        SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)TEXT(""));
		      }
		    }
		    break;
		  }
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Esempio n. 25
0
/*
============
CDAudio_AccessVolume
  JDH: get/set CD volume
       (code adpated from cd_player.c in avp package at icculus.org)
============
*/
void CDAudio_AccessVolume (float *vol, CDDA_OP op)
{
	int					numDevs, i;
	HMIXEROBJ			hMixer;
	MIXERLINEA			line;
	MIXERLINECONTROLSA	lineControls;
	MIXERCONTROL		control;
	MIXERCONTROLDETAILS details;
	MIXERCONTROLDETAILS_UNSIGNED detailValue;
	DWORD				range;
	
	numDevs = mixerGetNumDevs ();
	for (i = 0; i < numDevs; i++)
	{
		if (mixerOpen ((HMIXER *)&hMixer, i, 0, 0, MIXER_OBJECTF_MIXER) != MMSYSERR_NOERROR)
			continue;

		line.cbStruct = sizeof(MIXERLINE);
		line.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;

		if (mixerGetLineInfoA (hMixer, &line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
		{
			control.cbStruct = sizeof(MIXERCONTROL);
			
			lineControls.cbStruct = sizeof(MIXERLINECONTROLS);
			lineControls.dwLineID = line.dwLineID;
			lineControls.pamxctrl = &control;
			lineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
			lineControls.cControls = 1;
			lineControls.cbmxctrl = sizeof(MIXERCONTROL);
			
			if (mixerGetLineControlsA (hMixer, &lineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
			{
				details.cbStruct = sizeof(MIXERCONTROLDETAILS);
				details.dwControlID = control.dwControlID;
				details.cChannels = 1;
				details.cMultipleItems = 0;
				details.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
				details.paDetails = &detailValue;

				range = control.Bounds.dwMaximum - control.Bounds.dwMinimum;
				if (op == CDDA_SETVOL)
				{
					detailValue.dwValue = control.Bounds.dwMinimum + (*vol * range);
				
					mixerSetControlDetails (hMixer, &details, MIXER_SETCONTROLDETAILSF_VALUE);
				}
				else
				{
					mixerGetControlDetails (hMixer, &details, MIXER_GETCONTROLDETAILSF_VALUE);

					*vol = (float)(detailValue.dwValue - control.Bounds.dwMinimum) / range;
				}
				
				mixerClose ((HMIXER) hMixer);
				return;
			}
		}
		
		mixerClose ((HMIXER) hMixer);
	}
}
Esempio n. 26
0
static void PlatGetCDDAVolumeControl(void)
{
	int i;
	int numDev = mixerGetNumDevs();


	//go through the mixer devices searching for one that can deal with the cd volume
	for(i=0;i<numDev;i++)
	{
		HMIXER handle;
		if(mixerOpen(&handle,i,0,0,MIXER_OBJECTF_MIXER ) == MMSYSERR_NOERROR )
		{
			
			//try to get the compact disc mixer line
			MIXERLINE line;
			line.cbStruct=sizeof(MIXERLINE);
			line.dwComponentType=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;

			if(mixerGetLineInfo(handle,&line,MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
			{
				MIXERLINECONTROLS lineControls;
				MIXERCONTROL control;


				lineControls.cbStruct=sizeof(MIXERLINECONTROLS);
				lineControls.dwLineID=line.dwLineID;
				lineControls.pamxctrl=&control;
				lineControls.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME ;
				lineControls.cControls=1;
				lineControls.cbmxctrl=sizeof(MIXERCONTROL);
				
				 control.cbStruct=sizeof(MIXERCONTROL);


				//try to get the volume control
				if(mixerGetLineControls(handle,&lineControls,MIXER_GETLINECONTROLSF_ONEBYTYPE)==MMSYSERR_NOERROR)
				{

					MIXERCONTROLDETAILS details;
					MIXERCONTROLDETAILS_UNSIGNED detailValue;

					details.cbStruct=sizeof(MIXERCONTROLDETAILS);
					details.dwControlID=control.dwControlID;
					details.cChannels=1;
					details.cMultipleItems=0;
					details.cbDetails=sizeof(MIXERCONTROLDETAILS_UNSIGNED);
					details.paDetails=&detailValue;
					
					//get the current volume so that we can restore it later
					if(mixerGetControlDetails(handle,&details,MIXER_GETCONTROLDETAILSF_VALUE)==MMSYSERR_NOERROR)
					{
						PreGameCDVolume = detailValue.dwValue;
						mixerClose(handle);
						
						return; //success
					}
				}
			}
			 
			
			mixerClose(handle);
		}

	}

	return;
}
Esempio n. 27
0
int PlatChangeCDDAVolume(int volume)
{
    MMRESULT mmres;
	unsigned int newVolume;
	int i;
	int numDev = mixerGetNumDevs();

    /* check the cdDeviceId */
    if(cdDeviceID==NO_DEVICE) return SOUND_PLATFORMERROR;

	//go through the mixer devices searching for one that can deal with the cd volume
	for(i=0;i<numDev;i++)
	{
		HMIXER handle;
		if(mixerOpen(&handle,i,0,0,MIXER_OBJECTF_MIXER ) == MMSYSERR_NOERROR )
		{
			
			//try to get the compact disc mixer line
			MIXERLINE line;
			line.cbStruct=sizeof(MIXERLINE);
			line.dwComponentType=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;

			if(mixerGetLineInfo(handle,&line,MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
			{
				MIXERLINECONTROLS lineControls;
				MIXERCONTROL control;


				lineControls.cbStruct=sizeof(MIXERLINECONTROLS);
				lineControls.dwLineID=line.dwLineID;
				lineControls.pamxctrl=&control;
				lineControls.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME ;
				lineControls.cControls=1;
				lineControls.cbmxctrl=sizeof(MIXERCONTROL);
				
				control.cbStruct=sizeof(MIXERCONTROL);


				//try to get the volume control
				if(mixerGetLineControls(handle,&lineControls,MIXER_GETLINECONTROLSF_ONEBYTYPE)==MMSYSERR_NOERROR)
				{

					MIXERCONTROLDETAILS details;
					MIXERCONTROLDETAILS_UNSIGNED detailValue;

					details.cbStruct=sizeof(MIXERCONTROLDETAILS);
					details.dwControlID=control.dwControlID;
					details.cChannels=1;
					details.cMultipleItems=0;
					details.cbDetails=sizeof(MIXERCONTROLDETAILS_UNSIGNED);
					details.paDetails=&detailValue;
										
					
					if(volume==CDDA_VOLUME_RESTOREPREGAMEVALUE)
					{
						//set the volume to what it was before the game started
						newVolume=PreGameCDVolume;
					}
					else
					{
						//scale the volume
						newVolume = control.Bounds.dwMinimum +  WideMulNarrowDiv(volume,
							(control.Bounds.dwMaximum-control.Bounds.dwMinimum), (CDDA_VOLUME_MAX-CDDA_VOLUME_MIN));

						if(newVolume<control.Bounds.dwMinimum) newVolume=control.Bounds.dwMinimum;
						if(newVolume>control.Bounds.dwMaximum) newVolume=control.Bounds.dwMaximum;
					}
					//fill in the volume in the control details structure
					detailValue.dwValue=newVolume;
	
	
					mmres = mixerSetControlDetails(handle,&details,MIXER_SETCONTROLDETAILSF_VALUE);
					mixerClose(handle);

					if(mmres==MMSYSERR_NOERROR) return 1;
					else return SOUND_PLATFORMERROR;	
					
				}
			}
			 
			
			mixerClose(handle);
		}

	}

	return SOUND_PLATFORMERROR;
}
Esempio n. 28
0
bool PortAudioInput::InitMixer(void)
{
  MIXERLINE         mxl;
  MIXERCONTROL      mxc;
  MIXERLINECONTROLS mxlc;
  MMRESULT          mmresult;
  DWORD dwLineID = -1;

  m_isOpen = false;
  m_mixerNums = mixerGetNumDevs();
  if ( m_mixerNums < 1 ) return FALSE;
  m_mixerNums = min(m_mixerNums, HMIXER_NUM_MAX);

  mxl.cbStruct = sizeof(MIXERLINE);
  mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;

  /* Mixer Init */
  for ( int i = 0; i < m_mixerNums; i++ ) {
    mmresult = mixerOpen( &m_mixer[i], (UINT)i, 0, 0, MIXER_OBJECTF_MIXER );
    if ( mmresult == MMSYSERR_NOERROR ) {
      m_barrOpened[i] = true;
      m_isOpen = true;
      mmresult = mixerGetLineInfo( (HMIXEROBJ)m_mixer[i], &mxl,
				   MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
      if ( mmresult == MMSYSERR_NOERROR ) {
        m_mixerMic = m_mixer[i];
        break;
      }
    }
  }
  if ( m_mixerMic == 0 ) return false;
  /* Volume Control Init */
  for ( DWORD i = 0; i < mxl.cConnections; i++ ) {
    mxl.dwSource = i;
    mmresult = mixerGetLineInfo( (HMIXEROBJ)m_mixerMic, &mxl,
				 MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
    if ( mmresult != MMSYSERR_NOERROR ) {
      break;
    }
    if ( mxl.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ) {
      dwLineID = mxl.dwLineID;
      break;
    }
  }
  if ( dwLineID == -1 ) {
    return false;
  }

  mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
  mxlc.dwLineID = dwLineID;
  mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
  mxlc.cControls = 1;
  mxlc.cbmxctrl = sizeof(MIXERCONTROL);
  mxlc.pamxctrl = &mxc;
  mmresult = mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(m_mixerMic),
				  &mxlc,
				  MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE);
  if ( mmresult != MMSYSERR_NOERROR ) return false;
  m_dwCntlID = mxc.dwControlID;
  m_dwMax = mxc.Bounds.dwMaximum;
  m_dwMin = mxc.Bounds.dwMinimum;
  return true;
}