comfort_noise.h 2.2 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_COMFORT_NOISE_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_
  12. #include <stddef.h>
  13. #include "rtc_base/constructor_magic.h"
  14. namespace webrtc {
  15. // Forward declarations.
  16. class AudioMultiVector;
  17. class DecoderDatabase;
  18. class SyncBuffer;
  19. struct Packet;
  20. // This class acts as an interface to the CNG generator.
  21. class ComfortNoise {
  22. public:
  23. enum ReturnCodes {
  24. kOK = 0,
  25. kUnknownPayloadType,
  26. kInternalError,
  27. kMultiChannelNotSupported
  28. };
  29. ComfortNoise(int fs_hz,
  30. DecoderDatabase* decoder_database,
  31. SyncBuffer* sync_buffer)
  32. : fs_hz_(fs_hz),
  33. first_call_(true),
  34. overlap_length_(5 * fs_hz_ / 8000),
  35. decoder_database_(decoder_database),
  36. sync_buffer_(sync_buffer) {}
  37. // Resets the state. Should be called before each new comfort noise period.
  38. void Reset();
  39. // Update the comfort noise generator with the parameters in |packet|.
  40. int UpdateParameters(const Packet& packet);
  41. // Generates |requested_length| samples of comfort noise and writes to
  42. // |output|. If this is the first in call after Reset (or first after creating
  43. // the object), it will also mix in comfort noise at the end of the
  44. // SyncBuffer object provided in the constructor.
  45. int Generate(size_t requested_length, AudioMultiVector* output);
  46. // Returns the last error code that was produced by the comfort noise
  47. // decoder. Returns 0 if no error has been encountered since the last reset.
  48. int internal_error_code() { return internal_error_code_; }
  49. private:
  50. int fs_hz_;
  51. bool first_call_;
  52. size_t overlap_length_;
  53. DecoderDatabase* decoder_database_;
  54. SyncBuffer* sync_buffer_;
  55. int internal_error_code_;
  56. RTC_DISALLOW_COPY_AND_ASSIGN(ComfortNoise);
  57. };
  58. } // namespace webrtc
  59. #endif // MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_