blob: 1fd3ebc67ef1b27b709050e40aba5623d32c2c89 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/ns/noise_suppression_x.h"
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000012
13#include <stdlib.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#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.com470e71d2011-07-07 08:21:25 +000018
Bjorn Volcker9345e862015-06-10 21:43:36 +020019NsxHandle* WebRtcNsx_Create() {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000020 NoiseSuppressionFixedC* self = malloc(sizeof(NoiseSuppressionFixedC));
Bjorn Volcker9345e862015-06-10 21:43:36 +020021 WebRtcSpl_Init();
22 self->real_fft = NULL;
23 self->initFlag = 0;
24 return (NsxHandle*)self;
niklase@google.com470e71d2011-07-07 08:21:25 +000025}
26
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020027void WebRtcNsx_Free(NsxHandle* nsxInst) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000028 WebRtcSpl_FreeRealFFT(((NoiseSuppressionFixedC*)nsxInst)->real_fft);
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000029 free(nsxInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000030}
31
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000032int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000033 return WebRtcNsx_InitCore((NoiseSuppressionFixedC*)nsxInst, fs);
niklase@google.com470e71d2011-07-07 08:21:25 +000034}
35
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000036int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000037 return WebRtcNsx_set_policy_core((NoiseSuppressionFixedC*)nsxInst, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000038}
39
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000040void WebRtcNsx_Process(NsxHandle* nsxInst,
41 const short* const* speechFrame,
42 int num_bands,
43 short* const* outFrame) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000044 WebRtcNsx_ProcessCore((NoiseSuppressionFixedC*)nsxInst, speechFrame,
45 num_bands, outFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +000046}
Alejandro Luebsfa639f02016-02-09 11:24:32 -080047
Alejandro Luebs3b149962016-04-01 13:54:36 -070048const uint32_t* WebRtcNsx_noise_estimate(const NsxHandle* nsxInst,
49 int* q_noise) {
50 *q_noise = 11;
Alejandro Luebsfa639f02016-02-09 11:24:32 -080051 const NoiseSuppressionFixedC* self = (const NoiseSuppressionFixedC*)nsxInst;
52 if (nsxInst == NULL || self->initFlag == 0) {
53 return NULL;
54 }
Alejandro Luebs3b149962016-04-01 13:54:36 -070055 *q_noise += self->prevQNoise;
Alejandro Luebsfa639f02016-02-09 11:24:32 -080056 return self->prevNoiseU32;
57}
58
59size_t WebRtcNsx_num_freq() {
60 return HALF_ANAL_BLOCKL;
61}