blob: 5fe1692ccbc802a6f6214edbe22eba5b37a31b01 [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"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Peter Kastingdce40cf2015-08-24 14:52:23 -070016size_t WebRtcG711_EncodeA(const int16_t* speechIn,
17 size_t len,
18 uint8_t* encoded) {
19 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000020 for (n = 0; n < len; n++)
21 encoded[n] = linear_to_alaw(speechIn[n]);
22 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000023}
24
Peter Kastingdce40cf2015-08-24 14:52:23 -070025size_t WebRtcG711_EncodeU(const int16_t* speechIn,
26 size_t len,
27 uint8_t* encoded) {
28 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000029 for (n = 0; n < len; n++)
30 encoded[n] = linear_to_ulaw(speechIn[n]);
31 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000032}
33
Peter Kastingdce40cf2015-08-24 14:52:23 -070034size_t WebRtcG711_DecodeA(const uint8_t* encoded,
35 size_t len,
36 int16_t* decoded,
37 int16_t* speechType) {
38 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000039 for (n = 0; n < len; n++)
40 decoded[n] = alaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000041 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000042 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000043}
44
Peter Kastingdce40cf2015-08-24 14:52:23 -070045size_t WebRtcG711_DecodeU(const uint8_t* encoded,
46 size_t len,
47 int16_t* decoded,
48 int16_t* speechType) {
49 size_t n;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000050 for (n = 0; n < len; n++)
51 decoded[n] = ulaw_to_linear(encoded[n]);
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000052 *speechType = 1;
kwiberg@webrtc.org1c6239a2015-02-09 12:55:48 +000053 return len;
niklase@google.com470e71d2011-07-07 08:21:25 +000054}
55
pbos@webrtc.orgae4e2b32013-03-21 13:38:29 +000056int16_t WebRtcG711_Version(char* version, int16_t lenBytes) {
57 strncpy(version, "2.0.0", lenBytes);
58 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000059}