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
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@8294 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc b/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
index c2f6424..3dd8800 100644
--- a/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
+++ b/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
@@ -90,17 +90,13 @@
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
diff --git a/modules/audio_coding/codecs/g711/g711_interface.c b/modules/audio_coding/codecs/g711/g711_interface.c
index ec726c5..809a70e 100644
--- a/modules/audio_coding/codecs/g711/g711_interface.c
+++ b/modules/audio_coding/codecs/g711/g711_interface.c
@@ -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,
diff --git a/modules/audio_coding/codecs/g711/include/g711_interface.h b/modules/audio_coding/codecs/g711/include/g711_interface.h
index 545ca3e..aa3894d 100644
--- a/modules/audio_coding/codecs/g711/include/g711_interface.h
+++ b/modules/audio_coding/codecs/g711/include/g711_interface.h
@@ -38,9 +38,9 @@
* -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 @@
* -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 @@
* -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 @@
* -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);
diff --git a/modules/audio_coding/codecs/g711/test/testG711.cc b/modules/audio_coding/codecs/g711/test/testG711.cc
index 76950fa..e891810 100644
--- a/modules/audio_coding/codecs/g711/test/testG711.cc
+++ b/modules/audio_coding/codecs/g711/test/testG711.cc
@@ -57,7 +57,7 @@
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];
diff --git a/modules/audio_coding/main/acm2/acm_pcma.cc b/modules/audio_coding/main/acm2/acm_pcma.cc
index 008b1cf..5674210 100644
--- a/modules/audio_coding/main/acm2/acm_pcma.cc
+++ b/modules/audio_coding/main/acm2/acm_pcma.cc
@@ -29,9 +29,9 @@
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_;
diff --git a/modules/audio_coding/main/acm2/acm_pcmu.cc b/modules/audio_coding/main/acm2/acm_pcmu.cc
index 7ccc184..4c50696 100644
--- a/modules/audio_coding/main/acm2/acm_pcmu.cc
+++ b/modules/audio_coding/main/acm2/acm_pcmu.cc
@@ -29,9 +29,9 @@
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.
diff --git a/modules/audio_coding/neteq/audio_decoder_impl.cc b/modules/audio_coding/neteq/audio_decoder_impl.cc
index 9ea2429..6050585 100644
--- a/modules/audio_coding/neteq/audio_decoder_impl.cc
+++ b/modules/audio_coding/neteq/audio_decoder_impl.cc
@@ -41,9 +41,8 @@
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 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;
}
diff --git a/modules/audio_coding/neteq/test/RTPencode.cc b/modules/audio_coding/neteq/test/RTPencode.cc
index 543ed11..9aa207d 100644
--- a/modules/audio_coding/neteq/test/RTPencode.cc
+++ b/modules/audio_coding/neteq/test/RTPencode.cc
@@ -1558,12 +1558,12 @@
/* 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