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 | |
Mirko Bonadei | 7272453 | 2018-02-02 09:54:36 +0100 | [diff] [blame] | 11 | #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 13 | size_t WebRtcPcm16b_Encode(const int16_t* speech, |
| 14 | size_t len, |
| 15 | uint8_t* encoded) { |
| 16 | size_t i; |
kwiberg@webrtc.org | 648f5d6 | 2015-02-10 09:18:28 +0000 | [diff] [blame] | 17 | for (i = 0; i < len; ++i) { |
| 18 | uint16_t s = speech[i]; |
| 19 | encoded[2 * i] = s >> 8; |
| 20 | encoded[2 * i + 1] = s; |
| 21 | } |
| 22 | return 2 * len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 25 | size_t WebRtcPcm16b_Decode(const uint8_t* encoded, |
| 26 | size_t len, |
| 27 | int16_t* speech) { |
| 28 | size_t i; |
kwiberg@webrtc.org | 648f5d6 | 2015-02-10 09:18:28 +0000 | [diff] [blame] | 29 | for (i = 0; i < len / 2; ++i) |
| 30 | speech[i] = encoded[2 * i] << 8 | encoded[2 * i + 1]; |
| 31 | return len / 2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | } |