pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1 | /* |
saza | aa42ecd | 2020-04-01 15:24:40 +0200 | [diff] [blame] | 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +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_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
kwiberg | 85d8bb0 | 2016-02-16 20:39:36 -0800 | [diff] [blame] | 16 | #include <memory> |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 17 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 20 | // Detects transients in an audio stream and suppress them using a simple |
| 21 | // restoration algorithm that attenuates unexpected spikes in the spectrum. |
| 22 | class TransientSuppressor { |
| 23 | public: |
saza | aa42ecd | 2020-04-01 15:24:40 +0200 | [diff] [blame] | 24 | virtual ~TransientSuppressor() {} |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 25 | |
saza | aa42ecd | 2020-04-01 15:24:40 +0200 | [diff] [blame] | 26 | virtual int Initialize(int sample_rate_hz, |
| 27 | int detector_rate_hz, |
| 28 | int num_channels) = 0; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 29 | |
| 30 | // Processes a |data| chunk, and returns it with keystrokes suppressed from |
| 31 | // it. The float format is assumed to be int16 ranged. If there are more than |
| 32 | // one channel, the chunks are concatenated one after the other in |data|. |
| 33 | // |data_length| must be equal to |data_length_|. |
| 34 | // |num_channels| must be equal to |num_channels_|. |
| 35 | // A sub-band, ideally the higher, can be used as |detection_data|. If it is |
| 36 | // NULL, |data| is used for the detection too. The |detection_data| is always |
| 37 | // assumed mono. |
| 38 | // If a reference signal (e.g. keyboard microphone) is available, it can be |
| 39 | // passed in as |reference_data|. It is assumed mono and must have the same |
| 40 | // length as |data|. NULL is accepted if unavailable. |
| 41 | // This suppressor performs better if voice information is available. |
| 42 | // |voice_probability| is the probability of voice being present in this chunk |
| 43 | // of audio. If voice information is not available, |voice_probability| must |
| 44 | // always be set to 1. |
| 45 | // |key_pressed| determines if a key was pressed on this audio chunk. |
| 46 | // Returns 0 on success and -1 otherwise. |
saza | aa42ecd | 2020-04-01 15:24:40 +0200 | [diff] [blame] | 47 | virtual int Suppress(float* data, |
| 48 | size_t data_length, |
| 49 | int num_channels, |
| 50 | const float* detection_data, |
| 51 | size_t detection_length, |
| 52 | const float* reference_data, |
| 53 | size_t reference_length, |
| 54 | float voice_probability, |
| 55 | bool key_pressed) = 0; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace webrtc |
| 59 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 60 | #endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ |