OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/codecs/pcm16b/audio_decoder_pcm16b.h" | 11 #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h" | 14 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 AudioDecoderPcm16B::AudioDecoderPcm16B(size_t num_channels) | 18 AudioDecoderPcm16B::AudioDecoderPcm16B(int sample_rate_hz, size_t num_channels) |
19 : num_channels_(num_channels) { | 19 : sample_rate_hz_(sample_rate_hz), num_channels_(num_channels) { |
| 20 RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || |
| 21 sample_rate_hz == 32000 || sample_rate_hz == 48000) |
| 22 << "Unsupported sample rate " << sample_rate_hz; |
20 RTC_DCHECK_GE(num_channels, 1u); | 23 RTC_DCHECK_GE(num_channels, 1u); |
21 } | 24 } |
22 | 25 |
23 void AudioDecoderPcm16B::Reset() {} | 26 void AudioDecoderPcm16B::Reset() {} |
24 | 27 |
| 28 int AudioDecoderPcm16B::SampleRateHz() const { |
| 29 return sample_rate_hz_; |
| 30 } |
| 31 |
25 size_t AudioDecoderPcm16B::Channels() const { | 32 size_t AudioDecoderPcm16B::Channels() const { |
26 return num_channels_; | 33 return num_channels_; |
27 } | 34 } |
28 | 35 |
29 int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded, | 36 int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded, |
30 size_t encoded_len, | 37 size_t encoded_len, |
31 int sample_rate_hz, | 38 int sample_rate_hz, |
32 int16_t* decoded, | 39 int16_t* decoded, |
33 SpeechType* speech_type) { | 40 SpeechType* speech_type) { |
34 RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || | 41 RTC_DCHECK_EQ(sample_rate_hz_, sample_rate_hz); |
35 sample_rate_hz == 32000 || sample_rate_hz == 48000) | |
36 << "Unsupported sample rate " << sample_rate_hz; | |
37 size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded); | 42 size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded); |
38 *speech_type = ConvertSpeechType(1); | 43 *speech_type = ConvertSpeechType(1); |
39 return static_cast<int>(ret); | 44 return static_cast<int>(ret); |
40 } | 45 } |
41 | 46 |
42 int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded, | 47 int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded, |
43 size_t encoded_len) const { | 48 size_t encoded_len) const { |
44 // Two encoded byte per sample per channel. | 49 // Two encoded byte per sample per channel. |
45 return static_cast<int>(encoded_len / (2 * Channels())); | 50 return static_cast<int>(encoded_len / (2 * Channels())); |
46 } | 51 } |
47 | 52 |
48 } // namespace webrtc | 53 } // namespace webrtc |
OLD | NEW |