niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | #include <string.h> |
| 11 | #include "g711.h" |
| 12 | #include "g711_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 13 | #include "typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 15 | size_t WebRtcG711_EncodeA(const int16_t* speechIn, |
| 16 | size_t len, |
| 17 | uint8_t* encoded) { |
| 18 | size_t n; |
kwiberg@webrtc.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 19 | for (n = 0; n < len; n++) |
| 20 | encoded[n] = linear_to_alaw(speechIn[n]); |
| 21 | return len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 24 | size_t WebRtcG711_EncodeU(const int16_t* speechIn, |
| 25 | size_t len, |
| 26 | uint8_t* encoded) { |
| 27 | size_t n; |
kwiberg@webrtc.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 28 | for (n = 0; n < len; n++) |
| 29 | encoded[n] = linear_to_ulaw(speechIn[n]); |
| 30 | return len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 33 | size_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.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 38 | for (n = 0; n < len; n++) |
| 39 | decoded[n] = alaw_to_linear(encoded[n]); |
pbos@webrtc.org | ae4e2b3 | 2013-03-21 13:38:29 +0000 | [diff] [blame] | 40 | *speechType = 1; |
kwiberg@webrtc.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 41 | return len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 44 | size_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.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 49 | for (n = 0; n < len; n++) |
| 50 | decoded[n] = ulaw_to_linear(encoded[n]); |
pbos@webrtc.org | ae4e2b3 | 2013-03-21 13:38:29 +0000 | [diff] [blame] | 51 | *speechType = 1; |
kwiberg@webrtc.org | 1c6239a | 2015-02-09 12:55:48 +0000 | [diff] [blame] | 52 | return len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | } |
| 54 | |
pbos@webrtc.org | ae4e2b3 | 2013-03-21 13:38:29 +0000 | [diff] [blame] | 55 | int16_t WebRtcG711_Version(char* version, int16_t lenBytes) { |
| 56 | strncpy(version, "2.0.0", lenBytes); |
| 57 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | } |