1 /*
2 * Copyright (c) 2011 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 #include <string.h>
12
13 #include "modules/third_party/g711/g711.h"
14 #include "modules/audio_coding/codecs/g711/g711_interface.h"
15
WebRtcG711_EncodeA(const int16_t * speechIn,size_t len,uint8_t * encoded)16 size_t WebRtcG711_EncodeA(const int16_t* speechIn,
17 size_t len,
18 uint8_t* encoded) {
19 size_t n;
20 for (n = 0; n < len; n++)
21 encoded[n] = linear_to_alaw(speechIn[n]);
22 return len;
23 }
24
WebRtcG711_EncodeU(const int16_t * speechIn,size_t len,uint8_t * encoded)25 size_t WebRtcG711_EncodeU(const int16_t* speechIn,
26 size_t len,
27 uint8_t* encoded) {
28 size_t n;
29 for (n = 0; n < len; n++)
30 encoded[n] = linear_to_ulaw(speechIn[n]);
31 return len;
32 }
33
WebRtcG711_DecodeA(const uint8_t * encoded,size_t len,int16_t * decoded,int16_t * speechType)34 size_t WebRtcG711_DecodeA(const uint8_t* encoded,
35 size_t len,
36 int16_t* decoded,
37 int16_t* speechType) {
38 size_t n;
39 for (n = 0; n < len; n++)
40 decoded[n] = alaw_to_linear(encoded[n]);
41 *speechType = 1;
42 return len;
43 }
44
WebRtcG711_DecodeU(const uint8_t * encoded,size_t len,int16_t * decoded,int16_t * speechType)45 size_t WebRtcG711_DecodeU(const uint8_t* encoded,
46 size_t len,
47 int16_t* decoded,
48 int16_t* speechType) {
49 size_t n;
50 for (n = 0; n < len; n++)
51 decoded[n] = ulaw_to_linear(encoded[n]);
52 *speechType = 1;
53 return len;
54 }
55
WebRtcG711_Version(char * version,int16_t lenBytes)56 int16_t WebRtcG711_Version(char* version, int16_t lenBytes) {
57 strncpy(version, "2.0.0", lenBytes);
58 return 0;
59 }
60