preemptive_expand.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2012 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_CODING_NETEQ_PREEMPTIVE_EXPAND_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include "modules/audio_coding/neteq/time_stretch.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. class AudioMultiVector;
  18. class BackgroundNoise;
  19. // This class implements the PreemptiveExpand operation. Most of the work is
  20. // done in the base class TimeStretch, which is shared with the Accelerate
  21. // operation. In the PreemptiveExpand class, the operations that are specific to
  22. // PreemptiveExpand are implemented.
  23. class PreemptiveExpand : public TimeStretch {
  24. public:
  25. PreemptiveExpand(int sample_rate_hz,
  26. size_t num_channels,
  27. const BackgroundNoise& background_noise,
  28. size_t overlap_samples)
  29. : TimeStretch(sample_rate_hz, num_channels, background_noise),
  30. old_data_length_per_channel_(0),
  31. overlap_samples_(overlap_samples) {}
  32. // This method performs the actual PreemptiveExpand operation. The samples are
  33. // read from |input|, of length |input_length| elements, and are written to
  34. // |output|. The number of samples added through time-stretching is
  35. // is provided in the output |length_change_samples|. The method returns
  36. // the outcome of the operation as an enumerator value.
  37. ReturnCodes Process(const int16_t* pw16_decoded,
  38. size_t len,
  39. size_t old_data_len,
  40. AudioMultiVector* output,
  41. size_t* length_change_samples);
  42. protected:
  43. // Sets the parameters |best_correlation| and |peak_index| to suitable
  44. // values when the signal contains no active speech.
  45. void SetParametersForPassiveSpeech(size_t input_length,
  46. int16_t* best_correlation,
  47. size_t* peak_index) const override;
  48. // Checks the criteria for performing the time-stretching operation and,
  49. // if possible, performs the time-stretching.
  50. ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
  51. size_t input_length,
  52. size_t peak_index,
  53. int16_t best_correlation,
  54. bool active_speech,
  55. bool /*fast_mode*/,
  56. AudioMultiVector* output) const override;
  57. private:
  58. size_t old_data_length_per_channel_;
  59. size_t overlap_samples_;
  60. RTC_DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
  61. };
  62. struct PreemptiveExpandFactory {
  63. PreemptiveExpandFactory() {}
  64. virtual ~PreemptiveExpandFactory() {}
  65. virtual PreemptiveExpand* Create(int sample_rate_hz,
  66. size_t num_channels,
  67. const BackgroundNoise& background_noise,
  68. size_t overlap_samples) const;
  69. };
  70. } // namespace webrtc
  71. #endif // MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_