Skip to content

Commit

Permalink
WebRtcIsac_Encode and WebRtcIsacfix_Encode: Type encoded stream as ui…
Browse files Browse the repository at this point in the history
…nt8_t

We have to fix both at once, since there's a macro that calls one of
them or the other.

BUG=909
R=andrew@webrtc.org, bjornv@webrtc.org, henrik.lundin@webrtc.org, minyue@webrtc.org

Committed: https://code.google.com/p/webrtc/source/detail?r=7266

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7285 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
kwiberg@webrtc.org committed Sep 24, 2014
1 parent d60d79a commit 7ee24a7
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extern "C" {

int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
const int16_t *speechIn,
int16_t *encoded);
uint8_t* encoded);



Expand Down
25 changes: 17 additions & 8 deletions webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"

#include <assert.h>
#include <stdlib.h>

#include "webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.h"
Expand Down Expand Up @@ -355,10 +356,10 @@ int16_t WebRtcIsacfix_EncoderInit(ISACFIX_MainStruct *ISAC_main_inst,

int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
const int16_t *speechIn,
int16_t *encoded)
uint8_t* encoded)
{
ISACFIX_SubStruct *ISAC_inst;
int16_t stream_len;
int16_t stream_len, stream_len_even;
#ifndef WEBRTC_ARCH_BIG_ENDIAN
int k;
#endif
Expand All @@ -382,16 +383,24 @@ int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
return -1;
}

/* One would think that only even stream lengths would make sense here. We do
in fact observe odd lengths, however, and in those cases we copy an extra
byte. */
stream_len_even = stream_len % 2 == 0 ? stream_len : stream_len + 1;

/* convert from bytes to int16_t */
#ifndef WEBRTC_ARCH_BIG_ENDIAN
for (k=0;k<(stream_len+1)>>1;k++) {
encoded[k] = (int16_t)( ( (uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8 )
| (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8));
/* The encoded data vector is supposesd to be big-endian, but our internal
representation is little-endian. So byteswap. */
for (k = 0; k < stream_len_even / 2; ++k) {
uint16_t s = ISAC_inst->ISACenc_obj.bitstr_obj.stream[k];
/* In big-endian, we have... */
encoded[2 * k] = s >> 8; /* ...most significant byte at low address... */
encoded[2 * k + 1] = s; /* ...least significant byte at high address. */
}

#else
WEBRTC_SPL_MEMCPY_W16(encoded, (ISAC_inst->ISACenc_obj.bitstr_obj).stream, (stream_len + 1)>>1);
/* The encoded data vector and our internal representation are both
big-endian. */
memcpy(encoded, ISAC_inst->ISACenc_obj.bitstr_obj.stream, stream_len_even);
#endif


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ float IsacSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream,
size_t pointer = 0;
for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) {
value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer],
reinterpret_cast<int16_t*>(bit_stream));
bit_stream);
}
clocks = clock() - clocks;
EXPECT_GT(value, 0);
Expand Down
2 changes: 1 addition & 1 deletion webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ int main(int argc, char* argv[])
/* Encode */
stream_len = WebRtcIsacfix_Encode(ISAC_main_inst,
shortdata,
(int16_t*)streamdata);
(uint8_t*)streamdata);

/* If packet is ready, and CE testing, call the different API
functions from the internal API. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ int main(int argc, char* argv[])
/* iSAC encoding */

if (mode==0 || mode ==1) {
stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata, streamdata);
stream_len = WebRtcIsac_Encode(ISAC_main_inst,
shortdata,
(uint8_t*)streamdata);
if (stream_len < 0) {
/* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
Expand All @@ -449,7 +451,10 @@ int main(int argc, char* argv[])
} else if (mode==2 || mode==3) {
/* iSAC encoding */
if (nbTest != 1)
stream_len = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata, streamdata);
stream_len = WebRtcIsacfix_Encode(
ISACFIX_main_inst,
shortdata,
(uint8_t*)streamdata);
else
stream_len = WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ extern "C" {
int16_t WebRtcIsac_Encode(
ISACStruct* ISAC_main_inst,
const int16_t* speechIn,
int16_t* encoded);
uint8_t* encoded);


/******************************************************************************
Expand Down
41 changes: 18 additions & 23 deletions webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,14 @@ int16_t WebRtcIsac_EncoderInit(ISACStruct* ISAC_main_inst,
*/
int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
const int16_t* speechIn,
int16_t* encoded) {
uint8_t* encoded) {
float inFrame[FRAMESAMPLES_10ms];
int16_t speechInLB[FRAMESAMPLES_10ms];
int16_t speechInUB[FRAMESAMPLES_10ms];
int16_t streamLenLB = 0;
int16_t streamLenUB = 0;
int16_t streamLen = 0;
int16_t k = 0;
uint8_t* ptrEncodedUW8 = (uint8_t*)encoded;
int garbageLen = 0;
int32_t bottleneck = 0;
int16_t bottleneckIdx = 0;
Expand Down Expand Up @@ -643,23 +642,22 @@ int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
streamLenUB = 0;
}

