Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libfaad/lt_predict.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ static INLINE int16_t real_to_int16(real_t sig_in)
{
if (sig_in >= 0)
{
sig_in += (1 << (REAL_BITS-1));
if (sig_in <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
sig_in += (1 << (REAL_BITS-1));
if (sig_in >= REAL_CONST(32768))
return 32767;
} else {
sig_in += -(1 << (REAL_BITS-1));
if (sig_in >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
sig_in += -(1 << (REAL_BITS-1));
if (sig_in <= REAL_CONST(-32768))
return -32768;
}
Expand Down
18 changes: 12 additions & 6 deletions libfaad/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,15 @@ void* output_to_PCM(NeAACDecStruct *hDecoder,
hDecoder->internal_channel);
if (tmp >= 0)
{
tmp += (1 << (REAL_BITS-1));
if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
tmp += (1 << (REAL_BITS-1));
if (tmp >= REAL_CONST(32767))
{
tmp = REAL_CONST(32767);
}
} else {
tmp += -(1 << (REAL_BITS-1));
if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
tmp += -(1 << (REAL_BITS-1));
if (tmp <= REAL_CONST(-32768))
{
tmp = REAL_CONST(-32768);
Expand All @@ -511,14 +513,16 @@ void* output_to_PCM(NeAACDecStruct *hDecoder,
hDecoder->internal_channel);
if (tmp >= 0)
{
tmp += (1 << (REAL_BITS-9));
if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
tmp += (1 << (REAL_BITS-9));
tmp >>= (REAL_BITS-8);
if (tmp >= 8388607)
{
tmp = 8388607;
}
} else {
tmp += -(1 << (REAL_BITS-9));
if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
tmp += -(1 << (REAL_BITS-9));
tmp >>= (REAL_BITS-8);
if (tmp <= -8388608)
{
Expand All @@ -538,9 +542,11 @@ void* output_to_PCM(NeAACDecStruct *hDecoder,
hDecoder->internal_channel);
if (tmp >= 0)
{
tmp += half;
if (tmp <= 0x7FFFFFFF - half)
tmp += half;
} else {
tmp += -half;
if (tmp >= (int32_t)0x80000000 + half)
tmp += -half;
}
tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
int_sample_buffer[(i*channels)+ch] = tmp;
Expand Down
Loading