accelerate.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_ACCELERATE_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_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 Accelerate operation. Most of the work is done
  20. // in the base class TimeStretch, which is shared with the PreemptiveExpand
  21. // operation. In the Accelerate class, the operations that are specific to
  22. // Accelerate are implemented.
  23. class Accelerate : public TimeStretch {
  24. public:
  25. Accelerate(int sample_rate_hz,
  26. size_t num_channels,
  27. const BackgroundNoise& background_noise)
  28. : TimeStretch(sample_rate_hz, num_channels, background_noise) {}
  29. // This method performs the actual Accelerate operation. The samples are
  30. // read from |input|, of length |input_length| elements, and are written to
  31. // |output|. The number of samples removed through time-stretching is
  32. // is provided in the output |length_change_samples|. The method returns
  33. // the outcome of the operation as an enumerator value. If |fast_accelerate|
  34. // is true, the algorithm will relax the requirements on finding strong
  35. // correlations, and may remove multiple pitch periods if possible.
  36. ReturnCodes Process(const int16_t* input,
  37. size_t input_length,
  38. bool fast_accelerate,
  39. AudioMultiVector* output,
  40. size_t* length_change_samples);
  41. protected:
  42. // Sets the parameters |best_correlation| and |peak_index| to suitable
  43. // values when the signal contains no active speech.
  44. void SetParametersForPassiveSpeech(size_t len,
  45. int16_t* best_correlation,
  46. size_t* peak_index) const override;
  47. // Checks the criteria for performing the time-stretching operation and,
  48. // if possible, performs the time-stretching.
  49. ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
  50. size_t input_length,
  51. size_t peak_index,
  52. int16_t best_correlation,
  53. bool active_speech,
  54. bool fast_mode,
  55. AudioMultiVector* output) const override;
  56. private:
  57. RTC_DISALLOW_COPY_AND_ASSIGN(Accelerate);
  58. };
  59. struct AccelerateFactory {
  60. AccelerateFactory() {}
  61. virtual ~AccelerateFactory() {}
  62. virtual Accelerate* Create(int sample_rate_hz,
  63. size_t num_channels,
  64. const BackgroundNoise& background_noise) const;
  65. };
  66. } // namespace webrtc
  67. #endif // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_