blob: bae0f2e1e74472bdc2a4e2a765f0be5ca627abb4 [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
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000011#include "webrtc/modules/audio_processing/ns/include/noise_suppression.h"
kma@webrtc.org0221b782012-09-08 00:09:26 +000012
niklase@google.com470e71d2011-07-07 08:21:25 +000013#include <stdlib.h>
14#include <string.h>
15
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000016#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
17#include "webrtc/modules/audio_processing/ns/defines.h"
18#include "webrtc/modules/audio_processing/ns/ns_core.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000020int WebRtcNs_Create(NsHandle** NS_inst) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000021 *NS_inst = (NsHandle*)malloc(sizeof(NoiseSuppressionC));
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000022 if (*NS_inst != NULL) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000023 (*(NoiseSuppressionC**)NS_inst)->initFlag = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000024 return 0;
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000025 } else {
26 return -1;
27 }
niklase@google.com470e71d2011-07-07 08:21:25 +000028
29}
30
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000031int WebRtcNs_Free(NsHandle* NS_inst) {
32 free(NS_inst);
33 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000034}
35
36
aluebs@webrtc.org50883772014-09-26 14:33:08 +000037int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000038 return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs);
niklase@google.com470e71d2011-07-07 08:21:25 +000039}
40
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000041int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000042 return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000043}
44
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000045void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000046 WebRtcNs_AnalyzeCore((NoiseSuppressionC*)NS_inst, spframe);
aluebs@webrtc.orgfda2c2e2014-09-18 09:54:06 +000047}
niklase@google.com470e71d2011-07-07 08:21:25 +000048
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000049void WebRtcNs_Process(NsHandle* NS_inst,
50 const float* const* spframe,
51 int num_bands,
52 float* const* outframe) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000053 WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands,
54 outframe);
niklase@google.com470e71d2011-07-07 08:21:25 +000055}
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000056
57float WebRtcNs_prior_speech_probability(NsHandle* handle) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000058 NoiseSuppressionC* self = (NoiseSuppressionC*)handle;
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000059 if (handle == NULL) {
60 return -1;
61 }
62 if (self->initFlag == 0) {
63 return -1;
64 }
65 return self->priorSpeechProb;
66}