normal.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_NORMAL_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_NORMAL_H_
  12. #include <stdint.h>
  13. #include <string.h> // Access to size_t.
  14. #include "api/neteq/neteq.h"
  15. #include "rtc_base/checks.h"
  16. #include "rtc_base/constructor_magic.h"
  17. #include "rtc_base/numerics/safe_conversions.h"
  18. namespace webrtc {
  19. // Forward declarations.
  20. class AudioMultiVector;
  21. class BackgroundNoise;
  22. class DecoderDatabase;
  23. class Expand;
  24. // This class provides the "Normal" DSP operation, that is performed when
  25. // there is no data loss, no need to stretch the timing of the signal, and
  26. // no other "special circumstances" are at hand.
  27. class Normal {
  28. public:
  29. Normal(int fs_hz,
  30. DecoderDatabase* decoder_database,
  31. const BackgroundNoise& background_noise,
  32. Expand* expand)
  33. : fs_hz_(fs_hz),
  34. decoder_database_(decoder_database),
  35. background_noise_(background_noise),
  36. expand_(expand),
  37. samples_per_ms_(rtc::CheckedDivExact(fs_hz_, 1000)),
  38. default_win_slope_Q14_(
  39. rtc::dchecked_cast<uint16_t>((1 << 14) / samples_per_ms_)) {}
  40. virtual ~Normal() {}
  41. // Performs the "Normal" operation. The decoder data is supplied in |input|,
  42. // having |length| samples in total for all channels (interleaved). The
  43. // result is written to |output|. The number of channels allocated in
  44. // |output| defines the number of channels that will be used when
  45. // de-interleaving |input|. |last_mode| contains the mode used in the previous
  46. // GetAudio call (i.e., not the current one).
  47. int Process(const int16_t* input,
  48. size_t length,
  49. NetEq::Mode last_mode,
  50. AudioMultiVector* output);
  51. private:
  52. int fs_hz_;
  53. DecoderDatabase* decoder_database_;
  54. const BackgroundNoise& background_noise_;
  55. Expand* expand_;
  56. const size_t samples_per_ms_;
  57. const int16_t default_win_slope_Q14_;
  58. RTC_DISALLOW_COPY_AND_ASSIGN(Normal);
  59. };
  60. } // namespace webrtc
  61. #endif // MODULES_AUDIO_CODING_NETEQ_NORMAL_H_