blob: dd05e0ab3d7f905ca8f936d605e3bd90e0f78f46 [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
Henrik Kjellander9b72af92015-11-11 20:16:11 +010011#include "webrtc/modules/audio_processing/ns/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
Bjorn Volcker9345e862015-06-10 21:43:36 +020020NsHandle* WebRtcNs_Create() {
21 NoiseSuppressionC* self = malloc(sizeof(NoiseSuppressionC));
22 self->initFlag = 0;
23 return (NsHandle*)self;
niklase@google.com470e71d2011-07-07 08:21:25 +000024}
25
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020026void WebRtcNs_Free(NsHandle* NS_inst) {
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000027 free(NS_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000028}
29
aluebs@webrtc.org50883772014-09-26 14:33:08 +000030int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000031 return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs);
niklase@google.com470e71d2011-07-07 08:21:25 +000032}
33
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000034int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000035 return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000036}
37
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000038void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000039 WebRtcNs_AnalyzeCore((NoiseSuppressionC*)NS_inst, spframe);
aluebs@webrtc.orgfda2c2e2014-09-18 09:54:06 +000040}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000042void WebRtcNs_Process(NsHandle* NS_inst,
43 const float* const* spframe,
Peter Kastingdce40cf2015-08-24 14:52:23 -070044 size_t num_bands,
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000045 float* const* outframe) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000046 WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands,
47 outframe);
niklase@google.com470e71d2011-07-07 08:21:25 +000048}
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000049
50float WebRtcNs_prior_speech_probability(NsHandle* handle) {
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000051 NoiseSuppressionC* self = (NoiseSuppressionC*)handle;
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000052 if (handle == NULL) {
53 return -1;
54 }
55 if (self->initFlag == 0) {
56 return -1;
57 }
58 return self->priorSpeechProb;
59}