2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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.
12 #include "g711_interface.h"
13 #include "webrtc/typedefs.h"
15 int16_t WebRtcG711_EncodeA(int16_t* speechIn,
19 uint16_t tempVal, tempVal2;
21 // Sanity check of input length
26 // Loop over all samples
27 for (n = 0; n < len; n++) {
28 tempVal = (uint16_t) linear_to_alaw(speechIn[n]);
30 #ifdef WEBRTC_ARCH_BIG_ENDIAN
32 encoded[n >> 1] |= ((uint16_t) tempVal);
34 encoded[n >> 1] = ((uint16_t) tempVal) << 8;
38 tempVal2 |= ((uint16_t) tempVal) << 8;
39 encoded[n >> 1] |= ((uint16_t) tempVal) << 8;
41 tempVal2 = ((uint16_t) tempVal);
42 encoded[n >> 1] = ((uint16_t) tempVal);
49 int16_t WebRtcG711_EncodeU(int16_t* speechIn,
55 // Sanity check of input length
60 // Loop over all samples
61 for (n = 0; n < len; n++) {
62 tempVal = (uint16_t) linear_to_ulaw(speechIn[n]);
64 #ifdef WEBRTC_ARCH_BIG_ENDIAN
66 encoded[n >> 1] |= ((uint16_t) tempVal);
68 encoded[n >> 1] = ((uint16_t) tempVal) << 8;
72 encoded[n >> 1] |= ((uint16_t) tempVal) << 8;
74 encoded[n >> 1] = ((uint16_t) tempVal);
81 int16_t WebRtcG711_DecodeA(int16_t* encoded,
84 int16_t* speechType) {
88 // Sanity check of input length
93 for (n = 0; n < len; n++) {
94 #ifdef WEBRTC_ARCH_BIG_ENDIAN
96 tempVal = ((uint16_t) encoded[n >> 1] & 0xFF);
98 tempVal = ((uint16_t) encoded[n >> 1] >> 8);
101 if ((n & 0x1) == 1) {
102 tempVal = (encoded[n >> 1] >> 8);
104 tempVal = (encoded[n >> 1] & 0xFF);
107 decoded[n] = (int16_t) alaw_to_linear(tempVal);
114 int16_t WebRtcG711_DecodeU(int16_t* encoded,
117 int16_t* speechType) {
121 // Sanity check of input length
126 for (n = 0; n < len; n++) {
127 #ifdef WEBRTC_ARCH_BIG_ENDIAN
128 if ((n & 0x1) == 1) {
129 tempVal = ((uint16_t) encoded[n >> 1] & 0xFF);
131 tempVal = ((uint16_t) encoded[n >> 1] >> 8);
134 if ((n & 0x1) == 1) {
135 tempVal = (encoded[n >> 1] >> 8);
137 tempVal = (encoded[n >> 1] & 0xFF);
140 decoded[n] = (int16_t) ulaw_to_linear(tempVal);
147 int WebRtcG711_DurationEst(const uint8_t* payload,
148 int payload_length_bytes) {
150 /* G.711 is one byte per sample, so we can just return the number of bytes. */
151 return payload_length_bytes;
154 int16_t WebRtcG711_Version(char* version, int16_t lenBytes) {
155 strncpy(version, "2.0.0", lenBytes);