Skip to content
Snippets Groups Projects
Commit 41d62ad1 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9979: ulaw: normalize types

parent ca4fb50b
No related branches found
No related tags found
No related merge requests found
...@@ -44,27 +44,24 @@ class Ulaw : public sfl::AudioCodec { ...@@ -44,27 +44,24 @@ class Ulaw : public sfl::AudioCodec {
hasDynamicPayload_ = false; hasDynamicPayload_ = false;
} }
virtual int decode(short *dst, unsigned char *src, size_t buf_size) { virtual int decode(SFLDataFormat *dst, unsigned char *src, size_t buf_size) {
assert(buf_size == frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat)); assert(buf_size == frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat));
unsigned char* end = src+buf_size; for (unsigned char* end = src + buf_size; src < end; ++src, ++dst)
*dst = ULawDecode(*src);
while (src<end)
*dst++ = ULawDecode(*src++);
return frameSize_; return frameSize_;
} }
virtual int encode(unsigned char *dst, short *src, size_t buf_size) { virtual int encode(unsigned char *dst, SFLDataFormat *src, size_t buf_size) {
assert(buf_size >= frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat)); assert(buf_size >= frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat));
uint8* end = dst + frameSize_; for (uint8* end = dst + frameSize_; dst < end; ++src, ++dst)
*dst = ULawEncode(*src);
while (dst<end)
*dst++ = ULawEncode(*src++);
return frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat);; return frameSize_ / 2 /* compression factor = 2:1 */ * sizeof(SFLDataFormat);;
} }
int ULawDecode(uint8 ulaw) { SFLDataFormat ULawDecode(uint8 ulaw)
{
ulaw ^= 0xff; // u-law has all bits inverted for transmission ulaw ^= 0xff; // u-law has all bits inverted for transmission
int linear = ulaw & 0x0f; int linear = ulaw & 0x0f;
linear <<= 3; linear <<= 3;
...@@ -81,7 +78,8 @@ class Ulaw : public sfl::AudioCodec { ...@@ -81,7 +78,8 @@ class Ulaw : public sfl::AudioCodec {
return linear; return linear;
} }
uint8 ULawEncode(int16 pcm16) { uint8 ULawEncode(SFLDataFormat pcm16)
{
int p = pcm16; int p = pcm16;
uint u; // u-law value we are forming uint u; // u-law value we are forming
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment