blob: bb262b06847f1b28040ab387dc0d838dbc07910b [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
sazaaa42ecd2020-04-01 15:24:40 +02002 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
pbos@webrtc.org788acd12014-12-15 09:41:24 +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_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
12#define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
pbos@webrtc.org788acd12014-12-15 09:41:24 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
kwiberg85d8bb02016-02-16 20:39:36 -080016#include <memory>
pbos@webrtc.org788acd12014-12-15 09:41:24 +000017
pbos@webrtc.org788acd12014-12-15 09:41:24 +000018namespace webrtc {
19
pbos@webrtc.org788acd12014-12-15 09:41:24 +000020// Detects transients in an audio stream and suppress them using a simple
21// restoration algorithm that attenuates unexpected spikes in the spectrum.
22class TransientSuppressor {
23 public:
sazaaa42ecd2020-04-01 15:24:40 +020024 virtual ~TransientSuppressor() {}
pbos@webrtc.org788acd12014-12-15 09:41:24 +000025
sazaaa42ecd2020-04-01 15:24:40 +020026 virtual int Initialize(int sample_rate_hz,
27 int detector_rate_hz,
28 int num_channels) = 0;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000029
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.
sazaaa42ecd2020-04-01 15:24:40 +020047 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.org788acd12014-12-15 09:41:24 +000056};
57
58} // namespace webrtc
59
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_