memcpy(ptrEncodedUW8, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
streamLen = streamLenLB;
if (streamLenUB > 0) {
ptrEncodedUW8[streamLenLB] = (uint8_t)(streamLenUB + 1 +
LEN_CHECK_SUM_WORD8);
memcpy(&ptrEncodedUW8[streamLenLB + 1],
instUB->ISACencUB_obj.bitstr_obj.stream, streamLenUB);
streamLen += ptrEncodedUW8[streamLenLB];
encoded[streamLenLB] = streamLenUB + 1 + LEN_CHECK_SUM_WORD8;
memcpy(&encoded[streamLenLB + 1],
instUB->ISACencUB_obj.bitstr_obj.stream,
streamLenUB);
streamLen += encoded[streamLenLB];
} else {
ptrEncodedUW8[streamLenLB] = 0;
encoded[streamLenLB] = 0;
}
} else {
if (streamLenLB == 0) {
return 0;
}
memcpy(ptrEncodedUW8, instLB->ISACencLB_obj.bitstr_obj.stream,
streamLenLB);
memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
streamLenUB = 0;
streamLen = streamLenLB;
}
Expand Down Expand Up @@ -697,11 +695,11 @@ int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
* 255 is the max garbage length we can signal using 8 bits. */
if ((instISAC->bandwidthKHz == isac8kHz) ||
(streamLenUB == 0)) {
ptrGarbage = &ptrEncodedUW8[streamLenLB];
ptrGarbage = &encoded[streamLenLB];
limit = streamLen + 255;
} else {
ptrGarbage = &ptrEncodedUW8[streamLenLB + 1 + streamLenUB];
limit = streamLen + (255 - ptrEncodedUW8[streamLenLB]);
ptrGarbage = &encoded[streamLenLB + 1 + streamLenUB];
limit = streamLen + (255 - encoded[streamLenLB]);
}
minBytes = (minBytes > limit) ? limit : minBytes;

