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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_
13 
14 #include <stddef.h>
15 
16 #include "webrtc/typedefs.h"
17 
18 typedef struct NsHandleT NsHandle;
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /*
25  * This function creates an instance of the floating point Noise Suppression.
26  */
27 NsHandle* WebRtcNs_Create();
28 
29 /*
30  * This function frees the dynamic memory of a specified noise suppression
31  * instance.
32  *
33  * Input:
34  *      - NS_inst       : Pointer to NS instance that should be freed
35  */
36 void WebRtcNs_Free(NsHandle* NS_inst);
37 
38 /*
39  * This function initializes a NS instance and has to be called before any other
40  * processing is made.
41  *
42  * Input:
43  *      - NS_inst       : Instance that should be initialized
44  *      - fs            : sampling frequency
45  *
46  * Output:
47  *      - NS_inst       : Initialized instance
48  *
49  * Return value         :  0 - Ok
50  *                        -1 - Error
51  */
52 int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs);
53 
54 /*
55  * This changes the aggressiveness of the noise suppression method.
56  *
57  * Input:
58  *      - NS_inst       : Noise suppression instance.
59  *      - mode          : 0: Mild, 1: Medium , 2: Aggressive
60  *
61  * Output:
62  *      - NS_inst       : Updated instance.
63  *
64  * Return value         :  0 - Ok
65  *                        -1 - Error
66  */
67 int WebRtcNs_set_policy(NsHandle* NS_inst, int mode);
68 
69 /*
70  * This functions estimates the background noise for the inserted speech frame.
71  * The input and output signals should always be 10ms (80 or 160 samples).
72  *
73  * Input
74  *      - NS_inst       : Noise suppression instance.
75  *      - spframe       : Pointer to speech frame buffer for L band
76  *
77  * Output:
78  *      - NS_inst       : Updated NS instance
79  */
80 void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe);
81 
82 /*
83  * This functions does Noise Suppression for the inserted speech frame. The
84  * input and output signals should always be 10ms (80 or 160 samples).
85  *
86  * Input
87  *      - NS_inst       : Noise suppression instance.
88  *      - spframe       : Pointer to speech frame buffer for each band
89  *      - num_bands     : Number of bands
90  *
91  * Output:
92  *      - NS_inst       : Updated NS instance
93  *      - outframe      : Pointer to output frame for each band
94  */
95 void WebRtcNs_Process(NsHandle* NS_inst,
96                      const float* const* spframe,
97                      size_t num_bands,
98                      float* const* outframe);
99 
100 /* Returns the internally used prior speech probability of the current frame.
101  * There is a frequency bin based one as well, with which this should not be
102  * confused.
103  *
104  * Input
105  *      - handle        : Noise suppression instance.
106  *
107  * Return value         : Prior speech probability in interval [0.0, 1.0].
108  *                        -1 - NULL pointer or uninitialized instance.
109  */
110 float WebRtcNs_prior_speech_probability(NsHandle* handle);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif  // WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_
117