• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 
11 #include "webrtc/modules/audio_processing/ns/noise_suppression.h"
12 
13 #include <stdlib.h>
14 #include <string.h>
15 
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"
19 
WebRtcNs_Create()20 NsHandle* WebRtcNs_Create() {
21   NoiseSuppressionC* self = malloc(sizeof(NoiseSuppressionC));
22   self->initFlag = 0;
23   return (NsHandle*)self;
24 }
25 
WebRtcNs_Free(NsHandle * NS_inst)26 void WebRtcNs_Free(NsHandle* NS_inst) {
27   free(NS_inst);
28 }
29 
WebRtcNs_Init(NsHandle * NS_inst,uint32_t fs)30 int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) {
31   return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs);
32 }
33 
WebRtcNs_set_policy(NsHandle * NS_inst,int mode)34 int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
35   return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode);
36 }
37 
WebRtcNs_Analyze(NsHandle * NS_inst,const float * spframe)38 void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) {
39   WebRtcNs_AnalyzeCore((NoiseSuppressionC*)NS_inst, spframe);
40 }
41 
WebRtcNs_Process(NsHandle * NS_inst,const float * const * spframe,size_t num_bands,float * const * outframe)42 void WebRtcNs_Process(NsHandle* NS_inst,
43                       const float* const* spframe,
44                       size_t num_bands,
45                       float* const* outframe) {
46   WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands,
47                        outframe);
48 }
49 
WebRtcNs_prior_speech_probability(NsHandle * handle)50 float WebRtcNs_prior_speech_probability(NsHandle* handle) {
51   NoiseSuppressionC* self = (NoiseSuppressionC*)handle;
52   if (handle == NULL) {
53     return -1;
54   }
55   if (self->initFlag == 0) {
56     return -1;
57   }
58   return self->priorSpeechProb;
59 }
60