Esempio n. 1
0
BOOL
SndMixerSelect(PSND_MIXER Mixer,
               UINT MixerId)
{
    if (MixerId >= Mixer->MixersCount)
    {
        return FALSE;
    }

    SndMixerClose(Mixer);

    if (mixerOpen(&Mixer->hmx,
                  MixerId,
                  (DWORD_PTR)Mixer->hWndNotification,
                  0,
                  CALLBACK_WINDOW | MIXER_OBJECTF_MIXER) == MMSYSERR_NOERROR ||
        mixerOpen(&Mixer->hmx,
                  MixerId,
                  (DWORD_PTR)Mixer->hWndNotification,
                  0,
                  CALLBACK_WINDOW) == MMSYSERR_NOERROR ||
        mixerOpen(&Mixer->hmx,
                  MixerId,
                  0,
                  0,
                  0) == MMSYSERR_NOERROR)
    {
        if (mixerGetDevCaps(MixerId,
                            &Mixer->Caps,
                            sizeof(Mixer->Caps)) == MMSYSERR_NOERROR)
        {
            BOOL Ret = FALSE;

            Mixer->MixerId = MixerId;

            ClearMixerCache(Mixer);

            Ret = SndMixerQueryDestinations(Mixer);

            if (!Ret)
            {
                ClearMixerCache(Mixer);
            }

            return Ret;
        }
        else
        {
            mixerClose(Mixer->hmx);
        }
    }

    Mixer->hmx = NULL;
    Mixer->MixerId = NO_MIXER_SELECTED;
    return FALSE;
}
Esempio n. 2
0
File: volume.c Progetto: now/purels
BOOL mixer_init(DWORD dwCallback)
{
    MIXERLINE line;
    int i;
    int j;

    CHECK_MMRETURN(mixerOpen(&s_hMixer, 0, dwCallback, 0,
			     CALLBACK_WINDOW | MIXER_OBJECTF_MIXER));

    line.cbStruct	= sizeof(MIXERLINE);
    line.dwDestination	= 0;
    line.dwSource	= 0;

    CHECK_MMRETURN(mixerGetLineInfo((HMIXEROBJ)s_hMixer, &line,
				    MIXER_GETLINEINFOF_DESTINATION));

    if (!mixer_getlinecontrols(&line))
	return (FALSE);

    for (i = 0, j = line.cConnections; i < j; i++)
    {
	line.dwSource	= i;

	CHECK_MMRETURN(mixerGetLineInfo((HMIXEROBJ)s_hMixer, &line,
					MIXER_GETLINEINFOF_SOURCE));

	if (!mixer_getlinecontrols(&line))
	    return (FALSE);
    }

    return (TRUE);
}
Esempio n. 3
0
unsigned int CMyVolumeCtrl::vGetVolume(int   dev)//得到设备的音量dev=0主音量,1WAVE   ,2MIDI   ,3   LINE   IN 
{ 

	long   device;
	unsigned   int rt=0; 
	MIXERCONTROL   volCtrl; 
	HMIXER   hmixer; 
	switch   (dev) 
	{ 
	case   1: 
		device=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;   break; 
	case   2: 
		device=MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;   break; 
	case   3: 
		//     device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break;     //   cd   音量 
		//     device=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;   break;       //麦克风音量 
		//     device=MIXERLINE_COMPONENTTYPE_SRC_LINE;   break;                   //PC   扬声器音量 
		device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break; 

	default: 
		device=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; 
	} 

	if(mixerOpen(&hmixer,   0,   0,   0,   0))   return   0; 
	if(!vGetVolumeControl(hmixer,device,MIXERCONTROL_CONTROLTYPE_VOLUME,&volCtrl)) 
		return   0; 
	rt=vGetVolumeValue(hmixer,&volCtrl)*MAX_VOL/volCtrl.Bounds.lMaximum; 
	mixerClose(hmixer); 
	return   rt; 

} 
Esempio n. 4
0
BOOL CMyVolumeCtrl::vSetMute(long   dev,long   vol)//设置设备静音 
{ 
	//   dev   =0,1,2       分别表示主音量,波形,MIDI   ,LINE   IN 
	//   vol=0,1             分别表示取消静音,设置静音 
	//   retrun   false   表示取消或设置静音操作不成功 
	//   retrun   true     表示取消或设置静音操作成功 

	long   device; 
	BOOL   rc = FALSE; 
	MIXERCONTROL   volCtrl; 
	HMIXER   hmixer; 
	switch   (dev) 
	{ 
	case   1: 
		device=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;   break; 
	case   2: 
		device=MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;   break; 
	case   3: 
		device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break; 

	default: 
		device=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; 
	} 

	if(mixerOpen(&hmixer,   0,   0,   0,   0))   return   0; 
	if(vGetVolumeControl(hmixer,device,MIXERCONTROL_CONTROLTYPE_MUTE,&volCtrl)) 
		if(vSetMuteValue(hmixer,&volCtrl,(BOOL)vol)) 
			rc=TRUE; 
	mixerClose(hmixer); 
	return   rc; 
} 
Esempio n. 5
0
BOOL CMyVolumeCtrl::vGetMute(long   dev)//检查设备是否静音 
{ 
	//dev   =0,1,2     分别表示主音量,波形,MIDI   ,LINE   IN 
	//   retrun   false   表示没有静音 
	//   retrun   true     表示静音 
	long   device; 
	BOOL   rc = FALSE; 
	MIXERCONTROL   volCtrl; 
	HMIXER   hmixer; 
	switch   (dev) 
	{ 
	case   1: 
		device=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;   break; 
	case   2: 
		device=MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;   break; 
	case   3: 
		device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break; 
	default: 
		device=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; 
	} 

	if(mixerOpen(&hmixer,   0,   0,   0,   0))   return   0; 

	if(vGetVolumeControl(hmixer,device,MIXERCONTROL_CONTROLTYPE_MUTE,&volCtrl)) 
		rc = vGetMuteValue(hmixer,&volCtrl); 
	mixerClose(hmixer); 
	return   rc; 

} 
Esempio n. 6
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;
}
HMIXER CMicVolume::MixDevice(HMIXER current_mix, unsigned int mix_id)
{
	HMIXER h_mixer;
	MIXERCAPS mixer_caps;

	if(mixerGetDevCaps(mix_id, &mixer_caps, sizeof(mixer_caps)) != MMSYSERR_NOERROR)
		return NULL;

    if(mixerOpen(&h_mixer, mix_id, DWORD(NULL), 0L, CALLBACK_WINDOW) != MMSYSERR_NOERROR)
		return NULL;

    if(current_mix != NULL){
		if(mixerClose(current_mix) != MMSYSERR_NOERROR)
		{
#ifdef _DEBUG
			MessageBox(NULL,"Mixer 장치가 사용중입니다.", "Mixer 열기실패", MB_ICONSTOP);
#endif
        current_mix = NULL;
		}
    }

	//char szbuf[128];

	//wsprintf(szbuf,"Mixer 장치명: %s", mixer_caps.szPname);
    //SetWindowText(g_hWnd, szbuf);			//윈도우 타이틀바에 장치명 알림

    return h_mixer;
}
//##################################################
//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. 9
0
BOOL CMyVolumeCtrl::vSetVolume(long   dev,long   vol)//设置设备的音量 
{ 
	//   dev   =0,1,2       分别表示主音量,波形,MIDI   ,LINE   IN 
	//   vol=0-MAX_VOL           表示音量的大小   ,   设置与返回音量的值用的是百分比,即音量从0   -   MAX_VOL,而不是设备的绝对值 
	//   retrun   false   表示设置音量的大小的操作不成功 
	//   retrun   true     表示设置音量的大小的操作成功 

	long   device; 
	BOOL   rc = FALSE; 
	MIXERCONTROL   volCtrl; 
	HMIXER   hmixer; 
	switch   (dev) 
	{ 
	case   1: 
		device=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;   break; 
	case   2: 
		device=MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;   break; 
	case   3: 
		device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break; 

	default: 
		device=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; 
	} 

	if(mixerOpen(&hmixer,   0,   0,   0,   0))   return   0; 

	if(vGetVolumeControl(hmixer,device,MIXERCONTROL_CONTROLTYPE_VOLUME,&volCtrl)) 
	{ 
		vol=vol*volCtrl.Bounds.lMaximum/MAX_VOL; 
		if(vSetVolumeValue(hmixer,&volCtrl,vol)) 
			rc=true; 
	} 
	mixerClose(hmixer); 
	return   rc; 
} 
void Mixer::open(unsigned numChannels, unsigned samplingFrequency, unsigned granularityInMS) {
  HMIXER newHMixer = NULL;
  do {
    MIXERCAPS mc;
    if (mixerGetDevCaps(index, &mc, sizeof mc) != MMSYSERR_NOERROR) break;

    #ifdef UNICODE
    // Copy the mixer name:
        wcstombs(name, mc.szPname, MAXPNAMELEN);
    #else
        strncpy(name, mc.szPname, MAXPNAMELEN);
    #endif

    // Find the correct line for this mixer:
    unsigned i, uWavIn;
    unsigned nWavIn = waveInGetNumDevs();
    for (i = 0; i < nWavIn; ++i) {
      WAVEINCAPS wic;
      if (waveInGetDevCaps(i, &wic, sizeof wic) != MMSYSERR_NOERROR) continue;

      MIXERLINE ml;
      ml.cbStruct = sizeof ml;
      ml.Target.dwType  = MIXERLINE_TARGETTYPE_WAVEIN;

    #ifdef UNICODE
          wcsncpy(ml.Target.szPname, wic.szPname, MAXPNAMELEN);
    #else
          strncpy(ml.Target.szPname, wic.szPname, MAXPNAMELEN);
    #endif

      ml.Target.vDriverVersion = wic.vDriverVersion;
      ml.Target.wMid = wic.wMid;
      ml.Target.wPid = wic.wPid;

      if (mixerGetLineInfo((HMIXEROBJ)index, &ml, MIXER_GETLINEINFOF_TARGETTYPE/*|MIXER_OBJECTF_MIXER*/) == MMSYSERR_NOERROR) {
				// this is the right line
	uWavIn = i;
	dwRecLineID = ml.dwLineID;
	break;
      }
    }
    if (i >= nWavIn) break; // error: we couldn't find the right line

    if (mixerOpen(&newHMixer, index, (unsigned long)NULL, (unsigned long)NULL, MIXER_OBJECTF_MIXER) != MMSYSERR_NOERROR) break;
    if (newHMixer == NULL) break;

    // Sanity check: re-call "mixerGetDevCaps()" using the mixer device handle:
    if (mixerGetDevCaps((UINT)newHMixer, &mc, sizeof mc) != MMSYSERR_NOERROR) break;
    if (mc.cDestinations < 1) break; // error: this mixer has no destinations

	if (!WindowsAudioInputDevice_common::openWavInPort(uWavIn, numChannels, samplingFrequency, granularityInMS)) break;

    hMixer = newHMixer;
    return;
  } while (0);

  // An error occurred:
  close();
}
Esempio n. 11
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. 12
0
//设置设备静音   
bool SoundControl::SetMute(long dev, bool vol)
{   
	//   dev   =0,1,2   分别表示主音量,波形,MIDI   ,LINE   IN   
	//   vol=false,true   分别表示取消静音,设置静音   
	//   retrun   false   表示取消或设置静音操作不成功   
	//   retrun   true   表示取消或设置静音操作成功   

	long device;   
	bool rc = false;   
	MIXERCONTROL volCtrl;   
	HMIXER hmixer;   

	switch (dev)   
	{   
	case 1:   
		device = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT; 
		break;   
	case 2:   
		device = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;  
		break;   
	case 3:   
		device = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC; 
		break;     
	case 4:   
		device = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
		break;   
	default:     
		device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;   
		break;
	}

	if (mixerOpen(&hmixer, 0, 0, 0, 0)) 
	{
		return 0;     
	}
	if (SoundControl::GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_MUTE, &volCtrl))
	{
		if (SoundControl::SetMuteValue(hmixer, &volCtrl, vol))     
		{
			rc = true;   
		}
		//vol = vol * volCtrl.Bounds.lMaximum / 100;     
		//if (SoundControl::SetVolumeValue(hmixer, &volCtrl, vol))   
		//{
		//	rc = true;   
		//}
	}
	mixerClose(hmixer);     

	return rc;   
}     
Esempio n. 13
0
/////////////////////////////////////////////////
//  Component: value from dwComponentType member of MIXERLINE, eg://	MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
//  Kind : 0 Wave ouput tunnle, 1 Wave input tunle, 2... other. 
CMixer::CMixer(DWORD ComponentType, DestKind dkKind): m_dwControlID(-1), m_bOK(false), m_dwChannels(0)
{
	HMIXER hMixer;
	HRESULT hr;
	hr = mixerOpen(&hMixer, 0, 0, 0, 0);
	if (FAILED(hr)) return;

	MIXERLINE mxl;
	MIXERCONTROL mc;
	MIXERLINECONTROLS mxlc;
	DWORD kind, count;

	if (dkKind == Play)
		kind = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
	else 
		kind = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;

	mxl.cbStruct = sizeof(mxl);
	mxl.dwComponentType = kind;

    hr = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
	if (FAILED(hr))
	{
		mixerClose(hMixer);
		return;
	}

	count = mxl.dwSource;
	for(UINT i = 0; i < count; i++)
	{
		mxl.dwSource = i;
		mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_GETLINEINFOF_SOURCE);
		if (mxl.dwComponentType == ComponentType)
		{
			m_dwChannels = mxl.cChannels;
			mc.cbStruct = sizeof(mc);
			mxlc.cbStruct = sizeof(mxlc);
			mxlc.dwLineID = mxl.dwLineID;
			mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
			mxlc.cControls = 1;
			mxlc.cbmxctrl = sizeof(MIXERCONTROL);
			mxlc.pamxctrl = &mc;
			hr = mixerGetLineControls((HMIXEROBJ)hMixer, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
			m_dwControlID = mc.dwControlID;
			break;
		};
	}
	mixerClose(hMixer);
	m_bOK = true;
}
Esempio n. 14
0
void play()
{
	int targetval = 65535;
	if (volume != 100)
	{
		targetval = (int)((volume / 100.0) * 65535);
	}
	

	//credits to http://www.codeproject.com/Articles/4754/mixerSetControlDetails
	printf("creating mixer,volume = %d, targetval = %d\n",volume,targetval);

	/* obtain handle to mixer device */
	MMRESULT result;
	HMIXER hMixer;
	result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);

	/* get speaker line of the mixer device */
	MIXERLINE ml = { 0 };
	ml.cbStruct = sizeof(MIXERLINE);
	ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	result = mixerGetLineInfo((HMIXEROBJ)hMixer,&ml, MIXER_GETLINEINFOF_COMPONENTTYPE);

	/* get colume control of the speaker line */
	MIXERLINECONTROLS mlc = { 0 };
	MIXERCONTROL mc = { 0 };
	mlc.cbStruct = sizeof(MIXERLINECONTROLS);
	mlc.dwLineID = ml.dwLineID;
	mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
	mlc.cControls = 1;
	mlc.pamxctrl = &mc;
	mlc.cbmxctrl = sizeof(MIXERCONTROL);
	result = mixerGetLineControls((HMIXEROBJ)hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

	/* set the volume level */
	MIXERCONTROLDETAILS mcd = { 0 };
	MIXERCONTROLDETAILS_UNSIGNED mcdu = { 0 };
	mcdu.dwValue = targetval; // the volume is a number between 0 and 65535
	mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
	mcd.hwndOwner = 0;
	mcd.dwControlID = mc.dwControlID;
	mcd.paDetails = &mcdu;
	mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
	mcd.cChannels = 1;
	result = mixerSetControlDetails((HMIXEROBJ)hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);



	PlaySound(filename, NULL, SND_FILENAME);
}
Esempio n. 15
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. 16
0
//设置音量值
bool WINAPI SetVolume(LONG vol)
{
	bool Result=false;   //用于判断函数是否执行成功
	MIXERCONTROL volCtrl;
	HMIXER hmixer;
	if(mixerOpen(&hmixer, 0, 0, 0, 0)) return 0;
	if(GetVolumeControl(hmixer,MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERCONTROL_CONTROLTYPE_VOLUME,&volCtrl))
	{ 
		int ChangeValue=volCtrl.Bounds.lMaximum/INTERVAL;
		int TotalValue=ChangeValue*vol;
		if(SetVolumeValue(hmixer,&volCtrl,TotalValue))
			Result=true;
	}   
	mixerClose(hmixer);
	return Result;
}
Esempio n. 17
0
//设置设备的音量
bool SoundControl::SetVolume(long dev, long vol)
{   
	//   dev   =0,1,2   分别表示主音量,波形,MIDI   ,LINE   IN   
	//   vol=0-100   表示音量的大小   ,   设置与返回音量的值用的是百分比,即音量从0   -   100,而不是设备的绝对值   
	//   retrun   false   表示设置音量的大小的操作不成功   
	//   retrun   true   表示设置音量的大小的操作成功   

	long  device;   
	bool  rc = false;   
	MIXERCONTROL volCtrl;   
	HMIXER hmixer;   

	switch (dev)   
	{   
	case 1:   
		device = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;  
		break;
	case 2:   
		device = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;  
		break;   
	case 3:   
		device = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;  
		break;   
	case 4:   
		device = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
		break;   
	default:     
		device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;     
		break;
	}     

	if (mixerOpen(&hmixer, 0, 0, 0, 0))  
	{
		return 0;   
	}
	if (SoundControl::GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_VOLUME, &volCtrl))     
	{     
		vol = vol * volCtrl.Bounds.lMaximum / 100;     
		if (SoundControl::SetVolumeValue(hmixer, &volCtrl, vol))   
		{
			rc = true;   
		}
	}     
	mixerClose(hmixer);     

	return rc;     
}     
bool AgentType_Mixer_XP::Init ()
{
	bool errorflag = false; //If there's an error
	//Create the reciever window class if neccessary
	//No errors
	s_mixer_controlcount++;
	if (s_mixer_controlcount > 0 && !mixer_recieverregistered)
	{
		if (!window_helper_register(mixer_recieverclass, &agenttype_mixer_recieverevent))
			mixer_recieverregistered = true;
		else
			errorflag = true;
	}

	//Create the reciever window
	m_hwnd_reciever = NULL;
	if (!errorflag)
	{
		m_hwnd_reciever = window_helper_create(mixer_recieverclass);
		if (!m_hwnd_reciever) errorflag = true;
	}

	if (!errorflag)
	{
		//Initialize the mixer values
		if (MMSYSERR_NOERROR != mixerOpen(&m_mixer_handle, m_device, (DWORD_PTR) m_hwnd_reciever, 0, CALLBACK_WINDOW))
			errorflag = true;
	}

	if (!errorflag)
	{
		//Set the control properties
		m_mixer_controldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
		m_mixer_controldetails.dwControlID = m_control;
		m_mixer_controldetails.cChannels = 1;
		m_mixer_controldetails.cMultipleItems = 0;
		m_mixer_controldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
	}

	if (errorflag)
	{
		Destroy();
		return false;
	}
	return true;
}
Esempio n. 19
0
//获得音量部分, 目前只支持XP的主音量, 要完美支持看D:\workspace\DownLoadCode\VolumeCtrl
int CMyVolume::GetVolume()
{
	long device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	unsigned int rt = 0;
	MIXERCONTROL volCtrl;
	HMIXER hmixer;

	if ( mixerOpen(&hmixer, 0, 0, 0, 0) != MMSYSERR_NOERROR )
	{
		return 0;
	}
	GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_VOLUME, &volCtrl);

	int iValue = GetVolumeValue(hmixer, &volCtrl);
	iValue = iValue * MAX_VOL / volCtrl.Bounds.lMaximum;
	return iValue;
}
Esempio n. 20
0
//得到音量,得到设备的音量dev=0主音量,1WAVE, 2MIDI , 3 LINE IN
unsigned SoundControl::GetVolume(int dev)
{   
	long device;
	unsigned rt = 0;     
	MIXERCONTROL volCtrl;     
	HMIXER hmixer;

	switch (dev)   
	{   
	case 1:     
		device = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;  
		break;     
	case 2:     
		device = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;  
		break;     
	case 3:   
		//   device=MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;   break;   //   cd   音量     
		//   device=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;   break;   //麦克风音量     
		//   device=MIXERLINE_COMPONENTTYPE_SRC_LINE;   break;   //PC   扬声器音量     
		device = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;  
		break;     
	case 4:   
		device = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
		break;   
	default:   
		device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
		break;
	}   

	if (mixerOpen(&hmixer, 0, 0, 0, 0))
	{
		return 0;  
	}
	if (!SoundControl::GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_VOLUME, &volCtrl))
	{
		return 0;
	}
	rt = SoundControl::GetVolumeValue(hmixer, &volCtrl) * 100 / volCtrl.Bounds.lMaximum;   
	mixerClose(hmixer);   

	return rt;   
}
Esempio n. 21
0
//检查设备是否静音  
bool SoundControl::GetMute(long dev) 
{   
	//dev   =0,1,2   分别表示主音量,波形,MIDI   ,LINE   IN   
	//   retrun   false   表示没有静音   
	//   retrun   true   表示静音   

	long device;
	bool rc = false;   
	MIXERCONTROL volCtrl;   
	HMIXER hmixer;   

	switch (dev)   
	{   
	case 1:   
		device = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT; 
		break;   
	case 2:   
		device = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER; 
		break;   
	case 3:   
		device = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC; 
		break;   
	case 4:   
		device = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
		break;   
	default:   
		device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;   
		break;
	}     

	if (mixerOpen(&hmixer, 0, 0, 0, 0)) 
	{
		return 0;     
	}
	if (SoundControl::GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_MUTE, &volCtrl))   
	{
		rc = GetMuteValue(hmixer, &volCtrl);   
	}
	mixerClose(hmixer);   

	return rc;   
}
Esempio n. 22
0
BOOL
SndMixerEnumProducts(PSND_MIXER Mixer,
                     PFNSNDMIXENUMPRODUCTS EnumProc,
                     PVOID Context)
{
    MIXERCAPS Caps;
    HMIXER hMixer;
    UINT i;
    BOOL Ret = TRUE;

    for (i = 0; i < Mixer->MixersCount; i++)
    {
        if (mixerOpen(&hMixer,
                      i,
                      0,
                      0,
                      0) == MMSYSERR_NOERROR)
        {
            if (mixerGetDevCaps(i,
                                &Caps,
                                sizeof(Caps)) == MMSYSERR_NOERROR)
            {
                if (!EnumProc(Mixer,
                              i,
                              Caps.szPname,
                              Context))
                {
                    mixerClose(hMixer);
                    Ret = FALSE;
                    break;
                }
            }
            else
            {
                DPRINT("Failed to get device capabilities for mixer id %d!\n", i);
            }
            mixerClose(hMixer);
        }
    }

    return Ret;
}
Esempio n. 23
0
//设置/开启 静音
BOOL CMyVolume::SetMute(BOOL bMute)
{
	HMIXER hmixer;
	if ( mixerOpen(&hmixer, 0, 0, 0, 0) )
	{
		return FALSE;
	}
	
	long device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	MIXERCONTROL volCtrl;
	GetVolumeControl(hmixer, device, MIXERCONTROL_CONTROLTYPE_MUTE, &volCtrl);
	BOOL rc(FALSE);
	if (SetMuteValue(hmixer, &volCtrl, (BOOL)bMute))
	{
		 rc = TRUE;
	}
	mixerClose(hmixer);
	return rc;

}
/* 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. 25
0
//返回音量值
unsigned WINAPI GetVolume()
{
	unsigned rt=0; 
	MIXERCONTROL volCtrl;
	HMIXER hmixer; 
	if(mixerOpen(&hmixer, 0, 0, 0, 0)) return 0;

	MIXERLINE mxl = {0};
	mxl.cbStruct = sizeof(mxl);
	mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	MMRESULT mr = mixerGetLineInfo((HMIXEROBJ)hmixer, &mxl, MIXER_GETLINEINFOF_DESTINATION);

	mixerGetLineControls()

	if(!GetVolumeControl(hmixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERCONTROL_CONTROLTYPE_VOLUME,&volCtrl))
		return 0;
	int ChangeValue=volCtrl.Bounds.lMaximum/INTERVAL; //每一次调用函数改变的音量值
	rt=GetVolumeValue(hmixer,&volCtrl)/ChangeValue;   //GetVolumeValue得到的是具体值
	mixerClose(hmixer);
	return rt;
}
Esempio n. 26
0
long CMixer::GetPan()
{
	if (!m_bOK || m_dwControlPID==0) return 0;
	HMIXER hMixer;
	HRESULT hr;
	hr = mixerOpen(&hMixer, 0, 0, 0, 0);
	if (FAILED(hr)) return 0;

	MIXERCONTROLDETAILS mxcd;
	MIXERCONTROLDETAILS_SIGNED mxdu;


	mxcd.cMultipleItems = 0;
	mxcd.cChannels = 1;
	mxcd.cbStruct = sizeof(mxcd);
	mxcd.dwControlID = m_dwControlPID;
	mxcd.cbDetails = sizeof(mxdu);
	mxcd.paDetails = &mxdu;
	hr = mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE);	
	
	mixerClose(hMixer);
	return mxdu.lValue;
}
Esempio n. 27
0
BOOL CMyVolume::SetValue(int nVol)
{
	BOOL bSet = FALSE;
	HMIXER hmier;
	if (mixerOpen(&hmier, 0, 0, 0, 0))
	{
		return FALSE;
	}
	long device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	MIXERCONTROL volCtrl;
	BOOL bRet(FALSE);
	if ( GetVolumeControl(hmier, device, MIXERCONTROL_CONTROLTYPE_VOLUME, &volCtrl) )
	{
		nVol = nVol* volCtrl.Bounds.lMaximum/MAX_VOL;
		if ( SetVolumeValue(hmier,&volCtrl, nVol ) )
		{
			bRet = TRUE;			
		}

	}
	mixerClose(hmier);
	return bRet;
}
Esempio n. 28
0
void CMixer::SetPan(long dwVol)
{
	if (!m_bOK || m_dwControlPID==0) return;
	HMIXER hMixer;
	HRESULT hr;
	hr = mixerOpen(&hMixer, 0, 0, 0, 0);
	if (FAILED(hr)) return;

	MIXERCONTROLDETAILS mxcd;
	MIXERCONTROLDETAILS_SIGNED mxdu;

	mxdu.lValue = dwVol;

	mxcd.cMultipleItems = 0;
	mxcd.cChannels = 1;
	mxcd.cbStruct = sizeof(mxcd);
	mxcd.dwControlID = m_dwControlPID;
	mxcd.cbDetails = sizeof(mxdu);
	mxcd.paDetails = &mxdu;
	hr = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE| MIXER_OBJECTF_HMIXER);	
	
	mixerClose(hMixer);
}
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. 30
0
void CMixer::SetVolume(DWORD dwVol)
{
	if (!m_bOK) return;
	HMIXER hMixer;
	HRESULT hr;
	hr = mixerOpen(&hMixer, 0, 0, 0, 0);
	if (FAILED(hr)) return;

	MIXERCONTROLDETAILS mxcd;
	MIXERCONTROLDETAILS_UNSIGNED mxdu;

	mxdu.dwValue = dwVol;

	mxcd.cMultipleItems = 0;
	mxcd.cChannels = m_dwChannels;
	mxcd.cbStruct = sizeof(mxcd);
	mxcd.dwControlID = m_dwControlID;
	mxcd.cbDetails = sizeof(mxdu);
	mxcd.paDetails = &mxdu;
	hr = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);	
	
	mixerClose(hMixer);
}