blob: 0775ffa243cb3c5d30c957bc0654ce31a763b782 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.orgb9d7d932012-01-25 19:21:13 +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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_H_
12#define MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Peter Kastingdce40cf2015-08-24 14:52:23 -070014#include <stddef.h>
Niels Möllera12c42a2018-07-25 16:05:48 +020015#include <stdint.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17typedef struct NsHandleT NsHandle;
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*
Bjorn Volcker9345e862015-06-10 21:43:36 +020024 * This function creates an instance of the floating point Noise Suppression.
niklase@google.com470e71d2011-07-07 08:21:25 +000025 */
Mirko Bonadeid7573562018-03-19 16:23:48 +010026NsHandle* WebRtcNs_Create(void);
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28/*
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000029 * This function frees the dynamic memory of a specified noise suppression
niklase@google.com470e71d2011-07-07 08:21:25 +000030 * instance.
31 *
32 * Input:
33 * - NS_inst : Pointer to NS instance that should be freed
niklase@google.com470e71d2011-07-07 08:21:25 +000034 */
Bjorn Volckerf6a99e62015-04-10 07:56:57 +020035void WebRtcNs_Free(NsHandle* NS_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
37/*
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000038 * This function initializes a NS instance and has to be called before any other
39 * processing is made.
niklase@google.com470e71d2011-07-07 08:21:25 +000040 *
41 * Input:
42 * - NS_inst : Instance that should be initialized
43 * - fs : sampling frequency
44 *
45 * Output:
46 * - NS_inst : Initialized instance
47 *
48 * Return value : 0 - Ok
49 * -1 - Error
50 */
aluebs@webrtc.org50883772014-09-26 14:33:08 +000051int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs);
niklase@google.com470e71d2011-07-07 08:21:25 +000052
53/*
54 * This changes the aggressiveness of the noise suppression method.
55 *
56 * Input:
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000057 * - NS_inst : Noise suppression instance.
niklase@google.com470e71d2011-07-07 08:21:25 +000058 * - mode : 0: Mild, 1: Medium , 2: Aggressive
59 *
60 * Output:
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000061 * - NS_inst : Updated instance.
niklase@google.com470e71d2011-07-07 08:21:25 +000062 *
63 * Return value : 0 - Ok
64 * -1 - Error
65 */
kma@webrtc.orgaf57de02011-10-05 23:36:01 +000066int WebRtcNs_set_policy(NsHandle* NS_inst, int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000067
aluebs@webrtc.orgfda2c2e2014-09-18 09:54:06 +000068/*
69 * This functions estimates the background noise for the inserted speech frame.
70 * The input and output signals should always be 10ms (80 or 160 samples).
71 *
72 * Input
73 * - NS_inst : Noise suppression instance.
74 * - spframe : Pointer to speech frame buffer for L band
75 *
76 * Output:
77 * - NS_inst : Updated NS instance
aluebs@webrtc.orgfda2c2e2014-09-18 09:54:06 +000078 */
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000079void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
81/*
82 * This functions does Noise Suppression for the inserted speech frame. The
83 * input and output signals should always be 10ms (80 or 160 samples).
84 *
85 * Input
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000086 * - NS_inst : Noise suppression instance.
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000087 * - spframe : Pointer to speech frame buffer for each band
88 * - num_bands : Number of bands
niklase@google.com470e71d2011-07-07 08:21:25 +000089 *
90 * Output:
91 * - NS_inst : Updated NS instance
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000092 * - outframe : Pointer to output frame for each band
niklase@google.com470e71d2011-07-07 08:21:25 +000093 */
aluebs@webrtc.orgc5ebbd92014-12-10 19:30:57 +000094void WebRtcNs_Process(NsHandle* NS_inst,
Yves Gerey665174f2018-06-19 15:03:05 +020095 const float* const* spframe,
96 size_t num_bands,
97 float* const* outframe);
niklase@google.com470e71d2011-07-07 08:21:25 +000098
bjornv@webrtc.org08329f42012-07-12 21:00:43 +000099/* Returns the internally used prior speech probability of the current frame.
100 * There is a frequency bin based one as well, with which this should not be
101 * confused.
102 *
103 * Input
104 * - handle : Noise suppression instance.
105 *
106 * Return value : Prior speech probability in interval [0.0, 1.0].
107 * -1 - NULL pointer or uninitialized instance.
108 */
109float WebRtcNs_prior_speech_probability(NsHandle* handle);
110
Alejandro Luebsfa639f02016-02-09 11:24:32 -0800111/* Returns a pointer to the noise estimate per frequency bin. The number of
112 * frequency bins can be provided using WebRtcNs_num_freq().
113 *
114 * Input
115 * - handle : Noise suppression instance.
116 *
117 * Return value : Pointer to the noise estimate per frequency bin.
118 * Returns NULL if the input is a NULL pointer or an
119 * uninitialized instance.
120 */
121const float* WebRtcNs_noise_estimate(const NsHandle* handle);
122
123/* Returns the number of frequency bins, which is the length of the noise
124 * estimate for example.
125 *
126 * Return value : Number of frequency bins.
127 */
Mirko Bonadeid7573562018-03-19 16:23:48 +0100128size_t WebRtcNs_num_freq(void);
Alejandro Luebsfa639f02016-02-09 11:24:32 -0800129
niklase@google.com470e71d2011-07-07 08:21:25 +0000130#ifdef __cplusplus
131}
132#endif
133
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200134#endif // MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_H_