webrtc库的应用

对于声学回声消除目前比较流行的WEB_RTC开源库的应用日益增多,本人在这小试牛刀,希望日后能更深层次的进行学习。

以下分别是针对webrtc开源库的调用,包括create(),init(),config(),process(),close()

#include

int webrtc_open(void **webrtc_handle,int SampleRate)
{
	AecmConfig config;
	config.cngMode = AecmTrue;
	config.echoMode = 0;

	if(WebRtcAecm_Create(webrtc_handle) < 0)
	{
		perror("WebRtcAecm_Create error!");
		return -1;
	}

	if(WebRtcAecm_Init(*webrtc_handle, SampleRate) < 0) //8000 or 16000 Sample rate
	{
		perror("WebRtcAecm_Init error!");
		return -1;
	}

	if(WebRtcAecm_set_config(*webrtc_handle, config) < 0 )
	{
		perror("WebRtcAecm_set_config error!"); 
		return -1;
	}

	return 0;
}

int webrtc_close(void **webrtc_handle)
{
	
	return WebRtcAecm_Free(*webrtc_handle);//释放资源
}

/*
* Inserts an 80 or 160 sample block of data into the farend buffer.
* Inputs Description
* -------------------------------------------------------------------
* void* aecmInst Pointer to the AECM instance
* int16_t* farend In buffer containing one frame of
* farend signal
* int16_t nrOfSamples Number of samples in farend buffer, 80 or 160  
*
* Outputs Description
* -------------------------------------------------------------------
* int32_t return 0: OK
* 1200-12004,12100: error/warning
*/
int webrtcconfig(void **webrtc_handle, int16_t *farend, int16_t nrOfSamples)
{	
	
	if(WebRtcAecm_BufferFarend(*webrtc_handle, farend, nrOfSamples) < 0)
	{
		perror("webRtcAecm_config return error!");
		return -1;
	}

	return 0;
}

/*
* Runs the AECM on an 80 or 160 sample blocks of data.
*
* Inputs Description
* -------------------------------------------------------------------
* void* webrtc_handle Pointer to the AECM instance
* int16_t* farendIn buffer containing one frame of
* reference nearend+echo signal. If
* noise reduction is active, provide
* the noisy signal here.
* int16_t* nearend In buffer containing one frame of
* nearend+echo signal. If noise
* reduction is active, provide the
* clean signal here. Otherwise pass a
* NULL pointer.
* int16_t nrOfSamples Number of samples in nearend buffer , 80 or 160
* int16_t msInSndCardBuf Delay estimate for sound card and
* system buffers
*
* Outputs Description
* -------------------------------------------------------------------
* int16_t* out Out buffer, one frame of processed nearend
* int32_t return 0: OK
* 1200-12004,12100: error/warning
*/
int webrtc_process(void **webrtc_handle, int16_t *farend, int16_t *nearend, int16_t *outbuf,int16_t nrOfSamples,int msInSndCardBuf)
{
	if(WebRtcAecm_Process(*webrtc_handle, nearend, NULL, outbuf, nrOfSamples, echo_delay) < 0)
	{
		/**/
		return -1;
	}
	return 0;
}
根据以上封装函数,我们可以采用两个pcm格式的音频的音频文件作为输入,然后依次创建、配置、循环处理,最后再释放资源

你可能感兴趣的:(linux,C)