Skip to content

Commit

Permalink
Clip XLL samples by default.
Browse files Browse the repository at this point in the history
Even though XLL encoder is expected to handle all clipping issues, there
are XLL streams where decoded samples overflow indicated storage bit
depth after downmix reversal.

To work around this issue, always clip XLL samples unless DONT_CLIP
context flag was set by the user.
  • Loading branch information
foo86 committed Nov 6, 2015
1 parent 4de2117 commit 80258da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dcadec.c
Expand Up @@ -179,7 +179,7 @@ static void signal_handler(int sig)

int main(int argc, char **argv)
{
int flags = DCADEC_FLAG_STRICT;
int flags = DCADEC_FLAG_STRICT | DCADEC_FLAG_DONT_CLIP;
int wave_flags = 0;
bool parse_only = false;
bool no_progress = false;
Expand All @@ -191,9 +191,11 @@ int main(int argc, char **argv)
switch (opt) {
case '2':
flags |= DCADEC_FLAG_KEEP_DMIX_2CH;
flags &= ~DCADEC_FLAG_DONT_CLIP;
break;
case '6':
flags |= DCADEC_FLAG_KEEP_DMIX_6CH;
flags &= ~DCADEC_FLAG_DONT_CLIP;
break;
case 'b':
flags |= DCADEC_FLAG_CORE_BIT_EXACT;
Expand Down
6 changes: 4 additions & 2 deletions libdcadec/dca_context.c
Expand Up @@ -125,6 +125,9 @@ static void clip_samples(struct dcadec_context *dca, int nchannels)
{
int nsamples = dca->nframesamples;

if (dca->flags & DCADEC_FLAG_DONT_CLIP)
return;

switch (dca->bits_per_sample) {
case 24:
for (int ch = 0; ch < nchannels; ch++)
Expand Down Expand Up @@ -721,8 +724,7 @@ static int filter_hd_ma_frame(struct dcadec_context *dca)
dca->profile = DCADEC_PROFILE_HD_MA;

// Perform clipping
if (dca->flags & DCADEC_FLAG_KEEP_DMIX_MASK)
clip_samples(dca, ret);
clip_samples(dca, ret);

return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions libdcadec/dca_context.h
Expand Up @@ -113,6 +113,9 @@

/** Don't conceal errors */
#define DCADEC_FLAG_STRICT 0x100

/** Don't clip returned PCM samples to output bit depth */
#define DCADEC_FLAG_DONT_CLIP 0x200
/**@}*/

/**@{*/
Expand Down

0 comments on commit 80258da

Please sign in to comment.