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:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user