Skip to content

Commit

Permalink
Add Analyze API to NS
Browse files Browse the repository at this point in the history
This adds an empty API.
In a next CL I will separate the noise estimation from the Process API and fill this function.

BUG=webrtc:3811
R=bjornv@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/23599004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7218 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
aluebs@webrtc.org committed Sep 18, 2014
1 parent ab071da commit fda2c2e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions webrtc/modules/audio_processing/audio_processing_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ int AudioProcessingImpl::ProcessStreamLocked() {
if (echo_control_mobile_->is_enabled() && noise_suppression_->is_enabled()) {
ca->CopyLowPassToReference();
}
RETURN_ON_ERR(noise_suppression_->AnalyzeCaptureAudio(ca));
RETURN_ON_ERR(noise_suppression_->ProcessCaptureAudio(ca));
RETURN_ON_ERR(echo_control_mobile_->ProcessCaptureAudio(ca));
RETURN_ON_ERR(voice_detection_->ProcessCaptureAudio(ca));
Expand Down
27 changes: 24 additions & 3 deletions webrtc/modules/audio_processing/noise_suppression_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm,

NoiseSuppressionImpl::~NoiseSuppressionImpl() {}

int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
#if defined(WEBRTC_NS_FLOAT)
if (!is_component_enabled()) {
return apm_->kNoError;
}
assert(audio->samples_per_split_channel() <= 160);
assert(audio->num_channels() == num_handles());

for (int i = 0; i < num_handles(); ++i) {
Handle* my_handle = static_cast<Handle*>(handle(i));

int err = WebRtcNs_Analyze(my_handle,
audio->low_pass_split_data_f(i));
if (err != apm_->kNoError) {
return GetHandleError(my_handle);
}
}
#endif
return apm_->kNoError;
}

int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
int err = apm_->kNoError;

Expand All @@ -64,16 +85,16 @@ int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
assert(audio->samples_per_split_channel() <= 160);
assert(audio->num_channels() == num_handles());

for (int i = 0; i < num_handles(); i++) {
for (int i = 0; i < num_handles(); ++i) {
Handle* my_handle = static_cast<Handle*>(handle(i));
#if defined(WEBRTC_NS_FLOAT)
err = WebRtcNs_Process(static_cast<Handle*>(handle(i)),
err = WebRtcNs_Process(my_handle,
audio->low_pass_split_data_f(i),
audio->high_pass_split_data_f(i),
audio->low_pass_split_data_f(i),
audio->high_pass_split_data_f(i));
#elif defined(WEBRTC_NS_FIXED)
err = WebRtcNsx_Process(static_cast<Handle*>(handle(i)),
err = WebRtcNsx_Process(my_handle,
audio->low_pass_split_data(i),
audio->high_pass_split_data(i),
audio->low_pass_split_data(i),
Expand Down
1 change: 1 addition & 0 deletions webrtc/modules/audio_processing/noise_suppression_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NoiseSuppressionImpl : public NoiseSuppression,
CriticalSectionWrapper* crit);
virtual ~NoiseSuppressionImpl();

int AnalyzeCaptureAudio(AudioBuffer* audio);
int ProcessCaptureAudio(AudioBuffer* audio);

// NoiseSuppression implementation.
Expand Down
15 changes: 15 additions & 0 deletions webrtc/modules/audio_processing/ns/include/noise_suppression.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs);
*/
int WebRtcNs_set_policy(NsHandle* NS_inst, int mode);

/*
* This functions estimates the background noise for the inserted speech frame.
* The input and output signals should always be 10ms (80 or 160 samples).
*
* Input
* - NS_inst : Noise suppression instance.
* - spframe : Pointer to speech frame buffer for L band
*
* Output:
* - NS_inst : Updated NS instance
*
* Return value : 0 - OK
* -1 - Error
*/
int WebRtcNs_Analyze(NsHandle* NS_inst, float* spframe);

/*
* This functions does Noise Suppression for the inserted speech frame. The
Expand Down
3 changes: 3 additions & 0 deletions webrtc/modules/audio_processing/ns/noise_suppression.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
return WebRtcNs_set_policy_core((NSinst_t*) NS_inst, mode);
}

int WebRtcNs_Analyze(NsHandle* NS_inst, float* spframe) {
return WebRtcNs_AnalyzeCore((NSinst_t*) NS_inst, spframe);
}

int WebRtcNs_Process(NsHandle* NS_inst, float* spframe, float* spframe_H,
float* outframe, float* outframe_H) {
Expand Down
4 changes: 4 additions & 0 deletions webrtc/modules/audio_processing/ns/ns_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ void WebRtcNs_SpeechNoiseProb(NSinst_t* inst, float* probSpeechFinal, float* snr
}
}

int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* inFrame) {
return 0;
}

int WebRtcNs_ProcessCore(NSinst_t* inst,
float* speechFrame,
float* speechFrameHB,
Expand Down
19 changes: 17 additions & 2 deletions webrtc/modules/audio_processing/ns/ns_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs);
*/
int WebRtcNs_set_policy_core(NSinst_t* inst, int mode);

/****************************************************************************
* WebRtcNs_AnalyzeCore
*
* Estimate the background noise.
*
* Input:
* - inst : Instance that should be initialized
* - inFrame : Input speech frame for lower band
*
* Output:
* - inst : Updated instance
*
* Return value : 0 - OK
* -1 - Error
*/
int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* inFrame);

/****************************************************************************
* WebRtcNs_ProcessCore
*
Expand All @@ -164,8 +181,6 @@ int WebRtcNs_set_policy_core(NSinst_t* inst, int mode);
* Return value : 0 - OK
* -1 - Error
*/


int WebRtcNs_ProcessCore(NSinst_t* inst,
float* inFrameLow,
float* inFrameHigh,
Expand Down

0 comments on commit fda2c2e

Please sign in to comment.