directshow实现音频采集设备的输入音量控制和媒体文件播放音量控制

1,directshow实现音频采集设备的音量控制,代码如下:

void OnNMReleasedcaptureSoundSlider(NMHDR *pNMHDR, LRESULT *pResult)
{
	*pResult = 0;
	UpdateData(TRUE);
	CComPtr<IPin> pCapturePin=NULL;
	pCapturePin=GetInPin(m_pBF_Audio,0);//m_pBF_Audio是与音频采集设备绑定的filter
	CComPtr<IAMAudioInputMixer>pMixer=NULL;//给过滤器的输入端子设置音量
	int nPosition = m_Slider.GetPos();
	lVolume = (double)nPosition/(double)3000;//新的音量设置(0.0~1.0)
	pCapturePin->QueryInterface(IID_IAMAudioInputMixer,(void **)&pMixer);
	pMixer->put_MixLevel(lVolume);
}


2,directshow实现媒体文件播放音量控制,代码如下:

void OnNMReleasedcaptureSoundSlider2(NMHDR *pNMHDR, LRESULT *pResult)
{
	*pResult = 0;
	UpdateData(TRUE);
	if (!m_Ba)//m_Ba的声明:CComPtr<IBasicAudio> m_Ba;m_Gb->QueryInterface(IID_IBasicAudio,(void **)&m_Ba)
		return;
	int nPosition = m_Slider.GetPos();
	lVolume = nPosition-3000;
	if (lVolume==-3000)
	{
		m_Ba->put_Volume(-10000L);//静音
		return;
	}
	// Set new volume
	m_Ba->put_Volume(lVolume);
}


你可能感兴趣的:(directshow,directshow,directshow,音量控制)