niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | b9d7d93 | 2012-01-25 19:21:13 +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 | |
Per Åhgren | 0cbb58e | 2019-10-29 22:59:44 +0100 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_PROCESSING_LEGACY_NS_NOISE_SUPPRESSION_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_LEGACY_NS_NOISE_SUPPRESSION_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 14 | #include <stddef.h> |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 15 | #include <stdint.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
| 17 | typedef struct NsHandleT NsHandle; |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | /* |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 24 | * This function creates an instance of the floating point Noise Suppression. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | */ |
Mirko Bonadei | d757356 | 2018-03-19 16:23:48 +0100 | [diff] [blame] | 26 | NsHandle* WebRtcNs_Create(void); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 29 | * This function frees the dynamic memory of a specified noise suppression |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | * instance. |
| 31 | * |
| 32 | * Input: |
| 33 | * - NS_inst : Pointer to NS instance that should be freed |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | */ |
Bjorn Volcker | f6a99e6 | 2015-04-10 07:56:57 +0200 | [diff] [blame] | 35 | void WebRtcNs_Free(NsHandle* NS_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 38 | * This function initializes a NS instance and has to be called before any other |
| 39 | * processing is made. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | * |
| 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.org | 5088377 | 2014-09-26 14:33:08 +0000 | [diff] [blame] | 51 | int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * This changes the aggressiveness of the noise suppression method. |
| 55 | * |
| 56 | * Input: |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 57 | * - NS_inst : Noise suppression instance. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | * - mode : 0: Mild, 1: Medium , 2: Aggressive |
| 59 | * |
| 60 | * Output: |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 61 | * - NS_inst : Updated instance. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | * |
| 63 | * Return value : 0 - Ok |
| 64 | * -1 - Error |
| 65 | */ |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 66 | int WebRtcNs_set_policy(NsHandle* NS_inst, int mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
aluebs@webrtc.org | fda2c2e | 2014-09-18 09:54:06 +0000 | [diff] [blame] | 68 | /* |
| 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.org | fda2c2e | 2014-09-18 09:54:06 +0000 | [diff] [blame] | 78 | */ |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 79 | void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
| 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.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 86 | * - NS_inst : Noise suppression instance. |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 87 | * - spframe : Pointer to speech frame buffer for each band |
| 88 | * - num_bands : Number of bands |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | * |
| 90 | * Output: |
| 91 | * - NS_inst : Updated NS instance |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 92 | * - outframe : Pointer to output frame for each band |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | */ |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 94 | void WebRtcNs_Process(NsHandle* NS_inst, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 95 | const float* const* spframe, |
| 96 | size_t num_bands, |
| 97 | float* const* outframe); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
bjornv@webrtc.org | 08329f4 | 2012-07-12 21:00:43 +0000 | [diff] [blame] | 99 | /* 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 | */ |
| 109 | float WebRtcNs_prior_speech_probability(NsHandle* handle); |
| 110 | |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 111 | /* 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 | */ |
| 121 | const 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 Bonadei | d757356 | 2018-03-19 16:23:48 +0100 | [diff] [blame] | 128 | size_t WebRtcNs_num_freq(void); |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 129 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | #ifdef __cplusplus |
| 131 | } |
| 132 | #endif |
| 133 | |
Per Åhgren | 0cbb58e | 2019-10-29 22:59:44 +0100 | [diff] [blame^] | 134 | #endif // MODULES_AUDIO_PROCESSING_LEGACY_NS_NOISE_SUPPRESSION_H_ |