1 /*
2  *  Copyright (c) 2020 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 MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
12 #define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <memory>
17 
18 namespace webrtc {
19 
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:
~TransientSuppressor()24   virtual ~TransientSuppressor() {}
25 
26   virtual int Initialize(int sample_rate_hz,
27                          int detector_rate_hz,
28                          int num_channels) = 0;
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.
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;
56 };
57 
58 }  // namespace webrtc
59 
60 #endif  // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
61