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 | |
Henrik Kjellander | 9b72af9 | 2015-11-11 20:16:11 +0100 | [diff] [blame] | 11 | #include "webrtc/modules/audio_processing/ns/noise_suppression.h" |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 12 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 16 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 20 | NsHandle* WebRtcNs_Create() { |
| 21 | NoiseSuppressionC* self = malloc(sizeof(NoiseSuppressionC)); |
| 22 | self->initFlag = 0; |
| 23 | return (NsHandle*)self; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Bjorn Volcker | f6a99e6 | 2015-04-10 07:56:57 +0200 | [diff] [blame] | 26 | void WebRtcNs_Free(NsHandle* NS_inst) { |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 27 | free(NS_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | } |
| 29 | |
aluebs@webrtc.org | 5088377 | 2014-09-26 14:33:08 +0000 | [diff] [blame] | 30 | int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 31 | return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | } |
| 33 | |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 34 | int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 35 | return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | } |
| 37 | |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 38 | void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 39 | WebRtcNs_AnalyzeCore((NoiseSuppressionC*)NS_inst, spframe); |
aluebs@webrtc.org | fda2c2e | 2014-09-18 09:54:06 +0000 | [diff] [blame] | 40 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 42 | void WebRtcNs_Process(NsHandle* NS_inst, |
| 43 | const float* const* spframe, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 44 | size_t num_bands, |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 45 | float* const* outframe) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 46 | WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands, |
| 47 | outframe); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | } |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 49 | |
| 50 | float WebRtcNs_prior_speech_probability(NsHandle* handle) { |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 51 | NoiseSuppressionC* self = (NoiseSuppressionC*)handle; |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 52 | if (handle == NULL) { |
| 53 | return -1; |
| 54 | } |
| 55 | if (self->initFlag == 0) { |
| 56 | return -1; |
| 57 | } |
| 58 | return self->priorSpeechProb; |
| 59 | } |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 60 | |
| 61 | const float* WebRtcNs_noise_estimate(const NsHandle* handle) { |
| 62 | const NoiseSuppressionC* self = (const NoiseSuppressionC*)handle; |
| 63 | if (handle == NULL || self->initFlag == 0) { |
| 64 | return NULL; |
| 65 | } |
| 66 | return self->noise; |
| 67 | } |
| 68 | |
| 69 | size_t WebRtcNs_num_freq() { |
| 70 | return HALF_ANAL_BLOCKL; |
| 71 | } |