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:
parent
d0165c62b5
commit
1c6239a3b6
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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];
|
||||
|
@ -29,9 +29,9 @@ ACMPCMA::~ACMPCMA() { return; }
|
||||
|
||||
int16_t ACMPCMA::InternalEncode(uint8_t* bitstream,
|
||||
int16_t* bitstream_len_byte) {
|
||||
*bitstream_len_byte = WebRtcG711_EncodeA(
|
||||
&in_audio_[in_audio_ix_read_], frame_len_smpl_ * num_channels_,
|
||||
reinterpret_cast<int16_t*>(bitstream));
|
||||
*bitstream_len_byte =
|
||||
WebRtcG711_EncodeA(&in_audio_[in_audio_ix_read_],
|
||||
frame_len_smpl_ * num_channels_, bitstream);
|
||||
// Increment the read index this tell the caller that how far
|
||||
// we have gone forward in reading the audio buffer.
|
||||
in_audio_ix_read_ += frame_len_smpl_ * num_channels_;
|
||||
|
@ -29,9 +29,9 @@ ACMPCMU::~ACMPCMU() {}
|
||||
|
||||
int16_t ACMPCMU::InternalEncode(uint8_t* bitstream,
|
||||
int16_t* bitstream_len_byte) {
|
||||
*bitstream_len_byte = WebRtcG711_EncodeU(
|
||||
&in_audio_[in_audio_ix_read_], frame_len_smpl_ * num_channels_,
|
||||
reinterpret_cast<int16_t*>(bitstream));
|
||||
*bitstream_len_byte =
|
||||
WebRtcG711_EncodeU(&in_audio_[in_audio_ix_read_],
|
||||
frame_len_smpl_ * num_channels_, bitstream);
|
||||
|
||||
// Increment the read index this tell the caller that how far
|
||||
// we have gone forward in reading the audio buffer.
|
||||
|
@ -41,9 +41,8 @@ namespace webrtc {
|
||||
int AudioDecoderPcmU::Decode(const uint8_t* encoded, size_t encoded_len,
|
||||
int16_t* decoded, SpeechType* speech_type) {
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int16_t ret = WebRtcG711_DecodeU(
|
||||
reinterpret_cast<int16_t*>(const_cast<uint8_t*>(encoded)),
|
||||
static_cast<int16_t>(encoded_len), decoded, &temp_type);
|
||||
int16_t ret = WebRtcG711_DecodeU(encoded, static_cast<int16_t>(encoded_len),
|
||||
decoded, &temp_type);
|
||||
*speech_type = ConvertSpeechType(temp_type);
|
||||
return ret;
|
||||
}
|
||||
@ -58,9 +57,8 @@ int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded,
|
||||
int AudioDecoderPcmA::Decode(const uint8_t* encoded, size_t encoded_len,
|
||||
int16_t* decoded, SpeechType* speech_type) {
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int16_t ret = WebRtcG711_DecodeA(
|
||||
reinterpret_cast<int16_t*>(const_cast<uint8_t*>(encoded)),
|
||||
static_cast<int16_t>(encoded_len), decoded, &temp_type);
|
||||
int16_t ret = WebRtcG711_DecodeA(encoded, static_cast<int16_t>(encoded_len),
|
||||
decoded, &temp_type);
|
||||
*speech_type = ConvertSpeechType(temp_type);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1558,12 +1558,12 @@ int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * e
|
||||
/* Encode with the selected coder type */
|
||||
if (coder==webrtc::kDecoderPCMu) { /*g711 u-law */
|
||||
#ifdef CODEC_G711
|
||||
cdlen = WebRtcG711_EncodeU(indata, frameLen, (int16_t*) encoded);
|
||||
cdlen = WebRtcG711_EncodeU(indata, frameLen, encoded);
|
||||
#endif
|
||||
}
|
||||
else if (coder==webrtc::kDecoderPCMa) { /*g711 A-law */
|
||||
#ifdef CODEC_G711
|
||||
cdlen = WebRtcG711_EncodeA(indata, frameLen, (int16_t*) encoded);
|
||||
cdlen = WebRtcG711_EncodeA(indata, frameLen, encoded);
|
||||
}
|
||||
#endif
|
||||
#ifdef CODEC_PCM16B
|
||||
|
Loading…
x
Reference in New Issue
Block a user