summaryrefslogtreecommitdiffstats
path: root/libhb/deca52.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhb/deca52.c')
-rw-r--r--libhb/deca52.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/libhb/deca52.c b/libhb/deca52.c
index 510e1ea88..922b88132 100644
--- a/libhb/deca52.c
+++ b/libhb/deca52.c
@@ -322,9 +322,13 @@ static hb_buffer_t* Decode(hb_work_object_t *w)
/* Feed liba52 */
a52_frame(pv->state, pv->frame, &pv->flags, &pv->level, 0);
- /* If the user requested strong DRC (>1), adjust it.
- * If the user requested default DRC (1), leave it alone.
- * If the user requested no DRC (0), call a null function. */
+ /*
+ * If the user requested strong DRC (>1), adjust it.
+ * If the user requested default DRC (1), leave it alone.
+ * If the user requested no DRC (0), call a null function.
+ *
+ * a52_frame() resets the callback so it must be called for each frame.
+ */
if (pv->dynamic_range_compression > 1.0)
{
a52_dynrng(pv->state, dynrng_call, &pv->dynamic_range_compression);
@@ -334,30 +338,48 @@ static hb_buffer_t* Decode(hb_work_object_t *w)
a52_dynrng(pv->state, NULL, NULL);
}
- /* Update input channel layout and prepare remapping */
+ /*
+ * Update input channel layout, prepare remapping and downmixing
+ */
uint64_t new_layout = (acmod2layout[(pv->flags & A52_CHANNEL_MASK)] |
lfeon2layout[(pv->flags & A52_LFE) != 0]);
+
if (new_layout != pv->channel_layout)
{
pv->channel_layout = new_layout;
pv->nchannels = av_get_channel_layout_nb_channels(new_layout);
+ hb_audio_resample_set_channel_layout(pv->resample,
+ pv->channel_layout,
+ pv->nchannels);
hb_audio_remap_build_table(&hb_libav_chan_map, &hb_liba52_chan_map,
pv->channel_layout, pv->remap_table);
}
+ if (pv->use_mix_levels)
+ {
+ hb_audio_resample_set_mix_levels(pv->resample,
+ (double)pv->state->slev,
+ (double)pv->state->clev);
+ }
+ if (hb_audio_resample_update(pv->resample))
+ {
+ hb_log("deca52: hb_audio_resample_update() failed");
+ return NULL;
+ }
- /* 6 blocks per frame, 256 samples per block, pv->nchannels channels */
+ // 6 blocks per frame, 256 samples per block, pv->nchannels channels
flt = hb_buffer_init(1536 * pv->nchannels * sizeof(float));
+ // decode all blocks before downmixing
for (i = 0; i < 6; i++)
{
- sample_t *samples_in;
- float *samples_out;
+ float *samples_in, *samples_out;
a52_block(pv->state);
- samples_in = a52_samples(pv->state);
- samples_out = ((float*)flt->data) + 256 * pv->nchannels * i;
+ samples_in = (float*)a52_samples(pv->state);
+ samples_out = (float*)(flt->data +
+ (i * pv->nchannels * 256 * sizeof(float)));
- /* Planar -> interleaved, remap to Libav channel order */
+ // Planar -> interleaved, remap to Libav channel order
for (j = 0; j < 256; j++)
{
for (k = 0; k < pv->nchannels; k++)
@@ -367,21 +389,7 @@ static hb_buffer_t* Decode(hb_work_object_t *w)
}
}
}
- hb_audio_resample_set_channel_layout(pv->resample,
- pv->channel_layout,
- pv->nchannels);
- if (pv->use_mix_levels)
- {
- hb_audio_resample_set_mix_levels(pv->resample,
- (double)pv->state->slev,
- (double)pv->state->clev);
- }
- if (hb_audio_resample_update(pv->resample))
- {
- hb_log("deca52: hb_audio_resample_update() failed");
- hb_buffer_close(&flt);
- return NULL;
- }
+
out = hb_audio_resample(pv->resample, (void*)flt->data, 1536);
hb_buffer_close(&flt);
}