niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/ns/noise_suppression_x.h" |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 12 | |
| 13 | #include <stdlib.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "common_audio/signal_processing/include/real_fft.h" |
| 16 | #include "modules/audio_processing/ns/nsx_core.h" |
| 17 | #include "modules/audio_processing/ns/nsx_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 19 | NsxHandle* WebRtcNsx_Create() { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 20 | NoiseSuppressionFixedC* self = malloc(sizeof(NoiseSuppressionFixedC)); |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 21 | WebRtcSpl_Init(); |
| 22 | self->real_fft = NULL; |
| 23 | self->initFlag = 0; |
| 24 | return (NsxHandle*)self; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Bjorn Volcker | f6a99e6 | 2015-04-10 07:56:57 +0200 | [diff] [blame] | 27 | void WebRtcNsx_Free(NsxHandle* nsxInst) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 28 | WebRtcSpl_FreeRealFFT(((NoiseSuppressionFixedC*)nsxInst)->real_fft); |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 29 | free(nsxInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | } |
| 31 | |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 32 | int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 33 | return WebRtcNsx_InitCore((NoiseSuppressionFixedC*)nsxInst, fs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 36 | int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 37 | return WebRtcNsx_set_policy_core((NoiseSuppressionFixedC*)nsxInst, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 40 | void WebRtcNsx_Process(NsxHandle* nsxInst, |
| 41 | const short* const* speechFrame, |
| 42 | int num_bands, |
| 43 | short* const* outFrame) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 44 | WebRtcNsx_ProcessCore((NoiseSuppressionFixedC*)nsxInst, speechFrame, |
| 45 | num_bands, outFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | } |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 47 | |
Alejandro Luebs | 3b14996 | 2016-04-01 13:54:36 -0700 | [diff] [blame] | 48 | const uint32_t* WebRtcNsx_noise_estimate(const NsxHandle* nsxInst, |
| 49 | int* q_noise) { |
| 50 | *q_noise = 11; |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 51 | const NoiseSuppressionFixedC* self = (const NoiseSuppressionFixedC*)nsxInst; |
| 52 | if (nsxInst == NULL || self->initFlag == 0) { |
| 53 | return NULL; |
| 54 | } |
Alejandro Luebs | 3b14996 | 2016-04-01 13:54:36 -0700 | [diff] [blame] | 55 | *q_noise += self->prevQNoise; |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 56 | return self->prevNoiseU32; |
| 57 | } |
| 58 | |
| 59 | size_t WebRtcNsx_num_freq() { |
| 60 | return HALF_ANAL_BLOCKL; |
| 61 | } |