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