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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [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 NsxHandleT NsxHandle; |
| 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 fixed 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 | NsxHandle* WebRtcNsx_Create(void); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * This function frees the dynamic memory of a specified Noise Suppression |
| 30 | * instance. |
| 31 | * |
| 32 | * Input: |
| 33 | * - nsxInst : 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 WebRtcNsx_Free(NsxHandle* nsxInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * This function initializes a NS instance |
| 39 | * |
| 40 | * Input: |
| 41 | * - nsxInst : Instance that should be initialized |
| 42 | * - fs : sampling frequency |
| 43 | * |
| 44 | * Output: |
| 45 | * - nsxInst : Initialized instance |
| 46 | * |
| 47 | * Return value : 0 - Ok |
| 48 | * -1 - Error |
| 49 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 50 | int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * This changes the aggressiveness of the noise suppression method. |
| 54 | * |
| 55 | * Input: |
| 56 | * - nsxInst : Instance that should be initialized |
| 57 | * - mode : 0: Mild, 1: Medium , 2: Aggressive |
| 58 | * |
| 59 | * Output: |
| 60 | * - nsxInst : Initialized instance |
| 61 | * |
| 62 | * Return value : 0 - Ok |
| 63 | * -1 - Error |
| 64 | */ |
kma@webrtc.org | af57de0 | 2011-10-05 23:36:01 +0000 | [diff] [blame] | 65 | int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * This functions does noise suppression for the inserted speech frame. The |
| 69 | * input and output signals should always be 10ms (80 or 160 samples). |
| 70 | * |
| 71 | * Input |
| 72 | * - nsxInst : NSx instance. Needs to be initiated before call. |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 73 | * - speechFrame : Pointer to speech frame buffer for each band |
| 74 | * - num_bands : Number of bands |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | * |
| 76 | * Output: |
| 77 | * - nsxInst : Updated NSx instance |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 78 | * - outFrame : Pointer to output frame for each band |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | */ |
aluebs@webrtc.org | c5ebbd9 | 2014-12-10 19:30:57 +0000 | [diff] [blame] | 80 | void WebRtcNsx_Process(NsxHandle* nsxInst, |
| 81 | const short* const* speechFrame, |
| 82 | int num_bands, |
| 83 | short* const* outFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 85 | /* Returns a pointer to the noise estimate per frequency bin. The number of |
| 86 | * frequency bins can be provided using WebRtcNsx_num_freq(). |
| 87 | * |
| 88 | * Input |
| 89 | * - nsxInst : NSx instance. Needs to be initiated before call. |
Alejandro Luebs | 3b14996 | 2016-04-01 13:54:36 -0700 | [diff] [blame] | 90 | * - q_noise : Q value of the noise estimate, which is the number of |
| 91 | * bits that it needs to be right-shifted to be |
| 92 | * normalized. |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 93 | * |
| 94 | * Return value : Pointer to the noise estimate per frequency bin. |
| 95 | * Returns NULL if the input is a NULL pointer or an |
| 96 | * uninitialized instance. |
| 97 | */ |
Alejandro Luebs | 3b14996 | 2016-04-01 13:54:36 -0700 | [diff] [blame] | 98 | const uint32_t* WebRtcNsx_noise_estimate(const NsxHandle* nsxInst, |
| 99 | int* q_noise); |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 100 | |
| 101 | /* Returns the number of frequency bins, which is the length of the noise |
| 102 | * estimate for example. |
| 103 | * |
| 104 | * Return value : Number of frequency bins. |
| 105 | */ |
Mirko Bonadei | d757356 | 2018-03-19 16:23:48 +0100 | [diff] [blame] | 106 | size_t WebRtcNsx_num_freq(void); |
Alejandro Luebs | fa639f0 | 2016-02-09 11:24:32 -0800 | [diff] [blame] | 107 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | #ifdef __cplusplus |
| 109 | } |
| 110 | #endif |
| 111 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 112 | #endif // MODULES_AUDIO_PROCESSING_NS_NOISE_SUPPRESSION_X_H_ |