henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_coding/neteq/audio_multi_vector.h" |
| 15 | #include "rtc_base/constructormagic.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 16 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Forward declarations. |
| 21 | class DecoderDatabase; |
| 22 | class SyncBuffer; |
| 23 | struct Packet; |
| 24 | |
| 25 | // This class acts as an interface to the CNG generator. |
| 26 | class ComfortNoise { |
| 27 | public: |
| 28 | enum ReturnCodes { |
| 29 | kOK = 0, |
| 30 | kUnknownPayloadType, |
| 31 | kInternalError, |
| 32 | kMultiChannelNotSupported |
| 33 | }; |
| 34 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 35 | ComfortNoise(int fs_hz, |
| 36 | DecoderDatabase* decoder_database, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 37 | SyncBuffer* sync_buffer) |
| 38 | : fs_hz_(fs_hz), |
| 39 | first_call_(true), |
| 40 | overlap_length_(5 * fs_hz_ / 8000), |
| 41 | decoder_database_(decoder_database), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 42 | sync_buffer_(sync_buffer) {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 43 | |
| 44 | // Resets the state. Should be called before each new comfort noise period. |
| 45 | void Reset(); |
| 46 | |
| 47 | // Update the comfort noise generator with the parameters in |packet|. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 48 | int UpdateParameters(const Packet& packet); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 49 | |
| 50 | // Generates |requested_length| samples of comfort noise and writes to |
| 51 | // |output|. If this is the first in call after Reset (or first after creating |
| 52 | // the object), it will also mix in comfort noise at the end of the |
| 53 | // SyncBuffer object provided in the constructor. |
henrik.lundin@webrtc.org | fd11bbf | 2013-09-30 20:38:44 +0000 | [diff] [blame] | 54 | int Generate(size_t requested_length, AudioMultiVector* output); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 55 | |
| 56 | // Returns the last error code that was produced by the comfort noise |
| 57 | // decoder. Returns 0 if no error has been encountered since the last reset. |
| 58 | int internal_error_code() { return internal_error_code_; } |
| 59 | |
| 60 | private: |
| 61 | int fs_hz_; |
| 62 | bool first_call_; |
| 63 | size_t overlap_length_; |
| 64 | DecoderDatabase* decoder_database_; |
| 65 | SyncBuffer* sync_buffer_; |
| 66 | int internal_error_code_; |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 67 | RTC_DISALLOW_COPY_AND_ASSIGN(ComfortNoise); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_ |