OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_coding/neteq/comfort_noise.h" | 11 #include "webrtc/modules/audio_coding/neteq/comfort_noise.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 16 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
17 #include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" | |
18 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 17 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
19 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" | 18 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" |
20 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 19 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
21 | 20 |
22 namespace webrtc { | 21 namespace webrtc { |
23 | 22 |
24 void ComfortNoise::Reset() { | 23 void ComfortNoise::Reset() { |
25 first_call_ = true; | 24 first_call_ = true; |
26 internal_error_code_ = 0; | |
27 } | 25 } |
28 | 26 |
29 int ComfortNoise::UpdateParameters(Packet* packet) { | 27 int ComfortNoise::UpdateParameters(Packet* packet) { |
30 assert(packet); // Existence is verified by caller. | 28 assert(packet); // Existence is verified by caller. |
31 // Get comfort noise decoder. | 29 // Get comfort noise decoder. |
32 AudioDecoder* cng_decoder = decoder_database_->GetDecoder( | 30 if (decoder_database_->SetActiveCngDecoder(packet->header.payloadType) |
33 packet->header.payloadType); | 31 != kOK) { |
34 if (!cng_decoder) { | |
35 delete [] packet->payload; | 32 delete [] packet->payload; |
36 delete packet; | 33 delete packet; |
37 return kUnknownPayloadType; | 34 return kUnknownPayloadType; |
38 } | 35 } |
39 decoder_database_->SetActiveCngDecoder(packet->header.payloadType); | 36 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
40 CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); | 37 cng_decoder->UpdateSid(rtc::ArrayView<const uint8_t>( |
41 int16_t ret = WebRtcCng_UpdateSid(cng_inst, | 38 packet->payload, packet->payload_length)); |
kwiberg-webrtc
2016/04/12 13:35:31
You probably don't need to store the cng decoder i
ossu
2016/04/12 13:54:50
Yeah, it can but it never will. RTC_DCHECK?
It's g
hlundin-webrtc
2016/04/13 07:05:24
I vote for a DCHECK.
ossu
2016/04/13 11:57:07
Acknowledged.
| |
42 packet->payload, | |
43 packet->payload_length); | |
44 delete [] packet->payload; | 39 delete [] packet->payload; |
45 delete packet; | 40 delete packet; |
46 if (ret < 0) { | |
47 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); | |
48 LOG(LS_ERROR) << "WebRtcCng_UpdateSid produced " << internal_error_code_; | |
49 return kInternalError; | |
50 } | |
51 return kOK; | 41 return kOK; |
52 } | 42 } |
53 | 43 |
54 int ComfortNoise::Generate(size_t requested_length, | 44 int ComfortNoise::Generate(size_t requested_length, |
55 AudioMultiVector* output) { | 45 AudioMultiVector* output) { |
56 // TODO(hlundin): Change to an enumerator and skip assert. | 46 // TODO(hlundin): Change to an enumerator and skip assert. |
57 assert(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 || | 47 assert(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 || |
58 fs_hz_ == 48000); | 48 fs_hz_ == 48000); |
59 // Not adapted for multi-channel yet. | 49 // Not adapted for multi-channel yet. |
60 if (output->Channels() != 1) { | 50 if (output->Channels() != 1) { |
61 LOG(LS_ERROR) << "No multi-channel support"; | 51 LOG(LS_ERROR) << "No multi-channel support"; |
62 return kMultiChannelNotSupported; | 52 return kMultiChannelNotSupported; |
63 } | 53 } |
64 | 54 |
65 size_t number_of_samples = requested_length; | 55 size_t number_of_samples = requested_length; |
66 int16_t new_period = 0; | 56 int16_t new_period = 0; |
67 if (first_call_) { | 57 if (first_call_) { |
68 // Generate noise and overlap slightly with old data. | 58 // Generate noise and overlap slightly with old data. |
69 number_of_samples = requested_length + overlap_length_; | 59 number_of_samples = requested_length + overlap_length_; |
70 new_period = 1; | 60 new_period = 1; |
71 } | 61 } |
72 output->AssertSize(number_of_samples); | 62 output->AssertSize(number_of_samples); |
73 // Get the decoder from the database. | 63 // Get the decoder from the database. |
74 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 64 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
75 if (!cng_decoder) { | 65 if (!cng_decoder) { |
76 LOG(LS_ERROR) << "Unknwown payload type"; | 66 LOG(LS_ERROR) << "Unknwown payload type"; |
77 return kUnknownPayloadType; | 67 return kUnknownPayloadType; |
78 } | 68 } |
79 CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); | |
80 // The expression &(*output)[0][0] is a pointer to the first element in | 69 // The expression &(*output)[0][0] is a pointer to the first element in |
81 // the first channel. | 70 // the first channel. |
82 if (WebRtcCng_Generate(cng_inst, &(*output)[0][0], number_of_samples, | 71 if (!cng_decoder->Generate( |
83 new_period) < 0) { | 72 rtc::ArrayView<int16_t>(&(*output)[0][0], number_of_samples), |
73 new_period)) { | |
84 // Error returned. | 74 // Error returned. |
85 output->Zeros(requested_length); | 75 output->Zeros(requested_length); |
86 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); | 76 LOG(LS_ERROR) << |
87 LOG(LS_ERROR) << "WebRtcCng_Generate produced " << internal_error_code_; | 77 "ComfortNoiseDecoder::Genererate failed to generate comfort noise"; |
88 return kInternalError; | 78 return kInternalError; |
89 } | 79 } |
90 | 80 |
91 if (first_call_) { | 81 if (first_call_) { |
92 // Set tapering window parameters. Values are in Q15. | 82 // Set tapering window parameters. Values are in Q15. |
93 int16_t muting_window; // Mixing factor for overlap data. | 83 int16_t muting_window; // Mixing factor for overlap data. |
94 int16_t muting_window_increment; // Mixing factor increment (negative). | 84 int16_t muting_window_increment; // Mixing factor increment (negative). |
95 int16_t unmuting_window; // Mixing factor for comfort noise. | 85 int16_t unmuting_window; // Mixing factor for comfort noise. |
96 int16_t unmuting_window_increment; // Mixing factor increment. | 86 int16_t unmuting_window_increment; // Mixing factor increment. |
97 if (fs_hz_ == 8000) { | 87 if (fs_hz_ == 8000) { |
(...skipping 32 matching lines...) Loading... | |
130 } | 120 } |
131 // Remove |overlap_length_| samples from the front of |output| since they | 121 // Remove |overlap_length_| samples from the front of |output| since they |
132 // were mixed into |sync_buffer_| above. | 122 // were mixed into |sync_buffer_| above. |
133 output->PopFront(overlap_length_); | 123 output->PopFront(overlap_length_); |
134 } | 124 } |
135 first_call_ = false; | 125 first_call_ = false; |
136 return kOK; | 126 return kOK; |
137 } | 127 } |
138 | 128 |
139 } // namespace webrtc | 129 } // namespace webrtc |
OLD | NEW |