blob: b6de0b5e67b2acca0fa8e8bbd5d4a3ed7a52d36e [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
niklase@google.com470e71d2011-07-07 08:21:25 +000011#include "pcm16b.h"
12
andresp@webrtc.org262e6762014-09-04 13:28:48 +000013#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000014
kwiberg@webrtc.org648f5d62015-02-10 09:18:28 +000015int16_t WebRtcPcm16b_Encode(const int16_t* speech,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000016 int16_t len,
kwiberg@webrtc.org648f5d62015-02-10 09:18:28 +000017 uint8_t* encoded) {
18 int i;
19 for (i = 0; i < len; ++i) {
20 uint16_t s = speech[i];
21 encoded[2 * i] = s >> 8;
22 encoded[2 * i + 1] = s;
23 }
24 return 2 * len;
niklase@google.com470e71d2011-07-07 08:21:25 +000025}
26
kwiberg@webrtc.org648f5d62015-02-10 09:18:28 +000027int16_t WebRtcPcm16b_Decode(const uint8_t* encoded,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000028 int16_t len,
kwiberg@webrtc.org648f5d62015-02-10 09:18:28 +000029 int16_t* speech) {
30 int i;
31 for (i = 0; i < len / 2; ++i)
32 speech[i] = encoded[2 * i] << 8 | encoded[2 * i + 1];
33 return len / 2;
niklase@google.com470e71d2011-07-07 08:21:25 +000034}