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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 bool AudioDecoderG722::HasDecodePlc() const { | 29 bool AudioDecoderG722::HasDecodePlc() const { |
30 return false; | 30 return false; |
31 } | 31 } |
32 | 32 |
33 int AudioDecoderG722::DecodeInternal(const uint8_t* encoded, | 33 int AudioDecoderG722::DecodeInternal(const uint8_t* encoded, |
34 size_t encoded_len, | 34 size_t encoded_len, |
35 int sample_rate_hz, | 35 int sample_rate_hz, |
36 int16_t* decoded, | 36 int16_t* decoded, |
37 SpeechType* speech_type) { | 37 SpeechType* speech_type) { |
38 RTC_DCHECK_EQ(sample_rate_hz, 16000); | 38 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
39 int16_t temp_type = 1; // Default is speech. | 39 int16_t temp_type = 1; // Default is speech. |
40 size_t ret = | 40 size_t ret = |
41 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); | 41 WebRtcG722_Decode(dec_state_, encoded, encoded_len, decoded, &temp_type); |
42 *speech_type = ConvertSpeechType(temp_type); | 42 *speech_type = ConvertSpeechType(temp_type); |
43 return static_cast<int>(ret); | 43 return static_cast<int>(ret); |
44 } | 44 } |
45 | 45 |
46 void AudioDecoderG722::Reset() { | 46 void AudioDecoderG722::Reset() { |
47 WebRtcG722_DecoderInit(dec_state_); | 47 WebRtcG722_DecoderInit(dec_state_); |
48 } | 48 } |
49 | 49 |
50 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, | 50 int AudioDecoderG722::PacketDuration(const uint8_t* encoded, |
51 size_t encoded_len) const { | 51 size_t encoded_len) const { |
52 // 1/2 encoded byte per sample per channel. | 52 // 1/2 encoded byte per sample per channel. |
53 return static_cast<int>(2 * encoded_len / Channels()); | 53 return static_cast<int>(2 * encoded_len / Channels()); |
54 } | 54 } |
55 | 55 |
| 56 int AudioDecoderG722::SampleRateHz() const { |
| 57 return 16000; |
| 58 } |
| 59 |
56 size_t AudioDecoderG722::Channels() const { | 60 size_t AudioDecoderG722::Channels() const { |
57 return 1; | 61 return 1; |
58 } | 62 } |
59 | 63 |
60 AudioDecoderG722Stereo::AudioDecoderG722Stereo() { | 64 AudioDecoderG722Stereo::AudioDecoderG722Stereo() { |
61 WebRtcG722_CreateDecoder(&dec_state_left_); | 65 WebRtcG722_CreateDecoder(&dec_state_left_); |
62 WebRtcG722_CreateDecoder(&dec_state_right_); | 66 WebRtcG722_CreateDecoder(&dec_state_right_); |
63 WebRtcG722_DecoderInit(dec_state_left_); | 67 WebRtcG722_DecoderInit(dec_state_left_); |
64 WebRtcG722_DecoderInit(dec_state_right_); | 68 WebRtcG722_DecoderInit(dec_state_right_); |
65 } | 69 } |
66 | 70 |
67 AudioDecoderG722Stereo::~AudioDecoderG722Stereo() { | 71 AudioDecoderG722Stereo::~AudioDecoderG722Stereo() { |
68 WebRtcG722_FreeDecoder(dec_state_left_); | 72 WebRtcG722_FreeDecoder(dec_state_left_); |
69 WebRtcG722_FreeDecoder(dec_state_right_); | 73 WebRtcG722_FreeDecoder(dec_state_right_); |
70 } | 74 } |
71 | 75 |
72 int AudioDecoderG722Stereo::DecodeInternal(const uint8_t* encoded, | 76 int AudioDecoderG722Stereo::DecodeInternal(const uint8_t* encoded, |
73 size_t encoded_len, | 77 size_t encoded_len, |
74 int sample_rate_hz, | 78 int sample_rate_hz, |
75 int16_t* decoded, | 79 int16_t* decoded, |
76 SpeechType* speech_type) { | 80 SpeechType* speech_type) { |
77 RTC_DCHECK_EQ(sample_rate_hz, 16000); | 81 RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz); |
78 int16_t temp_type = 1; // Default is speech. | 82 int16_t temp_type = 1; // Default is speech. |
79 // De-interleave the bit-stream into two separate payloads. | 83 // De-interleave the bit-stream into two separate payloads. |
80 uint8_t* encoded_deinterleaved = new uint8_t[encoded_len]; | 84 uint8_t* encoded_deinterleaved = new uint8_t[encoded_len]; |
81 SplitStereoPacket(encoded, encoded_len, encoded_deinterleaved); | 85 SplitStereoPacket(encoded, encoded_len, encoded_deinterleaved); |
82 // Decode left and right. | 86 // Decode left and right. |
83 size_t decoded_len = WebRtcG722_Decode(dec_state_left_, encoded_deinterleaved, | 87 size_t decoded_len = WebRtcG722_Decode(dec_state_left_, encoded_deinterleaved, |
84 encoded_len / 2, decoded, &temp_type); | 88 encoded_len / 2, decoded, &temp_type); |
85 size_t ret = WebRtcG722_Decode( | 89 size_t ret = WebRtcG722_Decode( |
86 dec_state_right_, &encoded_deinterleaved[encoded_len / 2], | 90 dec_state_right_, &encoded_deinterleaved[encoded_len / 2], |
87 encoded_len / 2, &decoded[decoded_len], &temp_type); | 91 encoded_len / 2, &decoded[decoded_len], &temp_type); |
88 if (ret == decoded_len) { | 92 if (ret == decoded_len) { |
89 ret += decoded_len; // Return total number of samples. | 93 ret += decoded_len; // Return total number of samples. |
90 // Interleave output. | 94 // Interleave output. |
91 for (size_t k = ret / 2; k < ret; k++) { | 95 for (size_t k = ret / 2; k < ret; k++) { |
92 int16_t temp = decoded[k]; | 96 int16_t temp = decoded[k]; |
93 memmove(&decoded[2 * k - ret + 2], &decoded[2 * k - ret + 1], | 97 memmove(&decoded[2 * k - ret + 2], &decoded[2 * k - ret + 1], |
94 (ret - k - 1) * sizeof(int16_t)); | 98 (ret - k - 1) * sizeof(int16_t)); |
95 decoded[2 * k - ret + 1] = temp; | 99 decoded[2 * k - ret + 1] = temp; |
96 } | 100 } |
97 } | 101 } |
98 *speech_type = ConvertSpeechType(temp_type); | 102 *speech_type = ConvertSpeechType(temp_type); |
99 delete[] encoded_deinterleaved; | 103 delete[] encoded_deinterleaved; |
100 return static_cast<int>(ret); | 104 return static_cast<int>(ret); |
101 } | 105 } |
102 | 106 |
| 107 int AudioDecoderG722Stereo::SampleRateHz() const { |
| 108 return 16000; |
| 109 } |
| 110 |
103 size_t AudioDecoderG722Stereo::Channels() const { | 111 size_t AudioDecoderG722Stereo::Channels() const { |
104 return 2; | 112 return 2; |
105 } | 113 } |
106 | 114 |
107 void AudioDecoderG722Stereo::Reset() { | 115 void AudioDecoderG722Stereo::Reset() { |
108 WebRtcG722_DecoderInit(dec_state_left_); | 116 WebRtcG722_DecoderInit(dec_state_left_); |
109 WebRtcG722_DecoderInit(dec_state_right_); | 117 WebRtcG722_DecoderInit(dec_state_right_); |
110 } | 118 } |
111 | 119 |
112 // Split the stereo packet and place left and right channel after each other | 120 // Split the stereo packet and place left and right channel after each other |
(...skipping 16 matching lines...) Expand all Loading... |
129 // where N is the total number of samples. | 137 // where N is the total number of samples. |
130 for (size_t i = 0; i < encoded_len / 2; i++) { | 138 for (size_t i = 0; i < encoded_len / 2; i++) { |
131 uint8_t right_byte = encoded_deinterleaved[i + 1]; | 139 uint8_t right_byte = encoded_deinterleaved[i + 1]; |
132 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], | 140 memmove(&encoded_deinterleaved[i + 1], &encoded_deinterleaved[i + 2], |
133 encoded_len - i - 2); | 141 encoded_len - i - 2); |
134 encoded_deinterleaved[encoded_len - 1] = right_byte; | 142 encoded_deinterleaved[encoded_len - 1] = right_byte; |
135 } | 143 } |
136 } | 144 } |
137 | 145 |
138 } // namespace webrtc | 146 } // namespace webrtc |
OLD | NEW |