G711: Make input arrays const and use uint8_t[] for byte arrays

BUG=909
R=henrik.lundin@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/39809004

Cr-Commit-Position: refs/heads/master@{#8294}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8294 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kwiberg@webrtc.org
2015-02-09 12:55:48 +00:00
parent d0165c62b5
commit 1c6239a3b6
8 changed files with 39 additions and 137 deletions

View File

@ -90,17 +90,13 @@ bool AudioEncoderPcm::EncodeInternal(uint32_t rtp_timestamp,
int16_t AudioEncoderPcmA::EncodeCall(const int16_t* audio,
size_t input_len,
uint8_t* encoded) {
return WebRtcG711_EncodeA(const_cast<int16_t*>(audio),
static_cast<int16_t>(input_len),
reinterpret_cast<int16_t*>(encoded));
return WebRtcG711_EncodeA(audio, static_cast<int16_t>(input_len), encoded);
}
int16_t AudioEncoderPcmU::EncodeCall(const int16_t* audio,
size_t input_len,
uint8_t* encoded) {
return WebRtcG711_EncodeU(const_cast<int16_t*>(audio),
static_cast<int16_t>(input_len),
reinterpret_cast<int16_t*>(encoded));
return WebRtcG711_EncodeU(audio, static_cast<int16_t>(input_len), encoded);
}
} // namespace webrtc

View File

@ -12,136 +12,44 @@
#include "g711_interface.h"
#include "webrtc/typedefs.h"
int16_t WebRtcG711_EncodeA(int16_t* speechIn,
int16_t WebRtcG711_EncodeA(const int16_t* speechIn,
int16_t len,
int16_t* encoded) {
uint8_t* encoded) {
int n;
uint16_t tempVal, tempVal2;
// Sanity check of input length
if (len < 0) {
return (-1);
}
// Loop over all samples
for (n = 0; n < len; n++) {
tempVal = (uint16_t) linear_to_alaw(speechIn[n]);
#ifdef WEBRTC_ARCH_BIG_ENDIAN
if ((n & 0x1) == 1) {
encoded[n >> 1] |= ((uint16_t) tempVal);
} else {
encoded[n >> 1] = ((uint16_t) tempVal) << 8;
}
#else
if ((n & 0x1) == 1) {
tempVal2 |= ((uint16_t) tempVal) << 8;
encoded[n >> 1] |= ((uint16_t) tempVal) << 8;
} else {
tempVal2 = ((uint16_t) tempVal);
encoded[n >> 1] = ((uint16_t) tempVal);
}
#endif
}
return (len);
for (n = 0; n < len; n++)
encoded[n] = linear_to_alaw(speechIn[n]);
return len;
}
int16_t WebRtcG711_EncodeU(int16_t* speechIn,
int16_t WebRtcG711_EncodeU(const int16_t* speechIn,
int16_t len,
int16_t* encoded) {
uint8_t* encoded) {
int n;
uint16_t tempVal;
// Sanity check of input length
if (len < 0) {
return (-1);
}
// Loop over all samples
for (n = 0; n < len; n++) {
tempVal = (uint16_t) linear_to_ulaw(speechIn[n]);
#ifdef WEBRTC_ARCH_BIG_ENDIAN
if ((n & 0x1) == 1) {
encoded[n >> 1] |= ((uint16_t) tempVal);
} else {
encoded[n >> 1] = ((uint16_t) tempVal) << 8;
}
#else
if ((n & 0x1) == 1) {
encoded[n >> 1] |= ((uint16_t) tempVal) << 8;
} else {
encoded[n >> 1] = ((uint16_t) tempVal);
}
#endif
}
return (len);
for (n = 0; n < len; n++)
encoded[n] = linear_to_ulaw(speechIn[n]);
return len;
}
int16_t WebRtcG711_DecodeA(int16_t* encoded,
int16_t WebRtcG711_DecodeA(const uint8_t* encoded,
int16_t len,
int16_t* decoded,
int16_t* speechType) {
int n;
uint16_t tempVal;
// Sanity check of input length
if (len < 0) {
return (-1);
}
for (n = 0; n < len; n++) {
#ifdef WEBRTC_ARCH_BIG_ENDIAN
if ((n & 0x1) == 1) {
tempVal = ((uint16_t) encoded[n >> 1] & 0xFF);
} else {
tempVal = ((uint16_t) encoded[n >> 1] >> 8);
}
#else
if ((n & 0x1) == 1) {
tempVal = (encoded[n >> 1] >> 8);
} else {
tempVal = (encoded[n >> 1] & 0xFF);
}
#endif
decoded[n] = (int16_t) alaw_to_linear(tempVal);
}
for (n = 0; n < len; n++)
decoded[n] = alaw_to_linear(encoded[n]);
*speechType = 1;
return (len);
return len;
}
int16_t WebRtcG711_DecodeU(int16_t* encoded,
int16_t WebRtcG711_DecodeU(const uint8_t* encoded,
int16_t len,
int16_t* decoded,
int16_t* speechType) {
int n;
uint16_t tempVal;
// Sanity check of input length
if (len < 0) {
return (-1);
}
for (n = 0; n < len; n++) {
#ifdef WEBRTC_ARCH_BIG_ENDIAN
if ((n & 0x1) == 1) {
tempVal = ((uint16_t) encoded[n >> 1] & 0xFF);
} else {
tempVal = ((uint16_t) encoded[n >> 1] >> 8);
}
#else
if ((n & 0x1) == 1) {
tempVal = (encoded[n >> 1] >> 8);
} else {
tempVal = (encoded[n >> 1] & 0xFF);
}
#endif
decoded[n] = (int16_t) ulaw_to_linear(tempVal);
}
for (n = 0; n < len; n++)
decoded[n] = ulaw_to_linear(encoded[n]);
*speechType = 1;
return (len);
return len;
}
int WebRtcG711_DurationEst(const uint8_t* payload,

View File

@ -38,9 +38,9 @@ extern "C" {
* -1 - Error
*/
int16_t WebRtcG711_EncodeA(int16_t* speechIn,
int16_t WebRtcG711_EncodeA(const int16_t* speechIn,
int16_t len,
int16_t* encoded);
uint8_t* encoded);
/****************************************************************************
* WebRtcG711_EncodeU(...)
@ -59,9 +59,9 @@ int16_t WebRtcG711_EncodeA(int16_t* speechIn,
* -1 - Error
*/
int16_t WebRtcG711_EncodeU(int16_t* speechIn,
int16_t WebRtcG711_EncodeU(const int16_t* speechIn,
int16_t len,
int16_t* encoded);
uint8_t* encoded);
/****************************************************************************
* WebRtcG711_DecodeA(...)
@ -82,7 +82,7 @@ int16_t WebRtcG711_EncodeU(int16_t* speechIn,
* -1 - Error
*/
int16_t WebRtcG711_DecodeA(int16_t* encoded,
int16_t WebRtcG711_DecodeA(const uint8_t* encoded,
int16_t len,
int16_t* decoded,
int16_t* speechType);
@ -106,7 +106,7 @@ int16_t WebRtcG711_DecodeA(int16_t* encoded,
* -1 - Error
*/
int16_t WebRtcG711_DecodeU(int16_t* encoded,
int16_t WebRtcG711_DecodeU(const uint8_t* encoded,
int16_t len,
int16_t* decoded,
int16_t* speechType);

View File

@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
int16_t stream_len = 0;
int16_t shortdata[480];
int16_t decoded[480];
int16_t streamdata[500];
uint8_t streamdata[1000];
int16_t speechType[1];
char law[2];
char versionNumber[40];