blob: 7e7c294ff0ee151792c373f18643f120f4324fcb [file] [log] [blame]
henrik.lundin@webrtc.org9a400812013-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
11#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_COMFORT_NOISE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_COMFORT_NOISE_H_
13
14#include "webrtc/modules/audio_coding/neteq4/audio_multi_vector.h"
15#include "webrtc/system_wrappers/interface/constructor_magic.h"
16#include "webrtc/typedefs.h"
17
18namespace webrtc {
19
20// Forward declarations.
21class DecoderDatabase;
22class SyncBuffer;
23struct Packet;
24
25// This class acts as an interface to the CNG generator.
26class ComfortNoise {
27 public:
28 enum ReturnCodes {
29 kOK = 0,
30 kUnknownPayloadType,
31 kInternalError,
32 kMultiChannelNotSupported
33 };
34
35 ComfortNoise(int fs_hz, DecoderDatabase* decoder_database,
36 SyncBuffer* sync_buffer)
37 : fs_hz_(fs_hz),
38 first_call_(true),
39 overlap_length_(5 * fs_hz_ / 8000),
40 decoder_database_(decoder_database),
41 sync_buffer_(sync_buffer),
42 internal_error_code_(0) {
43 }
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|.
49 // Will delete the packet.
50 int UpdateParameters(Packet* packet);
51
52 // 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
54 // the object), it will also mix in comfort noise at the end of the
55 // SyncBuffer object provided in the constructor.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000056 int Generate(size_t requested_length, AudioMultiVector* output);
henrik.lundin@webrtc.org9a400812013-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_;
69 DISALLOW_COPY_AND_ASSIGN(ComfortNoise);
70};
71
72} // namespace webrtc
73#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_COMFORT_NOISE_H_