blob: 52f73fb9d8859b58453d65f91287772787c2f211 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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#include <string.h>
11#include "g711.h"
12#include "g711_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000014
Peter Kastingdce40cf2015-08-24 14:52:23 -070015size_t WebRtcG711_EncodeA(const int16_t* speechIn,
16 size_t len,
17 uint8_t* encoded) {
18 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000019 for (n = 0; n < len; n++)
20 encoded[n] = linear_to_alaw(speechIn[n]);
21 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000022}
23
Peter Kastingdce40cf2015-08-24 14:52:23 -070024size_t WebRtcG711_EncodeU(const int16_t* speechIn,
25 size_t len,
26 uint8_t* encoded) {
27 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000028 for (n = 0; n < len; n++)
29 encoded[n] = linear_to_ulaw(speechIn[n]);
30 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000031}
32
Peter Kastingdce40cf2015-08-24 14:52:23 -070033size_t WebRtcG711_DecodeA(const uint8_t* encoded,
34 size_t len,
35 int16_t* decoded,
36 int16_t* speechType) {
37 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000038 for (n = 0; n < len; n++)
39 decoded[n] = alaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000040 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000041 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000042}
43
Peter Kastingdce40cf2015-08-24 14:52:23 -070044size_t WebRtcG711_DecodeU(const uint8_t* encoded,
45 size_t len,
46 int16_t* decoded,
47 int16_t* speechType) {
48 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000049 for (n = 0; n < len; n++)
50 decoded[n] = ulaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000051 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000052 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000053}
54
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000055int16_t WebRtcG711_Version(char* version, int16_t lenBytes) {
56 strncpy(version, "2.0.0", lenBytes);
57 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000058}