transient_suppressor.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
  11. #define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <memory>
  15. namespace webrtc {
  16. // Detects transients in an audio stream and suppress them using a simple
  17. // restoration algorithm that attenuates unexpected spikes in the spectrum.
  18. class TransientSuppressor {
  19. public:
  20. virtual ~TransientSuppressor() {}
  21. virtual int Initialize(int sample_rate_hz,
  22. int detector_rate_hz,
  23. int num_channels) = 0;
  24. // Processes a |data| chunk, and returns it with keystrokes suppressed from
  25. // it. The float format is assumed to be int16 ranged. If there are more than
  26. // one channel, the chunks are concatenated one after the other in |data|.
  27. // |data_length| must be equal to |data_length_|.
  28. // |num_channels| must be equal to |num_channels_|.
  29. // A sub-band, ideally the higher, can be used as |detection_data|. If it is
  30. // NULL, |data| is used for the detection too. The |detection_data| is always
  31. // assumed mono.
  32. // If a reference signal (e.g. keyboard microphone) is available, it can be
  33. // passed in as |reference_data|. It is assumed mono and must have the same
  34. // length as |data|. NULL is accepted if unavailable.
  35. // This suppressor performs better if voice information is available.
  36. // |voice_probability| is the probability of voice being present in this chunk
  37. // of audio. If voice information is not available, |voice_probability| must
  38. // always be set to 1.
  39. // |key_pressed| determines if a key was pressed on this audio chunk.
  40. // Returns 0 on success and -1 otherwise.
  41. virtual int Suppress(float* data,
  42. size_t data_length,
  43. int num_channels,
  44. const float* detection_data,
  45. size_t detection_length,
  46. const float* reference_data,
  47. size_t reference_length,
  48. float voice_probability,
  49. bool key_pressed) = 0;
  50. };
  51. } // namespace webrtc
  52. #endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_