#include "hbffmpeg.h"
#include "audio_resample.h"
-hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt,
- uint64_t output_channel_layout,
- enum AVMatrixEncoding matrix_encoding,
+hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
+ int hb_amixdown, int do_remix,
int normalize_mix_level)
{
hb_audio_resample_t *resample = malloc(sizeof(hb_audio_resample_t));
return NULL;
}
- resample->out.sample_fmt = output_sample_fmt;
- resample->out.sample_size =
- av_get_bytes_per_sample(output_sample_fmt);
- resample->out.channel_layout = output_channel_layout;
- resample->out.channels =
- av_get_channel_layout_nb_channels(output_channel_layout);
+ // convert mixdown to channel_layout/matrix_encoding combo
+ int channels, matrix_encoding;
+ uint64_t channel_layout = hb_ff_mixdown_xlat(hb_amixdown, &matrix_encoding);
+ channels = av_get_channel_layout_nb_channels(channel_layout);
+
+ // requested channel_layout
+ resample->out.channels = channels;
+ resample->out.channel_layout = channel_layout;
resample->out.matrix_encoding = matrix_encoding;
resample->out.normalize_mix_level = normalize_mix_level;
- resample->resample_needed = 0;
- resample->avresample = NULL;
+
+ // requested sample_fmt
+ resample->out.sample_fmt = sample_fmt;
+ resample->out.sample_size = av_get_bytes_per_sample(sample_fmt);
// set default input characteristics
- resample->in.sample_fmt = resample->out.sample_fmt;
- resample->in.channel_layout = resample->out.channel_layout;
- resample->in.center_mix_level = HB_MIXLEV_DEFAULT;
- resample->in.surround_mix_level = HB_MIXLEV_DEFAULT;
+ resample->in.sample_fmt = resample->out.sample_fmt;
+ resample->in.channel_layout = resample->out.channel_layout;
+ resample->in.center_mix_level = HB_MIXLEV_DEFAULT;
+ resample->in.surround_mix_level = HB_MIXLEV_DEFAULT;
+
+ // by default, no conversion needed
+ resample->resample_needed = 0;
+ resample->avresample = NULL;
+ resample->do_remix = !!do_remix;
return resample;
}
uint64_t channel_layout,
int channels)
{
- if (resample != NULL)
+ if (resample != NULL && resample->do_remix)
{
channel_layout = hb_ff_layout_xlat(channel_layout, channels);
if (channel_layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
double surround_mix_level,
double center_mix_level)
{
- if (resample != NULL)
+ if (resample != NULL && resample->do_remix)
{
resample->in.center_mix_level = center_mix_level;
resample->in.surround_mix_level = surround_mix_level;
typedef struct
{
+ int do_remix;
int resample_needed;
AVAudioResampleContext *avresample;
} hb_audio_resample_t;
/* Initialize an hb_audio_resample_t for converting audio to the requested
- * sample_fmt and channel_layout, using the specified matrix_encoding.
+ * sample_fmt and mixdown.
*
* Also sets the default audio input characteristics, so that they are the same
* as the output characteristics (no conversion needed).
+ *
+ * If do_remix is 0, it will be assumed that any remixing was *already* done.
*/
-hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt,
- uint64_t output_channel_layout,
- enum AVMatrixEncoding matrix_encoding,
+hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
+ int hb_amixdown, int do_remix,
int normalize_mix_level);
/* The following functions set the audio input characteristics.
pv->dynamic_range_compression =
audio->config.out.dynamic_range_compression;
- int mode;
- uint64_t layout = hb_ff_mixdown_xlat(audio->config.out.mixdown, &mode);
- pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
- audio->config.out.normalize_mix_level);
+ pv->resample =
+ hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+ audio->config.out.mixdown, 1,
+ audio->config.out.normalize_mix_level);
if (pv->resample == NULL)
{
hb_error("deca52Init: hb_audio_resample_init() failed");
/* Downmixing & sample_fmt conversion */
if (!(w->audio->config.out.codec & HB_ACODEC_PASS_FLAG))
{
- int mode;
- uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown,
- &mode);
- pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
- w->audio->config.out.normalize_mix_level);
+ pv->resample =
+ hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+ w->audio->config.out.mixdown, 1,
+ w->audio->config.out.normalize_mix_level);
if (pv->resample == NULL)
{
hb_error("decavcodecaInit: hb_audio_resample_init() failed");
w->private_data = pv;
pv->job = job;
- int mode;
- uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown, &mode);
- pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
- w->audio->config.out.normalize_mix_level);
+ pv->resample =
+ hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+ w->audio->config.out.mixdown, 1,
+ w->audio->config.out.normalize_mix_level);
if (pv->resample == NULL)
{
hb_error("declpcmInit: hb_audio_resample_init() failed");
// sample_fmt conversion
pv->resample = hb_audio_resample_init(context->sample_fmt,
- context->channel_layout,
- AV_MATRIX_ENCODING_NONE, 0);
+ audio->config.out.mixdown, 0, 0);
hb_audio_resample_set_sample_fmt(pv->resample, AV_SAMPLE_FMT_FLT);
if (hb_audio_resample_update(pv->resample))
{