blob: 31fcee31d03d6fc4878d13e7efc2653bcfdd633b [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_
12#define MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000016namespace webrtc {
17
18// Forward declarations.
Yves Gerey988cc082018-10-23 12:03:01 +020019class AudioMultiVector;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000020class DecoderDatabase;
21class SyncBuffer;
22struct Packet;
23
24// This class acts as an interface to the CNG generator.
25class ComfortNoise {
26 public:
27 enum ReturnCodes {
28 kOK = 0,
29 kUnknownPayloadType,
30 kInternalError,
31 kMultiChannelNotSupported
32 };
33
Yves Gerey665174f2018-06-19 15:03:05 +020034 ComfortNoise(int fs_hz,
35 DecoderDatabase* decoder_database,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000036 SyncBuffer* sync_buffer)
37 : fs_hz_(fs_hz),
38 first_call_(true),
39 overlap_length_(5 * fs_hz_ / 8000),
40 decoder_database_(decoder_database),
Yves Gerey665174f2018-06-19 15:03:05 +020041 sync_buffer_(sync_buffer) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000042
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090043 ComfortNoise(const ComfortNoise&) = delete;
44 ComfortNoise& operator=(const ComfortNoise&) = delete;
45
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000046 // Resets the state. Should be called before each new comfort noise period.
47 void Reset();
48
Artem Titovd00ce742021-07-28 20:00:17 +020049 // Update the comfort noise generator with the parameters in `packet`.
ossua73f6c92016-10-24 08:25:28 -070050 int UpdateParameters(const Packet& packet);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000051
Artem Titovd00ce742021-07-28 20:00:17 +020052 // Generates `requested_length` samples of comfort noise and writes to
53 // `output`. If this is the first in call after Reset (or first after creating
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000054 // the object), it will also mix in comfort noise at the end of the
55 // SyncBuffer object provided in the constructor.
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000056 int Generate(size_t requested_length, AudioMultiVector* output);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000057
58 // Returns the last error code that was produced by the comfort noise
59 // decoder. Returns 0 if no error has been encountered since the last reset.
60 int internal_error_code() { return internal_error_code_; }
61
62 private:
63 int fs_hz_;
64 bool first_call_;
65 size_t overlap_length_;
66 DecoderDatabase* decoder_database_;
67 SyncBuffer* sync_buffer_;
68 int internal_error_code_;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000069};
70
71} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020072#endif // MODULES_AUDIO_CODING_NETEQ_COMFORT_NOISE_H_