Expand All @@ -718,13 +716,12 @@ int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
* That is the only way to preserve backward compatibility. */
if ((instISAC->bandwidthKHz == isac8kHz) ||
(streamLenUB == 0)) {
ptrEncodedUW8[streamLenLB] = (uint8_t)garbageLen;
encoded[streamLenLB] = garbageLen;
} else {
ptrEncodedUW8[streamLenLB] += (uint8_t)garbageLen;
encoded[streamLenLB] += garbageLen;
/* Write the length of the garbage at the end of the upper-band
* bit-stream, if exists. This helps for sanity check. */
ptrEncodedUW8[streamLenLB + 1 + streamLenUB] =
(uint8_t)garbageLen;
encoded[streamLenLB + 1 + streamLenUB] = garbageLen;

}
streamLen += garbageLen;
Expand All @@ -741,16 +738,14 @@ int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
if ((instISAC->bandwidthKHz != isac8kHz) && (streamLenUB > 0)) {
uint32_t crc;

WebRtcIsac_GetCrc((int16_t*)(&(ptrEncodedUW8[streamLenLB + 1])),
WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])),
streamLenUB + garbageLen, &crc);
#ifndef WEBRTC_ARCH_BIG_ENDIAN
for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) {
ptrEncodedUW8[streamLen - LEN_CHECK_SUM_WORD8 + k] =
(uint8_t)((crc >> (24 - k * 8)) & 0xFF);
encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = crc >> (24 - k * 8);
}
#else
memcpy(&ptrEncodedUW8[streamLenLB + streamLenUB + 1], &crc,
LEN_CHECK_SUM_WORD8);
memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8);
#endif
}
return streamLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IsacTest : public ::testing::Test {

int16_t speech_data_[kIsacNumberOfSamples];
int16_t output_data_[kIsacNumberOfSamples];
int16_t bitstream_[kMaxBytes / 2];
uint8_t bitstream_[kMaxBytes];
uint8_t bitstream_small_[7]; // Simulate sync packets.
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ int main(int argc, char* argv[])
if(!(testNum == 3 && framecnt == 0))
{
stream_len = WebRtcIsac_Encode(ISAC_main_inst,
shortdata,
(int16_t*)streamdata);
shortdata,
(uint8_t*)streamdata);
if((payloadSize != 0) && (stream_len > payloadSize))
{
if(testNum == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ int main(int argc, char* argv[])


streamLen = WebRtcIsac_Encode(codecInstance[senderIdx],
audioBuff10ms, (short*)bitStream);
audioBuff10ms,
(uint8_t*)bitStream);
int16_t ggg;
if (streamLen > 0) {
if(( WebRtcIsac_ReadFrameLen(codecInstance[receiverIdx],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ valid values are 8 and 16.\n", sampFreqKHz);
cur_framesmpls += samplesIn10Ms;

//-------- iSAC encoding ---------
stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata,
(int16_t*)payload);
stream_len = WebRtcIsac_Encode(
ISAC_main_inst,
shortdata,
(uint8_t*)payload);

if(stream_len < 0)
{
Expand Down
5 changes: 3 additions & 2 deletions webrtc/modules/audio_coding/main/acm2/acm_isac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ int16_t ACMISAC::InternalEncode(uint8_t* bitstream,
return -1;
}
*bitstream_len_byte = ACM_ISAC_ENCODE(
codec_inst_ptr_->inst, &in_audio_[in_audio_ix_read_],
reinterpret_cast<int16_t*>(bitstream));
codec_inst_ptr_->inst,
&in_audio_[in_audio_ix_read_],
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_ += samples_in_10ms_audio_;
Expand Down
27 changes: 9 additions & 18 deletions webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,11 @@ class AudioDecoderIsacFloatTest : public AudioDecoderTest {
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
uint8_t* output) {
// Insert 3 * 10 ms. Expect non-zero output on third call.
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
input += input_size_;
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
input += input_size_;
int enc_len_bytes =
WebRtcIsac_Encode(encoder_, input, reinterpret_cast<int16_t*>(output));
int enc_len_bytes = WebRtcIsac_Encode(encoder_, input, output);
EXPECT_GT(enc_len_bytes, 0);
return enc_len_bytes;
}
Expand Down Expand Up @@ -388,14 +385,11 @@ class AudioDecoderIsacSwbTest : public AudioDecoderTest {
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
uint8_t* output) {
// Insert 3 * 10 ms. Expect non-zero output on third call.
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
input += input_size_;
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
input += input_size_;
int enc_len_bytes =
WebRtcIsac_Encode(encoder_, input, reinterpret_cast<int16_t*>(output));
int enc_len_bytes = WebRtcIsac_Encode(encoder_, input, output);
EXPECT_GT(enc_len_bytes, 0);
return enc_len_bytes;
}
Expand Down Expand Up @@ -441,14 +435,11 @@ class AudioDecoderIsacFixTest : public AudioDecoderTest {
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
uint8_t* output) {
// Insert 3 * 10 ms. Expect non-zero output on third call.
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
input += input_size_;
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input,
reinterpret_cast<int16_t*>(output)));
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
input += input_size_;
int enc_len_bytes = WebRtcIsacfix_Encode(
encoder_, input, reinterpret_cast<int16_t*>(output));
int enc_len_bytes = WebRtcIsacfix_Encode(encoder_, input, output);
EXPECT_GT(enc_len_bytes, 0);
return enc_len_bytes;
}
Expand Down
12 changes: 9 additions & 3 deletions webrtc/modules/audio_coding/neteq/test/RTPencode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,13 @@ int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * e
cdlen=0;
while (cdlen<=0) {
#ifdef CODEC_ISAC /* floating point */
cdlen=WebRtcIsac_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
cdlen = WebRtcIsac_Encode(ISAC_inst[k],
&indata[noOfCalls * 160],
encoded);
#else /* fixed point */
cdlen=WebRtcIsacfix_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
cdlen = WebRtcIsacfix_Encode(ISAC_inst[k],
&indata[noOfCalls * 160],
encoded);
#endif
noOfCalls++;
}
Expand All @@ -1645,7 +1649,9 @@ int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * e
int noOfCalls=0;
cdlen=0;
while (cdlen<=0) {
cdlen=WebRtcIsac_Encode(ISACSWB_inst[k],&indata[noOfCalls*320],(int16_t*)encoded);
cdlen = WebRtcIsac_Encode(ISACSWB_inst[k],
&indata[noOfCalls * 320],
encoded);
noOfCalls++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ int NetEqIsacQualityTest::EncodeBlock(int16_t* in_data,
// The Isac encoder does not perform encoding (and returns 0) until it
// receives a sequence of sub-blocks that amount to the frame duration.
EXPECT_EQ(0, value);
value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer],
reinterpret_cast<int16_t*>(payload));
value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer], payload);
}
EXPECT_GT(value, 0);
return value;
Expand Down

0 comments on commit 7ee24a7

Please sign in to comment.