blob: 361350796fb9a0da1a68bbc6548fb0a02e686366 [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 */
Mirko Bonadei2bf82c12018-02-01 14:25:11 +010010
niklase@google.com470e71d2011-07-07 08:21:25 +000011#include <string.h>
Mirko Bonadei2bf82c12018-02-01 14:25:11 +010012
Artem Titove095b812018-07-25 12:10:22 +020013#include "modules/third_party/g711/g711.h"
Mirko Bonadei2bf82c12018-02-01 14:25:11 +010014#include "modules/audio_coding/codecs/g711/g711_interface.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000016
Peter Kastingdce40cf2015-08-24 14:52:23 -070017size_t WebRtcG711_EncodeA(const int16_t* speechIn,
18 size_t len,
19 uint8_t* encoded) {
20 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000021 for (n = 0; n < len; n++)
22 encoded[n] = linear_to_alaw(speechIn[n]);
23 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000024}
25
Peter Kastingdce40cf2015-08-24 14:52:23 -070026size_t WebRtcG711_EncodeU(const int16_t* speechIn,
27 size_t len,
28 uint8_t* encoded) {
29 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000030 for (n = 0; n < len; n++)
31 encoded[n] = linear_to_ulaw(speechIn[n]);
32 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000033}
34
Peter Kastingdce40cf2015-08-24 14:52:23 -070035size_t WebRtcG711_DecodeA(const uint8_t* encoded,
36 size_t len,
37 int16_t* decoded,
38 int16_t* speechType) {
39 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000040 for (n = 0; n < len; n++)
41 decoded[n] = alaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000042 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000043 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
45
Peter Kastingdce40cf2015-08-24 14:52:23 -070046size_t WebRtcG711_DecodeU(const uint8_t* encoded,
47 size_t len,
48 int16_t* decoded,
49 int16_t* speechType) {
50 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000051 for (n = 0; n < len; n++)
52 decoded[n] = ulaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000053 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000054 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000055}
56
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000057int16_t WebRtcG711_Version(char* version, int16_t lenBytes) {
58 strncpy(version, "2.0.0", lenBytes);
59 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000060}